- OrderSelect function question
- Count how many lost orders from the last profit order
- Is the Cauchy difference a precursor to a reversal and/or correction?
This should look though history going backwards from most recent to earliest trades:
for(i=0;i<Total;i++){ OrderSelect(OrdersHistoryTotal()-i-1,SELECT_BY_POS,MODE_HISTORY);
static datetime lastClose; datetime lastClosePrev = lastClose; for(int pos=0; pos < HistoryTotal(); pos++) if ( OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderCloseTime() > lastClosePrev // not yet processed, && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL){ // Avoid cr/bal forum.mql4.com/32363
thanks for your timely response.
This has been the problem with my EA ever since. i have even posted this problem earlier before now @ https://forum.mql4.com/39521
as
"my Ea keeps opening same type position when it opens one and make profit it will
open another one on this same direction after takeprofit point even if trade is about
to go the other way. Pls i need a simple order management code that will prevent
this from happening. i want the one that will wait until opposite signal is
available before making the next trade after it has finished with the current order by takeproft."
when i finish with this info you have given me, i will attach the EA for you to see if there is any other error.
Thanks once again for your help.
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
if (AccountBalance()>10.00)
{
OrderSelect(0,SELECT_BY_POS,MODE_HISTORY);
if (OrderCloseTime()>TimeCurrent()+60)
{
Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
}
}
-
If there is no history, this code breaks. If there is, this checks if the oldest order (whatever pair, whatever EA) closed one minute in the future.
please what will be the right code if i don't want the same order type with same symbol to open one after another!
pls help me out.
please what will be the right code if i don't want the same order type with same symbol to open one after another!
pls help me out.
for (int i = 0; i < Total; i ++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) { IsTrade = True; if(OrderType() == OP_BUY) {
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
1 OP_BUY - buying position, 2 OP_SELL - selling position, 3 OP_BUYLIMIT - buy limit pending position, 4 OP_BUYSTOP - buy stop pending position, 5 OP_SELLLIMIT - sell limit pending position, 6 OP_SELLSTOP - sell stop pending position. 1<2 means OP_BUY<OP_SELL. Is this what the above means? "OrderType() <=OP_SELL" pls help me out |
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use