Help for ATR indicator

 

This is a indicator for the ACD Mark Fisher strategy, it sets a daily range for the first "x" time, and then adds to the range, a "A up line" ( aUp = openRangeHigh + aValue;)
 and "A down line" (aDown = openRangeLow - aValue;), iam trying to modify this indicador for the aValue be based on a percentage of ATR.

ex:

Avaluebuffer[i] = (Apercentage/100) * iATR(NULL,PERIOD_D1,ATRPeriod,i);

aValue = Avaluebuffer[i]; 
But i don´t know where i am getting it wrong..

 Can anybody help me....

/**
* ACD_1.mq4
* A and C values
**/

#property indicator_chart_window
#property indicator_buffers 9
#property indicator_color1 Blue //open range
#property indicator_color2 Blue
#property indicator_color3 Yellow //a values
#property indicator_color4 Yellow
#property indicator_color5 Aqua //c values
#property indicator_color6 Aqua

//Input Params
extern string OpenRangeStart = "08:30";
extern string OpenRangeEnd = "09:00";
//extern bool Use_Default_A_and_C_Values = true;
//extern double A_Value_Pips = 0;
//extern double C_Value_Pips = 0;
extern bool UseAlerts = false;
extern bool DisplayOpeningRange = true;
extern bool DisplayAs = true;
extern bool DisplayCs = true;

extern int ATRPeriod = 10;
extern double Apercentage = 10;
extern double Cpercentage = 15;

double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Avaluebuffer[];
double Cvaluebuffer[];

double aValue;
double cValue;
double aUp=0;
double aDown=0;
double cUp=0;
double cDown=0;
double openRangeHigh;
double openRangeLow;

bool aUpBefore=false;
bool aDownBefore=false;
bool cUpBefore=false;
bool cDownBefore=false; 
    
int init()
{
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0, 158);
   SetIndexBuffer(0,Buffer1);
   SetIndexLabel(0,"O/R High");

   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1, 158);
   SetIndexBuffer(1,Buffer2);
   SetIndexLabel(1,"O/R Low");

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2, 250);
   SetIndexBuffer(2,Buffer3);
   SetIndexLabel(2,"A Up");

   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3, 250);
   SetIndexBuffer(3,Buffer4);
   SetIndexLabel(3,"A Down");

   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4, 167);
   SetIndexBuffer(4,Buffer5);
   SetIndexLabel(4,"C Up");

   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5, 167);
   SetIndexBuffer(5,Buffer6);
   SetIndexLabel(5,"C Down");
   
   SetIndexBuffer(6,Avaluebuffer);
   SetIndexLabel(6,"A line Atr");
   
   SetIndexBuffer(7,Cvaluebuffer);
   SetIndexLabel(7,"C line Atr");

   return(0);
}

int deinit()
{
   return(0);
}

int start()
{
   
       
        
   if (UseAlerts) displayAlert();    
   
   string barTime="";         
   int openBar, closeBar;
   bool openRangeStarted = false;
   bool openRangeCompleted = false;   
          
   for(int i=Bars; i>=0; i--)
   {  
      barTime = TimeToStr(Time[i], TIME_MINUTES);
      
           
      
      if (!openRangeStarted && barTime>=OpenRangeStart && barTime<OpenRangeEnd)
      {
          openBar = i;
          openRangeStarted = true;
          openRangeHigh= 0;
          openRangeLow = 0;
          aValue = 0;
          cValue = 0;
          
      }
      
      if (openRangeStarted && !openRangeCompleted && barTime >= OpenRangeEnd)
      {
         closeBar = i + 1;
         openRangeCompleted = true;
         
         
      }
      
      if (openRangeStarted && openRangeCompleted)
      {
         calculateOpenRangeValues(openBar, closeBar);
         openRangeStarted = false;
         openRangeCompleted = false;
         
      }    
      
      if (openBar>0)
      {
          Avaluebuffer[i] = (Apercentage/100) * iATR(NULL,PERIOD_D1,ATRPeriod,i);
          aValue = Avaluebuffer[i];
          Cvaluebuffer[i] = (Cpercentage/100) * iATR(NULL,PERIOD_D1,ATRPeriod,i);
          cValue = Cvaluebuffer[i];
          
          drawIndicators(i);
      }     
   }
   return(0);
    
}

void calculateOpenRangeValues(int openBar, int closeBar)
{
   openRangeHigh = High[Highest(NULL, 0, MODE_HIGH, (openBar - closeBar + 1), closeBar)];
   openRangeLow = Low[Lowest(NULL, 0, MODE_LOW, (openBar - closeBar + 1), closeBar)];
}

void drawIndicators(int curBar)
{
   if (openRangeHigh<=0 || openRangeLow <=0)
   {
      aUp=0;
      cUp=0;
      aDown=0;
      cDown=0;
      return(0);
   }   
   
    
   aUp = openRangeHigh + aValue; 
   cUp = openRangeHigh + cValue;
   aDown = openRangeLow - aValue;
   cDown = openRangeLow - cValue; 

   if (DisplayOpeningRange)
   {
      Buffer1[curBar]=openRangeHigh;
      Buffer2[curBar]=openRangeLow;
   }
   
   if (DisplayAs)
   {
      Buffer3[curBar]=aUp;
      Buffer4[curBar]=aDown;
   }
   
   if (DisplayCs)
   {     
      Buffer5[curBar]=cUp;  
      Buffer6[curBar]=cDown;
   }
}

void displayAlert()
{  
   if (cDownBefore || cUpBefore)
   {
      return;
   }
    
   if (aUpBefore || aDownBefore)
   {
      if (aUpBefore && cDown!=0 && Bid<cDown)
      {
         cDownBefore=true;
         Alert(Symbol()," ","C Down"," ", Bid);         
      }
      else if (aDownBefore && cUp!=0 && Bid>cUp)
      {
         cUpBefore=true;
         Alert(Symbol()," ","C Up"," ", Bid);
      }
   }
   else if (aUp!=0 && Bid>aUp)
   {
      aUpBefore=true;
      Alert(Symbol()," ","A Up"," ", Bid);  
   }
   else if (aDown!=0 && Bid<aDown)
   {
      aDownBefore=true;
      Alert(Symbol()," ","A Down"," ", Bid);  
   }
}
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.


 
Alain Verleyen:

Sorry..Thanks

 
Alain Verleyen:

Alain how much for you to fix the indicator? Are you interested?

Do i have to put it  in the freelance section...

Regards 

 
Solved...
Reason: