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

mme 10 and 20 histogram

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

    mme 10 and 20 histogram

    Hello,
    Sorry for my english i am french


    I would like to develop an indicator as an histogram in green and it says to buy and red when it says to sell

    it is based on the mme 10 and 20, the crossover of them

    is this code correct ? because i dont arrive to compile it in ninjascript editor, there are error messages
    thank you



    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class MMECrossHistogram : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Histogram for EMA 10 and EMA 20 Crossings";
    Name = "MMECrossHistogram";
    Calculate = Calculate.OnEachTick;
    IsOverlay = false;
    DisplayInDataBox = true;
    }
    else if (State == State.DataLoaded)
    {
    AddPlot(new Stroke(Brushes.Transparent, 2), PlotStyle.Histogram, "Histogram");
    }
    }

    protected override void OnBarUpdate()
    {
    double ema10 = EMA(Close, 10)[0];
    double ema20 = EMA(Close, 20)[0];

    if (CrossAbove(ema10, ema20, 1))
    {
    PlotBrushes[0][0] = Brushes.Green;
    PlotValues[0][0] = ema10 - ema20;
    }
    else if (CrossBelow(ema10, ema20, 1))
    {
    PlotBrushes[0][0] = Brushes.Red;
    PlotValues[0][0] = ema10 - ema20;
    }
    else
    {
    PlotBrushes[0][0] = Brushes.Transparent;
    PlotValues[0][0] = 0;
    }
    }
    }
    }​






    Last edited by Esteban890; 08-09-2023, 05:45 AM.

    #2
    Hello Esteban890,

    The PlotValues is not correct, if you are trying to set a plot that is Value[0]. You can see some examples of setting a plot here: https://ninjatrader.com/support/help...ghtsub=addplot

    The EMA use is also not correct, you can see an example of calling the EMA here: https://ninjatrader.com/support/help...onential_e.htm

    There is an example of using the EMA with the crossabove condition here: https://ninjatrader.com/support/help...sub=CrossAbove
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello Esteban890,

      The PlotValues is not correct, if you are trying to set a plot that is Value[0]. You can see some examples of setting a plot here: https://ninjatrader.com/support/help...ghtsub=addplot

      The EMA use is also not correct, you can see an example of calling the EMA here: https://ninjatrader.com/support/help...onential_e.htm

      There is an example of using the EMA with the crossabove condition here: https://ninjatrader.com/support/help...sub=CrossAbove
      Hello Jesse, and thank you very much for your help . Actually, to be honest, I'm not a good developer in addition to not speaking English well I've been pulling my hair out for hours to generate good code. Despite your links, thank you for those, I still can't do it. I'd be very grateful if you could give me the code for what I'm looking for, either the generation of the histogram from the ema 10 and 20, or a buy or sell signal appearing on the chart. I'm aware that my request is a bit daring, but I'm trying because to be honest I'm starting to get desperate. Thanks in advance

      Comment


        #4
        Hello Esteban890,

        Our support cannot create or debug custom items for you but we can assist with questions you have surrounding your own learning. If you are not clear on any of the parts from the links we could go over those items in more detail. You can also look at the built in indicators for some examples of how indicators are coded and how to plot values. If you want to have items created for you you can also reach out to a third party developer, if you would like further information on that topic I can have another member of our team post information about how to contact developers.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello, I understand Jesse very well, there's nothing to worry about. My request was a bit daring, I admit. If everyone did the same, you wouldn't have time for anything. I'll try to fix the errors in my code thanks to your links or the help of a developer. Thank you very much and have a nice day.

          Comment


            #6
            Hello Jesse and everybody
            Do you think the next code is correct ? thanks


            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.Gui.Tools;
            using NinjaTrader.Data;
            using NinjaTrader.NinjaScript;
            using NinjaTrader.Core.FloatingPoint;
            using NinjaTrader.NinjaScript.DrawingTools;
            #endregion

            //This namespace holds Indicators in this folder and is required. Do not change it.
            namespace NinjaTrader.NinjaScript.Indicators
            {
            public class Crossmme : Indicator
            {
            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Entrer la description du nouveau Indicateur ici.";
            Name = "Crossmme";
            Calculate = Calculate.OnBarClose;
            IsOverlay = false;
            DisplayInDataBox = true;
            DrawOnPricePanel = true;
            DrawHorizontalGridLines = true;
            DrawVerticalGridLines = true;
            PaintPriceMarkers = true;
            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
            //Disable this property if your indicator requires custom values that cumulate with each new market data event.
            //See Help Guide for additional information.
            IsSuspendedWhileInactive = true;
            }
            else if (State == State.Configure)
            {
            }
            }
            private double ema10Value;
            private double ema20Value;
            protected override void OnBarUpdate()
            {
            ema10Value = EMA(Close, 10)[0];
            ema20Value = EMA(Close, 20)[0];
            //Ajouter le logique personnalisée pour indicator ici.
            if (CrossAbove(ema10Value, ema20Value, 1))
            {
            Draw.ArrowUp(this, "SignalAchatArrow" + CurrentBar, true, 0, Low[0] - TickSize * 5, Brushes.Green);
            Draw.ArrowDown(this, "SignalVenteArrow" + CurrentBar, false, 0, High[0] + TickSize * 5, Brushes.Transparent);
            }
            else if (CrossBelow(ema10Value, ema20Value, 1))
            {
            Draw.ArrowDown(this, "SignalVenteArrow" + CurrentBar, true, 0, High[0] + TickSize * 5, Brushes.Red);
            Draw.ArrowUp(this, "SignalAchatArrow" + CurrentBar, false, 0, Low[0] - TickSize * 5, Brushes.Transparent);
            }
            else
            {
            Draw.ArrowUp(this, "SignalAchatArrow" + CurrentBar, false, 0, Low[0] - TickSize * 5, Brushes.Transparent);
            Draw.ArrowDown(this, "SignalVenteArrow" + CurrentBar, false, 0, High[0] + TickSize * 5, Brushes.Transparent);
            }
            }
            }
            }
            }

            region NinjaScript generated code. Neither change nor remove.

            namespace NinjaTrader.NinjaScript.Indicators
            {
            public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
            {
            private Crossmme[] cacheCrossmme;
            public Crossmme Crossmme()
            {
            return Crossmme(Input);
            }

            public Crossmme Crossmme(ISeries<double> input)
            {
            if (cacheCrossmme != null)
            for (int idx = 0; idx < cacheCrossmme.Length; idx++)
            if (cacheCrossmme[idx] != null && cacheCrossmme[idx].EqualsInput(input))
            return cacheCrossmme[idx];
            return CacheIndicator<Crossmme>(new Crossmme(), input, ref cacheCrossmme);
            }
            }
            }

            namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
            {
            public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
            {
            public Indicators.Crossmme Crossmme()
            {
            return indicator.Crossmme(Input);
            }

            public Indicators.Crossmme Crossmme(ISeries<double> input )
            {
            return indicator.Crossmme(input);
            }
            }
            }

            namespace NinjaTrader.NinjaScript.Strategies
            {
            public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
            {
            public Indicators.Crossmme Crossmme()
            {
            return indicator.Crossmme(Input);
            }

            public Indicators.Crossmme Crossmme(ISeries<double> input )
            {
            return indicator.Crossmme(input);
            }
            }
            }

            #endregion​

            Comment


              #7
              Hello Esteban890,

              Does it work when you run it? As mentioned our support cannot provide debugging services, testing the scripts you may would be part of the development process that you would go through. If you are getting a compile error or having a problem with that code I would suggest to include the error you are seeing or point out which line of code you needed help with.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Hello Jesse, I understand, there is no problem. Thank you for your reply have a nice day

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by KonAdams, 05-07-2024, 10:53 PM
                9 responses
                25 views
                0 likes
                Last Post KonAdams  
                Started by haas88, 03-21-2024, 02:22 AM
                16 responses
                193 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by JimB17, 01-10-2020, 10:27 AM
                75 responses
                2,792 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by JGriff5646, 05-07-2024, 10:02 PM
                3 responses
                29 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by dp8282, Today, 07:35 AM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Erick  
                Working...
                X