double TakeProfitBuy=Ask+TakeProfit*Pips(); double StopLossBuy=Low[0]-(StopLoss*Pips()); int BuyTrade=OrderSend(Symbol(),OP_BUYSTOP,0.01,Ask+(0.5*Pips()),0,StopLossBuy,TakeProfitBuy
- There is no need to create pending orders in code.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
- Don't worry about it unless you're scalping M1 or trading news.
- Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
-
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
-
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 -
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.)
Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).
-
-
If TakeProfit - 0.5 is less than the spread, your send fails.
- If Bid-Low[0] is less then the spread, your send fails.
- There is no need to create pending orders in code.
- The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
- Don't worry about it unless you're scalping M1 or trading news.
- Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
-
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
-
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 -
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.)
Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).
-
-
If TakeProfit - 0.5 is less than the spread, your send fails.
- If Bid-Low[0] is less then the spread, your send fails.
Hi William, I'm using the pending stops to scalp M1.
So what you saying is that, for Buystop should be:
int BuyTrade=OrderSend(Symbol(),OP_BUYSTOP,0.01,Bid+(1*Pips())
For SellStop:
int SellTrade=OrderSend(Symbol(),OP_SELLSTOP,0.01,Ask-(1*Pips())
For spreads I'm using raw spreads accounts meaning zero spreads.
As for modifying pending orders it's still modifying once instead of twice.
///Buystop///// for(int x=OrdersTotal()-1;x>=0;x--) { double TrailStep=0.1;//0.2 if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUYSTOP) if(OrderOpenPrice()-Ask>TrailStep*Pips()) { bool ModBuyStop=OrderModify(OrderTicket(),Ask+(TrailStep*Pips()),OrderStopLoss(),OrderTakeProfit(),0,clrNONE); } } } ///Sellstop///// for(int y=OrdersTotal()-1;y>=0;y--) { double TrailStep=0.1;//0.2 if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_SELLSTOP) if(Bid-OrderOpenPrice()>TrailStep*Pips()) { bool ModSellStop=OrderModify(OrderTicket(),Bid-(TrailStep*Pips()),OrderStopLoss(),OrderTakeProfit(),0,clrNONE); } }
I figured out why it's modifying once. I just had to create a void and add to the Ontick function:
void TrailStopOrders() { for(int x=OrdersTotal()-1;x>=0;x--) { double TrailStep=1;//0.5; if(OrderSelect(x,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_BUYSTOP) if(OrderOpenPrice()-Ask>TrailStep*Pips()) bool ModBuyStop=OrderModify(OrderTicket(),Ask+(TrailStep*Pips()),OrderStopLoss(),OrderTakeProfit(),0,clrNONE); } for(int y=OrdersTotal()-1;y>=0;y--) { double TrailStep=1;//0.5; if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber) if(OrderType()==OP_SELLSTOP) if(Bid-OrderOpenPrice()>TrailStep*Pips()) bool ModSellStop=OrderModify(OrderTicket(),Bid-(TrailStep*Pips()),OrderStopLoss(),OrderTakeProfit(),0,clrNONE); } } void OnTick() { TrailStopOrders(); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All
I would like to modify pending orders (BuyStop & SellStop). It only modifies once instead of several times. Please help if you know the problem.