Avoid Slippage without Pending Orders.

 

Hello Friends ,I have a question in mq5 EA coding:
How could I open position when the price = A .

without using Pending (limit / stop) order...

I mean instantly ,  and let Max Slippage  = 1 pip for example   ...   And avoid more slippage
This question is for when the volatility is high OR execution time of server and computer is high OR when the internet speed is low.
Here is my Code:

void OpenPosition(string symbol, ENUM_ORDER_TYPE OrdType, double op_price, double lots, double TheTP, double TheSL, int slip, string commentID, ulong MgcNumber)
  {
   MqlTradeRequest myrequest;
   MqlTradeResult myresult;
   ZeroMemory(myrequest);
   ZeroMemory(myresult);
   myrequest.type = OrdType;
   myrequest.price = op_price;
   myrequest.action = TRADE_ACTION_DEAL;
   myrequest.symbol = symbol;
   myrequest.type_filling = OrderFilling;
   myrequest.comment = commentID;
   myrequest.magic = MgcNumber;
   myrequest.volume = lots;
   myrequest.tp = TheTP;
   myrequest.sl = TheSL;
   myrequest.deviation = slip;
   int a = OrderSend(myrequest, myresult);
  }


Is  :   

myrequest.price = op_price;

  Works or not?

Thanks a lot.

 
JacksonClay: How could I open position when the price = A. without using Pending (limit / stop) order... I mean instantly,  and let Max Slippage  = 1 pip for example   ...   And avoid more slippage

This question is for when the volatility is high OR execution time of server and computer is high OR when the internet speed is low.

For "Market Execution" policy , used by ECN/STP/NDD brokers, you can NEVER avoid slippage. You can only:

  1. Wait for a more favourable price condition, and then place your order, or ...
  2. Try to adjust your trading to compensate for it as best you can.
The only time you can set limits for slippage or price deviation, is when using "Instant Execution" policy, used by Market Maker and Dealing Desk brokers or similar accounts.
 
Fernando Carreiro:

For "Market Execution" policy , used by ECN/STP/NDD brokers, you can NEVER avoid slippage. You can only:

  1. Wait for a more favourable price condition, and then place your order, or ...
  2. Try to adjust your trading to compensate for it as best you can.
The only time you can set limits for slippage or price deviation, is when using "Instant Execution" policy, used by Market Maker and Dealing Desk brokers or similar accounts.
Thanks a lot.
My main question is :  set the price by code :
myrequest.price = ...//(Ask or Bid)

in Fill or Kill method affects the Function or in anyway the position will open?


If giving price to the function is maintained by the function, the position will not open if the price changes more than slippage allowed.


And it's good , Because rejecting by market is better than opening position with big slippage.


Thanks.

 
JacksonClay: My main question is :  set the price by code : in Fill or Kill method affects the Function or in anyway the position will open? If giving price to the function is maintained by the function, the position will not open if the price changes more than slippage allowed. And it's good, Because rejecting by market is better than opening position with big slippage.

As I have already explained, for "Market Execution" policy, the opening price is ignored and you will get whatever price is available at the time.

With "Instant Execution" policy, then the price is important and if it deviates too far away from the current price, you will get a "requote" error.

Remember that Buy orders open at the Ask price and close at the Bid price, and Sell orders open at the Bid price and close at the Ask price.

EDIT: Also read the following:

 
JacksonClay:

Hello Friends ,I have a question in mq5 EA coding:
How could I open position when the price = A .

without using Pending (limit / stop) order...

I mean instantly ,  and let Max Slippage  = 1 pip for example   ...   And avoid more slippage
This question is for when the volatility is high OR execution time of server and computer is high OR when the internet speed is low.
Here is my Code:


Is  :   

  Works or not?

Thanks a lot.

//+------------------------------------------------------------------+
//|                                                       EATest.mq5 |
//|                                          Copyright 2021, Haskaya |
//|                                   https://www.haskayayazilim.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Haskaya"
#property link      "https://www.haskayayazilim.net"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//-
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  double lots=0.10; 
  double TheTP=300;// 30 Pips
  double TheSL=400;
  int slip=30;
   string commentID=" Deneme";
  ulong MgcNumber=99243;
   MqlTick last_tick={}; 
   SymbolInfoTick(_Symbol,last_tick); 
   // BUY Orders
   
   OpenPosition(Symbol(),ORDER_TYPE_BUY, last_tick.bid,lots, TheTP, TheSL,  slip,  commentID,  MgcNumber);
   // SELL Orders
   OpenPosition(Symbol(),ORDER_TYPE_SELL, last_tick.ask, lots, TheTP, TheSL, slip, commentID, MgcNumber);
   ExpertRemove();// exit EA


  }
//+------------------------------------------------------------------+
void OpenPosition(string symbol, ENUM_ORDER_TYPE OrdType, double op_price, double lots, double TheTP, double TheSL, int slip, string commentID, ulong MgcNumber)
{
MqlTradeRequest myrequest;
MqlTradeResult myresult;
ZeroMemory(myrequest);
ZeroMemory(myresult);
myrequest.type = OrdType;
myrequest.price = op_price;
myrequest.action = TRADE_ACTION_DEAL;
myrequest.symbol = symbol;
//myrequest.type_filling = OrderFilling;
myrequest.comment = commentID;
myrequest.magic = MgcNumber;
myrequest.volume = lots;
if(OrdType==ORDER_TYPE_BUY)
{
myrequest.tp = op_price+TheTP*SymbolInfoDouble(symbol,SYMBOL_POINT);
myrequest.sl = op_price-TheSL*SymbolInfoDouble(symbol,SYMBOL_POINT);
}

if(OrdType==ORDER_TYPE_SELL)
{
myrequest.tp = op_price-TheTP*SymbolInfoDouble(symbol,SYMBOL_POINT);
myrequest.sl = op_price+TheSL*SymbolInfoDouble(symbol,SYMBOL_POINT);
}
myrequest.deviation = slip;
int aord = OrderSend(myrequest, myresult);
if(GetLastError()!=0) Print(" Error Codes is :"+ string(GetLastError())+" ");
}
////////////////
//Is : myrequest.price = op_price; >>> Works or not?
 
even pending orders cant avoid slippage..
 
Pak Hong Poon:
even pending orders cant avoid slippage..
Yes , But You can control it by parameters( Allowed deviation). If Slippage is more than you want you can refuse opening.
Reason: