Forex
Google

Go Back   Forex Trading > Programming > Metatrader Programming
Forex Forum Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-24-2007, 06:39 AM
el cid's Avatar
el cid el cid is offline
Senior Member
 
Join Date: Nov 2006
Posts: 970
el cid is an unknown quantity at this point
multiple order send by error

Hi Folks

The EAS can place more than the desired number of trades .I was using a single chart on platform and only one EA but the EA placed 3 orders inplace of one trade.

How can the order send function be tightened and the code improved to prevent more than the required number of orders being placed?

Should there be a time gap between orders ?

Should every order sent be checked on log and should resending should be frozen for 10 minutes and should resending only be valid only after checking filled orders(total open trades) show trade as not executed?

Could anyone advise please

Here is what the broker stated in email

Hi

I wrote to a broker and asked why the orders were duplicated

Hi,



Sorry for the delay in reply. We were waiting fro our programmer to come back to us.



He said that expert advisor does not have any errors in its code.



What might be have happened:



1. the “UseTF2” parameter is TRUE, that’s why the EA uses the second timeframe in addition to the first one.



2. the expert was attached to two charts instead of one that is why it produces signals twice. To check this you would need to carefully look through log files. If log files contacin a record that expert produced two signals one by one then chance are that expert is attached on two charts.







He also gave you a couple of advices:



Sometimes in the source code (for example, in the CloseAllOrders function) the return value of the trading functions (OrderModify, OrderSend etc.) is not checked. So, if an error occurs, there will be no error messages in the log file and it could be difficult to understand why the trading operation has failed.



Sometimes, when several EAs start trading at the same time, trading functions may fail because the trading context is busy and only one EA is allowed to trade at the moment. So, other EAs will not open positions/modify orders etc. and the signal will be missed. To avoid this, you can either use WaitUntilTradingIsAllowed() function or StartTrading()/StopTrading() functions.





Option 1.







//+-------------------------------------------------------------------+



//| WaitUntilTradingIsAllowed() returns: |



//| 0 – if trade context is not busy |



//| 1 – if EA has been stopped |



//| 2 – if client terminal’s setting don’t allow EAs |



//| to trade |



//+-------------------------------------------------------------------+



int WaitUntilTradingIsAllowed()



{



if (IsTradeAllowed()) return(0);







while (!IsStopped())



{



if (!IsExpertEnabled()) return(2);







if (!IsTradeContextBusy())



{



RefreshRates();



return(0);



}







Sleep(100);



}







return(1);



}











Example:







void start()

{







If(WaitUntilTradingIsAllowed()==0)



{



int t = OrderSend(…);







}







}











Option 2.







Please note:



a) It’s not a good idea to use the functions below if you attach other EAs to your trading account or trade manually.



b) I recommend that you call StopTrading() in the init() function of your EA to cleanup “critical section” variable (GLOB_VAR_NAME).











#define GLOB_VAR_NAME "TradeIsAllowed"







//+----------------------------------------------------------------------------------------+



//| StartTrading() returns: |



//| |



//| 0 – if this EA can trade |



//| 1 - if EA has been stopped |



//| 2 – if client terminal’s setting don’t allow EAs to trade |



//+----------------------------------------------------------------------------------------+



int StartTrading()



{



if (IsTesting()) return(0);







int LastError;







while (!IsStopped())



{



if (!IsExpertEnabled()) return(2);







if (GlobalVariableCheck(GLOB_VAR_NAME)) break;







LastError = GetLastError();



if (LastError!=0)



{



Print("StartTrading():GlobalVariableCheck(“,GLOB_V AR_NAME, ”) failed with the error code ", LastError);



Sleep(100);



continue;



}







if (GlobalVariableSet(GLOB_VAR_NAME, 0)>0) break;







LastError = GetLastError();



Print("StartTrading():GlobalVariableSet(“,GLOB_VAR _NAME, ”) failed with the error code ", LastError);



Sleep(100);



}







while (!IsStopped())



{



if (!IsExpertEnabled()) return(2);







if (GlobalVariableSetOnCondition(GLOB_VAR_NAME, 1, 0))



{



RefreshRates();



return(0);



}







Sleep(100);



}







return(1);



}







//+----------------------------------------------------------------------------------------+



//| StopTrading() returns: |



//| |



//| 0 – if other EAs can trade |



//| 1 - if EA has been stopped |



//| 2 – if client terminal’s setting don’t allow EAs to trade |



//+----------------------------------------------------------------------------------------+



int StopTrading()



{



if (IsTesting()) return(0);







int LastError;







while (!IsStopped())



{



if (!IsExpertEnabled()) return(2);







if (GlobalVariableSet(GLOB_VAR_NAME, 0)>0)



{



return(0);



}







LastError = GetLastError();



Print("StopTrading():GlobalVariableSet(“,GLOB_VAR_ NAME, ”) failed with the error code ", LastError);







Sleep(100);



}







return(1);



}















Example:







void start()

{







If(StartTrading()==0)



{



int t = OrderSend(…);



StopTrading();







}







}







Please use the source code above as guidance only and amend it to suit your requirements.



Should you have any questions feel free to get back in touch.



Best regards,



Helpdesk / Customer Support
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-25-2007, 07:01 AM
el cid's Avatar
el cid el cid is offline
Senior Member
 
Join Date: Nov 2006
Posts: 970
el cid is an unknown quantity at this point
Hi

Any chance the following will eliminate multiple entries?Any comments or suggestons to make safety improvements?

Hi

Working on the following on metatrader EA improvements for live trading

I am thinking of using EAS for trading a master and slave.
>
> 1)The master will be created with maximum emphasis on safety and
> security.The master will monitor all orders sent and prevent duplicate
> orders and multiple orders created by ordersend functions.The master
> will log all orders sent and wait 10 mins before resending order. And
> before resending it will check orders filled and open positions , it
> will do the same everytime the metatrader programme reboots and will
> never allow orders above the maximum to be sent.
>
> 2)Sometimes, when several EAs start trading at the same time, trading
> functions may fail because the trading context is busy and only one EA
> is allowed to trade at the moment. So, other EAs will not open
> positions/modify orders etc. and the signal will be missed. To avoid
> this, you can either use WaitUntilTradingIsAllowed() function or
> StartTrading()/StopTrading() functions.

>
> 3)Your work will ensure the EA performs robustly and EA is coded to
> deal with situations where MT > feed is interrupted in some way. For
> instance, many/most EA's take no > account of MT simply being closed
> down and restarted - one of the most > basic requirements - and lose
> all their trade stats....The master will also not allow duplicate
> trades created by requotes in times of high volatility
>
> 4)A lot of EAS are not able to deal with requotes and platforms
> freezing during high volatility.The order send functions often send
> multiiple orders whilst the platforms are frozen.Please advise how you
> will code this.
>
> 5)The master will override the functions of the slave on many other
> commands.

El
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-25-2007, 07:24 AM
omelette omelette is offline
Senior Member
 
Join Date: Jan 2006
Posts: 984
omelette is on a distinguished road
El Cid, as I have said before, 95% of EAs are just done to check an idea - it's this 95% that are freely available! Every mishap you have mentioned can be accounted for in code but it can take longer to make an EA 'robust' than it took to code the main idea - believe it or not!

But the only reason an EA will send multiple orders is shoddy programming - get yourself a better programmer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Send Mail cardio Setup Questions 7 10-23-2006 03:51 AM
Send Order problem intelligent_14 Questions 0 08-03-2006 10:37 AM
Multiple Order Entry timing....coding help requested.. Aaragorn General Discussion 2 07-18-2006 12:17 AM
Script to Send Emails babarmughal Expert Advisors - Metatrader 4 7 05-16-2006 02:27 AM


All times are GMT. The time now is 10:21 PM.