int MovinBarsQuant =20;
int Shift=0;
CiMA moving;
int OnInit()
{
moving.Create(_Symbol,_Period,MovinBarsQuant,Shift,MODE_SMA,PRICE_CLOSE);
moving.Refresh();
}
//---
return(INIT_SUCCEEDED);
}
moving.Refresh();
moving.AddToChart(0,0);
I need help and just can't find 1 example that fits. I just need a code that will copy iMA values and create a moving average, i dont know
how to set the loop and array correctly, just that, please.
mrluck1: help me to create this simple moving average indicator. I dont know what i'm missing, can anyone help me?
double MovAverage= iMA (NULL,0,5,0,MODE_SMA,PRICE_CLOSE,0); while (i>=0){ MovingAverage [i]= MovAverage; i= i-1; } |
|
To whroeder: Yes i noted that it created just a straight line, but how can i assign the current iMA value to every buffer element to create this moving average? I dont know how to do it and i'm new in mql4
and mql4 book doesnt teach you this. Thanks
mrluck1: but how can i assign the current iMA value to every buffer element to create this moving average?
|
|
|
could you just provide me the code and i will understand imediatelly, i have a problem with arrays, and also in mql4 book they dont teach you this, just assigning to High, Low, thats not the case.
so i need to see the code, to create a moving averege copying iMA values, for learning purposes. thanks
could you just provide me the code and i will understand imediatelly, i have a problem with arrays, and also in mql4 book they dont teach you this, just assigning to High, Low, thats not the case.
so i need to see the code, to create a moving averege copying iMA values, for learning purposes. thanks
You have to use i for the bar shift otherwise you assign the same value to each position in the array, as i think you noticed.
while (i>=0)
{
MovingAverage [i]= iMA (NULL,0,5,0,MODE_SMA,PRICE_CLOSE,i);
i= i-1;
}
To Marco Vd Heijden: Thanks a lot man, you basically teached me how to create EAs and custom indicators, if it wasn't for you this forum wouldn't be the same, i'll be forever in debt
Best regards
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm having a little problem in learning to create custom indicators, EA's seem more easy, and i'm new to mql4 and programming, could anyone
help me to create this simple moving average indicator. I dont know what i'm missing, can anyone help me?
//| MovingAverage.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_color1 Red
#property indicator_buffers 2
double MovingAverage [];
int init()
{
SetIndexBuffer(0,MovingAverage);
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);
return(INIT_SUCCEEDED);
}
int start ()
{
int i=1000;
double MovAverage= iMA (NULL,0,5,0,MODE_SMA,PRICE_CLOSE,0);
while (i>=0)
{
MovingAverage [i]= MovAverage;
i= i-1;
}
return (0);
}