bot fails to open traders upon signal

Created at 19 Oct 2022, 01:13
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!
SE

sejdinimarkelian

Joined 18.11.2020

bot fails to open traders upon signal
19 Oct 2022, 01:13


i have noticed the bot since ive let it live has skiped trades and when i run the backtest it shows that it should have opened positions while when live it didnt, any solution ?

 


@sejdinimarkelian
Replies

PanagiotisChar
19 Oct 2022, 09:29

Hi there,

In order for us to help you, you need to share with us the source code and steps to reproduce the problem.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

sejdinimarkelian
19 Oct 2022, 21:57

RE: here it is

PanagiotisChar said:

Hi there,

In order for us to help you, you need to share with us the source code and steps to reproduce the problem.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class XAUUSD : Robot
    {
    //atr indicator
    private AverageTrueRange atr;
    
    private HistoricalVolatility hvv;
    private ExponentialMovingAverage emmahvv;
    
    private WilliamsPctR wpctr;
    private ExponentialMovingAverage wpctrema;
    
    private LinearRegressionForecast lrf;
    private ExponentialMovingAverage lrfema;
    
    private OnBalanceVolume obv;
    private ExponentialMovingAverage obvema;
    
    private TradeVolumeIndex tvi;
    private ExponentialMovingAverage tviema;
    
    private Vidya vidyaa;
    private ExponentialMovingAverage vidyaema;
    
    private Aroon aroon;
    
    private AverageDirectionalMovementIndexRating admir;
    
    private DirectionalMovementSystem  dms;
    
    private AcceleratorOscillator accelero;
    
    private AwesomeOscillator aweso;
    
    private MacdCrossOver macdco;
    
    private MacdHistogram macdh;
    
    private BollingerBands bb;
    
    private KeltnerChannels kch;
    
    private IchimokuKinkoHyo ichimokuu;
    
    
    
        //risk parameters
        [Parameter("volume", DefaultValue = 0.05)]
        public double riskpct { get; set; }
        
        //atr periods
        [Parameter("Atr Periods", DefaultValue = 14)]
        public int atrprds { get; set; }
        
        //atr multiplier
        [Parameter("Atr multiplier", DefaultValue = 1.5)]
        public double atrmltp { get; set; }

        
       
        
        //historical volatility
        [Parameter("historical volatil 1", DefaultValue = 20)]
        public int hv1 { get; set; }
        [Parameter("historical volatil 2", DefaultValue = 252)]
        public int hv2 { get; set; }
        [Parameter("historical volatil ema", DefaultValue = 21)]
        public int hvema { get; set; }

        protected override void OnStart()
        {
            //indicators loading
            atr = Indicators.AverageTrueRange(atrprds,MovingAverageType.Exponential);
            
            wpctr= Indicators.WilliamsPctR(14);
            wpctrema= Indicators.ExponentialMovingAverage(wpctr.Result,21);
            
            hvv=Indicators.HistoricalVolatility(Bars.ClosePrices,hv1,hv2);
            emmahvv=Indicators.ExponentialMovingAverage(hvv.Result,hvema);
            
            lrf= Indicators.LinearRegressionForecast(Bars.ClosePrices,9);
            lrfema= Indicators.ExponentialMovingAverage(lrf.Result,21);
            
            obv= Indicators.OnBalanceVolume(Bars.ClosePrices);
            obvema= Indicators.ExponentialMovingAverage(obv.Result,21);
            
            tvi = Indicators.TradeVolumeIndex(Bars.ClosePrices);
            tviema= Indicators.ExponentialMovingAverage(tvi.Result,21);
            
            vidyaa= Indicators.Vidya(Bars.ClosePrices,14,0.65);
            vidyaema= Indicators.ExponentialMovingAverage(vidyaa.Result,21);
            
            aroon = Indicators.Aroon(25);
            
            admir= Indicators.AverageDirectionalMovementIndexRating(14);
            
            dms= Indicators.DirectionalMovementSystem(14);
            
            accelero=Indicators.AcceleratorOscillator();
            
            aweso= Indicators.AwesomeOscillator();
            
            macdco= Indicators.MacdCrossOver(Bars.ClosePrices,26,12,9);
             
            macdh= Indicators.MacdHistogram(Bars.ClosePrices,26,12,9);
            
            bb= Indicators.BollingerBands(Bars.ClosePrices,20,2,MovingAverageType.Simple);
            
            kch= Indicators.KeltnerChannels(20,MovingAverageType.Simple,10,MovingAverageType.Simple,2);
            
            ichimokuu= Indicators.IchimokuKinkoHyo(9,26,52);
            
        }

        protected override void OnBar()
        {
        
            //variables
            
            var prevatr = Math.Round(atr.Result.Last(1) / Symbol.PipSize);
            var tradeamount = (Account.Equity *riskpct) / (1.5*prevatr *Symbol.PipValue);
            tradeamount = Symbol.NormalizeVolumeInUnits(tradeamount, RoundingMode.Down);
            
            var price = Bars.ClosePrices.Last(1);
            var prevprice = Bars.ClosePrices.Last(2);
            
            var longpst = Positions.Find("long");
            var shortpst = Positions.Find("short");
            
            var emahv=emmahvv.Result.Last(1);
            var hv=hvv.Result.Last(1);
            
            var wpctrr=wpctr.Result.Last(1);
            var prevwpctrr=wpctr.Result.Last(2);
            var wpctrremaa=wpctrema.Result.Last(1);
            var prevwpctrremaa=wpctrema.Result.Last(2);
            
            var lrff=lrf.Result.Last(1);
            var prevlrff=lrf.Result.Last(2);
            var lrffema=lrfema.Result.Last(1);
            var prevlrffema=lrfema.Result.Last(2);
            
            var obvv=obv.Result.Last(1);
            var prevobvv=obv.Result.Last(2);
            var obvvemaa=obvema.Result.Last(1);
            var prevobvvemaa=obvema.Result.Last(2);
            
            var tvii=tvi.Result.Last(1);
            var prevtvii=tvi.Result.Last(2);
            var tviiemaa=tviema.Result.Last(1);
            var prevtviiemaa=tviema.Result.Last(2);
            
            var vidyaaa=vidyaa.Result.Last(1);
            var prevvidyaaa=vidyaa.Result.Last(2);
            var vidyaaemaa=vidyaema.Result.Last(1);
            var prevvidyaaemaa=vidyaema.Result.Last(2);
            
            var aroonup=aroon.Up.Last(1);
            var prevaroonup=aroon.Up.Last(2);
            var aroondown=aroon.Down.Last(1);
            var prevaroondown=aroon.Down.Last(2);
              
            var diminus=admir.DIMinus.Last(1);
            var prevdiminus=admir.DIMinus.Last(2);
            var diplus=admir.DIPlus.Last(1);
            var prevdiplus=admir.DIPlus.Last(2);
            
            var dmsadx=dms.ADX.Last(1);
            var prevdmsadx=dms.ADX.Last(2);
            var dmsdiplus=dms.DIPlus.Last(1);
            var prevdmsdiplus=dms.DIPlus.Last(2);
            var dmsdiminus=dms.DIMinus.Last(1);
            var prevdmsdiminus=dms.DIMinus.Last(2);
           
            var acceleroo=accelero.Result.Last(1);
            var prevacceleroo=accelero.Result.Last(2);
            
            var awesoo=aweso.Result.Last(1);
            var prevawesoo=aweso.Result.Last(2);
            
            var macd=macdco.MACD.Last(1);
            var prevmacd=macdco.MACD.Last(2);
            var signalmac=macdco.Signal.Last(1);
            var prevsignalmac=macdco.Signal.Last(2);
            
            var macdhist=macdh.Histogram.Last(1);
            var prevmacdhist=macdh.Histogram.Last(2);
            
            var bbb=bb.Main.Last(1);
            var prevbbb=bb.Main.Last(2);
            
            var kchh=kch.Main.Last(1);
            var prevkchh=kch.Main.Last(2);
            
            var kijun=ichimokuu.KijunSen.Last(1);
            var prevkijun=ichimokuu.KijunSen.Last(2);


            // trade entry
            {
            if (Positions.Count<1)
            if (wpctrr>wpctrremaa)//&prevwpctrr<prevwpctrremaa)
            if (lrff>lrffema)//&prevlrff<prevlrffema)
           
            if (hv>emahv)
  
            ExecuteMarketOrder(TradeType.Buy , Symbol.Name ,tradeamount, "long" ,atrmltp*prevatr ,0);
            }
            
            
            {
            if (Positions.Count<1)
            if (wpctrr<wpctrremaa)//&prevwpctrr>prevwpctrremaa)
            if (lrff<lrffema)//&prevlrff>prevlrffema)
            
            if (hv>emahv)

            ExecuteMarketOrder(TradeType.Sell , Symbol.Name ,tradeamount , "short" ,atrmltp*prevatr ,0);
            }
            
            
            
            
            {
            
            if (shortpst !=null &lrff>lrffema&prevlrff<prevlrffema)
            ClosePosition(shortpst);
            
            }
            
            {
            
            if (longpst !=null &lrff<lrffema&prevlrff>prevlrffema)
            ClosePosition(longpst);
            
            }
            
           
            
        
}
        protected override void OnStop()
        {
            // Handle cBot stop here
            }
    }
}


@sejdinimarkelian

sejdinimarkelian
19 Oct 2022, 21:57

RE: here it is

PanagiotisChar said:

Hi there,

In order for us to help you, you need to share with us the source code and steps to reproduce the problem.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class XAUUSD : Robot
    {
    //atr indicator
    private AverageTrueRange atr;
    
    private HistoricalVolatility hvv;
    private ExponentialMovingAverage emmahvv;
    
    private WilliamsPctR wpctr;
    private ExponentialMovingAverage wpctrema;
    
    private LinearRegressionForecast lrf;
    private ExponentialMovingAverage lrfema;
    
    private OnBalanceVolume obv;
    private ExponentialMovingAverage obvema;
    
    private TradeVolumeIndex tvi;
    private ExponentialMovingAverage tviema;
    
    private Vidya vidyaa;
    private ExponentialMovingAverage vidyaema;
    
    private Aroon aroon;
    
    private AverageDirectionalMovementIndexRating admir;
    
    private DirectionalMovementSystem  dms;
    
    private AcceleratorOscillator accelero;
    
    private AwesomeOscillator aweso;
    
    private MacdCrossOver macdco;
    
    private MacdHistogram macdh;
    
    private BollingerBands bb;
    
    private KeltnerChannels kch;
    
    private IchimokuKinkoHyo ichimokuu;
    
    
    
        //risk parameters
        [Parameter("volume", DefaultValue = 0.05)]
        public double riskpct { get; set; }
        
        //atr periods
        [Parameter("Atr Periods", DefaultValue = 14)]
        public int atrprds { get; set; }
        
        //atr multiplier
        [Parameter("Atr multiplier", DefaultValue = 1.5)]
        public double atrmltp { get; set; }

        
       
        
        //historical volatility
        [Parameter("historical volatil 1", DefaultValue = 20)]
        public int hv1 { get; set; }
        [Parameter("historical volatil 2", DefaultValue = 252)]
        public int hv2 { get; set; }
        [Parameter("historical volatil ema", DefaultValue = 21)]
        public int hvema { get; set; }

        protected override void OnStart()
        {
            //indicators loading
            atr = Indicators.AverageTrueRange(atrprds,MovingAverageType.Exponential);
            
            wpctr= Indicators.WilliamsPctR(14);
            wpctrema= Indicators.ExponentialMovingAverage(wpctr.Result,21);
            
            hvv=Indicators.HistoricalVolatility(Bars.ClosePrices,hv1,hv2);
            emmahvv=Indicators.ExponentialMovingAverage(hvv.Result,hvema);
            
            lrf= Indicators.LinearRegressionForecast(Bars.ClosePrices,9);
            lrfema= Indicators.ExponentialMovingAverage(lrf.Result,21);
            
            obv= Indicators.OnBalanceVolume(Bars.ClosePrices);
            obvema= Indicators.ExponentialMovingAverage(obv.Result,21);
            
            tvi = Indicators.TradeVolumeIndex(Bars.ClosePrices);
            tviema= Indicators.ExponentialMovingAverage(tvi.Result,21);
            
            vidyaa= Indicators.Vidya(Bars.ClosePrices,14,0.65);
            vidyaema= Indicators.ExponentialMovingAverage(vidyaa.Result,21);
            
            aroon = Indicators.Aroon(25);
            
            admir= Indicators.AverageDirectionalMovementIndexRating(14);
            
            dms= Indicators.DirectionalMovementSystem(14);
            
            accelero=Indicators.AcceleratorOscillator();
            
            aweso= Indicators.AwesomeOscillator();
            
            macdco= Indicators.MacdCrossOver(Bars.ClosePrices,26,12,9);
             
            macdh= Indicators.MacdHistogram(Bars.ClosePrices,26,12,9);
            
            bb= Indicators.BollingerBands(Bars.ClosePrices,20,2,MovingAverageType.Simple);
            
            kch= Indicators.KeltnerChannels(20,MovingAverageType.Simple,10,MovingAverageType.Simple,2);
            
            ichimokuu= Indicators.IchimokuKinkoHyo(9,26,52);
            
        }

        protected override void OnBar()
        {
        
            //variables
            
            var prevatr = Math.Round(atr.Result.Last(1) / Symbol.PipSize);
            var tradeamount = (Account.Equity *riskpct) / (1.5*prevatr *Symbol.PipValue);
            tradeamount = Symbol.NormalizeVolumeInUnits(tradeamount, RoundingMode.Down);
            
            var price = Bars.ClosePrices.Last(1);
            var prevprice = Bars.ClosePrices.Last(2);
            
            var longpst = Positions.Find("long");
            var shortpst = Positions.Find("short");
            
            var emahv=emmahvv.Result.Last(1);
            var hv=hvv.Result.Last(1);
            
            var wpctrr=wpctr.Result.Last(1);
            var prevwpctrr=wpctr.Result.Last(2);
            var wpctrremaa=wpctrema.Result.Last(1);
            var prevwpctrremaa=wpctrema.Result.Last(2);
            
            var lrff=lrf.Result.Last(1);
            var prevlrff=lrf.Result.Last(2);
            var lrffema=lrfema.Result.Last(1);
            var prevlrffema=lrfema.Result.Last(2);
            
            var obvv=obv.Result.Last(1);
            var prevobvv=obv.Result.Last(2);
            var obvvemaa=obvema.Result.Last(1);
            var prevobvvemaa=obvema.Result.Last(2);
            
            var tvii=tvi.Result.Last(1);
            var prevtvii=tvi.Result.Last(2);
            var tviiemaa=tviema.Result.Last(1);
            var prevtviiemaa=tviema.Result.Last(2);
            
            var vidyaaa=vidyaa.Result.Last(1);
            var prevvidyaaa=vidyaa.Result.Last(2);
            var vidyaaemaa=vidyaema.Result.Last(1);
            var prevvidyaaemaa=vidyaema.Result.Last(2);
            
            var aroonup=aroon.Up.Last(1);
            var prevaroonup=aroon.Up.Last(2);
            var aroondown=aroon.Down.Last(1);
            var prevaroondown=aroon.Down.Last(2);
              
            var diminus=admir.DIMinus.Last(1);
            var prevdiminus=admir.DIMinus.Last(2);
            var diplus=admir.DIPlus.Last(1);
            var prevdiplus=admir.DIPlus.Last(2);
            
            var dmsadx=dms.ADX.Last(1);
            var prevdmsadx=dms.ADX.Last(2);
            var dmsdiplus=dms.DIPlus.Last(1);
            var prevdmsdiplus=dms.DIPlus.Last(2);
            var dmsdiminus=dms.DIMinus.Last(1);
            var prevdmsdiminus=dms.DIMinus.Last(2);
           
            var acceleroo=accelero.Result.Last(1);
            var prevacceleroo=accelero.Result.Last(2);
            
            var awesoo=aweso.Result.Last(1);
            var prevawesoo=aweso.Result.Last(2);
            
            var macd=macdco.MACD.Last(1);
            var prevmacd=macdco.MACD.Last(2);
            var signalmac=macdco.Signal.Last(1);
            var prevsignalmac=macdco.Signal.Last(2);
            
            var macdhist=macdh.Histogram.Last(1);
            var prevmacdhist=macdh.Histogram.Last(2);
            
            var bbb=bb.Main.Last(1);
            var prevbbb=bb.Main.Last(2);
            
            var kchh=kch.Main.Last(1);
            var prevkchh=kch.Main.Last(2);
            
            var kijun=ichimokuu.KijunSen.Last(1);
            var prevkijun=ichimokuu.KijunSen.Last(2);


            // trade entry
            {
            if (Positions.Count<1)
            if (wpctrr>wpctrremaa)//&prevwpctrr<prevwpctrremaa)
            if (lrff>lrffema)//&prevlrff<prevlrffema)
           
            if (hv>emahv)
  
            ExecuteMarketOrder(TradeType.Buy , Symbol.Name ,tradeamount, "long" ,atrmltp*prevatr ,0);
            }
            
            
            {
            if (Positions.Count<1)
            if (wpctrr<wpctrremaa)//&prevwpctrr>prevwpctrremaa)
            if (lrff<lrffema)//&prevlrff>prevlrffema)
            
            if (hv>emahv)

            ExecuteMarketOrder(TradeType.Sell , Symbol.Name ,tradeamount , "short" ,atrmltp*prevatr ,0);
            }
            
            
            
            
            {
            
            if (shortpst !=null &lrff>lrffema&prevlrff<prevlrffema)
            ClosePosition(shortpst);
            
            }
            
            {
            
            if (longpst !=null &lrff<lrffema&prevlrff>prevlrffema)
            ClosePosition(longpst);
            
            }
            
           
            
        
}
        protected override void OnStop()
        {
            // Handle cBot stop here
            }
    }
}


@sejdinimarkelian

... Deleted by UFO ...

PanagiotisChar
20 Oct 2022, 10:22

Hi there,

You did not provide any steps to reproduce the problem. What do we need to do to see it?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us


@PanagiotisChar