where is the mistake?

Created at 06 May 2020, 12:45
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!
LU

luca.tocchi

Joined 25.03.2020

where is the mistake?
06 May 2020, 12:45


this is my ichimoku-based bot it works, but the OnTick () does not start, and therefore the "trail stop loss" does not start

where is the mistake?

the program works i removed the instructions as i don't want anyone to steal my job. the fact that the trail doesn't start I think it's due to something else

 

 

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 ichimokubot : Robot
    {

        [Parameter("Volume (Lots)", Group = "Volume", DefaultValue = 0.2, MinValue = 0.01, Step = 0.01)]
        public double Volume { get; set; }

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

        [Parameter("Trigger When Gaining", DefaultValue = 0.5)]
        public double TriggerWhenGaining { get; set; }

        [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)]
        public double TrailingStopLossDistance { get; set; }

        private double _highestGain;
        private bool _isTrailing;

        private Random random = new Random();
        private IchimokuKinkoHyo ichimoku;
        private ParabolicSAR parabolicSAR;
        public bool Restart;
        Symbol _symbol;

        protected override void OnStart()
        {
            Inizio:
            RefreshData();

            string EURUSD = Symbols[random.Next(Symbols.Count)];
            Symbols.GetSymbol("EURUSD");
            Print(EURUSD);

            var symbol = MarketData.GetSymbol(EURUSD);

            _symbol = Symbols.GetSymbol(EURUSD);

            ichimoku = Indicators.IchimokuKinkoHyo(MarketData.GetBars(TimeFrame.Minute10, EURUSD), 9, 26, 52);
            parabolicSAR = Indicators.ParabolicSAR(MarketData.GetBars(TimeFrame.Minute10, EURUSD), 0.02, 0.2);

            var EURUSDSeries = MarketData.GetBars(TimeFrame.Minute10, EURUSD);
            var volumeInUnits = symbol.QuantityToVolumeInUnits(Volume);

            var position = Positions.Find("MyLabel");

            while (...)
            {
                if (...)
                {
                    if (....)
                    {
                        if (...)
                        {
                            if (..)
                            {
                                if (s...6)
                                {
                                    if (...)
                                    {
                                        if (..))
                                        {
                                            if (..)
                                            {
                                                if (...)
                                                {
                                                    var result = ExecuteMarketOrder(TradeType.Buy, EURUSD, volumeInUnits, "MyLabel", StopLoss, null);
                                                    _highestGain = Positions[0].Pips;
                                                    if (result.Error == ErrorCode.BadVolume)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Disconnected)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.EntityNotFound)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidRequest)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidStopLossTakeProfit)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.MarketClosed)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.NoMoney)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.TechnicalError)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Timeout)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.UnknownSymbol)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    System.Threading.Thread.Sleep(300000);
                                                    //break;
                                                }
                                                else
                                                {
                                                    goto Inizio;
                                                }
                                            }
                                            else
                                            {
                                                goto Inizio;
                                            }
                                        }
                                        else
                                        {
                                            goto Inizio;
                                        }
                                    }
                                    else
                                    {
                                        goto Inizio;
                                    }
                                }
                                else
                                {
                                    goto Inizio;
                                }
                            }
                            else
                            {
                                goto Inizio;
                            }
                        }
                        else
                        {
                            goto Inizio;
                        }
                    }
                    else
                    {
                        if (...)
                        {
                            if (...)
                            {
                                if (...)
                                {
                                    if (...)
                                    {
                                        if (..)
                                        {
                                            if (..)
                                            {
                                                if (...)
                                                {
                                                    var result = ExecuteMarketOrder(TradeType.Buy, EURUSD, volumeInUnits, "MyLabel", StopLoss, null);
                                                    _highestGain = Positions[0].Pips;
                                                    if (result.Error == ErrorCode.BadVolume)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Disconnected)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.EntityNotFound)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidRequest)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidStopLossTakeProfit)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.MarketClosed)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.NoMoney)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.TechnicalError)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Timeout)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.UnknownSymbol)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    System.Threading.Thread.Sleep(300000);
                                                    //break;
                                                }
                                                else
                                                {
                                                    goto Inizio;
                                                }
                                            }
                                            else
                                            {
                                                goto Inizio;
                                            }
                                        }
                                        else
                                        {
                                            goto Inizio;
                                        }

                                    }
                                    else
                                    {
                                        goto Inizio;
                                    }
                                }
                                else
                                {
                                    goto Inizio;
                                }
                            }
                            else
                            {
                                goto Inizio;
                            }
                        }
                        else
                        {
                            goto Inizio;
                        }
                    }
                }
                else
                {
                    if (...)
                    {
                        if (...)
                        {
                            if (..)
                            {
                                if (...)
                                {
                                    if (...)
                                    {
                                        if (...)
                                        {
                                            if (...)
                                            {
                                                if (...)
                                                {
                                                    var result = ExecuteMarketOrder(TradeType.Sell, EURUSD, volumeInUnits, "MyLabel", StopLoss, null);
                                                    _highestGain = Positions[0].Pips;
                                                    if (result.Error == ErrorCode.BadVolume)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Disconnected)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.EntityNotFound)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidRequest)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidStopLossTakeProfit)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.MarketClosed)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.NoMoney)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.TechnicalError)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Timeout)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.UnknownSymbol)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    System.Threading.Thread.Sleep(300000);
                                                    //break;
                                                }
                                                else
                                                {
                                                    goto Inizio;
                                                }
                                            }
                                            else
                                            {
                                                goto Inizio;
                                            }
                                        }
                                        else
                                        {
                                            goto Inizio;
                                        }
                                    }
                                    else
                                    {
                                        goto Inizio;
                                    }
                                }
                                else
                                {
                                    goto Inizio;
                                }
                            }
                            else
                            {
                                goto Inizio;
                            }
                        }
                        else
                        {
                            goto Inizio;
                        }
                    }
                    else
                    {
                        if (...)
                        {
                            if ()
                            {
                                if ()
                                {
                                    if ()
                                    {
                                        if ()
                                        {
                                            if ()
                                            {
                                                if ()
                                                {
                                                    //La chiusura della penultima candela deve essere a ribasso
                                                    var result = ExecuteMarketOrder(TradeType.Sell, EURUSD, volumeInUnits, "MyLabel", StopLoss, null);
                                                    _highestGain = Positions[0].Pips;
                                                    if (result.Error == ErrorCode.BadVolume)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Disconnected)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.EntityNotFound)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidRequest)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidStopLossTakeProfit)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.MarketClosed)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.NoMoney)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.TechnicalError)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Timeout)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.UnknownSymbol)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    System.Threading.Thread.Sleep(300000);
                                                    //break;
                                                }
                                                else
                                                {
                                                    goto Inizio;
                                                }
                                            }
                                            else
                                            {
                                                goto Inizio;
                                            }
                                        }
                                        else
                                        {
                                            goto Inizio;
                                        }
                                    }
                                    else
                                    {
                                        goto Inizio;
                                    }
                                }
                                else
                                {
                                    goto Inizio;
                                }
                            }
                            else
                            {
                                goto Inizio;
                            }
                        }
                        else
                        {
                            goto Inizio;
                        }
                    }
                }
            }
            if (Restart == false)
            {
                goto Inizio;
            }
        }
        protected override void OnTick()
        {
            var position = Positions.Find("MyLabel");

            if (position == null)
            {
                Stop();
                return;
            }
            //If the trigger is reached, the robot starts trailing
            if (!_isTrailing && position.Pips >= TriggerWhenGaining)
            {
                _isTrailing = true;
            }
            //If the cBot is trailing and the profit in pips is at the highest level, we need to readjust the stop loss
            if (_isTrailing && _highestGain < position.Pips)
            {
                //Based on the position's direction, we calculate the new stop loss price and we modify the position
                if (position.TradeType == TradeType.Buy)
                {
                    var newSLprice = _symbol.Ask - (_symbol.PipSize * TrailingStopLossDistance);
                    if (newSLprice > position.StopLoss)
                    {
                        ModifyPosition(position, newSLprice, null);
                    }
                }
                else
                {
                    var newSLprice = _symbol.Bid + (_symbol.PipSize * TrailingStopLossDistance);
                    if (newSLprice < position.StopLoss)
                    {
                        ModifyPosition(position, newSLprice, null);
                    }
                }
                //We reset the highest gain
                _highestGain = position.Pips;
            }
        }
        protected override void OnStop()
        {
            //This method is called when the cBot is stopped
            Restart = false;
        }

    }
}


@luca.tocchi
Replies

luca.tocchi
07 May 2020, 10:58

RE:

luca.tocchi said:

this is my ichimoku-based bot it works, but the OnTick () does not start, and therefore the "trail stop loss" does not start

where is the mistake?

the program works i removed the instructions as i don't want anyone to steal my job. the fact that the trail doesn't start I think it's due to something else

 

 

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 ichimokubot : Robot
    {

        [Parameter("Volume (Lots)", Group = "Volume", DefaultValue = 0.2, MinValue = 0.01, Step = 0.01)]
        public double Volume { get; set; }

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

        [Parameter("Trigger When Gaining", DefaultValue = 0.5)]
        public double TriggerWhenGaining { get; set; }

        [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)]
        public double TrailingStopLossDistance { get; set; }

        private double _highestGain;
        private bool _isTrailing;

        private Random random = new Random();
        private IchimokuKinkoHyo ichimoku;
        private ParabolicSAR parabolicSAR;
        public bool Restart;
        Symbol _symbol;

        protected override void OnStart()
        {
            Inizio:
            RefreshData();

            string EURUSD = Symbols[random.Next(Symbols.Count)];
            Symbols.GetSymbol("EURUSD");
            Print(EURUSD);

            var symbol = MarketData.GetSymbol(EURUSD);

            _symbol = Symbols.GetSymbol(EURUSD);

            ichimoku = Indicators.IchimokuKinkoHyo(MarketData.GetBars(TimeFrame.Minute10, EURUSD), 9, 26, 52);
            parabolicSAR = Indicators.ParabolicSAR(MarketData.GetBars(TimeFrame.Minute10, EURUSD), 0.02, 0.2);

            var EURUSDSeries = MarketData.GetBars(TimeFrame.Minute10, EURUSD);
            var volumeInUnits = symbol.QuantityToVolumeInUnits(Volume);

            var position = Positions.Find("MyLabel");

            while (...)
            {
                if (...)
                {
                    if (....)
                    {
                        if (...)
                        {
                            if (..)
                            {
                                if (s...6)
                                {
                                    if (...)
                                    {
                                        if (..))
                                        {
                                            if (..)
                                            {
                                                if (...)
                                                {
                                                    var result = ExecuteMarketOrder(TradeType.Buy, EURUSD, volumeInUnits, "MyLabel", StopLoss, null);
                                                    _highestGain = Positions[0].Pips;
                                                    if (result.Error == ErrorCode.BadVolume)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Disconnected)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.EntityNotFound)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidRequest)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidStopLossTakeProfit)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.MarketClosed)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.NoMoney)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.TechnicalError)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Timeout)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.UnknownSymbol)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    System.Threading.Thread.Sleep(300000);
                                                    //break;
                                                }
                                                else
                                                {
                                                    goto Inizio;
                                                }
                                            }
                                            else
                                            {
                                                goto Inizio;
                                            }
                                        }
                                        else
                                        {
                                            goto Inizio;
                                        }
                                    }
                                    else
                                    {
                                        goto Inizio;
                                    }
                                }
                                else
                                {
                                    goto Inizio;
                                }
                            }
                            else
                            {
                                goto Inizio;
                            }
                        }
                        else
                        {
                            goto Inizio;
                        }
                    }
                    else
                    {
                        if (...)
                        {
                            if (...)
                            {
                                if (...)
                                {
                                    if (...)
                                    {
                                        if (..)
                                        {
                                            if (..)
                                            {
                                                if (...)
                                                {
                                                    var result = ExecuteMarketOrder(TradeType.Buy, EURUSD, volumeInUnits, "MyLabel", StopLoss, null);
                                                    _highestGain = Positions[0].Pips;
                                                    if (result.Error == ErrorCode.BadVolume)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Disconnected)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.EntityNotFound)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidRequest)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidStopLossTakeProfit)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.MarketClosed)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.NoMoney)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.TechnicalError)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Timeout)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.UnknownSymbol)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    System.Threading.Thread.Sleep(300000);
                                                    //break;
                                                }
                                                else
                                                {
                                                    goto Inizio;
                                                }
                                            }
                                            else
                                            {
                                                goto Inizio;
                                            }
                                        }
                                        else
                                        {
                                            goto Inizio;
                                        }

                                    }
                                    else
                                    {
                                        goto Inizio;
                                    }
                                }
                                else
                                {
                                    goto Inizio;
                                }
                            }
                            else
                            {
                                goto Inizio;
                            }
                        }
                        else
                        {
                            goto Inizio;
                        }
                    }
                }
                else
                {
                    if (...)
                    {
                        if (...)
                        {
                            if (..)
                            {
                                if (...)
                                {
                                    if (...)
                                    {
                                        if (...)
                                        {
                                            if (...)
                                            {
                                                if (...)
                                                {
                                                    var result = ExecuteMarketOrder(TradeType.Sell, EURUSD, volumeInUnits, "MyLabel", StopLoss, null);
                                                    _highestGain = Positions[0].Pips;
                                                    if (result.Error == ErrorCode.BadVolume)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Disconnected)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.EntityNotFound)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidRequest)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidStopLossTakeProfit)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.MarketClosed)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.NoMoney)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.TechnicalError)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Timeout)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.UnknownSymbol)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    System.Threading.Thread.Sleep(300000);
                                                    //break;
                                                }
                                                else
                                                {
                                                    goto Inizio;
                                                }
                                            }
                                            else
                                            {
                                                goto Inizio;
                                            }
                                        }
                                        else
                                        {
                                            goto Inizio;
                                        }
                                    }
                                    else
                                    {
                                        goto Inizio;
                                    }
                                }
                                else
                                {
                                    goto Inizio;
                                }
                            }
                            else
                            {
                                goto Inizio;
                            }
                        }
                        else
                        {
                            goto Inizio;
                        }
                    }
                    else
                    {
                        if (...)
                        {
                            if ()
                            {
                                if ()
                                {
                                    if ()
                                    {
                                        if ()
                                        {
                                            if ()
                                            {
                                                if ()
                                                {
                                                    //La chiusura della penultima candela deve essere a ribasso
                                                    var result = ExecuteMarketOrder(TradeType.Sell, EURUSD, volumeInUnits, "MyLabel", StopLoss, null);
                                                    _highestGain = Positions[0].Pips;
                                                    if (result.Error == ErrorCode.BadVolume)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Disconnected)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.EntityNotFound)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidRequest)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.InvalidStopLossTakeProfit)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.MarketClosed)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.NoMoney)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.TechnicalError)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.Timeout)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    if (result.Error == ErrorCode.UnknownSymbol)
                                                    {
                                                        goto Inizio;
                                                    }
                                                    System.Threading.Thread.Sleep(300000);
                                                    //break;
                                                }
                                                else
                                                {
                                                    goto Inizio;
                                                }
                                            }
                                            else
                                            {
                                                goto Inizio;
                                            }
                                        }
                                        else
                                        {
                                            goto Inizio;
                                        }
                                    }
                                    else
                                    {
                                        goto Inizio;
                                    }
                                }
                                else
                                {
                                    goto Inizio;
                                }
                            }
                            else
                            {
                                goto Inizio;
                            }
                        }
                        else
                        {
                            goto Inizio;
                        }
                    }
                }
            }
            if (Restart == false)
            {
                goto Inizio;
            }
        }
        protected override void OnTick()
        {
            var position = Positions.Find("MyLabel");

            if (position == null)
            {
                Stop();
                return;
            }
            //If the trigger is reached, the robot starts trailing
            if (!_isTrailing && position.Pips >= TriggerWhenGaining)
            {
                _isTrailing = true;
            }
            //If the cBot is trailing and the profit in pips is at the highest level, we need to readjust the stop loss
            if (_isTrailing && _highestGain < position.Pips)
            {
                //Based on the position's direction, we calculate the new stop loss price and we modify the position
                if (position.TradeType == TradeType.Buy)
                {
                    var newSLprice = _symbol.Ask - (_symbol.PipSize * TrailingStopLossDistance);
                    if (newSLprice > position.StopLoss)
                    {
                        ModifyPosition(position, newSLprice, null);
                    }
                }
                else
                {
                    var newSLprice = _symbol.Bid + (_symbol.PipSize * TrailingStopLossDistance);
                    if (newSLprice < position.StopLoss)
                    {
                        ModifyPosition(position, newSLprice, null);
                    }
                }
                //We reset the highest gain
                _highestGain = position.Pips;
            }
        }
        protected override void OnStop()
        {
            //This method is called when the cBot is stopped
            Restart = false;
        }

    }
}

can I have an answer?


@luca.tocchi

PanagiotisCharalampous
07 May 2020, 11:08

Hi Luca,

There is no specific question here to be answered. You ask from people to go through a 500 lines cBot that does not even build, to spot your mistakes. This is time consuming and nobody will do it. Why should they? You should either teach yourself programming or pay somebody write the code for you. If you have specific questions, we are happy to answer them. But nobody will spend 3-4 hours trying to understand what are you trying to do and fix your code's logical mistakes.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous