I am a newbie when it comes to writing afl, I have this basic moving average crossover formula that I am using for back testing.
I need help writing a afl which generates a buy if the price closes above the initial buying price after the stop loss is triggered and the original buy condition is still valid.
I am attaching a screenshot of the chart with a brief description so its easier to understand.
The white arrow marks the buy point based on moving average crossover. Few candles later the price closed below the stop loss level (represented by yellow line) exiting the trade. And then a couple of candles later it closes above the initial buying price represented by dotted white line. while this happens the buy condition is still valid "FastMA(green line) > SlowMA (red line). Orange arrow marks the candle at the end of which the buy should be generated.
Below is the afl I am using to do backtesting
SetBarsRequired(10000,10000); SetFormulaName("Sample System"); SetTradeDelays( 1, 1, 1, 1 ); SetOption( "initialequity", 100 ); PositionSize = -100; SetOption( "MaxOpenPositions", 2 ); FastMA = 24; SlowMA = 46; buy = cross( ma( close, FastMA ), ma( close, SlowMA ) ); sell = cross( ma( close, SlowMA ), ma( close, FastMA ) ); Buy = ExRem( Buy, Sell ); Sell = ExRem( Sell, Buy ); Short = Sell; Cover = Buy; ApplyStop ( 0, 1, 3, 2, False, 1, 0, -1 );