Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entries/Exits Triggered Outside of Actual Price Action? How is that possible?

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

    Entries/Exits Triggered Outside of Actual Price Action? How is that possible?

    This strategy sets small swing lows into a DataSeries, then calculates targets/triggers for each swing low and sets them into their own respective DataSeries'. However, when backtesting on Strategy Analyzer or enabling strategy to a chart, I'm seeing entries being triggered away from the price action. The crossovers below the swingLow triggers never take place on the chart but trades are still initiated many ticks/points away!

    A great example is of the ES 06-12 on 5/23/2012. Using a 2min chart as primary.

    Here's some entry code:

    Code:
            // Variables
            private int sma1        = 50;
            private int sma2        = 200;
            private int ordQ         = 1;     // Quantity per Order
            private int pTot          = 100000;     // Total Positions Allowed - Allowing 100000 just to let it show all the bad entries it will make
    
            private DataSeries swingLow;
            private BoolSeries loTrade1;
            private BoolSeries loTrade2;
            private DataSeries loBar;
    
            private double trendIndy             = 0;    // Immediate trend
            private int pCount                      = 0;    // Position count - orders already placed
    
            protected override void Initialize()
            {
                swingLow    = new DataSeries(this, MaximumBarsLookBack.Infinite);
                loTrade1      = new BoolSeries(this, MaximumBarsLookBack.Infinite);
                loTrade2      = new BoolSeries(this, MaximumBarsLookBack.Infinite);
                loBar           = new DataSeries(this, MaximumBarsLookBack.Infinite);
    
                CalculateOnBarClose = false;
                EntriesPerDirection = pTot;
                EntryHandling = EntryHandling.AllEntries;
                ExitOnClose = false;
             }
    
             protected override void OnBarUpdate()
            {            
               if (CurrentBars[0] < sma2)
                    return;
           
                if (BarsInProgress == 0)
                {                
                    trendIndy = SMA(sma1)[0] - SMA(sma2)[0];
    
                    // Determine swing low points
                    if (Low[2] >= Low[1] &&
                        Low[1] <  Low[0])
                    {
                        swingLow.Set(Low[1]);
                        loTrade1.Set(true);
                        loBar.Set(CurrentBar);
    
                        // Indicate on the chart where the value came from
                        DrawTriangleUp("ua" + CurrentBar, false, 1, swingLow[0] - 2 * TickSize, Color.Green);
                    }
                 }
    
                if (BarsInProgress == 1)
                {
                    for (int i = 0; i < swingLow.Count; i++) 
                    {
                        #region LONG ENTRIES
                        // When price hits a swingLow value...
                        if (loTrade1[i] == true &&
                            CrossBelow(DefaultInput, swingLow[i], 1)) // MIGHT NEED TO BE DEFAULTINPUT[0] OR INPUT OR INPUT[0]???
                        {
                            // LONG ENTRY
                            if (Position.MarketPosition != MarketPosition.Short &&
                                pCount < pTot &&
                                ((trendIndy > 0 && (SMA(BarsArray[0], sma1)[0] < swingLow[i] || SMA(BarsArray[0], sma2)[0] > swingLow[i])) ||
                                 (trendIndy < 0 && (SMA(BarsArray[0], sma1)[0] < swingLow[i] && SMA(BarsArray[0], sma2)[0] > swingLow[i]))))
                            {
                                // Enter Long... if meets criteria
                                EnterLong(ordQ, "long" + loBar[i]);                                                
                                pCount = pCount + 1;
    
                                loTrade1[i] = false;
                                loTrade2[i] = true;
                                Print(Times[0][0].ToString() + "  LONG ENTER" + pCount + "  i " + i + "  CurrentBar" + CurrentBar + "  fromCurrentBar" + (CurrentBar-i) + "  swingLow" + swingLow[i] + "  loTrade1" + loTrade1[i] + "  loTrade2" + loTrade2[i]);                        
                            }
                            else
                            {
                                loTrade1[i] = false;
                                loTrade2[i] = false;
    //                            Print(Times[0][0].ToString() + "  LONG HIT" + "  i " + i + pCount + "  CurrentBar" + CurrentBar + "  fromCurrentBar" + (CurrentBar-i) + "  swingLow" + swingLow[i] + "  loTrade1" + loTrade1[i] + "  loTrade2" + loTrade2[i]);                        
                            }
                        }
                        #endregion
                    }
                 }
    At first I thought I should just reload the data, but that didn't change things. Is there a more thorough way of eliminating this as a possible cause besides right-click > Reload Historical Data?

    What do you think? And I suppose... if anything else looks horribly wrong and bothers you guys, wouldn't mind any additional suggestions!

    Thanks in advance for any help you can offer!!!

    #2
    Steve,

    I ran your code on 5/23 on the ES 06-12 but I do not immediately see where the trades are being initiated many ticks away.

    If you feel there is bad data causing this and the reload did not do the trick, please delete your historical minute data for the ES 06-12 using the instructions provided at the following page of the NinjaTrader Help Guide:
    Removing Historical Data

    Once the data has been deleted close NinjaTrader. Open the Documents\NinjaTrader7\db\cache folder. Select all files then right mouse click and select “delete.”

    Open NinjaTrader and connect to your data provider. Open an new chart.

    Please let me know if this resolves your issue. If not, can you please show me a screen shot of these trades?
    MatthewNinjaTrader Product Management

    Comment


      #3
      It does seem to fix, thanks. But I've had to do it a couple times. I don't understand why the data should become corrupted. Backtesting shouldn't affect the stored data, should it?

      Comment


        #4
        We're glad to hear that Steve, were you experiencing unexpected shutdowns or power outages while NT was open / running? Do you always disconnect NT before shutting it down for the session / weekend?

        Thanks,

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sjsj2732, Yesterday, 04:31 AM
        0 responses
        33 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        286 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        286 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        133 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        91 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X