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 sjsj2732, Yesterday, 04:31 AM
    0 responses
    38 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    287 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    289 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    134 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    95 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X