Good ++
Thanks.
To me it doesn-t let me compile the file.
I don-t know if there is any idea what id going on.
Thanks,
Jordi
Thanks!
Below is a simple example of this that I put together while playing around.
If it's wrong please correct me and I'll amend it.
What I do find strange is the values don't seem to match up to a simple moving average on the chart.
################### In a script
int period = 21; // The 21 bar moving average
int sampleSize = 100; //This is the number of bars of data you want to fetch
int handle = iCustom(Symbol(),0,"Examples\\Custom Moving Average",
period, // Period
0, // Offset
MODE_SMA, // Calculation method
PRICE_CLOSE // Calculating on Close prices
);
void OnTick()
{
// This is the array where you moving averages will get copied into.
// Each item in here is a moving average value
// The first item in this array (item at position 0) is the most recent
// The last item is the last item in the array ArraySize() - 1
double movingAverageValues[];
ArraySetAsSeries(movingAverageValues, true);
if (CopyBuffer(handle,0,0,sampleSize,movingAverageValues) < 0){Print("CopyBufferMA1 error =",GetLastError());}
double currentMovingAverage = movingAverageValues[0];
double earliestMovingAverage = movingAverageValues[ArraySize(movingAverageValues) - 1];
################################# In an EA (NOTE: the OnInit and OnTick)
int OnInit(){
int period = 21; // The 21 bar moving average
int sampleSize = 100; //This is the number of bars of data you want to fetch
int handle = iCustom(Symbol(),0,"Examples\\Custom Moving Average",
period, // Period
0, // Offset
MODE_SMA, // Calculation method
PRICE_CLOSE // Calculating on Close prices
);
}
OnTick()
{
// This is the array where you moving averages will get copied into.
// Each item in here is a moving average value
// The first item in this array (item at position 0) is the most recent
// The last item is the last item in the array ArraySize() - 1
double movingAverageValues[];
ArraySetAsSeries(movingAverageValues, true);
if (CopyBuffer(handle,0,0,sampleSize,movingAverageValues) < 0){Print("CopyBufferMA1 error =",GetLastError());}
double currentMovingAverage = movingAverageValues[0];
double earliestMovingAverage = movingAverageValues[ArraySize(movingAverageValues) - 1];
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article How to call indicators in MQL5 is published:
With new version of MQL programming language available not only the approach of dealing with indicators have changed, but there are also new ways of how to create indicators. Furthermore, you have additional flexibility working with indicator's buffers - now you can specify the desired direction of indexing and get exactly as many indicator's values as you want. This article explains the basic methods of calling indicators and retrieving data from the indicator's buffers.
In MQL5 there are several ways to call indicators, and they are mostly carried out using IndicatorCreate() and iCustom() functions. Moreover, these functions only return indicator handle, and further work on indicators is done through it. So what is a handle? How to deal with IndicatorCreate() and iCustom() functions? And how your expert will get indicator data? All these questions are covered in this article.
Author: KlimMalgin