DAily range to my Expert advisor

shashi6666

Trader
Jun 29, 2017
10
0
6
41
hi,
i imported daily range to my EA USING icustom. i want to generate signal if daily range is above 100 and today is above 10 and less than 50.
i wrote code like , but i am not able to get required output. can anyone help this.
and also can anyone help while importing technical indicator ...can you tell me how should i do it.
code is as follows
MQL4:
bool dailyrange()
{
double adr= iCustom(NULL,0,"Daily Range PeterE",10,1,1);
if (adr >=100)
{
return(True);
 
}
Else {
return(false);
}
 
}

this is my daily range mql4
MQL4:
#property indicator_chart_window
 
extern int      NumOfDays             = 10;
extern string   FontName              = "Courier New";
extern int      FontSize              = 10;
extern color    FontColor             = White;
extern int      Window                = 0;
extern int      Corner                = 0;
extern int      HorizPos              = 5;
extern int      VertPos               = 20;
 
double pnt;
int    dig;
string objname = "*DRPE";
 
//+------------------------------------------------------------------+
int init()  {
//+------------------------------------------------------------------+
  pnt = MarketInfo(Symbol(),MODE_POINT);
  dig = MarketInfo(Symbol(),MODE_DIGITS);
  if (dig == 3 || dig == 5) {
    pnt *= 10;
  }
  ObjectCreate(objname,OBJ_LABEL,Window,0,0);
  return(0);
}
 
//+------------------------------------------------------------------+
int deinit()  {
//+------------------------------------------------------------------+
  ObjectDelete(objname);
  return(0);
}
 
//+------------------------------------------------------------------+
int start()  {
//+------------------------------------------------------------------+
  int c=0;
  double sum=0;
  for (int i=1; i<Bars-1; i++)  {
    double hi = iHigh(NULL,PERIOD_D1,i);
    double lo = iLow(NULL,PERIOD_D1,i);
    datetime dt = iTime(NULL,PERIOD_D1,i);
    if (TimeDayOfWeek(dt) > 0 && TimeDayOfWeek(dt) < 6)  {
      sum += hi - lo;
      c++;
      if (c>=NumOfDays) break;
  } }
  hi = iHigh(NULL,PERIOD_D1,0);
  lo = iLow(NULL,PERIOD_D1,0);
  if (i>0 && pnt>0)  {
    string objtext = "ADR = " + DoubleToStr(sum/c/pnt,1) + "  (" + c + " days)     Today = " + DoubleToStr((hi-lo)/pnt,1);
    ObjectSet(objname,OBJPROP_CORNER,Corner);
    ObjectSet(objname,OBJPROP_XDISTANCE,HorizPos);
    ObjectSet(objname,OBJPROP_YDISTANCE,VertPos);
    ObjectSetText(objname,objtext,FontSize,FontName,FontColor);
  }
  return(0);
}
 
Last edited by a moderator:

shashi6666

Trader
Jun 29, 2017
10
0
6
41
The indicator uses chart objects to draw its values. You need to read the objects with ObjectGet() function to find the values in the EA.

should i add objectget() function in EA instead of iCustom or in indicator........ thanks for the reply
 

shashi6666

Trader
Jun 29, 2017
10
0
6
41
You do not need to use the iCustom() call in your EA - you need to attach the indicator to the chart before attaching the EA. The EA should use ObjectGet() function to get the indicator readings.
hi ,
thANKS IF YOU ARE backtesting for six months or older.....how can i do ,then
 

shashi6666

Trader
Jun 29, 2017
10
0
6
41
I am not sure. Perhaps, if you use also iCustom() call to let the Strategy Tester know that you need the indicator, it will load it during the backtest, so that you have the access to the chart objects.
hi,
i set the buffer in indicator to get values
#property indicator_buffers 2
#property indicator_chart_window

extern int NumOfDays = 10;
extern string FontName = "Courier New";
extern int FontSize = 10;
extern color FontColor = Black;
extern int Window = 0;
extern int Corner = 0;
extern int HorizPos = 5;
extern int VertPos = 20;

double pnt;
int dig;
string objname = "*DRPE";
double ADR[];
double today[];

//+------------------------------------------------------------------+
int init() {
//+------------------------------------------------------------------+
SetIndexBuffer(0,ADR);
SetIndexBuffer(1,today);



pnt = MarketInfo(Symbol(),MODE_POINT);
dig = MarketInfo(Symbol(),MODE_DIGITS);
if (dig == 3 || dig == 5) {
pnt *= 10;
}
ObjectCreate(objname,OBJ_LABEL,Window,0,0);
return(0);
}

//+------------------------------------------------------------------+
int deinit() {
//+------------------------------------------------------------------+
ObjectDelete(objname);
return(0);
}

//+------------------------------------------------------------------+
int start() {
//+------------------------------------------------------------------+

int c=0;
double sum=0;
for (int i=1; i<Bars-1; i++) {
double hi = iHigh(NULL,PERIOD_D1,i);
double lo = iLow(NULL,PERIOD_D1,i);
datetime dt = iTime(NULL,PERIOD_D1,i);
if (TimeDayOfWeek(dt) > 0 && TimeDayOfWeek(dt) < 6) {
sum += hi - lo;
c++;
if (c>=NumOfDays) break;
} }
hi = iHigh(NULL,PERIOD_D1,0);
lo = iLow(NULL,PERIOD_D1,0);
if (i>0 && pnt>0) {
string objtext = "ADR = " + DoubleToStr(sum/c/pnt,1) + " (" + c + " days) Today = " + DoubleToStr((hi-lo)/pnt,1);
ObjectSet(objname,OBJPROP_CORNER,Corner);
ObjectSet(objname,OBJPROP_XDISTANCE,HorizPos);
ObjectSet(objname,OBJPROP_YDISTANCE,VertPos);
ObjectSetText(objname,objtext,FontSize,FontName,FontColor);
today = (hi-lo)/pnt;
ADR= sum/c/pnt;
//ArrayResize(today,i+1);
//ArrayResize(ADR,i+1);

}
return(0);
}


now i try to use icustom but it is return value
2147483647

double dailyavrrange()
{
double ADR = iCustom(NULL,0,"Daily Range PeterE",NumOfDays,FontName,FontSize,FontColor,Window,Corner,HorizPos,VertPos,0,0);


return(ADR);
}
dont know what mistake i am doing
 

shashi6666

Trader
Jun 29, 2017
10
0
6
41
Please use code highlighting when inserting code, otherwise it is unreadable.
Please use code highlighting when inserting code, otherwise it is unreadable.
MQL4:
#property indicator_buffers 2
#property indicator_chart_window
 
extern int NumOfDays = 10;
extern string FontName = "Courier New";
extern int FontSize = 10;
extern color FontColor = Black;
extern int Window = 0;
extern int Corner = 0;
extern int HorizPos = 5;
extern int VertPos = 20;
 
double pnt;
int dig;
string objname = "*DRPE";
double ADR[];
double today[];
 
//+------------------------------------------------------------------+
int init() {
//+------------------------------------------------------------------+
SetIndexBuffer(0,ADR);
SetIndexBuffer(1,today);
 
 
pnt = MarketInfo(Symbol(),MODE_POINT);
dig = MarketInfo(Symbol(),MODE_DIGITS);
if (dig == 3 || dig == 5) {
pnt *= 10;
}
ObjectCreate(objname,OBJ_LABEL,Window,0,0);
return(0);
}
 
//+------------------------------------------------------------------+
int deinit() {
//+------------------------------------------------------------------+
ObjectDelete(objname);
return(0);
}
 
//+------------------------------------------------------------------+
int start() {
//+------------------------------------------------------------------+
 
int c=0;
double sum=0;
for (int i=1; i<Bars-1; i++) {
double hi = iHigh(NULL,PERIOD_D1,i);
double lo = iLow(NULL,PERIOD_D1,i);
datetime dt = iTime(NULL,PERIOD_D1,i);
if (TimeDayOfWeek(dt) > 0 && TimeDayOfWeek(dt) < 6) {
sum += hi - lo;
c++;
if (c>=NumOfDays) break;
} }
hi = iHigh(NULL,PERIOD_D1,0);
lo = iLow(NULL,PERIOD_D1,0);
if (i>0 && pnt>0) {
string objtext = "ADR = " + DoubleToStr(sum/c/pnt,1) + " (" + c + " days) Today = " + DoubleToStr((hi-lo)/pnt,1);
ObjectSet(objname,OBJPROP_CORNER,Corner);
ObjectSet(objname,OBJPROP_XDISTANCE,HorizPos);
ObjectSet(objname,OBJPROP_YDISTANCE,VertPos);
ObjectSetText(objname,objtext,FontSize,FontName,FontColor);
today = (hi-lo)/pnt;
ADR= sum/c/pnt;
//ArrayResize(today,i+1);
//ArrayResize(ADR,i+1);
 
}
return(0);
}
MQL4:
double dailyavrrange()
{
double ADR = iCustom(NULL,0,"Daily Range PeterE",NumOfDays,FontName,FontSize,FontColor,Window,Corner,HorizPos,VertPos,0,0);
 
 
return(ADR);
}
 

Enivid

Administrator
Staff member
Nov 30, 2008
18,532
1,355
144
Odesa
www.earnforex.com
When you assign something to an array, you have to specify the array element number in the square brackets. Change this:
MQL4:
today = (hi-lo)/pnt;
ADR= sum/c/pnt;
To this:
MQL4:
today[0] = (hi-lo)/pnt;
ADR[0]= sum/c/pnt;
 

shashi6666

Trader
Jun 29, 2017
10
0
6
41
When you assign something to an array, you have to specify the array element number in the square brackets. Change this:
MQL4:
today = (hi-lo)/pnt;
ADR= sum/c/pnt;
To this:
MQL4:
today[0] = (hi-lo)/pnt;
ADR[0]= sum/c/pnt;
MQL4:
today[i] = (hi-lo)/pnt;
ADR[i]= sum/c/pnt;

i added like this but its not working