Hi
I keep received a repeating "Buy hits 5" notification. How to adjust the programming to only SendNotification only 1 time ?
don't you want to sort your buy orders by magic number also and not just symbol?...plus i corrected return value of OrderSelect()
The way you have coded it all you will receive notifications as long as the count returns 5 and that is not how you want things right...?
Code it to sen a notification along with OrderSend() once, when order 5 sent, you get a notification...well that's how i should have done it....
This counter counts the total current open orders and you need to count a different way than this one....don't you want a count that only tells you when a 5th order been sent...?
extern int MagicNumber=123456; int CountBuyPositions() { int NumberOfBuyPositions=0; for(int i=OrdersTotal()-1; i >= 0; i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) NumberOfBuyPositions++; } } return (NumberOfBuyPositions); }
try something like this, a different counting example just counting how many orders been sent, not how many 'total' you have open as the other did...try it
extern int MagicNumber=123456; int ordercnt=0; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { SendBuy(); return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void SendBuy() { ticket = OrderSend(...); if(ticket<1) { Print("error"); return; } else { Print("Buy order sent"); ordercnt++; if(ordercnt==5) SendNotification("BUY hits 5"); } }
Hi
I keep received a repeating "Buy hits 5" notification. How to adjust the programming to only SendNotification only 1 time ?
you are calling sendnotification inside the loop..that's the root cause..
1. create a condition if the loop return any expected behavior/target
2. before returning NumberOfBuyPositions, you could send the notification if all desired condition is met
made a simple functional example for you with a buy order....as i understand you want the total open orders you have on current chart commented out plus you want a notification sent about when the 5th order been executed. However my example does not reset the counter, only deal with the 5th order and keep counting up.
Wish you all the best ;)
extern int MagicNumber=123456; int ordercnt=0; int take=100; int stop=100; int ticket=0; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { Comment("Total open : ",CountBuyPositions()); if(Pos()==0) SendBuy(); return; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void SendBuy() { ticket = OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-stop*Point,Ask+take*Point,NULL,123456,0,Green); if(ticket<1) { Print("error"); return; } else { Print("Buy order sent"); ordercnt++; if(ordercnt==5) SendNotification("BUY hits 5"); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int CountBuyPositions() { int NumberOfBuyPositions=0; for(int i=OrdersTotal()-1; i >= 0; i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) { if(OrderType()==OP_BUY) NumberOfBuyPositions++; } } return (NumberOfBuyPositions); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int Pos() { int poss=0; for(int k = OrdersTotal() - 1; k >= 0; k--) { if(!OrderSelect(k, SELECT_BY_POS)) break; if(OrderSymbol()!=Symbol() && OrderMagicNumber()!=MagicNumber) continue; if(OrderCloseTime() == 0 && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) { if(OrderType() == OP_BUY) poss = 1; if(OrderType() == OP_SELL) poss = -1; } } return(poss); }
- www.mql5.com
you are calling sendnotification inside the loop..that's the root cause..
1. create a condition if the loop return any expected behavior/target
2. before returning NumberOfBuyPositions, you could send the notification if all desired condition is met
hi Roshjardine
noted. how could i amend it? i m stuck on how to do it. ( honestly, i m newbie in the MQL programming). Appreciate if can amend from my code.
made a simple functional example for you with a buy order....as i understand you want the total open orders you have on current chart commented out plus you want a notification sent about when the 5th order been executed. However my example does not reset the counter, only deal with the 5th order and keep counting up.
Wish you all the best ;)
hi Kenneth.
thanks. that is my intention for my trade as I'd like to manage how many trade trigger from my EA and send notification + display in MT4 panel.
Thanks for the code too...appreciate it... i will try it out..
- 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
I keep received a repeating "Buy hits 5" notification. How to adjust the programming to only SendNotification only 1 time ?