help :) if order hit TP
void start() { static int OrderCount;bool TP=false; if(OrdersTotal()<OrderCount){ if(!OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))Alert("Error getting last trade"); if(OrderType()==0)if(OrderClosePrice()>=OrderTakeProfit())TP=true; if(OrderType()==1)if(OrderClosePrice()<=OrderTakeProfit())TP=true; } if(TP)PlaySound("take profit.wav"); OrderCount = OrdersTotal(); }I think that should work for you.
Thanks, works fine.
OrdersHistoryTotal()-1 OrderCount = OrdersTotal();
Means your EA in incompatible with every other including itself on other charts and manual trading.- Your code will be sounding EVERY tick.
if(OrderClosePrice()>=OrderTakeProfit())TP=true;
This may not work live. When price reaches the TP/SL a market order closes the trade. A down tick means the OCP would be below the OTP
- Order History sort by closing date - MQL4 forum
void PlayTakeProfit(){ int tickets[], nTickets = GetHistoryOrderByCloseTime(tickets); if (nTickets == 0) return; if (!OrderSelect(tickets[0], SELECT_BY_TICKET)){ Alert("OrderSelect(",tickets[0],") failed: ", GetLastError()); return; } datetime OCT = OrderCloseTime(); static datetime lastAlert; if (lastAlert == OCT) return; lastAlert = OCT; double OCP = OrderClosePrice(), distTP = MathAbs(OCP - OrderTakeProfit()), distSL = MathAbs(OCP - OrderStopLoss()); if (distTP < distSL) PlaySound("take profit.wav"); }
Hi all,
I'm looking for a simple code,, (EA ?)
that plays sound if order hit TP ?!
thanks in advance