How to convert indicator(e.g Regression indicator ) to function that return a value(e.g. regression value)
Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
Thank you.
Noted. Thank you
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
Hi all,
Good day.
GENERICALLY, how do we modify an indicator to a become a function that **return a value** to calling program ?
so that e.g. from the main program, we can call this EXAMPLE function to get a value e.g. linear-regression-indikator value
Just using this indicator to learn how to convert to function
In main program e.g. when condition-1 met, I like to call this linear-regression-indikator to get the regression value and get the
double Return_val=iCustom("SP-DEC18",0,"linear-regression-indikator",34,0,0);
This is just a example function to be called
Currently the linear-regression-indikator has parameters
extern int period=34;
extern int price=0;
extern int Shift=0;
---=== sample indicator script attached ====
..
int cmd;
for (i = limit;i>=0;i--){
tmp1=iMA(Symbol(),0,period,0,MODE_SMA,price,i);
tmp2=iMA(Symbol(),0,period,0,MODE_LWMA,price,i);
tmp3=3.0*tmp2-2.0*tmp1;
BufferGreen[i] =tmp3;
BufferYellow[i]=tmp3;
BufferRed[i] =tmp3;
//2018-10-1 plan to enhance Begin enhancement
if (i==1) // to return the latest regression value
{
Return_value =tmp3; //2008-10-01 how do I pass the return_value to calling program ? ***
}
//2018-10-1 plan to enhance End enhancement
if (BufferYellow[i]>BufferYellow[i+1]){
BufferRed[i]=EMPTY_VALUE;
} else if (BufferYellow[i]<BufferYellow[i+1]){
BufferGreen[i] =EMPTY_VALUE;
} else {
BufferRed[i]=EMPTY_VALUE;
BufferGreen[i] =EMPTY_VALUE;
}
}
return(0);
}
==== Note: Reference for icustom======
https://docs.mql4.com/indicators/icustom
double iCustom(
string symbol, // symbol
int timeframe, // timeframe
string name, // path/name of the custom indicator compiled program
... // custom indicator input parameters (if necessary)
int mode, // line index
int shift // shift
);
Thank you very much in advance
/