Timeseries functions 2
int main()
{
init_mt4();
string symbol1="EURUSD";
int period=15;
int ma_shift=0;
int ma_method=MODE_SMA;
int applied_price=PRICE_CLOSE;
for(int shift1=800;shift1<1800;shift1++)
{
//vector<int> b=vBarShift3(symbol1, shift1);
vector<int> t=vTimeShift3(symbol1, shift1);
vector<double> ma=vMA_Shift3(symbol1,period,ma_shift,ma_method,applied_price,shift1);
cout << t[0] << " - " << ma[0] << "," << ma[1] << "," << ma[2] << "," << ma[3] << endl;
}
return 0;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
vector<double> vMA_Shift3( string symbol1, int period, int ma_shift, int ma_method, int applied_price, int shift1)
{
vector<double> maverage;
int timeframe1=PERIOD_M1;
int timeframe2=PERIOD_M5;
int timeframe3=PERIOD_H1;
int timeframe4=PERIOD_H4;
vector<double> price1;
vector<double> price2;
vector<double> price3;
vector<double> price4;
price1.resize(period);
price2.resize(period);
price3.resize(period);
price4.resize(period);
vector<int> vshift= vBarShift3(symbol1, shift1+ma_shift-1);
switch (applied_price)
{
case PRICE_CLOSE: //0 Close price.
price1 = vClose(symbol1,timeframe1, vshift[0], -period);
price2 = vClose(symbol1,timeframe2, vshift[1], -period);
price3 = vClose(symbol1,timeframe3, vshift[2], -period);
price4 = vClose(symbol1,timeframe4, vshift[3], -period);
break;
case PRICE_OPEN: //1 Open price.
break;
case PRICE_HIGH: //2 High price.
break;
case PRICE_LOW: //3 Low price.
break;
case PRICE_MEDIAN: //4 Median price, (high+low)/2.
break;
case PRICE_TYPICAL: //5 Typical price, (high+low+close)/3.
break;
case PRICE_WEIGHTED: //6 Weighted close price, (high+low+close+close)/4.
break;
}
double sum1 = 0;
double ma1 = 0;
vector<double>::iterator it1;
for ( it1=price1.begin() ; it1 < price1.end(); it1++ )
sum1 += *it1;
double sum2 = 0;
double ma2 = 0;
vector<double>::iterator it2;
for ( it2=price2.begin() ; it2 < price2.end(); it2++ )
sum2 += *it2;
double sum3 = 0;
double ma3 = 0;
vector<double>::iterator it3;
for ( it3=price3.begin() ; it3 < price3.end(); it3++ )
sum3 += *it3;
double sum4 = 0;
double ma4 = 0;
vector<double>::iterator it4;
for ( it4=price4.begin() ; it4 < price4.end(); it4++ )
sum4 += *it4;
switch (ma_method)
{
case MODE_SMA: //0 Simple moving average,
ma1=sum1/period;
ma2=sum2/period;
ma3=sum3/period;
ma4=sum4/period;
break;
case MODE_EMA: //1 Exponential moving average,
break;
case MODE_SMMA: //2 Smoothed moving average,
break;
case MODE_LWMA: //3 Linear weighted moving average.
break;
}
maverage.push_back(ma1);
maverage.push_back(ma2);
maverage.push_back(ma3);
maverage.push_back(ma4);
return(maverage);
}