Forex Forum - EarnForex
Serving Traders Since 2005
 

Go Back   Forex Forum - EarnForex > MetaTrader > MetaTrader 5

MetaTrader 5 MT5 is already out of its beta stage, but the development is ongoing. Some brokers already offer real accounts and the interest of traders is growing. You can discuss anything related to MetaTrader 5 in this forum.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2nd January 2012, 10:09
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default error copying 4806

Hi

I do not know if I am doing something wrong here for that error to appear.
the error only appears on the s_Ma buffer "last line"

MQL5 Code:
            int x = Bars(pair.names[i], pair.periods[j]);  //-- x --- amount of bars to process ------
            int y = x-slow_iMa;                            //-- y --- amount of usable bars ----------
            // ... some other code here
            int f_iMa_Handle = iMA(pair.names[i], pair.periods[j],fast_iMa,0,MODE_SMA,PRICE_CLOSE);      
            int s_iMa_Handle = iMA(pair.names[i], pair.periods[j],slow_iMa,0,MODE_SMA,PRICE_CLOSE);
            if(CopyBuffer(f_iMa_Handle, 0, 0, y, f_Ma)<=0) Print("Error copying fast Ma ",GetLastError());
            if(CopyBuffer(s_iMa_Handle, 1, 0, y, s_Ma)<=0) Print("Error copying slow Ma ",GetLastError());

Last edited by samjesse; 2nd January 2012 at 10:11.
Reply With Quote
  #2 (permalink)  
Old 2nd January 2012, 12:06
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I switch the order of the last 2 lines, the last code line will produce the error copying 4806.
Reply With Quote
  #3 (permalink)  
Old 2nd January 2012, 17:13
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,547
Thanks: 18
Thanked 20 Times in 16 Posts
Default

It takes some time for MetaTrader to produce the indicator data, so it's possible that the second indicator isn't ready when you call CopyBuffer(). Try to catch that error and re-do copying until it disappears.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #4 (permalink)  
Old 2nd January 2012, 18:07
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
It takes some time for MetaTrader to produce
so the code that needs to be repeated would be the code that has to do with producing the indicator? i.e.
MQL5 Code:
int s_iMa_Handle = iMA(pair.names[i], pair.periods[j],slow_iMa,0,MODE_SMA,PRICE_CLOSE);


Quote:
re-do copying until it disappears.
you mean this code?
MQL5 Code:
if(CopyBuffer(s_iMa_Handle, 1, 0, y, s_Ma)<=0) Print("Error copying slow Ma ",GetLastError());

why redo the copy if the problem in the "produce" code that takes time?
Reply With Quote
  #5 (permalink)  
Old 3rd January 2012, 10:22
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,547
Thanks: 18
Thanked 20 Times in 16 Posts
Default

When you call iMA(), it takes some time for MetaTrader to calculate all the data. Until it's done, the handle doesn't point at the correct data.

There is no point in calling iMA() more than one time, as it will probably trigger MetaTrader to restart indicator calculation.

The point is to call CopyBuffer() in a cycle until it stops returning an error.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #6 (permalink)  
Old 3rd January 2012, 11:38
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is the following OK. if loops for a long time and I stop it manually.

MQL5 Code:
           int f_iMa_Handle = iMA(nm, tf,fast_iMa,0,MODE_SMA,PRICE_CLOSE);      
            while(CopyBuffer(f_iMa_Handle, 0, 0, y, f_Ma)<=0) Print("Error copying fast Ma ",GetLastError());
            int s_iMa_Handle = iMA(nm, tf,slow_iMa,0,MODE_SMA,PRICE_CLOSE);
            while(CopyBuffer(s_iMa_Handle, 1, 0, y, s_Ma)<=0) Print("Error copying slow Ma ",GetLastError());
Reply With Quote
  #7 (permalink)  
Old 3rd January 2012, 17:19
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,547
Thanks: 18
Thanked 20 Times in 16 Posts
Default

Looks OK. Do you also check the handles for INVALID_HANDLE value? Maybe the problem is there.
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
  #8 (permalink)  
Old 3rd January 2012, 19:22
Default Avatar
Senior Member
 
Join Date: Aug 2011
Posts: 115
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Enivid View Post
Looks OK. Do you also check the handles for INVALID_HANDLE value? Maybe the problem is there.
not sure how to do that. Also searched the docs "runtme errors" for INVALID_HANDLE for no avail.
Reply With Quote
  #9 (permalink)  
Old 4th January 2012, 10:40
Enivid's Avatar
Administrator
 
Join Date: Nov 2008
Posts: 1,547
Thanks: 18
Thanked 20 Times in 16 Posts
Default

Something like this:
MQL5 Code:
int f_iMa_Handle = iMA(nm, tf,fast_iMa,0,MODE_SMA,PRICE_CLOSE);
if (f_iMa_Handle == INVALID_HANDLE) Print("Error creating indicator handle);
__________________
Please, read the Forum Rules and the Signature Rules to avoid termination of your account.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array access error samjesse MetaTrader 5 1 28th October 2011 13:02
Error opening SELL order:130 pepe MetaTrader Expert Advisors 7 18th January 2011 21:18
Handling OrderSend Error 148 Enivid MetaTrader Expert Advisors 0 4th June 2010 15:09
Handling OrderSend Error 3 Enivid MetaTrader Expert Advisors 0 2nd June 2010 10:17


All times are GMT. The time now is 11:03.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Inactive Reminders By Icora Web Design

SEO by vBSEO 3.3.2