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

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 bortz, 11-06-2023, 08:04 AM
    47 responses
    1,605 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    8 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    4 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    13 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X