of course it is possible.
just some normal trading operations.
however, you may have to do the coding work by yourself or you can try :
- www.mql5.com
of course it is possible.
just some normal trading operations.
however, you may have to do the coding work by yourself or you can try :
Thanks tickfenix so much
I just update a simple peice of code to better describe my thought ... is it the right way to do the task?
I just read some of the Docs of OrderSend func & im confused a little bit! LOL
... if It s not Could you shed me some light on "some normal trading operations" ... I think i can code simple stuff pretty well :)
Do I have to use RefreshRates() before calling OrderSend func for the second Order?
Most brokers today accept several trading requests sent in a short period of time, say, one second.
However, because of the transaction mechanism on the broker's server, you will only get a deal at the "best possible" price.
It's quite normal that the price specified in the OrderSend() function is not the exact price to be executed.
The price you actually get depends on the latest quote on the server side at that time.
So, if your requirement is to get the deal done first, rather than the best price, you can simply set a looser "slippage" range and send the order request at the current Ask/Bid.
In other words, there is no need to use RefreshRates().
- www.mql5.com
And, I don't like that _IsTradeAllowed() in your code.
This is simpler:
if ( IsConnected() && IsTradeAllowed() && !IsTradeContextBusy() ) { //go! }
Also, there's a problem in your code: how do you avoid infinite open positions?
- www.mql5.com
And, I don't like that _IsTradeAllowed() in your code.
1. This is simpler...
2. Also, there's a problem in your code: how do you avoid infinite open positions?...
1. "This is simpler... " yep You re right, I just read some latest Infor on TradeContext! & Its a big help for me indeed, hey i just modified my code a bit, check it out please :)
2. "...how do you avoid infinite open positions? " Uhmm, I thought If I use this code line /if (!isNewPeriod(15)) return;/ then It should only open maximum one new order per signal generated if there is a new M15 candle, isnt it?
Thank you so much for your recent help ... I ve leant alot!
have a good day! :)
#property strict int magic1 = 333333; int magic2 = 999999; double lot1 = 0.02; double lot2 = 0.01; int MaxWaiting_sec = 10; //--- bool isNewPeriod(int period) { static datetime dtTime = 0; if( Time[period] != dtTime) {dtTime = Time[period];return(true);} else {return(false);} } //--- bool _CheckTradeContextBusy(int maxWaiting_Sec = 10) { bool check = true; int StartWaitingTime; // check whether the trade context is free if (IsTradeContextBusy()) { while(IsTradeContextBusy()) { StartWaitingTime = (int)GetTickCount(); if(IsStopped()) {Print("The expert was stopped by the user!");check=false; break;} if((int)GetTickCount() - StartWaitingTime > maxWaiting_Sec * 1000) {Print("The standby limit (" + (string)maxWaiting_Sec + " sec) exceeded!");check=false;break;} // if the trade context has become free, if(!IsTradeContextBusy()) {Print("Trade context is free!");check=true;break;} Sleep(10); } // if we make it here & (check == true) then TradeContext is not busy anymore! if(!IsTradeContextBusy()) {Print("Trade context is free!");check=true;} } else {Print("Trade context is free!"); check=true;} //--- return (check); } //--- void OnTick() { double ask; if (!isNewPeriod(15)) return; // Trading criteria double MA1 = iMA(NULL,15,10,0,MODE_LWMA,PRICE_TYPICAL,0); double MA2 = iMA(NULL,15,50,0,MODE_LWMA,PRICE_TYPICAL,0); // Opening BUY orders if (MA1 < MA2) { //Opening BUY1 if (IsConnected()&&IsTradeAllowed()&&_CheckTradeContextBusy(MaxWaiting_sec)){ // check whether the trade context is free RefreshRates(); // Refresh rates ask = MarketInfo(Symbol(),MODE_ASK); int TicketBUY1 = OrderSend(Symbol(),OP_BUY,lot1,ask,3,0,0,NULL,magic1); //Opening Buy1 if (TicketBUY1 < 0) {Alert("Error opening BUY1 ", GetLastError());} else {Alert("Successfully opened order BUY1 ",TicketBUY1);} } //Opening BUY2 if (IsConnected()&&IsTradeAllowed()&&_CheckTradeContextBusy(MaxWaiting_sec)){ // check whether the trade context is free RefreshRates(); // Refresh rates ask = MarketInfo(Symbol(),MODE_ASK); int TicketBUY2 = OrderSend(Symbol(),OP_BUY,lot2,ask,3,0,0,NULL,magic2); //Opening Buy2 if (TicketBUY2 < 0) {Alert("Error opening BUY2 ", GetLastError());} else {Alert("Successfully opened order BUY2 ",TicketBUY2);} } } } // end
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all pro coders,
Im quite new to OrderSend function in mql ... I want to know that is it posible to open 2 different Orders at the same tick when there is a new signal?
in fact, I want to open 2 different Orders with its own MagicNumbers at the same tick when there is a new signal generated ... then i will apply 2 different exit strategies later.
Do I have to use RefreshRates() before calling OrderSend func for the second Order?
is there any problem with the simple peice of code below ? ... could you guys please shed me some light :)
have a good day & thank you so much!