Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EMA on a Slope

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

    EMA on a Slope

    Hi, I am looking to create a EMA on a Slope, portion of the script is.

    private EMA, MyTrigger;
    private double Angle, MySlope;

    SLope = (MMB[0]-MMB[nbchandelierB]) / nbchandelierA * 180 / Math.PI; // ERROR on this line.

    MyTrigger = EMA(MySLope, nbchandelierB+lag);
    CondBuy2 = (MySLope > MyTrigger[0]) && (MySlope < 0);

    I am getting an error "The best Overloaded method match for NinjaTrader.NinjaScript.Strategy.EMA(NinjaTrader.N injaScript,Iseries<double>,int)' has some invalid arguments
    Argument 1 cannot convert from 'double' to NinjaTrader.NinjaScript,Iseries<double>.

    Please help, thanks, Marcelo

    #2
    Hello Marcelo,

    Thanks for your post.

    On this line: EMA(MySLope, nbchandelierB+lag); The issue would be that MySlope is a single double value and the EMA() method requires the first parameter to be a double data series. Also the second parameter, for the period of the EMA should be integer based. Please see the help guide here: https://ninjatrader.com/support/help...onential_e.htm

    Comment


      #3
      Thanks Paul, is there a way to assign the whole Iseries chain to MySlope?

      Comment


        #4
        Variables section;
        private DataSeries MySlope;
        private double SLope;

        Initialize() section:
        MySlope = new DataSeries(this);

        OnBarUpdate() section:
        (Calculate for SLope first)
        MySlope.Set(SLope);
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          Hello Marcelo,

          Thanks for your reply.

          Member eDanny has provided some detail to help.

          Where he refers to Initialize() (an NT7 method) in NT8 you would create the new series in State.DataLoaded of the OnStateChange().

          Reference: https://ninjatrader.com/support/help...tatechange.htm

          Comment


            #6
            Thanks eDanny and Paul, I tried what Danny mentioned but still not working, I am getting the type or namespace name 'DataSeries' cound not be found. (are you missing a using directive or an assembly reference?)

            Am I missing something? Thanks again!

            below the code

            public class BotMedicionAngulos: Strategy
            {
            private bool HorarioHabilitado=false;
            private int ResetSL, nbchandelierA, nbchandelierB;
            private int NivelStop, PeriodeA, PeriodeB, lag;
            private EMA ema40v10m;
            private EMA ema40v1h, MMA, MMB, MyTrigger;
            private bool CondBuy1, CondSell1, CondBuy2, CondSell2;
            private double Angle, Pente, SLope;
            private DataSeries MySlope;

            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Enter the description for your new custom Strategy here.";
            Name = "BotMedicionAngulo";
            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 = true;
            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;
            Target = 400;
            Stop = 200;
            }
            else if (State == State.Configure)
            {
            AddDataSeries("ES 09-19", Data.BarsPeriodType.Minute, 2, Data.MarketDataType.Last);
            AddDataSeries("ES 09-19", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);

            }
            else if (State == State.DataLoaded)
            {
            // EMAPeriod = 10;
            // SlopePeriod = 14;
            PeriodeA = 10;
            nbchandelierA = 15;
            PeriodeB = 20;
            nbchandelierB = 35;
            lag = 5;
            MMA = EMA(PeriodeA);
            MMB = EMA(PeriodeB);
            MySlope = new DataSeries(this);
            ClearOutputWindow();
            SetProfitTarget(@"", CalculationMode.Currency, Target);
            SetStopLoss("", CalculationMode.Currency, Stop, false);
            }
            }



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

            if (CurrentBars[0] < nbchandelierB)
            return;
            try
            {
            Angle=Math.Atan(Slope(EMA (Close, PeriodeA), nbchandelierA,0)) * 180 / Math.PI;
            CondBuy1 = Angle >= 45;
            CondSell1 = Angle <= - 37;

            Slope=Math.Atan(Slope(EMA (Close, PeriodeB), nbchandelierB,0)) * 180 / Math.PI;
            // MyTrigger = EMA(Pente, nbchandelierB+lag);
            MySlope.Set(EMA(SLope, nbchandelierB+lag));
            CondBuy2 = (Pente > MyTrigger[0]) && (Pente < 0);
            CondSell2 = (CrossBelow(Pente,MyTrigger,1)) && (Pente > -1);
            Print (Time[0] + "|Close[0]: |"+ Close[0] + "|MMA[0]: |" + MMA[0] + "|MMA[nbchandelierA]: |" + MMA[nbchandelierA] + "|nbchandelierA: |" + nbchandelierA + "|Angle: |" + Angle + "|MMB[0]: |" + MMB[0] + "|MMB[nbchandelierB]: |" + MMB[nbchandelierB] + "|nbchandelierB: |" + nbchandelierB + "|Pente: |" + Pente + "|Trigger[0]: |" + MyTrigger[0] + "|CondBuy1: |" + CondBuy1 + "|CondSell1:|" + CondSell1 + "|CondBuy2: |" + CondBuy2 + "|CondSell2:|" + CondSell2);

            }

            Comment


              #7
              Thanks for the answer Danny and Paul, I am still getting an error "the type or namespace name 'DataSeries' could not be found ( are you missing a using directive or an assembly reference?)

              Am I missing something?
              Below the full code, thanks again!

              public class BotMedicionAngulos: Strategy
              {
              private bool HorarioHabilitado=false;
              private int ResetSL, nbchandelierA, nbchandelierB;
              private int NivelStop, PeriodeA, PeriodeB, lag;
              private EMA ema40v10m;
              private EMA ema40v1h, MMA, MMB, MyTrigger;
              private bool CondBuy1, CondSell1, CondBuy2, CondSell2;
              private double Angle, Pente, SLope;
              private DataSeries MySlope;

              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Enter the description for your new custom Strategy here.";
              Name = "BotMedicionAngulo";
              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 = true;
              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;
              Target = 400;
              Stop = 200;
              }
              else if (State == State.Configure)
              {
              AddDataSeries("ES 09-19", Data.BarsPeriodType.Minute, 2, Data.MarketDataType.Last);
              AddDataSeries("ES 09-19", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);

              }
              else if (State == State.DataLoaded)
              {
              // EMAPeriod = 10;
              // SlopePeriod = 14;
              PeriodeA = 10;
              nbchandelierA = 15;
              PeriodeB = 20;
              nbchandelierB = 35;
              lag = 5;
              MMA = EMA(PeriodeA);
              MMB = EMA(PeriodeB);
              MySlope = new DataSeries(this);
              ClearOutputWindow();
              SetProfitTarget(@"", CalculationMode.Currency, Target);
              SetStopLoss("", CalculationMode.Currency, Stop, false);
              }
              }



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

              if (CurrentBars[0] < nbchandelierB)
              return;
              try
              {
              Angle=Math.Atan(Slope(EMA (Close, PeriodeA), nbchandelierA,0)) * 180 / Math.PI;
              CondBuy1 = Angle >= 45;
              CondSell1 = Angle <= - 37;

              Slope=Math.Atan(Slope(EMA (Close, PeriodeB), nbchandelierB,0)) * 180 / Math.PI;
              // MyTrigger = EMA(Pente, nbchandelierB+lag);
              MySlope.Set(EMA(SLope, nbchandelierB+lag));
              CondBuy2 = (Pente > MyTrigger[0]) && (Pente < 0);
              CondSell2 = (CrossBelow(Pente,MyTrigger,1)) && (Pente > -1);
              Print (Time[0] + "|Close[0]: |"+ Close[0] + "|MMA[0]: |" + MMA[0] + "|MMA[nbchandelierA]: |" + MMA[nbchandelierA] + "|nbchandelierA: |" + nbchandelierA + "|Angle: |" + Angle + "|MMB[0]: |" + MMB[0] + "|MMB[nbchandelierB]: |" + MMB[nbchandelierB] + "|nbchandelierB: |" + nbchandelierB + "|Pente: |" + Pente + "|Trigger[0]: |" + MyTrigger[0] + "|CondBuy1: |" + CondBuy1 + "|CondSell1:|" + CondSell1 + "|CondBuy2: |" + CondBuy2 + "|CondSell2:|" + CondSell2);

              }

              Comment


                #8
                Thanks for your answers, I am still getting an error message "the type or namespace name 'DataSeries' could not be found (are you missing a using directire or an assembly reference?)

                Am I missing something? thanks for the help.
                Below part of the code

                public class BotMedicionAngulos: Strategy
                {
                private bool HorarioHabilitado=false;
                private int ResetSL, nbchandelierA, nbchandelierB;
                private int NivelStop, PeriodeA, PeriodeB, lag;
                private EMA ema40v10m;
                private EMA ema40v1h, MMA, MMB, MyTrigger;
                private bool CondBuy1, CondSell1, CondBuy2, CondSell2;
                private double Angle, Pente, SLope;
                private DataSeries MySlope;

                else if (State == State.DataLoaded)
                {
                PeriodeA = 10;
                nbchandelierA = 15;
                PeriodeB = 20;
                nbchandelierB = 35;
                lag = 5;
                MMA = EMA(PeriodeA);
                MMB = EMA(PeriodeB);
                MySlope = new DataSeries(this);
                }

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

                if (CurrentBars[0] < nbchandelierB)
                return;
                try
                {
                Angle=Math.Atan(Slope(EMA (Close, PeriodeA), nbchandelierA,0)) * 180 / Math.PI;

                Slope=Math.Atan(Slope(EMA (Close, PeriodeB), nbchandelierB,0)) * 180 / Math.PI;
                MySlope.Set(EMA(SLope, nbchandelierB+lag));

                Print (Time[0] + "|Close[0]: |"+ Close[0] + "|MMA[0]: |" + MMA[0] + "|MMA[nbchandelierA]: |" + MMA[nbchandelierA] + "|nbchandelierA: |" + nbchandelierA + "|Angle: |" + Angle + "|MMB[0]: |" + MMB[0] + "|MMB[nbchandelierB]: |" + MMB[nbchandelierB] + "|nbchandelierB: |" + nbchandelierB + "|Pente: |" + Pente + "|Trigger[0]: |" + MyTrigger[0] + "|CondBuy1: |" + CondBuy1 + "|CondSell1:|" + CondSell1 + "|CondBuy2: |" + CondBuy2 + "|CondSell2:|" + CondSell2);

                }

                Comment


                  #9
                  Hello Marcelo,

                  Thanks for your reply.

                  It is difficult to answer with only part of the code displayed. If you would prefer discretion for your code, you are welcome to send the complete code file into PlatformSupport[at]NinjaTrader[dot] com. Mark the e-mail Atten Paul and ticket # 2266434, also please add a link in the text to this thread for reference.
                  Last edited by NinjaTrader_PaulH; 09-06-2019, 08:53 AM. Reason: removed unexpected character.

                  Comment


                    #10
                    My example was for NT7 since I didn't know which you were using. You will need to replace certain NT7 items with NT8 versions. private DataSeries MySlope; would change to private Series<double> MySlope; for example.
                    eDanny
                    NinjaTrader Ecosystem Vendor - Integrity Traders

                    Comment


                      #11
                      Thanks Danny and Paul, it was my first time using Series but now it works!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by NullPointStrategies, Today, 05:17 AM
                      0 responses
                      53 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      130 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      70 views
                      0 likes
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      44 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Started by TheRealMorford, 03-05-2026, 06:15 PM
                      0 responses
                      49 views
                      0 likes
                      Last Post TheRealMorford  
                      Working...
                      X