Forex Factory (https://www.forexfactory.com/)
-   Platform Tech (https://www.forexfactory.com/forum/69-platform-tech)
-   -   Pending Order Expiration... (https://www.forexfactory.com/thread/59997-pending-order-expiration)

lucidlamp Dec 10, 2007 7:11pm | Post# 1

Pending Order Expiration...
 
1 Attachment(s)
Hi,

The following script will place a buystop using the previous bar high as entry, the previous bar low as stop and the previous pivot high as take profit.

temp.mq4

Now i would like to add an expiration to the pending order. The expiration would correspond to the timeframe in which the script was run.

For example I run the script on a five minute chart. The time I run the script is 2007.12.10 01:22:34. So I would like the script to set the pending order expiration to 2007.12.10 01:25:00. Which would be the next five minute bar, since I am using it on a five minute chart.

For example I run the script on a one hour chart. The time I run the script is 2007.12.10 01:22:34. So I would like the script to set the pending order expiration to 2007.12.10 02:00:00. Which would be the next hour bar, since I am using it on an hourly chart.

For example I run the script on a four hour chart. The time I run the script is 2007.12.10 01:22:34. So I would like the script to set the pending order expiration to 2007.12.10 03:00:00 (which would correspond to my brokers four hour period regimine). Which would be the next four hour bar, since I am using it on an four hour chart.

For example I run the script on a daily chart. The time I run the script is 2007.12.10 01:22:34. So I would like the script to set the pending order expiration to 2007.12.11 00:00:00. Which would be the next daily bar, since I am using it on an daily chart.

The script would be applied to a daily chart primarily, so that would be my priority (setting expiration to the next daily bar). But I would think that when one timeframe is solved the rest will fall into place.

I've been at it for a day or so, trying to figure it out. I've checked code for 'time to next bar' indicators. I've tried multiple methods of swithing to datetime to string dataypes and vice versa. If anyone has a suggestion I am all ears.

Regards,
lucidlamp

Micro-MiniMe Dec 10, 2007 9:18pm | Post# 2

Firstly, expiration times must be at least 10 minutes from current time(check the MT4 UserGuide-search for 'expiration').

Here's a code snipit to set expiration time to 10 min:

int et = TimeCurrent()+(PERIOD_M5*60)*2;

OrderSend(Symbol(),OP_BUYSTOP,0.10,0,3,0,0,"0",0,et,Green);

Note: expiration time is set in seconds; hence the need to multiply PERIOD_M5*60 and that by 2 to get 10 min.

Good luck and thanks for this question. It helped me look at expiration times in more detail and I learned in the process as well.

lucidlamp Dec 10, 2007 10:51pm | Post# 3

1 Attachment(s)
Hi Micro-MiniMe,

Thanks for the reply.

I have got the script working for a one hour chart, although if it can be coded more effectively I would love to learn how:

temp.mq4

Running the script and checking the returns in the Expert Window should give you a better idea of what I meant, if you misread my earlier post. The expiration is set to expire upon a new hour bar, and for a four hour chart the expiration would be set to expire upon creation of the next four hour bar, same with daily charts...

I don't know what it will do if executed during the last hour of trading for the week, but I am not worried about that.

The script will also be run at the beginning of the hour bar so the ten minute clause you mentioned will not apply, although that is good to know.

Thanks again,
lucidlamp

Micro-MiniMe Dec 10, 2007 11:03pm | Post# 4

1 Attachment(s)
You were right. I misread your post. Perhaps you should concider deleting all pending orders when a new bar begins. Something like if(Volume[0]>1)run script.
Here's a script to delete all pending orders:
delete_pending.mq4


© Forex Factory