- Wrong Parameters count
- Trade List
- invalid stops
Another suggestion is to check
if the stop loss is lower that the current price for the buy position
and higher that the current price for the sell position.
Something like this:
if(posType == POSITION_TYPE_BUY) { bidPrice = SymbolInfoDouble(pSymbol,SYMBOL_BID); currentProfit = bidPrice - posOpenPrice; if(pTrailPrice > currentStopLoss + step && currentProfit >= minProfit) { request.sl = pTrailPrice; } else { //Print("TrailingStop, buy -> No conditions"); return(false); } } else if(posType == POSITION_TYPE_SELL) { askPrice = SymbolInfoDouble(pSymbol,SYMBOL_ASK); currentProfit = posOpenPrice - askPrice; if(pTrailPrice < currentStopLoss - step && currentProfit >= minProfit) { request.sl = pTrailPrice; } else { //Print("TrailingStop, sell -> No conditions"); return(false); } }
- www.mql5.com
For buy, you should also check that your sl are always below the imposed stop level
double currPrice = SymbolInfoDouble(pSymbol, SYMBOL_BID); double point = SymbolInfoDouble(pSymbol, SYMBOL_POINT); double stopLevel = SymbolInfoInteger(pSymbol, SYMBOL_TRADE_STOPS_LEVEL) * point; double stopPrice = currPrice - stopLevel; if(pPrice < stopPrice) { // StopLossTemp remains unchanged } else { StopLossTemp = stopPrice; }
ZeroMemory(mrequest); mrequest.action = TRADE_ACTION_DEAL; // immediate order execution mrequest.price = NormalizeDouble(latest_price.ask,_Digits); // latest ask price mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit mrequest.symbol = _Symbol; // currency pair mrequest.volume = Lot; // number of lots to trade mrequest.magic = EA_Magic; // Order Magic Number mrequest.type = ORDER_TYPE_BUY; // Buy Order mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type mrequest.deviation=100; // Deviation from current price //--- send order OrderSend(mrequest,mresult); // get the result code if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed { Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!"); } else { Alert("The Buy order request could not be completed -error:",GetLastError()); ResetLastError(); return; } } } /*
This is another problem, which I've just answer in another topic here
https://www.mql5.com/en/forum/12282
meaning that you need to send 2 orders:
1. for position opening
2. for setting the sl and tp
- www.mql5.com
When you use CopyXXX function, you have to check returned value, there is no garantie that the copy is done.
int copyht = CopyHigh(_Symbol,PERIOD_M30,Open_Trade_Time,TradeTimeCurrent,ht); int copylt = CopyLow(_Symbol,PERIOD_M30,Open_Trade_Time,TradeTimeCurrent,lt); if (copyht<1 || copylt <1) return;
You have to initialize the value of your structure, try to add :
ZeroMemory(request); request.action = TRADE_ACTION_SLTP;
You have also to follow the advice of launic, as there is no garantie that your stoploss value is valid.
If still that doesn't work, please post the log.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use