Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Trade not executing live when using CrossAbove()

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

    Trade not executing live when using CrossAbove()

    I have some interesting behavior I'm hoping someone can help me with. Very simple strategy that goes long when Close crosses above a pivot point. When I backtest, everything executes as I'd expect. During live trading, the trades are not taken. When adding debug code to print the output of boolean conditions, everything checks out ok. On top of that, when I change the code from CrossAbove() to Close0 > pivot && Close1 <= pivot, the trades execute properly live. Seems like I'm overlooking something simple, any ideas?

    BTAdjust just sets to 0 or 1 depending on if we are historical or live to accommodate FirstTickOfBar

    Code #1 (Backtest good, live bad)

    VarL1.Set(pivot.R2[BTAdjust]);
    EntCondL = CrossAbove(Close,VarL1,1);

    Code #2 (Backtest good, live good)

    VarL1.Set(pivot.R2[BTAdjust]);
    EntCondL = Close[BTAdjust] >= VarL1[0] && Close[BTAdjust+1] < VarL1[1];

    The entry order is triggered by:

    if (Position.MarketPosition == MarketPosition.Flat && EntCondL && (EntriesToday < 5 || EndofSess))
    {
    EnterLongMarket(NShares);
    //Print ("MarketEntry" + Position.MarketPosition + EntCondL + EntriesToday + EndofSess + Time[0].ToString() + Time[0].ToString("D"));
    }

    #2
    Hello nmk85roll,

    From the given code I can't tell what may be happening, have you tried to Print the actual values which are being used in the conditions?

    Comparing what the values being passed to CrossAbove vs the condition you made would help to better understand why that may be false.


    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse,

      That was my point in the debug print line that is commented out, the conditions print properly during back testing and everything comes in "true" that should to signal a market entry. I can attach all the code if that helps.

      Comment


        #4
        Hello nmk85roll,

        The place where you have the print will only happen if the condition is true which wont be helpful to know why its false. Have you tried checking what the values are outside the condition for the same timestamp as the condition that works?

        To find what is happening you would really need to see what the base values are before any of your variables, the items here:

        Code:
        EntCondL = CrossAbove([B]Close[/B],[B]VarL1,[/B]1);
        
        Code #2 (Backtest good, live good)
        
        VarL1.Set(pivot.R2[BTAdjust]);
        EntCondL = [B]Close[BTAdjust][/B] >= [B]VarL1[0][/B] && [B]Close[BTAdjust+1] [/B]< [B]VarL1[1][/B];

        You would need to compare the values on each bar between tests to see what part is different.

        The Cross methods when using 1 lookback period should be checking if the series [1] bars ago crossed the [0] bars ago. The value would need to be on the opposite side and not equal to the value being compared against.



        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse. I'm not following what you mean by this " The value would need to be on the opposite side and not equal to the value being compared against" Can you please explain?

          Comment


            #6
            Hello nmk85roll,

            That is based on the help guide note:
            Note: This method does not return true if both series being compared have equal values on the current or previous bar with a lookbackPeriod of 1.
            If you have used a lookback of 1, like you have, then it can return false if the values are equal. Your condition would likely need to be Series1[1] < Series2[1] && Series1[0] > Series2[0] to replicate the cross condition however I cannot see the actual source to tell you if your test exactly matches the internal code.

            The next best way to diagnose the problem would be to output the values and see specifically what they are so you have a example that's not just code. With the actual values you could review the notes with the cross method to see if that accurately represents how the cross is described to work.

            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,404 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by Shai Samuel, 07-02-2022, 02:46 PM
            4 responses
            95 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by DJ888, Yesterday, 10:57 PM
            0 responses
            8 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by MacDad, 02-25-2024, 11:48 PM
            7 responses
            159 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Yesterday, 09:29 PM
            0 responses
            8 views
            0 likes
            Last Post Belfortbucks  
            Working...
            X