Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please help with creating this strategy

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

    Please help with creating this strategy

    I have very new and have very basic knowledge of coding. I'm trying to create this strategy and here's what I got so far. Given I let ChatGPT code it because of my basic knowledge and fill in what I can using the Sample MACrossOver stratety. However, I'm running into road blocks at the compiling portion which I don't understand to get it fix.
    //
    // Copyright (C) 2023, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MACrossOver : Strategy
    {
    private SMA smaFast;
    private SMA smaSlow;
    private int timeFrame = 3;
    private double lastHeikenAshiClose;
    private double lastHeikenAshiOpen;
    private int lastBarTime;
    private Series<double> ma;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMACrossOver;
    Name = NinjaTrader.Custom.Resource.NinjaScriptStrategyNam eSampleMACrossOver;
    Fast = 9;
    Slow = 1;
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    PaintPriceMarkers = true;
    BarsRequired = 2;
    // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = false;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, timeFrame);
    AddHeikenAshi();
    }
    else if (State == State.DataLoaded)
    {
    smaFast = SMA(Fast);
    smaSlow = SMA(Slow);

    smaFast.Plots[0].Brush = Brushes.Goldenrod;
    smaSlow.Plots[0].Brush = Brushes.SeaGreen;

    AddChartIndicator(smaFast);
    AddChartIndicator(smaSlow);
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < BarsRequiredToTrade)
    return;

    if (CrossAbove(smaFast, smaSlow, 1))
    EnterLong();
    else if (CrossBelow(smaFast, smaSlow, 1))
    EnterShort();
    lastHeikenAshiClose = heikenAshi.Close;
    lastHeikenAshiOpen = heikenAshi.Open;
    }
    private int GetActivationBarTime()
    {
    var currentTime = Time[0];
    var activationBarTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, (int)Math.Floor(currentTime.Minute / (double)timeFrame) * timeFrame, 0);

    if (activationBarTime.Minute != lastBarTime)
    return activationBarTime.Minute;

    return 0;
    region Properties
    [Range(1, int.MaxValue), NinjaScriptProperty]
    {[Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]}}
    public int Fast;}}
    { get; set; }

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
    public int Slow
    { get; set; }
    #endregion
    }
    }


    Anyways, the strategy idea is using the 9 and 1 MA crossover for a 3 min heikin ashi timeframe that begins at 0930 to 1600. The trade exits once another crossover takes place. I need help building this strategy code. As I'm still learning python, explanations would be great also.

    #2
    Hello Komets,

    From our experience at this time, ChatGpt is not quite adequate to generate valid compilable NinjaScripts that function as the user has intentioned. We often find that the generated code will call non-existent properties and methods, use improper classes or inheritance, and may have incorrect logic. We highly encourage that you create a new NinjaScript yourself using the NinjaScript Editor, and use the help guide for direction on learning NinjaScript concepts.

    While It would not be within our support model to correct these scripts, we would be happy to provide insight for any direct specific inquiries you may have if you would like to create this script yourself. Our support is able to assist with finding resources in our help guide as well as linking to simple examples.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​

    Comment


      #3
      Thank you for the response. I have checked out the consultant ecosystem and I may have to go through that route due to the complexity of the code I want to build.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      560 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      325 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X