developping a new EA based on a custom indicator: signal always gives the same value - page 2

 
Alain Verleyen:
Show your last code.
managertop40:
I understood that, and I fixed adding this line
request.price=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
request.volume=0.1;

But now I get that:

2016.12.21 18:16:24.918    2016.01.04 01:26:09   failed instant sell 0.10 EURUSD at 1.08463 sl: 1.08957 tp: 1.08155 [Invalid request]


Why is the request invalid? Where is the problem?


Thanks again for all support

Thanks

failed instant sell 0.10 EURUSD at 1.08463 sl: 1.08957 tp: 1.08155 [Invalid request] = You use the Ask price for a sell order


you can read this document to solve your problem


 

Thanks for all replies.

if(STvalue1[0]<SymbolInfoDouble(_Symbol,SYMBOL_LAST) && STvalue1[1]<SymbolInfoDouble(_Symbol,SYMBOL_BID))
     {
      buy_sign=true;
      take_profit=0.6*SymbolInfoDouble(_Symbol,SYMBOL_LAST)+SymbolInfoDouble(_Symbol,SYMBOL_LAST);
      stop_loss=SymbolInfoDouble(_Symbol,SYMBOL_LAST);
      loss_risk=0.03*AccountInfoDouble(ACCOUNT_MARGIN_FREE)*(SymbolInfoDouble(_Symbol,SYMBOL_LAST)-stop_loss);
      profit_risk=0.03*AccountInfoDouble(ACCOUNT_MARGIN_FREE)*(take_profit-SymbolInfoDouble(_Symbol,SYMBOL_LAST));
      request.type=ORDER_TYPE_SELL;
      request.price=SymbolInfoDouble(Symbol(),SYMBOL_BID);      
     }
        
   request.action=TRADE_ACTION_DEAL;
   request.symbol=Symbol();
   request.volume=0.1;
   request.type_filling=ORDER_FILLING_FOK;
   request.sl=NormalizeDouble(stop_loss,Digits());
   request.tp=NormalizeDouble(take_profit,Digits());
  
   if(buy_sign!=sell_sign && PositionSelect(Symbol())==0 && OrderCheck(request,resultCheck))
      {
       OrderSend(request,result);
       Print("problem in sending an order!!");
       Print(__FUNCTION__,": ",result.comment," reply code ",result.retcode);
      }

}


But I have this warning from compiler: "return value of 'OrderSend' should be checked " referring to line 'OrderSend(request,result);' and this message from execution:

"        2016.12.27 10:30:57.177    2016.01.04 01:26:03   failed instant sell 0.10 EURUSD at 1.08464 sl: 1.08964 tp: 1.08164 [Invalid request]

        2016.12.27 10:31:00.656    2016.01.04 01:26:03   OnTick: Invalid request reply code 10013        "

Where is the problem now?


Thanks again

 
   MqlTradeRequest request={0};
 

Ok thanks.


It works. But there is something strange that it is not clear:

2016.12.27 12:00:03.020 2016.01.04 01:26:03   instant sell 0.10 EURUSD at 1.08464 sl: 1.08964 tp: 1.08164 (1.08464 / 1.08471 / 1.08464)
2016.12.27 12:00:03.020 2016.01.04 01:26:03   deal #2 sell 0.10 EURUSD at 1.08464 done (based on order #2)
2016.12.27 12:00:03.020 2016.01.04 01:26:03   deal performed [#2 sell 0.10 EURUSD at 1.08464]
2016.12.27 12:00:03.020 2016.01.04 01:26:03   order performed sell 0.10 at 1.08464 [#2 sell 0.10 EURUSD at 1.08464]
2016.12.27 12:00:03.027 2016.01.04 01:26:03   OnTick: Request executed reply code 10009
2016.12.27 12:01:38.225 2016.01.04 07:36:29   stop loss triggered #2 sell 0.10 EURUSD 1.08464 sl: 1.08964 tp: 1.08164 [#3 buy 0.10 EURUSD at 1.08964]
2016.12.27 12:01:38.225 2016.01.04 07:36:29   deal #3 buy 0.10 EURUSD at 1.08965 done (based on order #3)
2016.12.27 12:01:38.225 2016.01.04 07:36:29   deal performed [#3 buy 0.10 EURUSD at 1.08965]
2016.12.27 12:01:38.225 2016.01.04 07:36:29   order performed buy 0.10 at 1.08965 [#3 buy 0.10 EURUSD at 1.08964]


As you can see, it perform a buy operation after getting the stop loss. Why is there this operation?

It is not clear if the 'buy operation' is performed or not. On the tab Operations, I have only :

Time
 TicketSymbol
 ActionType
 VolumePrice
S/L
T/P
 Comment
2016.01.04 01:26:03
2
eurusd
instant
sell
0.1
1.08464
1.08964
1.08164

It's a simulation starting from the 1st January 2016.


While on History tab I have this situation:

 TimeOrder
Symbol
Type
 Volume PriceS/L
 T/PTime
State
 Comment
2016.01.04 01:26:032
eurusd
sell
0.1/0.1
1.08464
1.08964
1.08164
2016.01.04 01:26:03
filled

 2016.01.04 07:36:29
 3 eurusd buy 0.1/0.1 1.08964   2016.01.04 07:36:29 filled sl 1.08964

Thus, I don't understand why there is a buy operation, if effectively there is.

Actually I very new to Metatrader, so sorry if I don't understand well also the GUI.


Thanks

Reason: