
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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];
}
Great article