Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi- instument strategy giving results I'm not expecting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Multi- instument strategy giving results I'm not expecting

    Hi... I thought I had the basics down of multi-instrument strategies but apparently not. The strategy below is returning trades that have no similarities to the conditions coded. For example, entries at 9:35am and 4:00pm (I have coded only between 10-2), no moving average conditions present as specified, etc. Any ideas?

    Code:
    protected override void Initialize()
            {
                CalculateOnBarClose = true;
                Add("SPY",PeriodType.Minute,5);
            }
    
            protected override void OnBarUpdate()
            {
                if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired){return;}
                else
                {
                    if(BarsInProgress==0)
                    {
                        if(((ToTime(Time[0])>= 100000) && (ToTime(Time[0])<= 140000)) &&
                            (Closes[1][0]>Closes[1][Bars.BarsSinceSession-1]))    //is market up?
                        {
                            if((Close[0]>EMA(50)[0])&&
                                (Close[0]>EMA(10)[0])&&
                                (Open[0]<EMA(50)[0])&&
                                ((High[0]-Close[0])/(High[0]-Low[0])<=.25)&&
                                (CountIf(delegate{return High[1]<=EMA(20)[1];},30)>=28)&&
                                (CountIf(delegate{return EMA(20)[0]<EMA(50)[0];},30)==30)&&
                                (Volume[0]>=SMA(Volume,15)[2]*4))
                            {
                                EnterLong(0,100,"Signal");
                            }
                        }
                        if(Position.MarketPosition==MarketPosition.Long)
                        {
                            if(Close[0]<EMA(20)[0])
                                ExitLong(0,100,"Exit","Signal");
                        }
                    }
                }
            }

    #2
    Where are you testing this? Market Replay? Strategy Analyzer? Sim? Live?

    What is the time frame of the main series?

    The code looks right glancing at it, but your setup might be incorrect.



    Originally posted by CSharpTrader View Post
    Hi... I thought I had the basics down of multi-instrument strategies but apparently not. The strategy below is returning trades that have no similarities to the conditions coded. For example, entries at 9:35am and 4:00pm (I have coded only between 10-2), no moving average conditions present as specified, etc. Any ideas?

    Code:
    protected override void Initialize()
            {
                CalculateOnBarClose = true;
                Add("SPY",PeriodType.Minute,5);
            }
    
            protected override void OnBarUpdate()
            {
                if(CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired){return;}
                else
                {
                    if(BarsInProgress==0)
                    {
                        if(((ToTime(Time[0])>= 100000) && (ToTime(Time[0])<= 140000)) &&
                            (Closes[1][0]>Closes[1][Bars.BarsSinceSession-1]))    //is market up?
                        {
                            if((Close[0]>EMA(50)[0])&&
                                (Close[0]>EMA(10)[0])&&
                                (Open[0]<EMA(50)[0])&&
                                ((High[0]-Close[0])/(High[0]-Low[0])<=.25)&&
                                (CountIf(delegate{return High[1]<=EMA(20)[1];},30)>=28)&&
                                (CountIf(delegate{return EMA(20)[0]<EMA(50)[0];},30)==30)&&
                                (Volume[0]>=SMA(Volume,15)[2]*4))
                            {
                                EnterLong(0,100,"Signal");
                            }
                        }
                        if(Position.MarketPosition==MarketPosition.Long)
                        {
                            if(Close[0]<EMA(20)[0])
                                ExitLong(0,100,"Exit","Signal");
                        }
                    }
                }
            }

    Comment


      #3
      Thank you sledge. I was running it on 5 min bars in strategy analyzer. I had been backtesting a different strategy from the same analyzer before, and, going out on a limb here, I wonder if this had something to do with it. I say this since after restarting NT and rerunning the strategy (and removing the other instrument) it performed as expected..

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      56 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      143 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      160 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      96 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      276 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X