• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATR trailing stop indicator in Market Analyzer

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

    ATR trailing stop indicator in Market Analyzer

    Hi,
    I want to use ATR trailing stop indicator in market analyzer. I want to plot "Signal" (price is above ATR trailing, show UP, price is below ATR trailing, show DOWN". How should I modify the code? Thanks for your help.


    Frank
    Attached Files

    #2
    Hello ljiangd,

    Thank you for your post.

    The value in the Market Analyzer column will need to be a plot. You could set the plot to 1 for Up and -1 for Down, then use a Cell Condition in the Market Analyzer to change the cell to display the text "UP" or "DOWN".

    For information on Cell Conditions please visit the following link: http://www.ninjatrader.com/support/h..._and_filte.htm

    Please let me know if I may be of further assistance.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      The value in the Market Analyzer column will need to be a plot.

      The value in the Market Analyzer column will need to be a plot.
      But I don't know how to modify the code to make that a plot? Can you please help? Thanks.

      Comment


        #4
        Hello Frank,

        Thank you for your response.

        Below is an example:
        Code:
                protected override void Initialize()
                {
                    Add(new Plot(Color.Blue, PlotStyle.Line, "Trailing Stop"));
        			Add(new Plot(Color.Red, PlotStyle.Line, "Signal"));
                    CalculateOnBarClose	= true;
                    Overlay				= true;
        			BarsRequired = 1;
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
        			if (CurrentBar < 1)
        				return;
        
        			// Trailing stop
        			double trail;
        			double loss = ATR(Input, Period)[0] * Multi;
        			
        			if (Close[0] > Value[1] && Close[1] > Value[1])
        				trail = Math.Max(Value[1], Close[0] - loss);
        			
        			else if (Close[0] < Value[1] && Close[1] < Value[1])
        				trail = Math.Min(Value[1], Close[0] + loss);
        				
        			else if (Close[0] > Value[1])
        			{
        				trail = Close[0] - loss;
        				DrawArrowDown(CurrentBar.ToString(), false, 1, Value[1], Color.Orange);
        			}
        			
        			else
        			{
        				trail = Close[0] + loss;
        				DrawArrowUp(CurrentBar.ToString(), false, 1, Value[1], Color.Orange);
        			}
        
                    Values[0].Set(trail);
        			
        			if(Values[0][0] < Close[0])
        				Values[1][0] = 1;
        			else if(Values[0][0] > Close[0])
        				Values[1][0] = -1;
        			else
        				Values[1][0] = 0;
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Hi Patrick,
          I modified the code based on your suggestion. But now the indicator has 2 plots. One is "Signal" and it shows +1 and -1 value on the chart. Makes the chart unreadable. On the market analyzer, there is no option for the Signal plot. Can you please take another look? Thanks again.

          Comment


            #6
            Hello ljiangd,

            That was just an example to show you how to create a plot. I would recommend reviewing the information on plots at the following link: http://www.ninjatrader.com/support/h...plot_class.htm
            Patrick H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by davidwade, Today, 02:51 AM
            0 responses
            1 view
            0 likes
            Last Post davidwade  
            Started by aviat72, 04-26-2020, 09:41 PM
            10 responses
            90 views
            0 likes
            Last Post kissandfly  
            Started by healthooa, Today, 01:28 AM
            0 responses
            7 views
            0 likes
            Last Post healthooa  
            Started by superkolleech, Today, 12:46 AM
            0 responses
            9 views
            0 likes
            Last Post superkolleech  
            Started by harjinderjit, Yesterday, 08:24 PM
            0 responses
            20 views
            0 likes
            Last Post harjinderjit  
            Working...
            X