Replies

Vicktor
08 Nov 2024, 15:10

I totally agree with Patty and her observations.

I use MT5 because it works fine, and cTrader because i love its user interface.

If the developers will be able to maintain such friendly interface with the speed, stability and consistency of MT5, cTrader will become a real leader of trading platforms


@Vicktor

Vicktor
22 Sep 2024, 16:50

RE: RE: RE: RE: RE: What's wrong with cTrader 5.0.28 Optimization Report ?

PanagiotisCharalampous said: 

Hi Vicktor,

I did not ask for the cBot's source code. I asked for the contents of C:/Users/%USERNAME%/Documents/cAlgo/Data/cBots/%CBOT NAME%  to be sent at community@ctrader.com.

Best regards,

Panagiotis

 

Sorry for the misunderstanding.

As requested I sent the compressed copy of the folder cBots to community@ctrader.com.

Please keep me updated and thank you for your kind assistance.

Vicktor


@Vicktor

Vicktor
21 Sep 2024, 21:54

RE: RE: RE: What's wrong with cTrader 5.0.28 Optimization Report ?

PanagiotisCharalampous said: 

Vicktor said: 

PanagiotisCharalampous said: 

Hi there,

The next time this happens, please send us the contents of C:/Users/%USERNAME%/Documents/cAlgo/Data/cBots/%CBOT NAME% at community@ctrader.com.

Best regards,

Panagiotis

Hello,

I upgraded to cTrader 5.0.28 but the problems still persists: I cannot see any Report during and after the optimization.

Please help,

Vicktor

Hi Vicktor,

Please follow my instructions above.

Best regards,

Panagiotis

 

Hello again,

As requested, below is one of the cBots.

Btw, the same issue is with all other cBots.

I got a Mac machine from a friend and I did an extensive comparison using the above mentioned cBot.

Same cBot in a dedicated Windows 10 tower machine (intel i9, 10.900 CPU, 2.80 Ghz, 32 Gb RAM) and same cBot on a dedicated MacMini machine (OS Ventura on Apple M2 processor, 8 Gb RAM)

This is what I found.

  1. even if the Windows machine has more RAM and faster CPU, the optimization is faster with the Mac machine
  2. the “Remaining Time” during the optimization process, with the Mac is accurate, while with the Windows machine is very inaccurate, most often taking double the time declared
  3. with the Mac machine I can see the optimisation results during and after the optimization, while with the Windows machine I can NEVER see the optimization results

 

 

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.EEuropeStandardTime, AccessRights = AccessRights.None)]

    public class USNDAQ_1D : Robot

    {

        [Parameter("Vol Buy", DefaultValue = 0.2, MinValue = 0, MaxValue = 5)]

        public double VolumeBuy { get; set; }

 

        /[Parameter("MAX BUY", DefaultValue = 1, MinValue = 0, MaxValue = 5)]

        public int MaxBuy { get; set; }

 

        [Parameter("MAX BUY 1", DefaultValue = 1, MinValue = 0, MaxValue = 5)]

        public int MaxBuy_1 { get; set; }

 

        [Parameter("MAX BUY 2", DefaultValue = 1, MinValue = 0, MaxValue = 5)]

        public int MaxBuy_2 { get; set; }

 

        /[Parameter("MAX BUY 3", DefaultValue = 1, MinValue = 0, MaxValue = 5)]

        public int MaxBuy_3 { get; set; }

 

        [Parameter("Trade Type", DefaultValue = 1, MinValue = 1, MaxValue = 2)]

        public int Trade_Type { get; set; }

 

        [Parameter("Close Type", DefaultValue = 1, MinValue = 1, MaxValue = 2)]

        public int Close_Type { get; set; }

 

        [Parameter("SL Type", DefaultValue = 0, MinValue = 0, MaxValue = 3)]

        public int SL_Type { get; set; }

 

        [Parameter("Prpfit Calc", DefaultValue = 4.0, MinValue = 3.0, MaxValue = 5.0, Step = 0.5)]

        public double profit_calc { get; set; }

 

        [Parameter("Bars Period", DefaultValue = 12, MinValue = 1, MaxValue = 200)]

        public int BarsPeriod { get; set; }

 

        [Parameter("Fast Source", Group = "Fast")]

        public DataSeries MAfast { get; set; }

        [Parameter("Fast Period", MinValue = 1, DefaultValue = 5, Group = "Fast")]

        public int MAfastperiod { get; set; }

        [Parameter("Fast Type", DefaultValue = "Simple", Group = "Fast")]

        public MovingAverageType MAfasttype { get; set; }

        private MovingAverage MA_fast;

 

        [Parameter("200 Source", Group = "200")]

        public DataSeries MA200 { get; set; }

        [Parameter("200 Period", MinValue = 50, DefaultValue = 200, Group = "200")]

        public int MA200period { get; set; }

        [Parameter("200 Type", DefaultValue = "Simple", Group = "200")]

        public MovingAverageType MA200type { get; set; }

        private MovingAverage MA_200;

 

        private Bars m60;

        private Bars d1;

        private Bars M1;

 

        public string Titolo = "USNDAQ";

        public string Titolo__Br = "USNDAQ__Br";

        public string Titolo__B1r = "USNDAQ__B1r";

        public string Titolo__B2r = "USNDAQ__B2r";

        public string Titolo__B3r = "USNDAQ__B3r";

       public string m60_high = null;

        public string m60_low = null;

        public double profit_ratio = 0;

 

        // CALC

        protected override void OnStart()

        {

            MA_fast = Indicators.MovingAverage(MAfast, MAfastperiod, MAfasttype);

            MA_200 = Indicators.MovingAverage(MA200, MA200period, MA200type);

            m60 = MarketData.GetBars(TimeFrame.Hour);

            d1 = MarketData.GetBars(TimeFrame.Daily);

            M1 = MarketData.GetBars(TimeFrame.Monthly);

        }

 

        protected override void OnTick()

        {

            bool MA_fast_rise = Functions.IsRising(MA_fast.Result);

            bool MA_fast_fall = Functions.IsFalling(MA_fast.Result);

            bool MA_200_rise = Functions.IsRising(MA_200.Result);

            bool MA_200_fall = Functions.IsFalling(MA_200.Result);

 

            double m60_high = m60.Last(1).High;

            double m60_low = m60.Last(1).Low;

            double D1_high = d1.Last(1).High;

            double D1_low = d1.Last(1).Low;

            double M1_high = M1.Last(1).High;

            double M1_low = M1.Last(1).Low;

 

            Chart.DrawHorizontalLine("d1_High", D1_high, Color.Orange);

            Chart.DrawHorizontalLine("d1_Low", D1_low, Color.Orange);

            Chart.DrawHorizontalLine("M1_High", M1_high, Color.Cyan);

            Chart.DrawHorizontalLine("M1_Low", M1_low, Color.Cyan);

 

            ////////////////////////////////////

            // CLOSE

            ////////////////////////////////////

 

            ///// CLOSE 1

            if (Close_Type == 1)

            {

                // CLOSE BUY

                if (M1_high < D1_high)

                {

                    var close__Br = Positions.FindAll(Titolo__Br);

                    foreach (var positionBr in close__Br)

                    {

                        profit_ratio = Math.Max((positionBr.EntryPrice + (positionBr.EntryPrice * (profit_calc / 100))), M1_high);

                        if (positionBr.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                        {

                            positionBr.Close();

                            Print("CLOSE BUY Br");

                        }

                    }

                    var close__B1r = Positions.FindAll(Titolo__B1r);

                    foreach (var positionB1r in close__B1r)

                    {

                        profit_ratio = Math.Max((positionB1r.EntryPrice + (positionB1r.EntryPrice * (profit_calc / 100))), M1_high);

                        if (positionB1r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                        {

                            positionB1r.Close();

                            Print("CLOSE BUY B1r");

                        }

                    }

                    var close__B2r = Positions.FindAll(Titolo__B2r);

                    foreach (var positionB2r in close__B2r)

                    {

                        profit_ratio = Math.Max((positionB2r.EntryPrice + (positionB2r.EntryPrice * (profit_calc / 100))), M1_high);

                        if (positionB2r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                        {

                            positionB2r.Close();

                            Print("CLOSE BUY B2r");

                        }

                    }

                    var close__B3r = Positions.FindAll(Titolo__B3r);

                    foreach (var positionB3r in close__B3r)

                    {

                        profit_ratio = Math.Max((positionB3r.EntryPrice + (positionB3r.EntryPrice * (profit_calc / 100))), M1_high);

                        if (positionB3r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                        {

                            positionB3r.Close();

                            Print("CLOSE BUY B3r");

                        }

                    }

                    if (close__Br.Length > 0 | close__B1r.Length > 0 | close__B2r.Length > 0 | close__B3r.Length > 0)

                    {

                        Chart.DrawHorizontalLine("profit", profit_ratio, Color.Red);

                    }

                }

                else if (M1_high >= D1_high)

                {

                    var close__Br = Positions.FindAll(Titolo__Br);

                    foreach (var positionBr in close__Br)

                    {

                        profit_ratio = Math.Max((positionBr.EntryPrice + (positionBr.EntryPrice * (profit_calc / 100))), M1_high);

                        if (positionBr.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                        {

                            positionBr.Close();

                            Print("CLOSE BUY Br");

                        }

                    }

                    var close__B1r = Positions.FindAll(Titolo__B1r);

                    foreach (var positionB1r in close__B1r)

                    {

                        profit_ratio = Math.Max((positionB1r.EntryPrice + (positionB1r.EntryPrice * (profit_calc / 100))), M1_high);

                        if (positionB1r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                        {

                            positionB1r.Close();

                            Print("CLOSE BUY B1r");

                        }

                    }

                    var close__B2r = Positions.FindAll(Titolo__B2r);

                    foreach (var positionB2r in close__B2r)

                    {

                        profit_ratio = Math.Max((positionB2r.EntryPrice + (positionB2r.EntryPrice * (profit_calc / 100))), M1_high);

                        if (positionB2r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                        {

                            positionB2r.Close();

                            Print("CLOSE BUY B2r");

                        }

                    }

                    var close__B3r = Positions.FindAll(Titolo__B3r);

                    foreach (var positionB3r in close__B3r)

                    {

                        profit_ratio = Math.Max((positionB3r.EntryPrice + (positionB3r.EntryPrice * (profit_calc / 100))), M1_high);

                        if (positionB3r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                        {

                            positionB3r.Close();

                            Print("CLOSE BUY B3r");

                        }

                    }

                }

            }

 

            ///// CLOSE 2

            else if (Close_Type == 2)

            {

                // CLOSE BUY

                var close__Br = Positions.FindAll(Titolo__Br);

                foreach (var positionBr in close__Br)

                {

                    profit_ratio = Math.Max((positionBr.EntryPrice + (positionBr.EntryPrice * (profit_calc / 100))), M1_high);

                    if (positionBr.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                    {

                        positionBr.Close();

                        Print("CLOSE BUY Br");

                    }

                }

                var close__B1r = Positions.FindAll(Titolo__B1r);

                foreach (var positionB1r in close__B1r)

                {

                    profit_ratio = Math.Max((positionB1r.EntryPrice + (positionB1r.EntryPrice * (profit_calc / 100))), M1_high);

                    if (positionB1r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                    {

                        positionB1r.Close();

                        Print("CLOSE BUY B1r");

                    }

                }

                var close__B2r = Positions.FindAll(Titolo__B2r);

                foreach (var positionB2r in close__B2r)

                {

                    profit_ratio = Math.Max((positionB2r.EntryPrice + (positionB2r.EntryPrice * (profit_calc / 100))), M1_high);

                    if (positionB2r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                    {

                        positionB2r.Close();

                        Print("CLOSE BUY B2r");

                    }

                }

                var close__B3r = Positions.FindAll(Titolo__B3r);

                foreach (var positionB3r in close__B3r)

                {

                    profit_ratio = Math.Max((positionB3r.EntryPrice + (positionB3r.EntryPrice * (profit_calc / 100))), M1_high);

                    if (positionB3r.NetProfit > 0.1 && Symbol.Ask >= profit_ratio)

                    {

                        positionB3r.Close();

                        Print("CLOSE BUY B3r");

                    }

                }

            }

 

 

            ////////////////////////////////////

            // TRADE

            ////////////////////////////////////

 

            if (Symbol.Spread <= 1.3)

            {

                if (Trade_Type == 1)

                {

                    if (d1.Last(1).Close < d1.Last(1).Open && m60.Last(1).Close > d1.Last(1).Open && Symbol.Ask > D1_low && m60_low > D1_low)

                    {

                        var pos_b = Positions.FindAll(Titolo__Br);

                        if (pos_b.Length < MaxBuy && VolumeBuy > 0)

                        {

                            Print("BUY _____ C1 " + Titolo__Br);

                            ExecuteMarketOrder(TradeType.Buy, Symbol.Name, VolumeBuy, Titolo__Br, 0, 0);

                        }

                        var pos_b1 = Positions.FindAll(Titolo__B1r);

                        if (pos_b1.Length < MaxBuy_1 && VolumeBuy > 0)

                        {

                            Print("BUY _____ C1 " + Titolo__B1r);

                            ExecuteMarketOrder(TradeType.Buy, Symbol.Name, VolumeBuy, Titolo__B1r, 0, 0);

                        }

                    }

                }

 

                else if (Trade_Type == 2)

                {

                    if (d1.Last(1).Close < d1.Last(1).Open && Bars.LastBar.Low < D1_low && Symbol.Ask > D1_low && m60_low > D1_low)

                    {

                        var pos_b2 = Positions.FindAll(Titolo__B2r);

                        if (pos_b2.Length < MaxBuy_2 && VolumeBuy > 0)

                        {

                            Print("BUY _____ C1 " + Titolo__B2r);

                            ExecuteMarketOrder(TradeType.Buy, Symbol.Name, VolumeBuy, Titolo__B2r, 0, 0);

                        }

                        var pos_b3 = Positions.FindAll(Titolo__B3r);

                        if (pos_b3.Length < MaxBuy_3 && VolumeBuy > 0)

                        {

                            Print("BUY _____ C1 " + Titolo__B3r);

                            ExecuteMarketOrder(TradeType.Buy, Symbol.Name, VolumeBuy, Titolo__B3r, 0, 0);

                        }

                    }

                }

            }

 

 

            ////////////////////////////////////

            // SL

            ////////////////////////////////////

 

            // SL 1

            if (SL_Type == 1)

            {

                if (VolumeBuy > 0)

                {

                    var position_buy = Positions.FindAll(Titolo__Br);

                    foreach (var open_buy in position_buy)

                    {

                        if (open_buy.NetProfit > Symbol.Spread * 2 && MA_fast_fall == true)

                        {

                            open_buy.ModifyStopLossPrice(open_buy.EntryPrice + Symbol.Spread);

                        }

                        if (open_buy.StopLoss == null)

                        {

                            open_buy.ModifyStopLossPrice(M1_low);

                        }

                    }

                    var position_buy1 = Positions.FindAll(Titolo__B1r);

                    foreach (var open_buy in position_buy1)

                    {

                        if (open_buy.NetProfit > Symbol.Spread * 2 && MA_fast_fall == true)

                        {

                            open_buy.ModifyStopLossPrice(open_buy.EntryPrice + Symbol.Spread);

                        }

                        if (open_buy.StopLoss == null)

                        {

                            open_buy.ModifyStopLossPrice(M1_low);

                        }

                    }

                    var position_buy2 = Positions.FindAll(Titolo__B2r);

                    foreach (var open_buy in position_buy2)

                    {

                        if (open_buy.NetProfit > Symbol.Spread * 2 && MA_fast_fall == true)

                        {

                            open_buy.ModifyStopLossPrice(open_buy.EntryPrice + Symbol.Spread);

                        }

                        if (open_buy.StopLoss == null)

                        {

                            open_buy.ModifyStopLossPrice(M1_low);

                        }

                    }

                    var position_buy3 = Positions.FindAll(Titolo__B3r);

                    foreach (var open_buy in position_buy3)

                    {

                        if (open_buy.NetProfit > Symbol.Spread * 2 && MA_fast_fall == true)

                        {

                            open_buy.ModifyStopLossPrice(open_buy.EntryPrice + Symbol.Spread);

                        }

                        if (open_buy.StopLoss == null)

                        {

                            open_buy.ModifyStopLossPrice(M1_low);

                        }

                    }

                }

            }

 

            // SL 2

            else if (SL_Type == 2)

            {

                if (VolumeBuy > 0)

                {

                    var position_buy = Positions.FindAll(Titolo__Br);

                    foreach (var open_buy in position_buy)

                    {

                        if (open_buy.NetProfit > Symbol.Spread * 2 && MA_fast_fall == true)

                        {

                            open_buy.ModifyStopLossPrice(open_buy.EntryPrice + Symbol.Spread);

                        }

                        if (open_buy.StopLoss == null)

                        {

                            open_buy.ModifyStopLossPrice(MA_200.Result.LastValue - (Symbol.Spread * BarsPeriod));

                        }

                    }

                    var position_buy1 = Positions.FindAll(Titolo__B1r);

                    foreach (var open_buy in position_buy1)

                    {

                        if (open_buy.NetProfit > Symbol.Spread * 2 && MA_fast_fall == true)

                        {

                            open_buy.ModifyStopLossPrice(open_buy.EntryPrice + Symbol.Spread);

                        }

                        if (open_buy.StopLoss == null)

                        {

                            open_buy.ModifyStopLossPrice(MA_200.Result.LastValue - (Symbol.Spread * BarsPeriod));

                        }

                    }

                    var position_buy2 = Positions.FindAll(Titolo__B2r);

                    foreach (var open_buy in position_buy2)

                    {

                        if (open_buy.NetProfit > Symbol.Spread * 2 && MA_fast_fall == true)

                        {

                            open_buy.ModifyStopLossPrice(open_buy.EntryPrice + Symbol.Spread);

                        }

                        if (open_buy.StopLoss == null)

                        {

                            open_buy.ModifyStopLossPrice(MA_200.Result.LastValue - (Symbol.Spread * BarsPeriod));

                        }

                    }

                    var position_buy3 = Positions.FindAll(Titolo__B3r);

                    foreach (var open_buy in position_buy3)

                    {

                        if (open_buy.NetProfit > Symbol.Spread * 2 && MA_fast_fall == true)

                        {

                            open_buy.ModifyStopLossPrice(open_buy.EntryPrice + Symbol.Spread);

                        }

                        if (open_buy.StopLoss == null)

                        {

                            open_buy.ModifyStopLossPrice(MA_200.Result.LastValue - (Symbol.Spread * BarsPeriod));

                        }

                    }

                }

            }

 

            // SL 3

            else if (SL_Type == 3)

            {

                if (VolumeBuy > 0)

                {

                    var position_buy = Positions.FindAll(Titolo__Br);

                    foreach (var open_buy in position_buy)

                    {

                        open_buy.ModifyStopLossPrice(MA_200.Result.LastValue - (Symbol.Spread * BarsPeriod));

                    }

                    var position_buy1 = Positions.FindAll(Titolo__B1r);

                    foreach (var open_buy in position_buy1)

                    {

                        open_buy.ModifyStopLossPrice(MA_200.Result.LastValue - (Symbol.Spread * BarsPeriod));

                    }

                    var position_buy2 = Positions.FindAll(Titolo__B2r);

                    foreach (var open_buy in position_buy2)

                    {

                        open_buy.ModifyStopLossPrice(MA_200.Result.LastValue - (Symbol.Spread * BarsPeriod));

                    }

                    var position_buy3 = Positions.FindAll(Titolo__B3r);

                    foreach (var open_buy in position_buy3)

                    {

                        open_buy.ModifyStopLossPrice(MA_200.Result.LastValue - (Symbol.Spread * BarsPeriod));

                    }

                }

            }

 

        }

    }

}


 


@Vicktor

Vicktor
20 Sep 2024, 23:06

RE: What's wrong with cTrader 5.0.28 Optimization Report ?

PanagiotisCharalampous said: 

Hi there,

The next time this happens, please send us the contents of C:/Users/%USERNAME%/Documents/cAlgo/Data/cBots/%CBOT NAME% at community@ctrader.com.

Best regards,

Panagiotis

Hello,

I upgraded to cTrader 5.0.28 but the problems still persists: I cannot see any Report during and after the optimization.

Please help,

Vicktor


@Vicktor

Vicktor
16 Sep 2024, 21:20

RE: What's wrong with cTrader 5.0.28 Optimization Report ?

PanagiotisCharalampous said: 

Hi there,

The next time this happens, please send us the contents of C:/Users/%USERNAME%/Documents/cAlgo/Data/cBots/%CBOT NAME% at community@ctrader.com.

Best regards,

Panagiotis

Thank you for your replay.

If I understand correctly, I should send the cbot where the issue is happening, but it happens with every bot I use for optimization !!!

Vicktor


@Vicktor

Vicktor
26 Aug 2024, 09:04

RE: cTrader 5.0.28 optimization is missing some key options

Thank you for your replay.

The problem is that the Report tab during and after the optimization process gives me the following result

 

 

PanagiotisCharalampous said: 

Hi Victor,

This information has been incorporated in the Report tab.

Best regards,

Panagiotis

 


@Vicktor

Vicktor
28 Oct 2021, 11:52

RE:

I forgot to mention that when running optimization (using only 60% of CPU consumption), even if there are no cBots running, it happens that the Active Symbol Panel is updated regularly but going to one chart to an other is extremely slow.

If you have suggestions I will be glad to follow.

Many thanks,

Victor

 


@Vicktor

Vicktor
28 Oct 2021, 11:24

RE:

PanagiotisCharalampous said:

Hi Victor,

Do you run any cBots or custom indicators? If not, please send us some troubleshooting information the next time this happens. To do so, please press Ctrl+Alt+Shift+T, paste the link to this discussion in the textbox and press submit.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Yes I run one cBot, sometimes two.

We did a few benchmark tests, while cTrader is running all other applications (web, mail, Excel, Word, etc.) run fast as normal since the CPU is not overloaded and there is plenty of RAM available.

The issue is within cTrader which is unacceptably slow, and software speed is key in trading.

cTrader has a beautiful user interface but apparently does not take full advantage of powerful CPU and large RAM.

If I may suggest something, I would avoid some fancy graphical interface and focus on performance.

Best regards,

Victor


@Vicktor

Vicktor
02 Sep 2021, 00:50

RE:

amusleh said:

Hi,

ModifyPosition method requires Stop Loss and Take Profit in absolute Price not Pips.

To change stop loss and take profit based on Pips either you have to calculate the price levels by your self or use the helper ModifyStopLossPips/ModifyTakeProfitPips methods.

Try this:

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.EEuropeStandardTime, AccessRights = AccessRights.None)]
    public class BotExample : Robot

    {
        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Volume", DefaultValue = 2, MinValue = 1, MaxValue = 10)]
        public double volume { get; set; }

        //MAX BUY

        [Parameter("Max Buy", DefaultValue = 2, MinValue = 1, MaxValue = 5)]
        public int MaxBuy { get; set; }

        //MAX SELL

        [Parameter("Max Sell", DefaultValue = 2, MinValue = 1, MaxValue = 5)]
        public int MaxSell { get; set; }

        // MACD

        [Parameter("Macd Source", Group = "MACD")]
        public DataSeries MACD { get; set; }

        [Parameter("Macd Period", DefaultValue = 9, Group = "MACD")]
        public int MacdPeriod { get; set; }

        [Parameter("Macd Long Cycle", DefaultValue = 26, Group = "MACD")]
        public int MacdLongCycle { get; set; }

        [Parameter("Macd Short Cycle", DefaultValue = 12, Group = "MACD")]
        public int MacdShortCycle { get; set; }

        private MacdCrossOver _MACD;

        // SAR

        [Parameter("SAR Source", Group = "SAR")]
        public DataSeries SAR { get; set; }

        [Parameter("SAR Min AF", DefaultValue = 0.02, MinValue = 0, Group = "SAR")]
        public double MinAF { get; set; }

        [Parameter("SAR Max AF", DefaultValue = 0.2, MinValue = 0, Group = "SAR")]
        public double MaxAF { get; set; }

        private ParabolicSAR _SAR;

        // SMA FAST

        [Parameter("SMA Source", Group = "SMA")]
        public DataSeries SMAfast { get; set; }

        [Parameter("SMA Period", DefaultValue = 10, Group = "SMA")]
        public int FastSMAperiod { get; set; }

        private SimpleMovingAverage _SMA;

        // CALC

        protected override void OnStart()

        {
            _MACD = Indicators.MacdCrossOver(MacdLongCycle, MacdShortCycle, MacdPeriod);

            _SAR = Indicators.ParabolicSAR(MinAF, MaxAF);

            _SMA = Indicators.SimpleMovingAverage(SMAfast, FastSMAperiod);
        }

        protected override void OnTick()

        {
            bool macd_rising = Functions.IsRising(_MACD.MACD);

            bool sma_rising = Functions.IsRising(_SMA.Result);

            bool parab_rising = _SAR.Result.LastValue < Bars.LastBar.Close;

            // CLOSE BUY

            if (macd_rising == false | sma_rising == false)

            {
                var pos_B_US30 = Positions.FindAll("Buy");

                foreach (var position in pos_B_US30)

                {
                    if (_SAR.Result.LastValue > Bars.LastBar.Close)

                    {
                        if (position.NetProfit > 0)

                        {
                            position.Close();
                        }
                    }
                }
            }

            // CLOSE SELL

            if (macd_rising == true | sma_rising == true)

            {
                var pos_S_US30 = Positions.FindAll("Sell");

                foreach (var position in pos_S_US30)

                {
                    if (_SAR.Result.LastValue < Bars.LastBar.Close)

                    {
                        if (position.NetProfit > 0)

                        {
                            position.Close();
                        }
                    }
                }
            }

            // CHANGE TP/SL

            var pos_buy = Positions.Find("Buy");

            if (pos_buy != null)

            {
                if (pos_buy.NetProfit < 0)

                {
                    pos_buy.ModifyStopLossPips(200);
                    pos_buy.ModifyTakeProfitPips(300);
                }
            }

            var pos_sell = Positions.Find("Sell");

            if (pos_sell != null)

            {
                if (pos_sell.NetProfit < 0)

                {
                    pos_sell.ModifyStopLossPips(200);
                    pos_sell.ModifyTakeProfitPips(300);
                }
            }

            // TRADE

            var pos_b = Positions.FindAll("Buy");

            var pos_s = Positions.FindAll("Sell");

            if (pos_b.Length < MaxBuy && pos_s.Length < MaxSell)

            {
                if (macd_rising == true && sma_rising == true && parab_rising == true)

                {
                    var pos_1_US30 = Positions.FindAll("Buy");

                    if (pos_1_US30.Length < MaxBuy)

                    {
                        ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volume, "Buy");
                    }
                }

                if (macd_rising == false && sma_rising == false && parab_rising == false)

                {
                    var pos_2_US30 = Positions.FindAll("Sell");

                    if (pos_2_US30.Length < MaxSell)

                    {
                        ExecuteMarketOrder(TradeType.Sell, Symbol.Name, volume, "Sell");
                    }
                }
            }
        }
    }
}

 

Thank you for your input.

Using absolute price would be even easier for me.

in such case, if I am correct,  I guess I should use:

pos_buy. ModifyTakeProfitPrice( xxx)

and 

pos_sell. ModifyTakeProfitPrice( xxx)

where xxx is the price I want to set.

 

 


@Vicktor

Vicktor
31 Aug 2021, 21:35

RE:

PanagiotisCharalampous said:

Hi vittorioroncagli,

We need more information in order to help you. Please provide us with the following

  1. Complete cBot code
  2. A detailed explanation describing why do you think it doesn't work and explaining how to reproduce this behavior

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hello Panagiotis,

many thanks for your replay.

Answering to your questions:

1) The complete example cBot is listed below.

2) I run the cBot in Backtesting and the two values of target profit and stop loss do not change when they should accordingly with the cBot code.

 

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.EEuropeStandardTime, AccessRights = AccessRights.None)]

    public class BotExample : Robot

    {

        [Parameter()]

        public DataSeries SourceSeries { get; set; }

 

        [Parameter("Volume", DefaultValue = 2, MinValue = 1, MaxValue = 10)]

        public double volume { get; set; }

 

        //MAX BUY

        [Parameter("Max Buy", DefaultValue = 2, MinValue = 1, MaxValue = 5)]

        public int MaxBuy { get; set; }

 

        //MAX SELL

        [Parameter("Max Sell", DefaultValue = 2, MinValue = 1, MaxValue = 5)]

        public int MaxSell { get; set; }

 

        // MACD

        [Parameter("Macd Source", Group = "MACD")]

        public DataSeries MACD { get; set; }

        [Parameter("Macd Period", DefaultValue = 9, Group = "MACD")]

        public int MacdPeriod { get; set; }

        [Parameter("Macd Long Cycle", DefaultValue = 26, Group = "MACD")]

        public int MacdLongCycle { get; set; }

        [Parameter("Macd Short Cycle", DefaultValue = 12, Group = "MACD")]

        public int MacdShortCycle { get; set; }

        private MacdCrossOver _MACD;

 

        // SAR

        [Parameter("SAR Source", Group = "SAR")]

        public DataSeries SAR { get; set; }

        [Parameter("SAR Min AF", DefaultValue = 0.02, MinValue = 0, Group = "SAR")]

        public double MinAF { get; set; }

        [Parameter("SAR Max AF", DefaultValue = 0.2, MinValue = 0, Group = "SAR")]

        public double MaxAF { get; set; }

        private ParabolicSAR _SAR;

 

        // SMA FAST

        [Parameter("SMA Source", Group = "SMA")]

        public DataSeries SMAfast { get; set; }

        [Parameter("SMA Period", DefaultValue = 10, Group = "SMA")]

        public int FastSMAperiod { get; set; }

        private SimpleMovingAverage _SMA;

 

        // CALC

        protected override void OnStart()

        {

            _MACD = Indicators.MacdCrossOver(MacdLongCycle, MacdShortCycle, MacdPeriod);

            _SAR = Indicators.ParabolicSAR(MinAF, MaxAF);

            _SMA = Indicators.SimpleMovingAverage(SMAfast, FastSMAperiod);

        }

 

        protected override void OnTick()

        {

            bool macd_rising = Functions.IsRising(_MACD.MACD);

            bool sma_rising = Functions.IsRising(_SMA.Result);

            bool parab_rising = _SAR.Result.LastValue < Bars.LastBar.Close;

 

            // CLOSE BUY

            if (macd_rising == false | sma_rising == false)

            {

                var pos_B_US30 = Positions.FindAll("Buy");

                foreach (var position in pos_B_US30)

                {

                    if (_SAR.Result.LastValue > Bars.LastBar.Close)

                    {

                        if (position.NetProfit > 0)

                        {

                            position.Close();

                        }

                    }

                }

            }

 

            // CLOSE SELL

            if (macd_rising == true | sma_rising == true)

            {

                var pos_S_US30 = Positions.FindAll("Sell");

                foreach (var position in pos_S_US30)

                {

                    if (_SAR.Result.LastValue < Bars.LastBar.Close)

                    {

                        if (position.NetProfit > 0)

                        {

                            position.Close();

                        }

                    }

                }

            }

 

            // CHANGE TP/SL

            var pos_buy = Positions.Find("Buy");

            if (pos_buy != null)

            {

                if (pos_buy.NetProfit < 0)

                {

                    ModifyPosition(pos_buy, 200, 300);

                }

            }

            var pos_sell = Positions.Find("Sell");

            if (pos_sell != null)

            {

                if (pos_sell.NetProfit < 0)

                {

                    ModifyPosition(pos_sell, 200, 300);

                }

            }

 

            // TRADE

            var pos_b = Positions.FindAll("Buy");

            var pos_s = Positions.FindAll("Sell");

            if (pos_b.Length < MaxBuy && pos_s.Length < MaxSell)

            {

 

                if (macd_rising == true && sma_rising == true && parab_rising == true)

                {

                    var pos_1_US30 = Positions.FindAll("Buy");

                    if (pos_1_US30.Length < MaxBuy)

                    {

                        ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volume, "Buy", 0, 0);

                    }

                }

 

                if (macd_rising == false && sma_rising == false && parab_rising == false)

                {

                    var pos_2_US30 = Positions.FindAll("Sell");

                    if (pos_2_US30.Length < MaxSell)

                    {

                        ExecuteMarketOrder(TradeType.Sell, Symbol.Name, volume, "Sell", 0, 0);

                    }

                }

            }

        }

    }

}

 


@Vicktor