Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT randomly not executing trades

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

    NT randomly not executing trades

    Can anyone explain why the following two snippets of code should preform differently? When I use Example 1 I am always in the market whether long or short. When I use Example 2 the same thing happens except, for some reason I can't figure out, it randomly decides not to buy/sell in... it will jump out and wait 5.. 10.. 20... minutes and then jump back in... very odd. It is not the SMA, checked that and there are no other conditions. I am wanting to use Example 2 so that I can determine the criteria for entering the market and keep that separate from the conditions to exit the market.

    Any advice would be apprieciated.

    Example 1.

    Set 1

    if(SMA1[0] > SMA1[1]) {EnterLong(Convert.ToInt32(NumberShares), "long");}

    Set 2

    if(SMA1[0] < SMA1[1]) {EnterShort(Convert.ToInt32(NumberShares), "short");}

    Example 2.

    Set 1

    if(SMA1[0] > SMA1[1]) {EnterLong(Convert.ToInt32(NumberShares), "long");}
    if(SMA1[0] < SMA1[1]) {ExitLong(Convert.ToInt32(NumberShares), "CloseLong", "long");}

    Set 2

    if(SMA1[0] < SMA1[1]) {EnterShort(Convert.ToInt32(NumberShares), "short");}
    if(SMA1[0] > SMA1[1]) {ExitShort(Convert.ToInt32(NumberShares), "CloseShort", "long");}

    #2
    Hi Kensonprib,
    Example 1 is the right approach. This automatically closes the trade in the "wrong" direction, if any, and then sets you up in the "right" direction.
    Example 2 tries to execute subsequent actions on the exact same bar using the same conditions set.
    This implies the risk that only one of them is executed. Thus, you get out but not back in until the next signal.
    NT-Roland
    Last edited by NT-Roland; 04-29-2021, 01:55 PM.

    Comment


      #3
      Hello Kensonprib,

      Can you clarify the context of this strategy as you have posted in Ninjatrader7 General development forum and the subject would seem better suited for a strategy forum.

      Are you working with NinjaTrader7 Strategy Wizard or are you working with Ninjascript in NinjaTrader7?

      Are you working with NinjaTrader8 Strategy Builder or are you working Ninjascript in NinjaTrader8?

      Comment


        #4
        Roland... the thing is Example 2 does work perfectly and as designed 98% of the time... then randomly chooses not to... why would the program choose to obey simple rules one time and then choose not to the next? That's not how coding works. If it is working a one point and no conditions change than it shouldn't just stop working.

        Paul, my bad, I am the forth option "working Ninjascript in NinjaTrader8"

        Comment


          #5
          Hello Kensonprib,

          Thanks for your reply.

          No worries, I will this thread move to NinjaTrader8 strategy forums.

          I'm not sure if your Set 2 is just a type but the order name for the short side is "long".

          Do not use Entry and Exits with the same condition as this can lead to unexpected orders. What happens is the Entry method will see the opposite side position and will close the position and will see one market order for that then a 2nd market order to leave the strategy is the intended direction, meanwhile the exit order will itself issue a single market order and this could leave you with 2x what you expected.

          Comment


            #6
            Hey Paul, ya, I just typed it in wrong. I had it correct in my actual code.

            I will keep that in mind going forward. Thanks for your help.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            599 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            344 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            558 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            557 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X