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

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.

    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;

        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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by yertle, Yesterday, 08:38 AM
            7 responses
            28 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by bmartz, 03-12-2024, 06:12 AM
            2 responses
            20 views
            0 likes
            Last Post bmartz
            by bmartz
             
            Started by funk10101, Today, 12:02 AM
            0 responses
            4 views
            0 likes
            Last Post funk10101  
            Started by gravdigaz6, Yesterday, 11:40 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by MarianApalaghiei, Yesterday, 10:49 PM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X