Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 cupir2, Yesterday, 07:44 PM
    3 responses
    21 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by reynoldsn, Yesterday, 07:26 PM
    2 responses
    14 views
    0 likes
    Last Post reynoldsn  
    Started by MartinT, 05-17-2023, 06:00 AM
    18 responses
    173 views
    0 likes
    Last Post flybuzz
    by flybuzz
     
    Started by sgordet, Today, 05:24 AM
    2 responses
    20 views
    0 likes
    Last Post sgordet
    by sgordet
     
    Started by Board game geek, Today, 02:20 AM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X