Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Avg Range indicator

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

    Avg Range indicator

    I want to create an indicator with the following condition " if the 14 EMA of current bar range is 50% greater than the14 EMA of previous bar range" here is my code

    if (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1]) * (1 + 50))

    I'm not getting the desired plot, can someone please help correct this?

    #2
    Originally posted by chakriare View Post
    I want to create an indicator with the following condition " if the 14 EMA of current bar range is 50% greater than the14 EMA of previous bar range" here is my code

    if (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1]) * (1 + 50))

    I'm not getting the desired plot, can someone please help correct this?
    Your code contains 1 + 50 = 51. This cannot work. Please replace "1 + 50" with "1.5".

    Comment


      #3
      yes, I changed to 1.5, still not working. I changed to compare just with previous bar (ignoring 50%) but still not working.

      (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1]) ...this is not working too.

      Comment


        #4
        Originally posted by chakriare View Post
        yes, I changed to 1.5, still not working. I changed to compare just with previous bar (ignoring 50%) but still not working.

        (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1]) ...this is not working too.
        This line should work, but something else does not work. If you wish us to find the bug, you would need to post the entire code that you have created and not just one line.

        Comment


          #5
          Hello chakriare,

          Based on your original statement:
          if the 14 EMA of current bar range is 50% greater than the14 EMA of previous bar range
          This would be the correct condition:
          Code:
          if(EMA(Range(), 14)[0] > (EMA(Range(), 14)[1] * 1.5))
          {
          //Do something
          }
          This indicates that either you are trying to do something else or you have your condition in the wrong place in your code.

          Please provide additional information or the surrounding code you are using so we can better assist.

          Thank you in advance.
          Michael M.NinjaTrader Quality Assurance

          Comment


            #6
            Thanks all, still not working. I'm sure I'm doing wrong in the code or chart settings. here is my full code..

            protected override void OnBarUpdate()
            {
            //Add your custom indicator logic here.

            if (EMA(Range(), 14)[0] > (EMA(Range(), 14)[1] * 1.5))
            {

            Draw.Diamond(this, "MyDiamond" + CurrentBar.ToString(), false, 0, High[0] + 2 * TickSize, Brushes.Blue);
            }

            }

            Comment


              #7
              Hello chakraire,

              Thank you for the update. Could you please let me know what is happening when this is applied to a chart and whether this is code from a strategy or an indicator?

              Thank you in advance.
              Michael M.NinjaTrader Quality Assurance

              Comment


                #8
                its an indicator (price overlay is true so there is no separate plot). I would expect the blue dots above the price bar when the condition is true on the chart, and I"m not even seeing one blue dot in the last 4 months. I changed the if condition to something simple (like close >open), just to check if anything wrong on the chart settings, but with that condition it is accurately plotting the blue dots. however when I change it back to actual logic its not plotting.

                Comment


                  #9
                  Hello Chakriare,

                  Thank you for the update. You are likely getting an error in your log and the indicator is not running because you are trying to access an index which is out of range. Please add the following code to the top of your OnBarUpdate() method and let me know if the issue persists:
                  Code:
                  if(CurrentBar < 1) return;
                  Thank you in advance.
                  Michael M.NinjaTrader Quality Assurance

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kazisl, Today, 06:41 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post kazisl
                  by kazisl
                   
                  Started by einstein, Today, 06:20 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post einstein  
                  Started by op1031, Today, 05:51 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post op1031
                  by op1031
                   
                  Started by nighttrader99, Today, 04:34 PM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_ShawnB  
                  Started by Simon Investimens, Today, 02:51 PM
                  1 response
                  15 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Working...
                  X