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 TimePeriod SMA color rising/falling problem

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

    Multi TimePeriod SMA color rising/falling problem

    Hi, im trying to make a SMA applied to a 60Min bars, but on a 15 Min chart, to change colors from rising to falling, however, since it has intervals between the "steps" i dont know how to accomplish this,

    this is the idea

    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Trend"));
    Add(PeriodType. Minute , 60);



    protected override void OnBarUpdate()
    {

    Trend.Set( Inputs[1] );


    if (Trend[0] > Trend[1] )
    {


    {PlotColors[0][0]= risingAverage;}


    }
    else if (Trend[0] < Trend[1] )
    {


    { PlotColors[0][0]= fallingAverage;}


    }


    but the thing is it doesn't works because it looks like a stepMA, any help will be appreciated

    #2
    Hello
    You need to filter your code using the BarsInProgress property. Please refer to our help guide to know more about it.


    A sample code will be like
    Code:
    protected override void OnBarUpdate()
    {
               if (this.BarsInProgress == 0)
               {
    	            Value.Set(SMA(Closes[1], period)[0]);
               }
    }
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hi, thanks for pointing me to the right direction Joydeep, i been reading the help and got a couple doubts cleared, tho i cant really understand how do i properly color the resulting average , this is how it looks

      Click image for larger version

Name:	$AUDUSD (3-3 Dynamic Momentum No-Gap)  28_09_2012.jpg
Views:	1
Size:	54.8 KB
ID:	866121


      this is my script

      protected override void OnBarUpdate()
      {




      if (CurrentBars[0] <= period || CurrentBars[1] <= period) return;

      double maValue = 0;

      switch (matype)
      {
      case 1:
      {
      MAverage.Set(maValue = EMA(Inputs[1], period)[0]);
      MAverageB.Set(maValue = EMA(Inputs[1], ( period +2))[0]);
      break;
      }
      case 2:
      {
      MAverage.Set( maValue =HMA(Inputs[1], period)[0]);
      MAverageB.Set(maValue = HMA(Inputs[1], ( period +2))[0]);
      break;
      }
      case 3:
      {
      MAverage.Set( maValue =SMA(Inputs[1], period)[0]);
      MAverageB.Set(maValue = SMA(Inputs[1], ( period +2))[0]);
      break;
      }
      case 4:
      {
      MAverage.Set( maValue =TMA(Inputs[1], period)[0]);
      MAverageB.Set(maValue = TMA(Inputs[1], ( period +2))[0]);
      break;
      }
      case 5:
      {
      MAverage.Set( maValue =TEMA(Inputs[1], period)[0]);
      MAverageB.Set(maValue = TEMA(Inputs[1], ( period +2))[0]);
      break;
      }
      case 6:
      {
      MAverage.Set(maValue =WMA(Inputs[1], period)[0]);
      MAverageB.Set(maValue = WMA(Inputs[1], ( period +2))[0]);
      break;
      }
      case 7:
      {
      MAverage.Set( maValue =T3(Inputs[1], period ,3,0.7 )[0]);
      MAverageB.Set( maValue =T3(Inputs[1], ( period +2) ,3,0.7 )[0]);
      break;
      }
      }





      if (BarsInProgress == 1)
      {

      if (MAverage[0] > MAverage[1] )
      {


      Trend.Set(1);

      {PlotColors[0][0]= risingAverage;}
      { PlotColors[2][0]= risingAverage;}
      }
      else if (MAverage[0] < MAverage[1] )
      {
      Trend.Set(-1);

      { PlotColors[0][0]= fallingAverage;}
      { PlotColors[2][0]= fallingAverage;}
      }

      }


      i mean, i have to access the "MAverage" of the secondary period, how do i accomplish that?


      Hope you can help me, please, will be much appreciated
      Last edited by kabott; 09-28-2012, 09:30 AM.

      Comment


        #4
        Hello kabott,
        To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

        Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

        I look forward to assisting you further.

        *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          here it is Joydeep, the actual thingy, thanks so much man , you r tha best
          Last edited by kabott; 09-28-2012, 11:44 AM.

          Comment


            #6
            Hello kabott,
            Thanks for the code.

            The data series for the plot values are synced with your primary chart (15 minute chart). However since you are calculating the MA values based on the secondary data series, you need to create the DATA POINTS based on the secondary series.

            Please refer to this sample NinjaScript strategy which demonstrates how to do it
            Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series&lt;T&gt; (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for



            Also, the you have to color the plots in the primary bar only (BarsInProgress == 0) and not via the secondary series as you have done.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Hi again, does someone has/knows a multi-timeframe simple ma indicator i can install and study how the script works? its been a week or so and i have failed miserably to make the line smoothed as it should be.

              thanks in advance

              Comment


                #8
                Hello kabott,
                Please find the attached indicator which calculates the SMA based on a one minute timeframe.

                Please let me know if I can assist you any further.
                Last edited by NinjaTrader_Joydeep; 10-10-2012, 08:56 AM.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  hi Joydeep, thanks for the indie, but isnt showing up on the chart?

                  Comment


                    #10
                    Hello kabott,
                    My apologies, please try this indicator. It draws the SMA based on a 30 minute bar.
                    Attached Files
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      lol, now i feel better.. it happens to the bests

                      Comment


                        #12
                        Im sorry, i should have been more specific , my problem is the plot looks staggered, i have seen other multi timeframe ma's that doesn't look like that, the line is smooth as it should be if plotted directly on the higher time frame, you told me before this was acomplished using dataseries. and i have tried & tried .. but i just wished i just had a simple completed example to really understand why isnt working for me, i have other indicators that r multi timeframe, but they r very complex and with lots of extras that only get me more confused (one of them is called "xcMovAvg" i got it from this forum) i have done & redone many attempts .. thanks for the effort Joydeep
                        Last edited by kabott; 10-10-2012, 09:17 AM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by bortz, 11-06-2023, 08:04 AM
                        47 responses
                        1,602 views
                        0 likes
                        Last Post aligator  
                        Started by jaybedreamin, Today, 05:56 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post jaybedreamin  
                        Started by DJ888, 04-16-2024, 06:09 PM
                        6 responses
                        18 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by Jon17, Today, 04:33 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post Jon17
                        by Jon17
                         
                        Started by Javierw.ok, Today, 04:12 PM
                        0 responses
                        12 views
                        0 likes
                        Last Post Javierw.ok  
                        Working...
                        X