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

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.​
    JesseNinjaTrader Customer Service

    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 fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X