Market Order instead of Pending Order - How to set up a timer?

 

Hi all

I am a newcomer to MQL although I have been coding for 10+ years.

My question might have already been asked and for that I apologize but I can't appear to find it in a search. The problem is as follows:

I want upon close of a candle (say 1HR) to enter a pending BUYLIMIT order. However, 50% of these fail because the entry price is too close to the close price of the candle.

Hence, the only way to do this is to wrap a market order within an IF statement. My thoughts are to say:


During the course of the next hour

if the entry price is reached at any point then execute immediately a market order.

else cancel looking for it after the hour is up

Could someone help me in the direction of how I would code this? I want the order to be executed once only. Hence, if the entryprice is hit more than once then no further orders are executed.

Thanks in advance for your help.

Adi

 

Well something like this. Not compiled or tested.

double Price=99999;

int TimeStamp;

Start(){

          if(Price>99998 && TimeStamp != Time[0]){
                   Price=Algorithm_Set_NewPrice(); //--- In this case 1.2345

          }

          if(TimeStamp != Time[0] && Price<99999 && Ask>=Price){

                   if( OrderSend(.........) > 0 ){

                           TimeStamp=Time[0]; Price=99999;

                   } 

          } 

Return(0);}
 
ubzen:

Well something like this. Not compiled or tested.


Thank you for your swift response. I shall give it a whirl now.
Reason: