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

Multi Time Frame MTF Moving average SMA, EMA, WMA for NT8

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

    #16
    Hello Manu2356,

    I'm not certain I am understanding when you are stating: "I don't know how to assign secondary to value[0].

    Values[0] (plural) will be the first added plot added with AddPlot().

    This would be returned by the getter for the public Series<double> MomentumColoredSecondary.

    Then MomentumColoredSecondary would have the value set, and this would cause the plot to appear on the chart.

    Currently, it set to transparent, but you are wanting to change the color.

    Setting MomentumColoredSecondary[0] would also set Values[0][0] as this is returned in the getter.

    PlotBrushes would then set the bar color of that plot for each bar.

    May I see the code to confirm MomentumColoredSecondary returns Values[0]?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Ok, I finally assigned MomentumColoredSecondary[0] to Value[0] and It works. I joined a snapshot.
      Attached Files

      Comment


        #18
        Hi Chelsea B,

        I did solve the problem as written above. Thank you very much for your help, it gave me clues on about to solve it.

        Thanks

        Comment


          #19
          Chelsea B,

          I post the code here. Could you tell me if it's wrong ? Thanks in advance


          public class MomentumColoredMTF : Indicator
          {
          private Momentum MomentumColored1;
          private Momentum MomentumColored2;

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"";
          Name = "MomentumColoredMTF";
          Calculate = Calculate.OnBarClose;
          IsOverlay = true;
          DisplayInDataBox = true;

          BarsRequiredToPlot = 14;
          Period = 7;

          // AddPlot(Brushes.Transparent, NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionMomentum);
          AddPlot(Brushes.Green, "MomentumColored Primary Series");

          AddPlot(Brushes.DarkCyan, "MomentumColored Secondary Series");
          AddLine(Brushes.SlateBlue, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
          }
          else if (State == State.Configure)
          {
          // Adds a secondary bar object to the indicator
          AddDataSeries(BarsPeriodType.Minute, 15);
          }
          else if (State == State.DataLoaded)
          {
          // initialize the MomentumColored using the primary series and assign to MomentumColored1
          MomentumColored1 = Momentum(BarsArray[0], Period);
          // initialize the MomentumColored using the secondary 5 minute series and assign to MomentumColored1
          MomentumColored2 = Momentum(BarsArray[1], Period);
          }
          }

          protected override void OnBarUpdate()
          {
          Print(string.Format("{0} | MomentumColoredSecondary[0]: {1}", Time[0], MomentumColoredSecondary[0]));
          Print(string.Format("{0} | Values[0][0]: {1}", Time[0], Values[0][0]));
          Print(string.Format("{0} | MomentumColoredPrimary[0]: {1}", Time[0], MomentumColoredPrimary[0]));
          Print(string.Format("{0} | Value[0]: {1}", Time[0], Value[0]));

          // ensure both series have at least one bar
          if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
          return;

          // when the 15 minute series is processing set the secondary plot to the MomentumColored with the secondary series input
          if (BarsInProgress == 1)
          MomentumColoredSecondary[0] = MomentumColored2[0];

          // when the primary series is processing set the primary plot to the MomentumColored with the primary series input
          if (BarsInProgress == 0)
          {
          MomentumColoredPrimary[0] = MomentumColored1[0];

          // if the secondary 15 minute series did not close, set the current bar's value to the previous bar's value to prevent gaps
          if (!MomentumColoredSecondary.IsValidDataPoint(0))
          MomentumColoredSecondary[0] = MomentumColoredSecondary[1];
          }

          // here assign to value[0] the momentumcolored secondary
          Value[0] = MomentumColoredSecondary[0];


          if(Value[0] > 0)
          {
          PlotBrushes[0][0] = Brushes.Lime;
          }
          else if(Value[0] < 0)
          {
          PlotBrushes[0][0] = Brushes.Red;
          }
          }

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MomentumColoredPrimary
          {
          get { return Values[0]; }
          }

          [Browsable(false)]
          [XmlIgnore]
          public Series<double> MomentumColoredSecondary
          {
          get { return Values[1]; }
          }

          Comment


            #20
            Hello Manu2356,

            Is the plot being colored lime when Value[0] is greater than 0 in the prints?

            If so, that would imply the code is correct.

            If not, add a print above where PlotBrushes is being assigned to ensure that condition is evaluating as true.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Hi Chelsea B,

              Yes, the plot is being colored lime when Value[0] is above 0. It works fine. Thank you for your help.

              Comment


                #22
                is there an open code version of the multi-time frame Sma and EMAs etc... that can be posted here would be much appreciated. i understand how to do it by adding a second data series to my chart however it is conflicting with some drawing tools i use so trying to find this version posted earlier but open code so can change the lengths etc... thank you!

                Comment


                  #23
                  ayahh not sure where i got this but found it in my archives (so sincere credit to them for sure...just wish i remember :-) .... this is a multi-time frame EMA and SMA hope it helps ... code is open to tinker with ... just post back here if you make any enhancements thank you!
                  Attached Files

                  Comment


                    #24
                    Originally posted by chinapassage View Post
                    ayahh not sure where i got this but found it in my archives (so sincere credit to them for sure...just wish i remember :-) .... this is a multi-time frame EMA and SMA hope it helps ... code is open to tinker with ... just post back here if you make any enhancements thank you!
                    Hi, thank you so much for this indicator. There is however one thing hat i would like you to correct if possible. I would like the moving average to only display on timeframes lower than of the time frame that it is. Example: If i am using 20sma of 60m timeframe, i would like the htf sma to be hidden on 60m chart and above. Thank you and best regards.

                    Comment


                      #25
                      i am not a coder....good luck if you get it done do repost it.

                      Comment


                        #26
                        Hi, I found the VisEMA indicator by Romus which is posted as an open code on futures.io. https://futures.io/local_links.php?linkid=2321
                        1. Looking at the code, it's fairly simple. Simply add the minutes data series based on the desired number of minutes you need.
                        2. If you need multiple periods, just use a 1 minute data series and multiply the desired period by the number of minutes you need. This is not the same but very close. Look at the volume bar Chart I used. The red line is a 5 minute EMA with period 20, and the blue is a 1 minute EMA with 100 period.
                        3. You can add this simple code directly to a Strategy simply by adding a plot and these few lines of come in the strategy itself.
                        Click image for larger version  Name:	Screenshot 2023-05-10 at 10.53.56.png Views:	0 Size:	825.7 KB ID:	1250802

                        Hope this can help.

                        Shai

                        Comment


                          #27
                          hello,

                          when using the MTFMA indicator I can depict the hour1 10 EMA on the 1 min time frame perfectly, but switching to the Day1 TF without changing anything else just results in a horizontal line.

                          there are enough bars and I have tried changing everything I can, but it wont show that EMA.

                          does anyone have that problem or know the solution?
                          Attached Files
                          Last edited by hansintakt; 08-01-2023, 01:45 AM.

                          Comment


                            #28
                            I am looking for a EMA that is based on either the high or low of the price bar?

                            Comment


                              #29
                              Hello gjbeaudin,

                              Use the Low series as the input series for the indicator.

                              In code, supply the Low as the Input parameter.


                              On chart click Input series and select the Low series.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DayTradingDEMON, Today, 09:28 AM
                              2 responses
                              15 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by Stanfillirenfro, Today, 07:23 AM
                              8 responses
                              23 views
                              0 likes
                              Last Post Stanfillirenfro  
                              Started by navyguy06, Today, 09:28 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              8 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by helpwanted, Today, 03:06 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Working...
                              X