Hello guys, CBOT easy help.

Created at 14 May 2021, 18:35
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!
MA

marianrfitt

Joined 14.05.2021

Hello guys, CBOT easy help.
14 May 2021, 18:35


Hello traders, i ve been trading for about 4.5 years now and i  finally got the nerves to start building my own cbot with the stuff i use, i am not a programmer so it was hard for me to do so, i am almost done but i have a slight problem.

The strategy i used is made to work on many differ timeframes with many diff optimizations so i dont need tons of pips to take from trades, and for this to work, i need some coding to enter so that if i dont get the desired number of pips on the bar that opened the trade ( ex 1 pip ) the bot to close my trade on the second bar.

 

Can i get some help please?


@marianrfitt
Replies

amusleh
17 May 2021, 10:04

Hi,

You can use OnBar method which is called when a new bar opens with Position Pips property, example:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BarPip : Robot
    {
        [Parameter(DefaultValue = 10)]
        public double MinBarPips { get; set; }

        protected override void OnBar()
        {
            if (Positions.Count == 0)
            {
                var tradeType = Bars.Last(1).Close > Bars.Last(1).Open ? TradeType.Buy : TradeType.Sell;

                ExecuteMarketOrder(tradeType, SymbolName, Symbol.VolumeInUnitsMin);
            }
            else
            {
                foreach (var position in Positions)
                {
                    if (position.Pips < MinBarPips)
                    {
                        ClosePosition(position);
                    }
                }
            }
        }
    }
}

The above cBot will open a position, and when a new bar opens it checks if the position Pips is less than MinBarPips parameter value, if its then it closes the position.

If you need more samples please check the API references or ask a consultant to develop your cBot for you.


@amusleh