The existing EA is working very well, but an position need to be set as explained below. It is a martingal strategy based on two timeframes M5 with SMM26 and H1 with SMMA52 (configurable). I need an modification of OnTick() function. In the current version entering conditions are : Loop As soon as price cross above SMMA52 on H1 then If new candle is above SMMA19 in M5 then buy. As soon as price cross below SMMA52 on H1 then If new candle is below SMMA19 in M5 then sell. End loop ‌ The desired modified actions are : Loop As soon as price cross above SMMA52 on H1 then If new candle is above SMMA19 in M5 then buy. Add this action : IF new candle in H1 is below SMMA52 then sell. As soon as price cross below SMMA52 on H1 then If new candle is below SMMA19 in M5 then sell. Add this action : IF new candle in H1 is above SMMA52 then buy. End loop