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

Multiple order get executed

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

    Multiple order get executed

    I have below code which executes wired way, I debugged with no clue, it occurs in live data not in playback test.

    if (CrossAbove(DEMA1, SMA55, 1))
    {

    ExitShort(); // to exist all long positions
    EnterLong(1, "First Long A"); // start fresh long
    Print( "First Long A");

    }

    //other condition for adding to existing position
    { ..... }


    If my position is 10, the above block exits shorts of 10 then immediately adds 10 long and one for my "first long A" .
    What is wrong with this code or we have a bug here?

    #2
    Hello Akee5,

    Thanks for your post.

    All entry methods will automatically detect a position in the opposite direction and will issue orders to close the position (Called "Close Position") and then issue additional order(s) to leave the strategy in the desired position.

    What is happening is that you are submitting the ExitShort which will exit the 10 short orders with a buy order of 10 and you are submitting EnterLong(1) at the same time so the EnterLong sees the 10 short and will issue 10 buy Close position orders first and then enters the single buy order leaving you with 11 contracts long (10 from closing and 1 for new position).

    The issue here is the timing of orders. What you need to do is to change the exit condition so that you are not entering and exiting at the same time, or simply remove the exit order now that you know that the entry order will close any existing position in the opposite direction.



    Paul H.NinjaTrader Customer Service

    Comment


      #3
      If I have 10 short and then go for EnterLong(1, "First Long A"); will will close one lot or all 10 shorts?

      Comment


        #4
        Hello Akee5,

        Thanks for your reply.

        "If I have 10 short and then go for EnterLong(1, "First Long A"); will will close one lot or all 10 shorts?" It will close all short positions and leave you 1 long,

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          It worked thanks for your help. (it closes all shorts )

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ScottWalsh, Today, 06:52 PM
          4 responses
          32 views
          0 likes
          Last Post ScottWalsh  
          Started by olisav57, Today, 07:39 PM
          0 responses
          4 views
          0 likes
          Last Post olisav57  
          Started by trilliantrader, Today, 03:01 PM
          2 responses
          19 views
          0 likes
          Last Post helpwanted  
          Started by cre8able, Today, 07:24 PM
          0 responses
          6 views
          0 likes
          Last Post cre8able  
          Started by Haiasi, Today, 06:53 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X