Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please help...strategy uses BBMACD and EMA...

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

    Please help...strategy uses BBMACD and EMA...

    I am not a coder, I have tried the Strategy Builder and Copilot and ChatGPT to see what's wrong with my strategy. When I run backtesting on it, it generates Zero trades, not sure that makes sense. Please help me understand what I am doing wrong.

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class mcadbbemastrategy : Strategy

    {
    private EMA EMA1;
    private ImpMACDBB ImpMACDBB1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "mcadbbemastrategy";
    Calculate = Calculate.OnEachTick;
    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;
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Close, 4);
    ImpMACDBB1 = ImpMACDBB(Close, 12, 26, 6, 10, 1, Brushes.Green, Brushes.Red);
    EMA1.Plots[0].Brush = Brushes.Goldenrod;
    ImpMACDBB1.Plots[0].Brush = Brushes.Black;
    ImpMACDBB1.Plots[1].Brush = Brushes.Yellow;
    ImpMACDBB1.Plots[2].Brush = Brushes.Aqua;
    ImpMACDBB1.Plots[3].Brush = Brushes.Aqua;
    ImpMACDBB1.Plots[4].Brush = Brushes.Aqua;
    AddChartIndicator(EMA1);
    AddChartIndicator(ImpMACDBB1);
    SetProfitTarget("", CalculationMode.Ticks, 32);
    SetStopLoss("", CalculationMode.Ticks, 8, false);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    if (CrossAbove(EMA1, ImpMACDBB1.Lower, 1) && CrossAbove(ImpMACDBB1.MACDPlot, EMA1, 1))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }


    if (CrossBelow(EMA1, ImpMACDBB1.Upper, 1) && CrossBelow(ImpMACDBB1.MACDPlot, EMA1, 1))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }
    }
    }
    }

    #2
    Hello BadA$$B3ast,

    Thank you for your post.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

    The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.

    I am happy to assist you with analyzing the output from the output window.

    Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

    https://support.ninjatrader.com/s/ar...nd-TraceOrders
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Thanks Gaby! This will take some time for me to digest as it is the first time I have done code in over 30 years.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NasdaqAnalytica, Today, 03:33 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Auvrayphil, Today, 03:44 PM
      0 responses
      4 views
      0 likes
      Last Post Auvrayphil  
      Started by jamesbhardwaj, Today, 04:41 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by diorfo, Today, 12:48 PM
      5 responses
      23 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by cp202822, Today, 01:38 PM
      2 responses
      13 views
      0 likes
      Last Post cp202822  
      Working...
      X