Delaying entry by a set number of pips?

Created at 14 Oct 2014, 13:59
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
97

9718853

Joined 14.10.2014

Delaying entry by a set number of pips?
14 Oct 2014, 13:59


Hi all,

Could any of you lovely people explain how to delay entry until 5 pips after a Moving Average cross over?

I'm new to coding and am modifying the sample trend robot to fit my system. So far I have changed the code to maintain a position inline with the fast EMA and trending direction. However this creates a huge amount of micro trades when the Moving Averages are converging...

Please ponder over my changes, any advice is greatly appreciated...

  protected override void OnTick()
        {
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var SlowMa = slowMa.Result.Last(0);
            var FastMa = fastMa.Result.Last(0);


            if (SlowMa < FastMa && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label);
            }
            else if (SlowMa > FastMa && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label);
            }
        }
    }
}

Many Thanks, Ian...


@9718853
Replies

Spotware
14 Oct 2014, 14:05

Try something like this:

SlowMa > FastMa + 5 * Symbol.PipSize

and 

FastMa > SlowMa + 5 * Symbol.PipSize

 


@Spotware

9718853
14 Oct 2014, 20:40

Excellent... Thank you....


@9718853