Stop order entry price based on previous days high

Created at 20 Nov 2019, 23:07
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!
SA

samuelbreezey

Joined 10.04.2019

Stop order entry price based on previous days high
20 Nov 2019, 23:07


Hey guys,

I need some help on one of my bots I am creating. I need the stop orders entry price to be based on a previous days (-2) high plus 20% of the days range. My code is as follows, however I don't believe it's correct:

        [Parameter("Entry Percentage", DefaultValue = 20.0, MinValue = 0.1, MaxValue = 20.0)]
        public double EntryPercentage { get; set; }

protected override void OnBar()
        {

            // Calculate mother bar
            var motherCandleHigh = MarketSeries.High.Last(2);
            var motherCandleLow = MarketSeries.Low.Last(2);

var bsPercent = EntryPercentage / 100;
                    var targetPrice = motherCandleHigh + ((motherCandleHigh - motherCandleLow) * bsPercent);

DateTime expiry = Server.Time.AddHours(ExpTime);
                    PlaceStopOrder(TradeType.Buy, SymbolName, exactVolume, targetPrice, InstanceName, slPrice, tpPrice, expiry);
                }

Any help would be greatly appreciated,
Samuel


@samuelbreezey
Replies

PanagiotisCharalampous
21 Nov 2019, 08:40

Hi Samuel,

Why do you think is wrong. What did you expect to get and what did you get?

Best Regards,

Panagiotis


@PanagiotisCharalampous

samuelbreezey
21 Nov 2019, 22:20

RE:

Panagiotis Charalampous said:

Hi Samuel,

Why do you think is wrong. What did you expect to get and what did you get?

Best Regards,

Panagiotis

Hi Panagiotis,

This seems to work, however the actual top loss order does not. The stop loss is meant to be previous days (-2) low for long (buy) orders. 

The previous days low is 1.16840 however the stop loss on the place stop order is 1.17485!

Here's the code:

 

protected override void OnBar()
        {

            // Calculate mother bar
            var motherCandleHigh = MarketSeries.High.Last(2);
            var motherCandleLow = MarketSeries.Low.Last(2);
            var motherCandleOpen = MarketSeries.Open.Last(2);
            var motherCandleClose = MarketSeries.Close.Last(2); 

var slPrice = motherCandleLow;


DateTime expiry = Server.Time.AddHours(ExpTime);
                    PlaceStopOrder(TradeType.Buy, SymbolName, exactVolume, targetPrice, InstanceName, slPrice, tpPrice, expiry);
                }

 


@samuelbreezey

PanagiotisCharalampous
22 Nov 2019, 08:46

Hi Samuel,

This happens because you are using the actual price as a stop loss. Stop loss should be set in pips instead.

Best Regards,

Panagiotis


@PanagiotisCharalampous

samuelbreezey
22 Nov 2019, 15:09

RE:

Panagiotis Charalampous said:

Hi Samuel,

This happens because you are using the actual price as a stop loss. Stop loss should be set in pips instead.

Best Regards,

Panagiotis

Thank you Panagiotis.

 


@samuelbreezey