Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

getting out of a trade going the wrong way

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

    getting out of a trade going the wrong way

    Hi there. I have a strategy that does the right thing most of the time. Occasionally, the market moves in opposite direction than anticipated (that's just life, right?). To account for these unexpected market actions, I am trying to use NBarsDown/NBarsUp to exit from these conditions. However, it doesn't always work. Here's how I'm implementing it:

    protected override void Initialize()
    {
    CalculateOnBarClose = false;
    }

    protected override void OnBarUpdate()
    {
    ...
    bool goingdown = false;
    ....
    if (NBarsDown(3, true, true, true)[0] == 1)
    goingdown = true;
    ...
    // If you have 3 consecutive bars go against the trade, get out
    if (goingdown)
    ExitLong();
    }

    However, when I run the code on real data, I still have conditions where there are 3 bars going down (in my LONG trade) but the strategy doesn't exit the long condition. Any ideas? I do set a stop loss prior to these lines of code using:

    SetStopLoss(CalculationMode.Price, smaT);

    Does the SetStopLoss inclusion override the logical "if going down, get out" logic? Any feedback or pointers would be appreciated.

    Regards,
    Dwayne

    #2
    Hello,

    From what you posted I can't tell. Try printing out your variables and check if your market position is what you think it is:
    DenNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X