Hello forum,
there are some strange occurrences when I call indicators in EAs. In this test I call iMA and iRSI and Copy their buffers. The initialisation throws no error, buf when copying, I get -1 as CopyBuffer return value. The buffers are resized to the data_size that I set but they contain only "0.0" values. Then when I try printing the buffer contents in a for loop, in debug observation the index is incremented, but it counts only "0" bar values...???
When I test the for loop to count up and print the indizes it does it no problem. Here it seems that CopyBuffer makes something about the for loop crash...? Installed MT5 build is 4153.
The problem error occurs also with while loop:
Have I overlooked something? It compiles with no error though...
Hello forum,
there are some strange occurrences when I call indicators in EAs. In this test I call iMA and iRSI and Copy their buffers. The initialisation throws no error, buf when copying, I get -1 as CopyBuffer return value. The buffers are resized to the data_size that I set but they contain only "0.0" values. Then when I try printing the buffer contents in a for loop, in debug observation the index is incremented, but it counts only "0" bar values...???
When I test the for loop to count up and print the indizes it does it no problem. Here it seems that CopyBuffer makes something about the for loop crash...? Installed MT5 build is 4153.
The problem error occurs also with while loop:
Have I overlooked something? It compiles with no error though...
Oh thanks Dominik. So I did what you said now and Copybuffer is now working fine but the loop doesn't print the index except "0" which is strange. And it doesn't throw any error.
It should print
"bar 0 value x.yz"
"bar 1 value w.vu"
etc.
int handle_ma = 0; double buf_ma[]; int handle_rsi = 0; double buf_rsi[]; int data_size = 50; ulong error_rsi = 0; ulong error_ma = 0; int check_copy_ima = 0; int check_copy_rsi = 0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- handle_ma = iMA(_Symbol, _Period, 12, 0, MODE_SMA, PRICE_CLOSE); handle_rsi = iRSI(_Symbol, _Period, 12, PRICE_CLOSE); //both are initialised to valid handles 10 and 11 if(handle_ma == INVALID_HANDLE || handle_rsi == INVALID_HANDLE) { Print("invalid handle!"); return(INIT_FAILED); } ulong error_init = GetLastError(); Print("Last Error: " + string(error_init)); ResetLastError(); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- check_copy_ima = CopyBuffer(handle_ma, 0, 0, data_size, buf_ma); if(check_copy_ima == -1) { error_ma = GetLastError(); Print("Last Error: " + string(error_ma)); ResetLastError(); } // There are two different indicators that both produce 4802 errors when copying check_copy_rsi = CopyBuffer(handle_rsi, 0, 0, data_size, buf_rsi); if(check_copy_rsi == -1) { error_rsi = GetLastError(); Print("Last Error: " + string(error_rsi)); ResetLastError(); } if(IsStopped()) Print("Is Stopped!"); int i = 0; while(i < data_size && !IsStopped()) // after that the bar value is incremented in debugger, but it is always { // printed as "0". The buffers are resized to 50 though, but contain only 0.0 values if(buf_ma[i] != EMPTY_VALUE) PrintFormat("bar %d value %g", string(i), buf_ma[i]); i++; ulong error_loop = GetLastError(); if(error_loop != 0) { Print("loop_error: " + string(error_loop)); ResetLastError(); return; } } i = 0; while(i < data_size && !IsStopped()) { if(buf_rsi[i] != EMPTY_VALUE) PrintFormat("bar %d value %g", string(i), buf_rsi[i]); i++; ulong error_loop = GetLastError(); if(error_loop != 0) { Print("loop_error: " + string(error_loop)); ResetLastError(); return; } } } //+------------------------------------------------------------------+Should I open a new topic because it is no about loops?
Oh thanks Dominik. So I did what you said now and Copybuffer is now working fine but the loop doesn't print the index except "0" which is strange. And it doesn't throw any error.
It should print
"bar 0 value x.yz"
"bar 1 value w.vu"
etc.
Should I open a new topic because it is no about loops?int handle_ma = INVALID_HANDLE;
Oh thanks Dominik. So I did what you said now and Copybuffer is now working fine but the loop doesn't print the index except "0" which is strange. And it doesn't throw any error.
It should print
"bar 0 value x.yz"
"bar 1 value w.vu"
etc.
Should I open a new topic because it is no about loops?PrintFormat("bar %d value %g", string(i)
No god please no. Thank you. 🤦🏻♂️ 😂 Got too secure with the Printformat here.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello forum,
there are some strange occurrences when I call indicators in EAs. In this test I call iMA and iRSI and Copy their buffers. The initialisation throws no error, buf when copying, I get -1 as CopyBuffer return value. The buffers are resized to the data_size that I set but they contain only "0.0" values. Then when I try printing the buffer contents in a for loop, in debug observation the index is incremented, but it counts only "0" bar values...???
When I test the for loop to count up and print the indizes it does it no problem. Here it seems that CopyBuffer makes something about the for loop crash...? Installed MT5 build is 4153.
The problem error occurs also with while loop:
Have I overlooked something? It compiles with no error though...