Estimate ATR low and high automatically

 

Hi,

How do I automatically estimate the ATR Low and High?

 
mrwick:

Hi,

How do I automatically estimate the ATR Low and High?

You have a value interval.. When it reaches high value it is considered high otherwise low this shall be an estimate ..how much atr value converges to that limit.
 
Marius Ovidiu Sunzuiana:
You have a value band.. When it reaches high band it is considered high otherwise low this shall be an estimate ..how much atr value converges to that limit.
Thanks Marius. I want to do it with code. At the moment I'm entering the estimate low and high manually but would love to automate as the Low/High are dynamic. I normally go into my code and change low/high every day.
 
mrwick: How do I automatically estimate the ATR Low and High?
  1. You have an array of values, either use ArrayMax/min, or
  2. Use a power mean
              Generalized mean - Wikipedia
    #define EMA(P, C, L) ((P) + ((C)-(P))*2./(L+1))
    // https://en.wikipedia.org/wiki/Generalized_mean#Special_cases (Power Mean)
    #define PMA(P, C, L, PM) MathPow(EMA(MathPow(P,PM), MathPow(C,PM), L), 1.0/PM)
    
    double tr = TR[iBar] = MathMax(Close[iBar+1], High[iBar]) - MathMin(Close[iBar+1], Low[iBar]);
    ATR[iBar] = iMAOnArray(TR, …);
    
    ATRmax[iBar] = PMA(ATRmax[iBar+1], tr, Length,  15);
    ATRmin[iBar] = PMA(ATRmin[iBar+1], tr, Length, -15);
 
William Roeder:
  1. You have an array of values, either use ArrayMax/min, or
  2. Use a power mean
              Generalized mean - Wikipedia

Yike!. Sorry totally noob here. Below is my code with your code. What am I doing wrong?


string CheckATRSignal()
{

   string Signal="";
   
   double ATRHigh="";
   double ATRLow="";
   
   // Create an Array for several prices
   double myPriceArray[];
   
   // 1 hour ATR
   if(_Symbol=="AUDUSD")
     {
     #define EMA(P, C, L) ((P) + ((C)-(P))*2./(L+1))
      // https://en.wikipedia.org/wiki/Generalized_mean#Special_cases (Power Mean)
     #define PMA(P, C, L, PM) MathPow(EMA(MathPow(P,PM), MathPow(C,PM), L), 1.0/PM)
   
      double tr = TR[iBar] = MathMax(Close[iBar+1], High[iBar]) - MathMin(Close[iBar+1], Low[iBar]);
      ATR[iBar] = iMAOnArray(TR, …);
      
      ATRmax[iBar] = PMA(ATRmax[iBar+1], tr, Length,  15);
      ATRmin[iBar] = PMA(ATRmin[iBar+1], tr, Length, -15);

       ATRHigh = ATRmax[iBar];
       ATRLow =  ATRmin[iBar];
      
      
     }
 
   
   
   // Define the propertues of the AverageTrueRangeValue EA
   int AverageTrueRangeDefinition = iATR(_Symbol,_Period,10);
   
   // Sort the price array from the current candle downwards
   ArraySetAsSeries(myPriceArray,true);
   
   // Defined MA1, one line, current candle, 3 candles, store results
   CopyBuffer(AverageTrueRangeDefinition, 0, 0, 3, myPriceArray);
   
   // Get the value of the current candle
   double AverageTrueRangeValue=NormalizeDouble(myPriceArray[0],5);
   
   // Long Signal
   if (AverageTrueRangeValue > ATRHigh) Signal="BUY";
   // Short Signal
   if (AverageTrueRangeValue < ATRLow) Signal="SELL";
   
   if ((AverageTrueRangeValue > ATRLow) && (AverageTrueRangeValue < ATRHigh)) Signal="NO_SIGNAL_ATR_MIDDLE";
   
   return Signal;
}

Reason: