Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with order and 2 positions

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

    Problem with order and 2 positions

    I have a system that is working good except it does not exit both positions when a certain condition is met.....I have it set up like this below, but it only exits one of the positions and not both for some reason?????

    Add("$GBPUSD", PeriodType.Minute, 1);
    Add("$EURUSD", PeriodType.Minute, 1);

    then when condition is met and both positions are open.......

    {
    if ((Positions[1].MarketPosition == MarketPosition.Long)
    && (Positions[2].MarketPosition == MarketPosition.Short)
    && currentTotal > myTarget)
    {
    Print ("Profit Target was Hit");
    if (BarsInProgress == 1)
    ExitLong();
    if (BarsInProgress == 2)
    ExitShort();
    }
    }

    Any ideas?????? Thanks!

    #2
    btw........ I did try putting a private bool into the variables section and set "exitBoth" = false and tried to state exitboth = true when condition was met........ and then did the 'ol if exitboth = true, then exit both positions and that didn't work either????

    Comment


      #3
      Hello edgeliner,
      Thanks for writing in and I am happy to assist you.

      You have filtered the exit code with BarsInProgress. Thus when the primary bar is in progress (BarsArray == 0) then the both the exit codes are ignored. When the first secondary bar is in progress (BarsArray == 1) then the ExitLong() code is executed and the short is filtered out. Similarly when the second bar is in progress then the ExitShort() code is only executed and the long is filtered out.

      To know more on how the multi series concept works please refer to the below links:



      Please let me know if I can assist you any further.
      JoydeepNinjaTrader Customer Service

      Comment


        #4
        Thanks Joydeep......

        Just to make sure I understand this correctly, because I was starting the strategy on the gbp/usd chart, the gbp/usd was considered BarsInProgress 0 and BarsInProgress 1 because I had used

        Add("$GBPUSD", PeriodType.Minute, 1);
        Add("$EURUSD", PeriodType.Minute, 1);

        So, I am assuming I ended up with..........
        BarsInProgress 0 =gbp/usd
        BarsInProgress 1 =gbp/usd
        BarsInProgress 2 = eur/usd

        Am I assuming correctly?????

        Comment


          #5
          Hello edgeliner,
          Yes, you are right.

          Please let me know if I can assist you any further.
          JoydeepNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          574 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X