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 take
Basically to prevent same OrderType() same Symbol() from following each other.
thanks
int start(){ static int lastType=-1; if (BuyCondition && lastType != OP_BUY){ lastType=OP_BUY; orderSend(buy); } if (SellCondition && lastType != OP_SELL){
Is there an echo in here?
Thanks a lot. I really appreciate.
This is how i finally arrange the trading function. please help me check if this code needs a better adjustment.
i am very grateful. Thanks once again
//Buy if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) { if(!IsTrade ) { for (Total=0; Total<=OrdersTotal()-1; Total++) { if(HistoryTotal()>mytradingpairs) { static datetime lastClose; datetime lastClosePrev = lastClose; for(int pos=0; pos < HistoryTotal(); pos++) { if (OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)==true && OrderCloseTime() > lastClosePrev && OrderMagicNumber() == g_magic_152 && OrderSymbol() == Symbol() && OrderType() < 6 ) { if(OrderType() == OP_BUY && TimeCurrent()- OrderCloseTime()< 600) { return(0); } } } } } //Check free margin if (AccountFreeMargin() < (100 * Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0; if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0; Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + g_magic_152 + ")", g_magic_152, 0, DodgerBlue); if(Ticket > 0) { if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) { Print("BUY order opened : ", OrderOpenPrice()); if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy"); } else { Print("Error opening BUY order : ", GetLastError()); } } if (EachTickMode) TickCheck = True; if (!EachTickMode) BarCount = Bars; return(0); } } //Sell if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) { if(!IsTrade ) { for (Total=0; Total<=OrdersTotal()-1; Total++) { if(HistoryTotal()>mytradingpairs) { static datetime lastClosed; datetime lastClosedPrev = lastClosed; for(int posi=0; posi < HistoryTotal(); posi++) { if (OrderSelect(posi, SELECT_BY_POS, MODE_HISTORY)==true && OrderCloseTime() > lastClosedPrev && OrderMagicNumber() == g_magic_152 && OrderSymbol() == Symbol() && OrderType() < 6 ) { if(OrderType() == OP_SELL && TimeCurrent()- OrderCloseTime()< 600) { return(0); } } } } } //Check free margin if (AccountFreeMargin() < (100 * 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; Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + g_magic_152 + ")", g_magic_152, 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 (!EachTickMode) BarCount = Bars; return(0); }
function

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.