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

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?

      Paul H.NinjaTrader Customer Service

      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.

          Paul H.NinjaTrader Customer Service

          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 terkk, Today, 01:16 PM
            2 responses
            17 views
            0 likes
            Last Post desjaimz  
            Started by TraderElegante, Today, 12:14 PM
            1 response
            19 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by dgee949, Today, 11:44 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_JustinD  
            Started by NinjaTrader_Kate, Today, 12:01 PM
            0 responses
            20 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by efeuvejota01, Today, 11:42 AM
            4 responses
            37 views
            0 likes
            Last Post efeuvejota01  
            Working...
            X