Download MetaTrader 5
To add comments, please log in or register
Make profit on MQL5 services. It's easy!
Robert Mihali
5875
Robert Mihali 2014.09.04 09:59 

hello everyone, 

Is everyone ready for the important news, which are comming out today? I'm looking forward to a very volatile market.

But now to my question:

I'm working on an Expert advisor and everythink is going well except from one thing. I have here my two functions BUY() and SELL(), with the parameters H and L, which are prices. If I start the expert advisor, the SELL() function works fine but not the BUY() function. I get the OrderSend error 130 (https://docs.mql4.com/constants/errorswarnings/enum_trade_return_codes), which says "invalid stops". I tried to put the StopLoss on 0, but it didn't worked. I also want to mention that these two functions are called at the same time and are absolutely identical (except for Buystop / Sellstop). Does anyone know what I could do ?

void BUY()
  {

   double H = ChannelH();
   double L = ChannelL();
   double Spread=Ask-Bid;
   ticketBuy=OrderSend(Symbol(),OP_BUYSTOP,Size,H + Spread*Point,5,L - Spread*Point,0,"Kommentar",123,0,Green);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SELL()
  {

   double H = ChannelH();
   double L = ChannelL();
   double Spread=Ask-Bid;
   ticketSell=OrderSend(Symbol(),OP_SELLSTOP,Size,L-Spread*Point,3,H+Spread*Point,0,"Kommentar",321,0,Red);
  }
whroeder1
13619
whroeder1 2014.09.04 12:50  
cornesti: which says "invalid stops". I tried to put the StopLoss on 0, but it didn't worked.  
  1. Spread = Bid - Ask = 0.00020. L - Spread * Point == L - 0.00020 * 0.00001 = L. Why are you multiplying the spread by point?
  2. Using 0 on SL but not on the TP changed nothing.
  3. When I tried using pending orders, years ago, I never could get stops to work. I think it was comparing the stops to current market, not where the market would be when the order opens.
    • A) Don't set stops. Create the pending order, then try to set them.
    • B) Don't set stops. Create the pending order, then, after the order opens, try to set them.
    • C) Don't use stops/limits. Humans can't watch the market every second, EA's can. Wait for the market to reach your trigger price and then open.
Robert Mihali
5875
Robert Mihali 2014.09.04 13:34  
WHRoeder:
cornesti: which says "invalid stops". I tried to put the StopLoss on 0, but it didn't worked.  
  1. Spread = Bid - Ask = 0.00020. L - Spread * Point == L - 0.00020 * 0.00001 = L. Why are you multiplying the spread by point?
  2. Using 0 on SL but not on the TP changed nothing.
  3. When I tried using pending orders, years ago, I never could get stops to work. I think it was comparing the stops to current market, not where the market would be when the order opens.
    • A) Don't set stops. Create the pending order, then try to set them.
    • B) Don't set stops. Create the pending order, then, after the order opens, try to set them.
    • C) Don't use stops/limits. Humans can't watch the market every second, EA's can. Wait for the market to reach your trigger price and then open.



thank you a lot for your answer

to the first point: you are absoultely right, I don't have to multiply the Spread with POINT, but this wasn't the problem.

 The problem was, that I was backtesting the EA from 1.1.2013 and H was calculated using data from the last year and was lower than the Ask price. Therefor I couldn't open a Buystop.

 wish you a nice day. 

/
To add comments, please log in or register