CBOT works on Forex Pairs but not on NASDAQ100/SPX500

Created at 12 Aug 2023, 14:40
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!
80

8064102

Joined 18.07.2020

CBOT works on Forex Pairs but not on NASDAQ100/SPX500
12 Aug 2023, 14:40


hiya!!

I have this code that works great on forex pairs for backtesting/optimising. however if you try to run this code on the nasdaq 100 indices then it just doesn't work, it picks up no trades and I haven't a clue why. have a look yourself it works on all forex pairs just won't trigger on the nasdaq. could anyone help?

 

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 Amir : Robot
    {
//Check the general naming conventions
        [Parameter("SMA1 Period", DefaultValue = 2, Group = "Parameters")]
        public int PeriodsSma1 { get; set; }

        [Parameter("SMA2 Period", DefaultValue = 2, Group = "Parameters")]
        public int PeriodsSma2 { get; set; }

        [Parameter("Distance above SMA1 Pips", DefaultValue = 5, Group = "Parameters")]
        public double SMA1_Pips { get; set; }

        [Parameter("Distance below SMA2 Pips", DefaultValue = 5, Group = "Parameters")]
        public double SMA2_Pips { get; set; }

        [Parameter("Volume", DefaultValue = 10000, Group = "Money Management")]
        public int _volume { get; set; }

        [Parameter("Take Profit", DefaultValue = 5, Group = "Money Management")]
        public int TP { get; set; }
        [Parameter("Stop Loss", DefaultValue = 5, Group = "Money Management")]
        public int SL { get; set; }

        private SimpleMovingAverage _sma1;
        private SimpleMovingAverage _sma2;

        protected override void OnStart()
        {

            _sma1 = Indicators.SimpleMovingAverage(Bars.HighPrices, PeriodsSma1);
            _sma2 = Indicators.SimpleMovingAverage(Bars.LowPrices, PeriodsSma2);
        }

        protected override void OnTick()
        {
            if (IsPoOpen())
            {
//For Long Trade
//We buy at the ask, but for the price action distance I only took Bid into account
//Chnage to Symbol.Ask if you prefer
                if (Symbol.Bid < _sma2.Result.LastValue - (SMA2_Pips / 10000))
                {
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, _volume, "DSMA", SL, TP, "comments", false, StopTriggerMethod.DoubleOpposite);
                }

//For Short Trade
//We sell at the bid, so for the price action distance I only took Bid into account
                if (Symbol.Bid > _sma1.Result.LastValue + (SMA1_Pips / 10000))
                {
                    ExecuteMarketOrder(TradeType.Sell, SymbolName, _volume, "DSMA", SL, TP, "comments", false, StopTriggerMethod.DoubleOpposite);
                }
            }
        }

        protected bool IsPoOpen()
        {
            var pos = Positions.FindAll("DSMA", SymbolName);

            if (pos.Length == 0)
            {
//Print("None");
                return true;

            }
            else
            {
//Print(pos);
                return false;

            }
        }

        protected override void OnStop()
        {
// Put your deinitialization logic here
        }
    }

 


@8064102
Replies

firemyst
13 Aug 2023, 05:17

Have you looked at any error messages of the logging tab?

I'll give you a hint as to why you're probably having issues – change the volume to “1” and run again on NAS, then change back to 10,000. 

You should be able to figure it out from there. :-)


@firemyst

PanagiotisChar
14 Aug 2023, 05:07

Hi there,

The reason is probably hidden in the log. Have a look at it.

Aieden Technologies

Need help? Join us on Telegram


 


@PanagiotisChar