//+------------------------------------------------------------------+
//| I-MA-Multitime.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//|
http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
//#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_color2 Yellow
#property indicator_color3 Blue
//
extern int period=80;
extern int TimeFrame=15;
extern int price=0; // PRICE_CLOSE
extern int method=3; // MODE_SMA
extern bool Smooth=1;
double Curve1[],Curve2[],Curve3[],Curve4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void init() {
IndicatorBuffers(1);
IndicatorShortName("I-MA-Multitime");
//
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Curve1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Curve2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,Curve3);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,Curve4);
return;
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void deinit() {
return;
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void start() {
int i,j,limit,cbars,a,x,e;
double maxA,maxC,minL;
//---------------------------------------------------
int counted_bars = IndicatorCounted();
if(counted_bars < 0)
return(-1);
e = Bars-counted_bars;
limit=e;
//----------------------------------------------------
// ---------- CALCULO DE ARRAYS EN TIMEFRAME EQUIVALENTES
double MFClose[],MFOpen[],MFMax[],MFMin[];
ArrayResize(MFClose, e);
ArraySetAsSeries(MFClose, true);
ArrayResize(MFOpen, e);
ArraySetAsSeries(MFOpen, true);
ArrayResize(MFMax, e);
ArraySetAsSeries(MFMax, true);
ArrayResize(MFMin, e);
ArraySetAsSeries(MFMin, true);
//----------------------------------------------------
for(i=0;i<=e;i++) {
MFClose
=0;
MFOpen=0;
MFMax=0;
MFMin=0;
}
for(i=0;i<=e;i++) {
if(MathFloor(i/TimeFrame)*100==(i*100/TimeFrame)) {
maxA=0;
minL=2;
for(j=0;j<TimeFrame>maxA) maxA=High[i+j];
if(Low[i+j]<minL) minL=Low[i+j];
}
}
a=(MathFloor(i/TimeFrame)+1)*TimeFrame;
MFClose=Close[a];
a=(MathFloor(i/TimeFrame)+1)*TimeFrame;
MFOpen=Open[a];
MFMax=maxA;
MFMin=minL;
}
//----------------------------------------------------
// ----- CALCULO de los vect Aux1 y 2 (los del period y period/2)
double Aux1[],Aux2[],Aux3[];
ArrayResize(Aux1, e);
ArraySetAsSeries(Aux1, true);
ArrayResize(Aux2, e);
ArraySetAsSeries(Aux2, true);
ArrayResize(Aux3, e);
ArraySetAsSeries(Aux3, true);
//----------------------------------------------------
if(price==0) {// CLOSE prices
for(x = 0; x < e; x++) {
Aux1[x]=iMAOnArray(MFClose,0,period*TimeFrame,0,method,x);// Subida
}
}
//----------------------------------------------------
if(price==1) {// OPEN prices
for(x = 0; x < e; x++) {
Aux1[x]=iMAOnArray(MFOpen,0,period*TimeFrame,0,method,x);// Subida
}
}
//----------------------------------------------------
if(price==2) {// HIGH prices
for(x = 0; x < e; x++) {
Aux1[x]=iMAOnArray(MFMax,0,period*TimeFrame,0,method,x);// Subida
}
}
//----------------------------------------------------
if(price==3) {// LOW prices
for(x = 0; x < e; x++) {
Aux1[x]=iMAOnArray(MFMin,0,period*TimeFrame,0,method,x);// Subida
}
}
//----------------------------------------------------
if(price==4) {// MEDIAN prices
for(x = 0; x < e; x++) {
Aux3[x]=(MFMax[x]+MFMin[x])/2;
}
for(x = 0; x < e; x++) {
Aux1[x]=iMAOnArray(Aux3,0,period*TimeFrame,0,method,x);// Subida
}
}
//----------------------------------------------------
if(price==5) {// TYPICAL prices
for(x = 0; x < e; x++) {
Aux3[x]=(MFMax[x]+MFMin[x]+MFClose[x])/3;
}
for(x = 0; x < e; x++) {
Aux1[x]=iMAOnArray(Aux3,0,period*TimeFrame,0,method,x);// Subida
}
}
//----------------------------------------------------
if(price==6) {// WEIGHTED prices
for(x = 0; x < e; x++) {
Aux3[x]=(MFMax[x]+MFMin[x]+MFClose[x]+MFClose[x])/4;
}
for(x = 0; x < e; x++) {
Aux1[x]=iMAOnArray(Aux3,0,period*TimeFrame,0,method,x);// Subida
}
}
//----------------------------------------------------
//CALCULAMOS LA FUNCION A REPRESENTAR
//----------------------------------------------------
if(Smooth==0) {
for(i=0;i<=limit;i++) {
if(MathFloor(i/TimeFrame)*100==(i*100/TimeFrame)) {
for(j=0;j<=TimeFrame;j++) {
Curve1[i+j]=Aux1;
}
}
}
}
if(Smooth==1) {
for(i=0;i<=limit;i++) {
Curve1=Aux1[i];
}
}
//
//-----------------------------------------------------------
return(0);
}
//+------------------------------------------------------------------+