Coding to place Buy Limit Order using Bid Candle Open Price

 

Hello Coder

If anyone have idea or advice for an issue I am facing, it would be very appreciated.

When I place buy trade, I use previous candle open price.

To ensure Buy Limit order is triggered. I need to use Open Price + Spread when placing Buy Limit order.

I have coded below to place buy limit for Open + spread using current spread. But whenever I use below script, width between current bid and ask price line

looks very different from Open + current (ask - bid).

For example, If I am placing buy limit using Open price for 4 candle back:

  int Mode = OP_BUYSTOP;
  double spread = (MarketInfo(0,MODE_ASK)- (MarketInfo(0,MODE_BID);

  Entry=Open[4]+spread;
  if (Ask > Entry && Entry > 0) Mode = OP_BUYLIMIT; 
  if (Entry == 0)  {Entry = Ask; Mode = OP_BUY;}
  if(Lots > 0)
   OrderSend(Symbol(),Mode, Lots, Entry, 2,0, 0, "", 0, NULL, LimeGreen);

Am I missing any understanding for bid base drawn chart?

Or is there any script to place Ask base buy limit for bid base MT4 chart?

Mofube

Files:
OpenjSpread.png  50 kb
 
mofube:

Hello Coder

If anyone have idea or advice for an issue I am facing, it would be very appreciated.

When I place buy trade, I use previous candle open price.

To ensure Buy Limit order is triggered. I need to use Open Price + Spread when placing Buy Limit order.

I have coded below to place buy limit for Open + spread using current spread. But whenever I use below script, width between current bid and ask price line

looks very different from Open + current (ask - bid).

For example, If I am placing buy limit using Open price for 4 candle back:

Am I missing any understanding for bid base drawn chart?

Or is there any script to place Ask base buy limit for bid base MT4 chart?

Mofube

simple by experts or scipts code.

//+------------------------------------------------------------------+
//|                                                     SpreadEA.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
input double Lots=0.10;
int OnInit()
  {
//--- create timer
 //  EventSetTimer(60);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
  // EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
    int Mode = OP_BUYSTOP;
  double spread = MarketInfo(Symbol(),MODE_SPREAD);

  double Entry=NormalizeDouble((Open[4]+spread*Point),MODE_DIGITS);
  if (Ask > Entry && Entry > 0) Mode = OP_BUYLIMIT; 
  if (Entry == 0)  {Entry = Ask; Mode = OP_BUY;}
  if(Lots > 0)
  {
   OrderSend(Symbol(),Mode, Lots, Entry, 2,0, 0, "", 0, NULL, LimeGreen);
   ExpertRemove();
   }
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
 
mofube: width between current bid and ask price line looks very different from Open + current (ask - bid).

The "current bid and ask price" lines on the MT4 chart are bogus. They are almost 20 points wider than the Market Watch Tick Chart on some brokers.

 

Mehmet, whroeder1,

Thank you very much for replying.

I have tested with below but no difference.

Mode_Spread is around 2.2 pips according to simultaneously placed pending trades. But visual Ask-Bid is around 4pips.

  double spread = MarketInfo(Symbol(),MODE_SPREAD);

I have been monitoring closely to trade manually, but ask line does not touch the line that I expect.

So most semi-auto or programming trader is using market watch based "mode_spread" and ignore visual bugus Ask line?

I have been testing but having hard time to catch the price I am expecting.

Thanks.

Mofube

Files:
Reason: