Hi All,
I want to loop through a number of moving averages as part of my trading system.
...but use Value as on MT4.
For example PERIOD_D1 = 1440;
Then set and access timeframes as an Array.
// for example: int TF[]={1440,240,60,30,15,5}; // and loop TF[] for(int x=0; x<6; x++) Grad = MAGradient(_Symbol,TF[x],LoopDatapoints);
Hi All,
I want to loop through a number of moving averages as part of my trading system.
Input variables are as below
My loop is per below
input ENUM_TIMEFRAMES TimeFrame1 = PERIOD_D1; // First MA to use input int Period1 =10; // Number of periods for first MA input ENUM_TIMEFRAMES TimeFrame2 = PERIOD_D1; // Second MA to use input int Period2 =10; // Number of periods for second MA ENUM_TIMEFRAMES inputTF[NumberofMAtoUse]; int inputPeriod[NumberofMAtoUse]; OnInit() { inputTF[0]=TimeFrame1; inputTF[1]=TimeFrame2; ... inputPeriod[0]=Period1; inputPeriod[1]=Period2; ... } ... for(int count =0;count<NumberofMAtoUse; count++) { // Get Gradient for all MA's requested string LoopTimeFrame = "TimeFrame" + count; string LoopDatapoints = "Period" + count; Grad = MAGradient(_Symbol, inputTF[count], inputPeriod[count] ); ... }
Thanks Roberto
Sorry if this is a dumb question but i then get an error in my subsequent function which is expecting an ENUM_TIMEFRAMES input into the MA function.
Any thoughts on what im doing wrong?
double MAGradient(string pSymbol,int ChartPeriodDefinition,int NumberofDataPoints) { double ma[]; double Gradient; ArraySetAsSeries(ma,true); int maHandle = iMA(pSymbol,ChartPeriodDefinition, NumberofDataPoints,0,MODE_EMA,PRICE_CLOSE); CopyBuffer(maHandle,0,0,5,ma); double MAValuea = ma[0]; double MAValueb=ma[1]; if(MAValuea>MAValueb) { Gradient = 1; } if(MAValuea<MAValueb) { Gradient = -1; } return(Gradient); }
Thanks Roberto
Sorry if this is a dumb question but i then get an error in my subsequent function which is expecting an ENUM_TIMEFRAMES input into the MA function.
Any thoughts on what im doing wrong?
and amount of CopyBuffer is not 0
Thanks Roberto
Sorry if this is a dumb question but i then get an error in my subsequent function which is expecting an ENUM_TIMEFRAMES input into the MA function.
Any thoughts on what im doing wrong?
While using Alain's code,
change
double MAGradient(string pSymbol,int ChartPeriodDefinition,int NumberofDataPoints)
back to
double MAGradient(string pSymbol,ENUM_TIMEFRAMES ChartPeriodDefinition,int NumberofDataPoints)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
I want to loop through a number of moving averages as part of my trading system.
Input variables are as below
My loop is per below