I'm new to programming and i wrote a code for my ea but the journal shows failed narket buy 0.2 BTCUSDm sl: 105348.0200 tp: 105349.5200 [invalid request] and i do not know what to do. this is my OpenTrade Function.
- Define SL and TP mt5
- Help - modification of pending order failed [invalid S/L or T/P]
- EA Not Trading
request.type = (orderType == ORDER_BUY) ? ORDER_TYPE_BUY : ORDER_TYPE_SELL;
Remove the condition checks and pass ORDER_TYPE_BUY or ORDER_TYPE_SELL as the OpenTrade function argument.
request.volume = 0.2; // Adjust lot size
You should check the SYMBOL_VOLUME_MIN, SYMBOL_VOLUME_STEP and SYMBOL_VOLUME_MAX and then adjust the volume as needed
request.sl = (orderType == ORDER_BUY) ? request.price - (StopLoss * _Point) : request.price - (StopLoss * _Point); request.tp = (orderType == ORDER_BUY) ? request.price + (TakeProfit * _Point) : request.price + (TakeProfit * _Point);
Also check the SYMBOL_TRADE_STOPS_LEVEL and SYMBOL_TRADE_TICK_SIZE then adjust the stop loss or take profit.
Finally Calculated values of StopLoss, TakeProfit, and values of open prices for pending orders must be normalized with the accuracy, the value of which can be obtained by Digits().
Thermo5phere:
I'm new to programming and i wrote a code for my ea but the journal shows failed narket buy 0.2 BTCUSDm sl: 105348.0200 tp: 105349.5200 [invalid request] and i do not know what to do. this is my OpenTrade Function.
I'm new to programming and i wrote a code for my ea but the journal shows failed narket buy 0.2 BTCUSDm sl: 105348.0200 tp: 105349.5200 [invalid request] and i do not know what to do. this is my OpenTrade Function.
hello try this , i marked the places where additions were made with the yellow marker
#property version "1.00" #define ORDER_BUY 1 #define ORDER_SELL -1 input int StopLoss=1000;//stop loss input int TakeProfit=1000;//take profit int OnInit() { EventSetMillisecondTimer(600); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { } void OnTimer() { EventKillTimer(); OpenTrade(ORDER_BUY); } void OpenTrade(int orderType) { MqlTradeRequest request={}; MqlTradeResult result; request.action = TRADE_ACTION_DEAL; request.type = (orderType == ORDER_BUY) ? ORDER_TYPE_BUY : ORDER_TYPE_SELL; request.symbol = Symbol(); request.volume = 0.2; // Adjust lot size request.price = SymbolInfoDouble(Symbol(), (orderType == ORDER_BUY) ? SYMBOL_ASK : SYMBOL_BID); request.sl = (orderType == ORDER_BUY) ? request.price - (StopLoss * _Point) : request.price - (StopLoss * _Point); request.tp = (orderType == ORDER_BUY) ? request.price + (TakeProfit * _Point) : request.price + (TakeProfit * _Point); request.deviation = 10; request.magic = 6; request.type_filling=GetFillingA(_Symbol,0); if (!OrderSend(request, result)) { Print("Trade execution failed: ", result.comment); } else { Print("Trade opened: ", result.order); } } ENUM_ORDER_TYPE_FILLING GetFillingA( const string Symb, const uint Type = ORDER_FILLING_FOK ) { const ENUM_SYMBOL_TRADE_EXECUTION ExeMode = (ENUM_SYMBOL_TRADE_EXECUTION)::SymbolInfoInteger(Symb, SYMBOL_TRADE_EXEMODE); const int FillingMode = (int)::SymbolInfoInteger(Symb, SYMBOL_FILLING_MODE); return((FillingMode == 0 || (Type >= ORDER_FILLING_RETURN) || ((FillingMode & (Type + 1)) != Type + 1)) ? (((ExeMode == SYMBOL_TRADE_EXECUTION_EXCHANGE) || (ExeMode == SYMBOL_TRADE_EXECUTION_INSTANT)) ? ORDER_FILLING_RETURN : ((FillingMode == SYMBOL_FILLING_IOC) ? ORDER_FILLING_IOC : ORDER_FILLING_FOK)) : (ENUM_ORDER_TYPE_FILLING)Type); }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register