Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceExit - avoid multiple closing trades

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

    BarsSinceExit - avoid multiple closing trades

    Dear all,

    I have the current setup:
    - Open simultaneously 3 positions (S1, S2, S3), based on a channel ("Box").
    - If price goes against me and crosses the middle of the box, I close one position at the time. If it happens three times, all positions are closed.

    Initially, I used a "counter", set at 0 when no trades are closed, then 1 if S1 is closed, 2 if S2 is closed but it doesnt work with an object based code.
    I am now using the BarsSinceExit but I am still failing.

    Please find below the code extract and also attached a screenshot that shows that S1 and S2 are closed simultaneously and not one after the other.

    // Partial close of short position S1 & then S2
    if ((Close[1] < midboxSize) && (Close[0] >= midboxSize) &&
    (Position.MarketPosition == MarketPosition.Short))
    // && (tradeShClosingCounter == 0))
    {
    ExitShort(
    "S1");
    //tradeShClosingCounter = tradeShClosingCounter + 1;
    }
    if ((Close[1] < midboxSize) && (Close[0] >= midboxSize) && (BarsSinceExit(0,"S1",0) > 2) &&
    (Position.MarketPosition == MarketPosition.Short))
    // && (tradeShClosingCounter == 1))
    {
    ExitShort(
    "S2");
    //tradeShClosingCounter = tradeShClosingCounter + 1;
    }

    Thank you,
    Best

    Nicolas
    Attached Files

    #2
    The code you have here is triggering both exits at the same time since bars since entry is greater than 2 for both situations.

    Your initial thought of using a counter should work as long as you are resetting it properly after all three trades exit.

    You may want to add Print() statements throughout your code to ensure the tracking variable is being set as expected.
    LanceNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rdtdale, Today, 01:02 PM
    0 responses
    2 views
    0 likes
    Last Post rdtdale
    by rdtdale
     
    Started by alifarahani, Today, 09:40 AM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by RookieTrader, Today, 09:37 AM
    4 responses
    18 views
    0 likes
    Last Post RookieTrader  
    Started by PaulMohn, Today, 12:36 PM
    0 responses
    7 views
    0 likes
    Last Post PaulMohn  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    41 views
    0 likes
    Last Post love2code2trade  
    Working...
    X