Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Inconsistency Strategy Performance Analysis

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

    Inconsistency Strategy Performance Analysis

    I'm building a simple strategy.
    Long order if MACD crosses over Avg AND price close over 21 EMA. Short order if MACD crosses below Avg AND price close is below 21 EMA.
    The profit target is 2 points and the stop loss is when the MACD crosses over the other direction. (I know very risky, but it's just testing)
    Here is the code

    Code:
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"MACD cross over strategy. Long order if MACD crosses over Avg AND price close over 21 EMA. Short order if MACD crosses below Avg AND price close is below 21 EMA. Profit target is small (i.e. 2 points max) with quicker time frame (i.e. 5 min, 10 min)";
    Name = "MACDEMA21";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    ProfitTarget = 8;
    StopLoss = 20;
    EMALength = 21;
    OrderSize = 5;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    MACD1 = MACD(Close, 12, 26, 9);
    EMA1 = EMA(Close, Convert.ToInt32(EMALength));
    SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    
    if (CurrentBars[0] < 1)
    return;
    
    // Set 1
    if ((CrossAbove(MACD1.Default, MACD1.Avg, 1))
    && (Close[0] > EMA1[0]))
    {
    EnterLong(Convert.ToInt32(OrderSize), @"Long");
    }
    
    // Set 2
    if ((CrossBelow(MACD1.Default, MACD1.Avg, 1))
    && (Close[0] < EMA1[0]))
    {
    EnterLong(Convert.ToInt32(OrderSize), @"Short");
    }
    
    }
    When I'm running the Strategy Performance Analysis, the strategy does behave how it should most of the time, but I have two instances where I can't explain why the strategy is doing that. The two cases are in the attachment (with red arrows). Is there something with the strategy of the Analyzer that is doing something incorrectly? Why are these two orders
    1. Didn't take the profit even though both of them had 2 point gain? And
    2. Why did both of them stay active for so long even though there were multiple MACD cross-overs in the other direction?
    Attached Files
    Last edited by hasana1; 09-03-2022, 12:07 PM.

    #2
    Hello hasana1,

    Use Print() to understand when conditions are evaluating as true or false.
    Use TraceOrders to understand if orders are submitted, ignored, rejected, or automatically cancelled.

    Below is a link to a forum post that demonstrates using Print() and TraceOrders to debug a script understand behavior.


    Please print the time of the bar and all values used in the condition that triggers the order in question with labels showing what each value is and how it is being compared.
    Attach the output with your next post and will be happy to assist with analyzing the output to understand if the condition was true or false and if any orders were submitted.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    52 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    142 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    276 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X