PendingOrder - PlaceStopOrder (Buy Stop) placement help please

Created at 01 Aug 2019, 08:14
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!
AI

Aiki1000

Joined 22.07.2019

PendingOrder - PlaceStopOrder (Buy Stop) placement help please
01 Aug 2019, 08:14


 

Greetings -

I have made a random grouping of three bars (just to keep track of where I am on the chart) in order to learn about robot development .

In the picture, you can see that bars 3, 2, 1, together, satisfy the IF requirements.

 

I then set a pending order buy stop with a targetPrice of MarketSeries.High.Last(1). I expected the stop price to be the high of what is labelled bar1, the bar before the trade opens.

Instead, it shows the bar1's open price.

 

I have played with different combinations for both IF, and the targetPrice. All do something, but no combo yet places the stop at the high of the first bar that satisfies the IF, that should trigger the trade.

FYI - The code block is all under OnBar

I am clearly missing something here, so any pointers/help are greatly appreciated - 

Thx!

 

 


@Aiki1000
Replies

PanagiotisCharalampous
01 Aug 2019, 09:21

Hi Aiki1000,

If you share the cBot code we might be able to point you to the right direction.

Best Regards,

Panagiotis


@PanagiotisCharalampous

Aiki1000
01 Aug 2019, 19:09

RE:

Panagiotis Charalampous said:

Hi Aiki1000,

If you share the cBot code we might be able to point you to the right direction.

Best Regards,

Panagiotis

No probelem - thank you. Here you go:

 

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CT_PlaceStopOrderLearn : Robot
    {
        #region User Supplied Parameters

        [Parameter("Volume", DefaultValue = 10000.0)]
        public int Volume { get; set; }

        [Parameter("Sop Loss (pips)", DefaultValue = 12)]
        public int StopLossPips { get; set; }

        [Parameter("Take Profit (pips)", DefaultValue = 30)]
        public int TakeProfitPips { get; set; }

        #endregion


        #region cTrader Events


        protected override void OnStart()
        {

        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnBar()
        {



            // Define Bars:

            //Define (last FORMING bar) OHLC - think of this as bar 0.
            double currOpen = MarketSeries.Open.LastValue;
            double currHigh = MarketSeries.High.LastValue;
            double currLow = MarketSeries.Low.LastValue;
            double currClose = MarketSeries.Close.LastValue;

            // Define Bar (last closed bar) OHLC
            double Open1 = MarketSeries.Open.Last(1);
            double High1 = MarketSeries.High.Last(1);
            double Low1 = MarketSeries.Low.Last(1);
            double Close1 = MarketSeries.Close.Last(1);

            // Define (1 Bars before last closed bar) bar OHLC
            double Open2 = MarketSeries.Open.Last(2);
            double High2 = MarketSeries.High.Last(2);
            double Low2 = MarketSeries.Low.Last(2);
            double Close2 = MarketSeries.Close.Last(2);

            // Define (2 Bars before last closed) bar OHLC
            double Open3 = MarketSeries.Open.Last(3);
            double High3 = MarketSeries.High.Last(3);
            double Low3 = MarketSeries.Low.Last(3);
            double Close3 = MarketSeries.Close.Last(3);

            // Define (3 Bars before last closed) bar OHLC
            double Open4 = MarketSeries.Open.Last(4);
            double High4 = MarketSeries.High.Last(4);
            double Low4 = MarketSeries.Low.Last(4);
            double Close4 = MarketSeries.Close.Last(4);


            if (Close1 < Open1 && Close2 < Open2 && Close3 > Open3)
            {

                PlaceStopOrder(TradeType.Buy, Symbol, 10000, MarketSeries.High.Last(1), "ctwm_StopTest", StopLossPips, TakeProfitPips);
                Print("The stop is: ", MarketSeries.High.Last(1));
            }


        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
        #endregion



    }

}



 


@Aiki1000

PanagiotisCharalampous
02 Aug 2019, 09:31 ( Updated at: 21 Dec 2023, 09:21 )

Hi Aiki1000,

Thanks. I tested it and it seems to return the results you expect. It prints the high bar value. See below

Best Regards,

Panagiotis


@PanagiotisCharalampous