Invalid Stops,can't place an order

 

Hi !

I'm having trouble to place a pending order.

Everyprice is fine but i couldn't put it to work.

i'm using this method:

void EnviarOrdemVenda(double preco_entrada,double stop_loss,double take_profit)
{

 MqlTradeRequest request={0}; 
    ZeroMemory(request);
   request.action=TRADE_ACTION_PENDING;         // setting a pending order 
   request.order = ORDER_FILLING_FOK;
   request.magic=12345;                  // ORDER_MAGIC 
   request.symbol=_Symbol;                      // symbol 
   request.volume=Lote;                          // volume in 0.01 lots 
   request.sl=stop_loss;                                // Stop Loss is not specified 
   request.tp=take_profit;                                // Take Profit is not specified   
   datetime Tempo_Novo[];
    int TempoCopiado =CopyTime(_Symbol,_Period,0,1,Tempo_Novo);   
   request.type_time =ORDER_TIME_SPECIFIED;
   datetime expiracao = Tempo_Novo[0] + (PeriodSeconds()*2);
   request.expiration =expiracao;
//--- form the order type 
      request.type=ORDER_TYPE_SELL_STOP_LIMIT;  
  
 
//--- form the price for the pending order 
   request.price=preco_entrada+200;  // open price 
//--- send a trade request 
   MqlTradeResult result={0}; 
   OrderSend(request,result); 
//--- write the server reply to log   
   Print(__FUNCTION__,":",result.comment); 
  
   if(result.retcode==10016) Print(result.bid,result.ask,result.price,"ERROR:"+GetLastError()); 

  }


i'm trying to sell for example at : 79255 ,i set my stoploss to 79555 ( difference of 300 points) and my tp to 78900 but still can't place any order.

Would you have an Idea that can help me ? Thanks !

 

ServerName?

SymbolName?

 
fxsaber:

ServerName?

SymbolName?

Hi, I'm using activtrades And the symbol is bra50feb18
 
Bilal Said:
Hi, I'm using activtrades And the symbol is bra50feb18
request.type=ORDER_TYPE_SELL_STOP_LIMIT; // Are you sure? Where is request.stoplimit?

Tester's EA

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

#define TOSTRING(A)  #A + " = " + (string)(A) + "\n"
#define TOSTRING2(A) #A + " = " + EnumToString(A) + " (" + (string)(A) + ")\n"

string ToString( const MqlTradeRequest &Request )
{
  return(TOSTRING2(Request.action) + TOSTRING(Request.magic) + TOSTRING(Request.order) +
         TOSTRING(Request.symbol) + TOSTRING(Request.volume) + TOSTRING(Request.price) +
         TOSTRING(Request.stoplimit) + TOSTRING(Request.sl) +  TOSTRING(Request.tp) +
         TOSTRING(Request.deviation) + TOSTRING2(Request.type) + TOSTRING2(Request.type_filling) +
         TOSTRING2(Request.type_time) + TOSTRING(Request.expiration) + TOSTRING(Request.comment) +
         TOSTRING(Request.position) + TOSTRING(Request.position_by));
}

string ToString( const MqlTradeResult &Result )
{
  return(TOSTRING(Result.retcode) + TOSTRING(Result.deal) + TOSTRING(Result.order) +
         TOSTRING(Result.volume) + TOSTRING(Result.price) + TOSTRING(Result.bid) +
         TOSTRING(Result.ask) + TOSTRING(Result.comment) + TOSTRING(Result.request_id) +
         TOSTRING(Result.retcode_external));
}

#define Bid SymbolInfoDouble(_Symbol, SYMBOL_BID)
#define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

#define PRINT(A) A; Print(#A + "\n" + ToString(MT4ORDERS::LastTradeRequest) + ToString(MT4ORDERS::LastTradeResult));

void OnTick()
{
  PRINT(OrderSend(_Symbol, OP_BUYLIMIT, 1, Ask - 100 * _Point, 0, Ask - 200 * _Point, 0))
  
  ExpertRemove();
}

Result

Bra50Feb18: history synchronization started
Bra50Feb18: load 35 bytes of history data to synchronize in 0:00:00.000
Bra50Feb18: history synchronized from 2017.01.02 to 2018.01.19
Bra50Feb18,M1: history cache allocated for 394971 bars and contains 90702 bars from 2017.01.02 12:00 to 2018.01.12 21:09
Bra50Feb18,M1: history begins from 2017.01.02 12:00
Bra50Feb18,M1 (ActivTrades-Server): 1 minutes OHLC ticks generating
Bra50Feb18,M1: testing of Experts\Test2.ex5 from 2018.01.15 00:00 to 2018.01.20 00:00 started
USDBRL: history synchronization started
USDBRL: load 27 bytes of history data to synchronize in 0:00:00.093
USDBRL: history synchronized from 2017.01.02 to 2018.01.19
2018.01.15 12:00:00   buy limit 1.00 Bra50Feb18 at 79505 sl: 79405 (79595 / 79605 / 79595)
2018.01.15 12:00:00   OrderSend(_Symbol,OP_BUYLIMIT,1,Ask-100*_Point,0,Ask-200*_Point,0)
2018.01.15 12:00:00   Request.action = TRADE_ACTION_PENDING (5)
2018.01.15 12:00:00   Request.magic = 0
2018.01.15 12:00:00   Request.order = 0
2018.01.15 12:00:00   Request.symbol = Bra50Feb18
2018.01.15 12:00:00   Request.volume = 1.0
2018.01.15 12:00:00   Request.price = 79505.0
2018.01.15 12:00:00   Request.stoplimit = 0.0
2018.01.15 12:00:00   Request.sl = 79405.0
2018.01.15 12:00:00   Request.tp = 0.0
2018.01.15 12:00:00   Request.deviation = 0
2018.01.15 12:00:00   Request.type = ORDER_TYPE_BUY_LIMIT (2)
2018.01.15 12:00:00   Request.type_filling = ORDER_FILLING_FOK (0)
2018.01.15 12:00:00   Request.type_time = ORDER_TIME_GTC (0)
2018.01.15 12:00:00   Request.expiration = 1970.01.01 00:00:00
2018.01.15 12:00:00   Request.comment = 
2018.01.15 12:00:00   Request.position = 0
2018.01.15 12:00:00   Request.position_by = 0
2018.01.15 12:00:00   Result.retcode = 10009
2018.01.15 12:00:00   Result.deal = 0
2018.01.15 12:00:00   Result.order = 2
2018.01.15 12:00:00   Result.volume = 1.0
2018.01.15 12:00:00   Result.price = 0.0
2018.01.15 12:00:00   Result.bid = 79595.0
2018.01.15 12:00:00   Result.ask = 79605.0
2018.01.15 12:00:00   Result.comment = Request executed
2018.01.15 12:00:00   Result.request_id = 0
2018.01.15 12:00:00   Result.retcode_external = 0
 
Bilal Said:
Hi, I'm using activtrades And the symbol is bra50feb18

Please to provide the return code you got when you tried to place it. You'll find it in the "Journal" tab. 

 
Icham Aidibe :

Tolong dapatkan kode pengembalian yang anda dapatkan saat mencoba menempatkannya. Tolong berikan kode pengembalian yang Anda dapatkan saat mencoba menempatkannya. Anda akan menemukannya di tab "Jurnal". Anda akan menemukannya di tab "Jurnal". 

 
Icham Aidibe:

Please to provide the return code you got when you tried to place it. You'll find it in the "Journal" tab. 


Hi,Here is the error :

fxsaber:

Tester's EA

Result


Hi,i'm not sure  about 

request.type=ORDER_TYPE_SELL_STOP_LIMIT; // Are you sure? Where is request.stoplimit?

i tried ORDER_TYPE_SELL too and didn't work.


Thanks for helping !

 
Bilal Said:

i tried ORDER_TYPE_SELL too and didn't work.

2018.01.15 12:00:00   market sell 1.00 Bra50Feb18 sl: 79695 (79595 / 79605 / 79595)
2018.01.15 12:00:00   deal #2 sell 1.00 Bra50Feb18 at 79595 done (based on order #2)
2018.01.15 12:00:00   deal performed [#2 sell 1.00 Bra50Feb18 at 79595]
2018.01.15 12:00:00   order performed sell 1.00 at 79595 [#2 sell 1.00 Bra50Feb18 at 79595]
2018.01.15 12:00:00   OrderSend(_Symbol,OP_SELL,1,Bid,0,Bid+100*_Point,0)
2018.01.15 12:00:00   Request.action = TRADE_ACTION_DEAL (1)
2018.01.15 12:00:00   Request.magic = 0
2018.01.15 12:00:00   Request.order = 0
2018.01.15 12:00:00   Request.symbol = Bra50Feb18
2018.01.15 12:00:00   Request.volume = 1.0
2018.01.15 12:00:00   Request.price = 79595.0
2018.01.15 12:00:00   Request.stoplimit = 0.0
2018.01.15 12:00:00   Request.sl = 79695.0
2018.01.15 12:00:00   Request.tp = 0.0
2018.01.15 12:00:00   Request.deviation = 0
2018.01.15 12:00:00   Request.type = ORDER_TYPE_SELL (1)
2018.01.15 12:00:00   Request.type_filling = ORDER_FILLING_FOK (0)
2018.01.15 12:00:00   Request.type_time = ORDER_TIME_GTC (0)
2018.01.15 12:00:00   Request.expiration = 1970.01.01 00:00:00
2018.01.15 12:00:00   Request.comment = 
2018.01.15 12:00:00   Request.position = 0
2018.01.15 12:00:00   Request.position_by = 0
 
fxsaber:

i dont know why is not working here.

i set the sl and the entry price manually:


the red line is where my stop is ,the blue line my ENTRY PRICE, and still getting invalid stops :(

 
 
fxsaber:
Market closed.

in the strategy tester ?