Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy executes trade when conditions are wrong

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

    strategy executes trade when conditions are wrong

    I am having a puzzling time figuring out some NT performance errors. I have a simple strategy that enters a LONG trade when several indicators are all moving UP. The reverse is true for SHORT trades. However, I am finding several instances where NT executes a LONG trade when the SMA is actually going DOWN. Yikes! I have attached a screen shot to illustrate. The gold line is the SMA of price. It is clearly going DOWN, but NT executes a LONG trade. Here is the code from the strategy:

    protected override void OnBarUpdate()
    {...
    double sma1 = SMA(Close, periodMovingAverage)[1];
    double sma0 = SMA(Close, periodMovingAverage)[0];
    ...
    bool HigherSMA = false;
    ...
    if(sma0 > sma1)
    HigherSMA = true;
    ...
    If(HigherSMA)
    {EnterLongLimit(...)}

    Any ideas why NT enters a LONG trade when the condition is visibly not met? I have confirmed the action by manually observing the SMA values in the data box. SMA is definitely going down, not up.

    Thanks for your feedback,
    D
    Attached Files

    #2
    You should print the values of your bools each step of the way and isolate what is happening under the hood.

    Print(HigherSMA);
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    65 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    35 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    59 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Working...
    X