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 KenneGaray, Today, 03:48 AM
            0 responses
            3 views
            0 likes
            Last Post KenneGaray  
            Started by thanajo, 05-04-2021, 02:11 AM
            4 responses
            470 views
            0 likes
            Last Post tradingnasdaqprueba  
            Started by aa731, Today, 02:54 AM
            0 responses
            4 views
            0 likes
            Last Post aa731
            by aa731
             
            Started by Christopher_R, Today, 12:29 AM
            0 responses
            10 views
            0 likes
            Last Post Christopher_R  
            Started by sidlercom80, 10-28-2023, 08:49 AM
            166 responses
            2,237 views
            0 likes
            Last Post sidlercom80  
            Working...
            X