I can drop a grid of orders just fine, but why can't I use WindowPriceOnDropped() as my price point?

 

Hello,

I've been trading with grid orders for some time now, but just realized there is a WindowPriceOnDropped() function that I'd like to incorporate.

My standard order placement is written like this. Here is sample code for 5 orders spaced 5 pips apart, all micro lots, with 50 pip stops and 100 pip take profits. The first order appears close to market, just 1 pip down, and the rest follow:

int start()
  {
   int    ticket;
   double point;

//----

   point=MarketInfo(Symbol(),MODE_POINT);

//----

    ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-100*point,0,Ask-600*point,Ask+900*point,"[5] 1k, 1 pip down");
    ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-150*point,0,Ask-650*point,Ask+850*point,"[5] 1k, 1 pip down");
    ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-200*point,0,Ask-700*point,Ask+800*point,"[5] 1k, 1 pip down");
    ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-250*point,0,Ask-750*point,Ask+750*point,"[5] 1k, 1 pip down");
    ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-300*point,0,Ask-800*point,Ask+700*point,"[5] 1k, 1 pip down");

//----

   return(0);
  }
  
//+------------------------------------------------------------------+


I've incorporated WindowPriceOnDropped(), like this:

#include <stdlib.mqh>
#include <WinUser32.mqh>

int start()
  {
   int    ticket;
   double point;
   double Price = WindowPriceOnDropped();

//----

   point=MarketInfo(Symbol(),MODE_POINT);

//----

    ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Price*point,0,Price-500*point,Price+1000*point, "[5] 1k test");

//----

   return(0);
  }
  
//+------------------------------------------------------------------+

However, the order simply doesn't appear at all. I'm testing with just 1, but nothing happens. Am I missing something here? The only thing I've changed is "Price", which ought to store the point value on drop, as opposed to Ask minus point value.

Thank you.

 
WindowPriceOnDropped() returns a price, no need to multiply by point.
 
Alain Verleyen:
WindowPriceOnDropped() returns a price, no need to multiply by point.
Thank you for the response. I've tried this already, and there's still no order on the chart. Does WindowPriceOnDropped() not interact with OrderSend() in the same way?
 
oandauser0001:
Thank you for the response. I've tried this already, and there's still no order on the chart. Does WindowPriceOnDropped() not interact with OrderSend() in the same way?
Check the error returned with GetLastError() and also print the price. Probably your price is not correct. For a BUY LIMIT it needs to be below current market price.
 
Alain Verleyen:
Check the error returned with GetLastError() and also print the price. Probably your price is not correct. For a BUY LIMIT it needs to be below current market price.
Alain Verleyen:
Check the error returned with GetLastError() and also print the price. Probably your price is not correct. For a BUY LIMIT it needs to be below current market price.

Thanks. How do I use GetLastError() and where does it appear on the terminal? I have:


   int error=GetLastError();
   
   Print("Error = ",ErrorDescription(error));


but don't see any output. Thanks!

 
oandauser0001: with 50 pip stops and 100 pip take profits.
    ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-100*point,0,Ask-600*point,Ask+900*point,"[5] 1k, 1 pip down");

Those are 50 point stops and 100 point TP. A PIP is not a Point.
          What is a TICK? - MQL4 programming forum

 
William Roeder:

Those are 50 point stops and 100 point TP. A PIP is not a Point.
          What is a TICK? - MQL4 programming forum

No, Ask - 100 means the first order drops 10 pips (not points) below the Ask line, and Ask-600 means the stop is 60 pips below the Ask, or 50 pips below the first dropped order (since it was dropped 10 points below the Ask line).

The take profit is 90 pips above the Ask line, for a total of 100 pips since the order itself is dropped 10 points below the Ask line.

 
oandauser0001: No, Ask - 100 means the first order drops 10 pips (not points) below the Ask line,
  1. Yes, you said PIP but your code is using Point. Using Point means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
              How to manage JPY pairs with parameters? - MQL4 programming forum
              Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum

  2.  ticket=OrderSend(Symbol(),OP_BUYLIMIT,0.01,Ask-100*point,0,Ask-600*point,Ask+900*point,"[5] 1k, 1 pip down");
    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)

  3. You would know why, if you Check your return codes for errors, and report them including GLE/LE and your variable values. Don't look at GLE/LE. unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles