cbot terminated unexpectedly

Created at 01 Apr 2023, 17: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!
KE

kerming

Joined 20.12.2017

cbot terminated unexpectedly
01 Apr 2023, 17:07


I compiled the following code without error.  But when I ran an instance of the cbot, the was an error.  The process terminated.  I am new to writing cbot.  Just wanted to try opening 2 long trades when threshold price is crossed.  If condition triggered, the buy orders are opened with stop loss and take profits.  Appreciate any help to fix the problem.  thanks

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CustomEA : Robot
    {
        [Parameter("Threshold Price", DefaultValue = 0.0)]
        public double ThresholdPrice { get; set; }

        [Parameter("Limit 1", DefaultValue = 0.0)]
        public double Limit1 { get; set; }

        [Parameter("Limit 2", DefaultValue = 0.0)]
        public double Limit2 { get; set; }

        [Parameter("Stop Loss", DefaultValue = 0.0)]
        public double StopLoss { get; set; }

        [Parameter("Profit 1", DefaultValue = 0.0)]
        public double Profit1 { get; set; }

        [Parameter("Profit 2", DefaultValue = 0.0)]
        public double Profit2 { get; set; }

        private bool ordersCreated = false;

        protected override void OnStart()
        {
            Print("Threshold Price: ", ThresholdPrice);
            Print("Limit 1: ", Limit1);
            Print("Limit 2: ", Limit2);
            Print("Stop Loss: ", StopLoss);
            Print("Profit 1: ", Profit1);
            Print("Profit 2: ", Profit2);
        }

        protected override void OnTick()
        {
            Print("Current price: ", Symbol.Ask);

            if (Symbol.Ask >= ThresholdPrice && !ordersCreated)
            {
                CreateBuyLimitOrder(Limit1, Profit1);
                CreateBuyLimitOrder(Limit2, Profit2);
                ordersCreated = true;
            }
        }

        private void CreateBuyLimitOrder(double limit, double takeProfit)
        {
            var entryPrice = Symbol.Ask - limit * Symbol.PipSize;
            var stopLossPrice = entryPrice - StopLoss * Symbol.PipSize;
            var takeProfitPrice = entryPrice + takeProfit * Symbol.PipSize;

            PlaceLimitOrder(TradeType.Buy, SymbolName, 0.01, entryPrice, "BuyLimit", stopLossPrice, takeProfitPrice);
        }

        protected override void OnStop()
        {
            //
        }
    }
}


@kerming
Replies

kerming
03 Apr 2023, 10:58

RE:

PanagiotisChar said:

Hi there,

Which version of cTrader do you use?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

I am running on 4.5.9  


@kerming

PanagiotisChar
03 Apr 2023, 11:08

Hi,

Try 4.6.5. They have fixed a lot of issues since then.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

kerming
03 Apr 2023, 11:18

RE:

PanagiotisChar said:

Hi,

Try 4.6.5. They have fixed a lot of issues since then.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Alright.  will try it out on 4.6.5  thanks


@kerming

don.schriefer
03 Apr 2023, 19:46

RE: RE:

kerming said:

PanagiotisChar said:

Hi,

Try 4.6.5. They have fixed a lot of issues since then.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

Alright.  will try it out on 4.6.5  thanks

Hi Kerming,

try setting the AccessRights to Full in your cBot and see if that works. I had the same issue.

Don


@don.schriefer