Contents tagged with moving average

  • How to avoid many if during programming for cAlgo

    Hello everybody,

    today I want to write few words about how to avoid nested ifs if you program for cAlgo.

    Recently I've got following request ( code is modified in order to protect privacy of customers idea ):

    buy in following case:

    price is above moving average 20

    price is above moving average 30

    stochastic is above 40

    each of indciators from 1 - 3 can be turned on/off

    As example consider following case:

    if( movingAverage30On && MarketSeries.Low[1] > longMa.Result[1])

    {

    if(movingAverage20On && MarketSeries.Low[1] > shortMa.Result[1])

    {

    if(stochasticOn && _stochastic.PercentD[1] > 40)

    {

    //Buy

    }

    }

    }

    if(movingAverage20 … more