Announcement

Collapse
No announcement yet.

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.



    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,

        Comment


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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          43 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          21 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          31 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          50 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          42 views
          0 likes
          Last Post CarlTrading  
          Working...
          X