I'm trying but I can't understand what put as "position"!
In MT5 you have to use the iMA part to get a handle , once , and then use the handle to request data
Here is one example
inputint period=200;
inputENUM_MA_METHOD method=MODE_SMA;
inputENUM_APPLIED_PRICE price=PRICE_CLOSE;
//handle of the indicator int moving_average_handle=INVALID_HANDLE;
intOnInit()
{
//initialize the handle of the indicator (s) - ideally when the symbol is ready
moving_average_handle=iMA(_Symbol,_Period,period,0,method,price);
if(moving_average_handle!=INVALID_HANDLE){
/* this is how you get values from the indicator */double values[];//you need an array//and you need to call a function that will copy data with the indicator handle//into your valuesint copied_total=CopyBuffer(moving_average_handle,0,0,10,values);
Print("Copied "+IntegerToString(copied_total)+" values");
for(int i=0;i<copied_total;i++){
Print("MA["+IntegerToString(i)+"] "+DoubleToString(values[i],_Digits));
}
}else{
Print("Can't init ma");
}
return(INIT_SUCCEEDED);
}
voidOnDeinit(constint reason)
{
IndicatorRelease(moving_average_handle);
}
Hello everyone, I've recently started learning MQL5, and I wrote a simple code for iMA, but unfortunately, I keep getting Error 2. Can anyone guide me on where my problem might be?
voidOnStart()
{
int ma_handle = iMA(_Symbol, PERIOD_M15, 6, 0, MODE_SMMA, PRICE_OPEN);
if(ma_handle == INVALID_HANDLE)
Print("Error 1: Failed to create moving average indicator.");
double maOpen[];
ArraySetAsSeries(maOpen, true);
ArrayFree(maOpen);
ResetLastError();
int start_pos = 0,count = 20;
int copied = CopyBuffer(ma_handle, 0, start_pos, count, maOpen);
if(copied != count)
PrintFormat("Error 2: ERROR! EA: %s, FUNCTION: %s, amount to copy: %d, copied: %d, error code %d",
__FILE__,__FUNCTION__, count, copied, GetLastError());
string text = "";
for(int i = 0; i < count; i++)
text = text + IntegerToString(i) + ": " + DoubleToString(maOpen[i], Digits() + 1) + "\n";
Print(text);
}
Babak Ramezani #: Hello everyone, I've recently started learning MQL5, and I wrote a simple code for iMA, but unfortunately, I keep getting Error 2. Can anyone guide me on where my problem might be?
note the comments regarding handles. check the comment above yours for OnInit.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello, me too I'm trying to create SMA on price but I can't understand what I have to insert as "position" variable... (the first parameters).
Example: if I want a SMA 200 periods writing SimpleMA(?, 200, close) where close is native array of OnCalculate function
Whether I put zero (as positoin) it doesn't work, even because into the code there is
so 0-1 isn't possible...
Thanks in advance.
AND why don't you try to pass with the ima() function?
AND why don't you try to pass with the ima() function?
I'm trying but I can't understand what put as "position"!
I'm trying but I can't understand what put as "position"!
there is no "position" to give in ima()
iMA - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
I'm trying but I can't understand what put as "position"!
In MT5 you have to use the iMA part to get a handle , once , and then use the handle to request data
Here is one example
Hello everyone, I've recently started learning MQL5, and I wrote a simple code for iMA, but unfortunately, I keep getting Error 2. Can anyone guide me on where my problem might be?
note the comments regarding handles. check the comment above yours for OnInit.