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

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
    Paul H.NinjaTrader Customer Service

    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
          Paul H.NinjaTrader Customer Service

          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.
                  Paul H.NinjaTrader Customer Service

                  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 Tim-c, Today, 03:54 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post Tim-c
                      by Tim-c
                       
                      Started by FrancisMorro, Today, 03:24 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post FrancisMorro  
                      Started by Segwin, 05-07-2018, 02:15 PM
                      10 responses
                      1,770 views
                      0 likes
                      Last Post Leafcutter  
                      Started by Rapine Heihei, 04-23-2024, 07:51 PM
                      2 responses
                      31 views
                      0 likes
                      Last Post Max238
                      by Max238
                       
                      Started by Shansen, 08-30-2019, 10:18 PM
                      24 responses
                      945 views
                      0 likes
                      Last Post spwizard  
                      Working...
                      X