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

Moving Average Stop

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

    Moving Average Stop

    I am attempting to add another data series to the SMA indicator that plots a line a specified percent below the SMA that I can use as a type of trailing stop. Here is what I have so far:

    In Variables region I added
    private DataSeries smaStop;

    In Initialization section
    Add(new Plot(Color.Blue, "SMA"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Hash, "smaStop"));
    smaStop = new DataSeries(this);

    OnBarUpdate () method
    // the added smaStop code to go here similar to below
    // with idea to trail SMA
    smaStop.Set(SMA(20)[0]*0.97);
    An image similar to what I want to get is
    The image above is the SMA 20 based on close(blue line) and SMA 20 based on low(red hash line). However, what I would like to achieve is the SMA line and a hash line based on a percent below the SMA line. Your help is appreciated. Thanks, Jim
    Attached Files

    #2
    Not sure I follow you. Isn't what you want already what you have created already?
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh for your reply,

      Please take a look at the code I have attached as a modified version of the SMA indicator. It fails to plot a second DataSeries and only plots the SMA, though the smaStop does appear in the Data Box but without any value.
      Last edited by winja; 05-18-2009, 09:20 PM.

      Comment


        #4
        winja,

        You have not created two plots. You need to add them into the Properties region of your code when you use more than one plot. Please see the MACD indicator for an example.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh,

          I have attached a corrected version which works well for those who may be interested. Please see post 8 above.
          Attached Files
          Last edited by winja; 05-19-2009, 04:46 PM.

          Comment


            #6
            Thanks winja
            Is it possible to make the indicator enable for different types of moving average
            and percent of the stop below 1 ?
            Have a nice day

            Comment


              #7
              Thanks Primoto for the suggestion. I have modified the indicator as you requested however I am having a problem exporting it to an archive file. As soon as I can do that I will post it.

              Comment


                #8
                Here is the finished version with choice of moving average type: SMA, EMA, HMA, or WMA. The moving average stop is displayed by a colored dot and is offset from the moving average by tenths of a percent. I have set the moving average default color to transparent and only the stop dots appear.
                Attached Files

                Comment


                  #9
                  Thanks for sharing this winja!
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Well done winja , thanks

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by cre8able, 02-11-2023, 05:43 PM
                    3 responses
                    236 views
                    0 likes
                    Last Post rhubear
                    by rhubear
                     
                    Started by frslvr, 04-11-2024, 07:26 AM
                    8 responses
                    113 views
                    1 like
                    Last Post NinjaTrader_BrandonH  
                    Started by stafe, 04-15-2024, 08:34 PM
                    10 responses
                    46 views
                    0 likes
                    Last Post stafe
                    by stafe
                     
                    Started by rocketman7, Today, 09:41 AM
                    3 responses
                    11 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by traderqz, Today, 09:44 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X