Can I have help on How to call iCustom indicator from my EA mql4. I have been trying to tell my EA to send orders when the price riches UniqueprcLineup or UniqueprcLinedown.
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
input int inpPeriod = 5; // Period for month
string inpUniqueID = "Unique";
int period;
bool initFailed = false;
//------------------------------------------------------------------
// Custom indicator initialization function
//------------------------------------------------------------------
int OnInit()
{
period = PeriodSeconds(PERIOD_MN1)/PeriodSeconds() * inpPeriod;
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) { ObjectsDeleteAll(0,inpUniqueID+":"); }
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if(initFailed)
{
return(prev_calculated);
}
ArraySetAsSeries(close,false);
if(period>rates_total-1)
{
period = rates_total-1;
}
double prcError; double prcSlope; double lrPrc = iLrValue(close,period,prcSlope,prcError,rates_total-1);
createChannel(0 ,lrPrc,lrPrc-(period-1.0)*prcSlope,"prcLine",clrBlack,clrNONE,0,0,clrNONE,prcError*2.0);
return(rates_total);
}
//------------------------------------------------------------------
// Custom function(s)
//------------------------------------------------------------------
//
//---
//
void createChannel(int window, double price1, double price2, string addName, color theColor,color middleColor, int theStyle, int theMiddleStyle, color backColor, double error)
{
string name = inpUniqueID+addName;
if (ObjectFind(0,name)==-1)
ObjectCreate(0,name,OBJ_TREND,window,0,0,0,0);
ObjectSetDouble(0,name,OBJPROP_PRICE,0,price1);
ObjectSetDouble(0,name,OBJPROP_PRICE,1,price2);
ObjectSetInteger(0,name,OBJPROP_TIME,0,iTime(NULL,_Period,0)+PeriodSeconds(_Period)-1);
ObjectSetInteger(0,name,OBJPROP_TIME,1,iTime(NULL,_Period,period-1));
ObjectSetInteger(0,name,OBJPROP_RAY,false);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name,OBJPROP_COLOR,middleColor);
ObjectSetInteger(0,name,OBJPROP_STYLE,theMiddleStyle);
if (error<=0) return;
name = inpUniqueID+addName+"up";
if (ObjectFind(0,name)==-1)
ObjectCreate(0,name,OBJ_TREND,window,0,0,0,0);
ObjectSetDouble(0,name,OBJPROP_PRICE,0,price1+error);
ObjectSetDouble(0,name,OBJPROP_PRICE,1,price2+error);
ObjectSetInteger(0,name,OBJPROP_TIME,0,iTime(NULL,_Period,0)+PeriodSeconds(_Period)-1);
ObjectSetInteger(0,name,OBJPROP_TIME,1,iTime(NULL,_Period,period-1));
ObjectSetInteger(0,name,OBJPROP_RAY,false);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name,OBJPROP_COLOR,theColor);
ObjectSetInteger(0,name,OBJPROP_STYLE,theStyle);
name = inpUniqueID+addName+"down";
if (ObjectFind(0,name)==-1)
ObjectCreate(0,name,OBJ_TREND,window,0,0,0,0);
ObjectSetDouble(0,name,OBJPROP_PRICE,0,price1-error);
ObjectSetDouble(0,name,OBJPROP_PRICE,1,price2-error);
ObjectSetInteger(0,name,OBJPROP_TIME,0,iTime(NULL,_Period,0)+PeriodSeconds(_Period)-1);
ObjectSetInteger(0,name,OBJPROP_TIME,1,iTime(NULL,_Period,period-1));
ObjectSetInteger(0,name,OBJPROP_RAY,false);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,name,OBJPROP_COLOR,theColor);
ObjectSetInteger(0,name,OBJPROP_STYLE,theStyle);
//
//
//
if (backColor!=clrNONE)
{
name = inpUniqueID+addName+"tup";
if (ObjectFind(0,name)==-1)
ObjectCreate(0,name,OBJ_TRIANGLE,window,0,0,0,0);
ObjectSetInteger(0,name,OBJPROP_TIME,0,iTime(NULL,_Period,0)+PeriodSeconds(_Period)-1);
ObjectSetInteger(0,name,OBJPROP_TIME,1,iTime(NULL,_Period,0)+PeriodSeconds(_Period)-1);
ObjectSetInteger(0,name,OBJPROP_TIME,2,iTime(NULL,_Period,period-1));
ObjectSetInteger(0,name,OBJPROP_COLOR,backColor);
ObjectSetInteger(0,name,OBJPROP_BACK,true);
ObjectSetInteger(0,name,OBJPROP_FILL,true);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetDouble(0,name,OBJPROP_PRICE,0,price1+error);
ObjectSetDouble(0,name,OBJPROP_PRICE,1,price1-error);
ObjectSetDouble(0,name,OBJPROP_PRICE,2,price2-error);
name = inpUniqueID+addName+"tdn";
if (ObjectFind(0,name)==-1)
ObjectCreate(0,name,OBJ_TRIANGLE,window,0,0,0,0);
ObjectSetInteger(0,name,OBJPROP_TIME,0,iTime(NULL,_Period,0)+PeriodSeconds(_Period)-1);
ObjectSetInteger(0,name,OBJPROP_TIME,1,iTime(NULL,_Period,period-1));
ObjectSetInteger(0,name,OBJPROP_TIME,2,iTime(NULL,_Period,period-1));
ObjectSetInteger(0,name,OBJPROP_COLOR,backColor);
ObjectSetInteger(0,name,OBJPROP_BACK,true);
ObjectSetInteger(0,name,OBJPROP_FILL,true);
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
ObjectSetDouble(0,name,OBJPROP_PRICE,0,price1+error);
ObjectSetDouble(0,name,OBJPROP_PRICE,1,price2-error);
ObjectSetDouble(0,name,OBJPROP_PRICE,2,price2+error);
}
}
template <typename T>
double iLrValue(T& values[], int period, double& slope, double& error, int i)
{
double sumx=0, sumxx=0, sumxy=0, sumy=0, sumyy=0;
for (int k=0; k<period && i>=k; k++)
{
double price = values[i-k];
sumx += k;
sumxx += k*k;
sumxy += k*price;
sumy += price;
sumyy += price*price;
}
slope = (period*sumxy-sumx*sumy)/(sumx*sumx-period*sumxx);
error = MathSqrt((period*sumyy-sumy*sumy-slope*slope*(period*sumxx-sumx*sumx))/(period*(period-2)));
//
//---
//
return((sumy + slope*sumx)/period);
}
- Everything about RSI
- expert advisor - miscellaneous questions
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
-
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
Messages Editor - Nelson3056: Can I have help on How to call iCustom indicator from my EA mql4.
ICustom reads buffers; your indicator doesn't have any.
thank you.. I apologies for send this message on a wrong platform.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register