Coding Pending orders: DAY/GTC

Questions about MultiCharts and user contributed studies.
Eduardo
Posts: 21
Joined: 22 May 2020

Coding Pending orders: DAY/GTC

Postby Eduardo » 27 Jul 2020

Hello, I was not able to find an answer to my question in the forum, a little help would be appreciated.

I use OANDA. The OANDA plugin allows the option for DAY or GTC for pending orders.

Let's say I have this simple code to enter pending orders:

Code: Select all

buy next bar at High + x Stop; sellshort next bar at Low - x Stop;
If in the Autotrading window I use DAY, the answer I guess is simple, the pending orders will cancel at the end of the current day (or is it the end of the current session?)

But, if I use GTC, how long are the pending orders going to last? I haven't found any way to cancel pending orders by code, so will they be pending forever?

Thank you!
Ed

granitepeak
Posts: 25
Joined: 07 Jul 2020
Has thanked: 2 times
Been thanked: 4 times

Re: Coding Pending orders: DAY/GTC

Postby granitepeak » 27 Jul 2020

As it relates to GTC, it will be cancelled once the bar your referencing has new bar with a different High. Same process for a short. Might run it on a OANDA demo using a 1 minute chart to see it in action.
GP

Eduardo
Posts: 21
Joined: 22 May 2020

Re: Coding Pending orders: DAY/GTC

Postby Eduardo » 27 Jul 2020

Thank you! I made some tests in the M1 chart with the following code for simplicity:

Code: Select all

If Time >= 1000 and Time <= 1002 then buy next bar at Close + x Stop;
I added a simple condition to be true only for 3 bars.

Results: the same for DAY and GTC

First bar -> the pending order is created
Second bar -> the pending order is modified according to the new Close
Third bar - > the pending order is modified according to the new Close
Fourth bar - > the pending order is canceled.

So, what's the difference between DAY and GTC? Both got canceled when the condition turned to False

granitepeak
Posts: 25
Joined: 07 Jul 2020
Has thanked: 2 times
Been thanked: 4 times

Re: Coding Pending orders: DAY/GTC

Postby granitepeak » 27 Jul 2020

Your welcome,

Basically...

A Good Till Cancelled (GTC) order remains in the system until you cancels it. (unless OANDA has a limit to the number of days)

Day orders are valid for the current trading day and expire at the end of the trading session if the order hasn't been executed. If you place it after the session close it will be treated as a day order for the next trading day.

Think of it in terms of a NYSE stock trading the NYSE session. So at the close of the session if you had a protective stop or profit target a Day order would be cancelled. At market open you would not have an order in place.

For OANDA it would happen at session close on Friday.

I have always set mine to GTC so I am in control of it.

GP

Eduardo
Posts: 21
Joined: 22 May 2020

Re: Coding Pending orders: DAY/GTC

Postby Eduardo » 27 Jul 2020

Got it, so an additional question would be: How do I keep an order pending once the condition for entering the order is not true anymore? (see my little test above)

Many strategies identify one bar when the conditions are true to enter the pending order, but after that bar, the conditions are not true anymore and the strategy just waits until the pending order gets hit.

granitepeak
Posts: 25
Joined: 07 Jul 2020
Has thanked: 2 times
Been thanked: 4 times

Re: Coding Pending orders: DAY/GTC

Postby granitepeak » 28 Jul 2020

If the code says buy at the high of the previous high, there is always going to be a pending order based on the previous high. Every bar will have a high. When the new high closes and upon the opening of the next bar, the order will be cancelled and a new one will take place. This has to take place every bar.

If you want the order to remain and not cancel, then you need to rethink your code. If I understand your question.

Eduardo
Posts: 21
Joined: 22 May 2020

Re: Coding Pending orders: DAY/GTC

Postby Eduardo » 28 Jul 2020

Thank you, yes I want to keep the pending order static (not moving nor canceled) until it's hit or canceled by a new signal. So I'll have to find a way to do it.

In my strategy when the condition is met, then the pending orders are sent and they just wait in the same place for the price to hit them.

For example, a very simple strategy: At the 6pm bar enter two pending orders: at the high and at the low of yesterday's session. Then wait until the price triggers one of them. At that time the other pending order is canceled.

I don't want the pending orders to disappear when the bar is not the 6 pm bar anymore.

granitepeak
Posts: 25
Joined: 07 Jul 2020
Has thanked: 2 times
Been thanked: 4 times

Re: Coding Pending orders: DAY/GTC

Postby granitepeak » 28 Jul 2020

What time frame are you using on the chart?

granitepeak
Posts: 25
Joined: 07 Jul 2020
Has thanked: 2 times
Been thanked: 4 times

Re: Coding Pending orders: DAY/GTC

Postby granitepeak » 28 Jul 2020

If your automated order set to GTC, and for clarity, should that bar be a 1 hour bar. Every hour you will get a new pending orders and the old orders will be cancelled.

Eduardo
Posts: 21
Joined: 22 May 2020

Re: Coding Pending orders: DAY/GTC

Postby Eduardo » 29 Jul 2020

Thank you for your help! I'm working on several TF. I just wanted to understand the concept, not necessarily attached to a TF in particular.

I've realized that:
- while the conditions are true, the pending orders are valid and they will change after each bar if they depend on a movable point of reference (say, the High of the previous bar).
- When the conditions are not true, the pending orders will be automatically canceled.

So I'll have to code taking these two principles into account.


Return to “MultiCharts”