How do I create a Buy Limit Day order?
Author: cravens
Creation Date: 2/12/2012 12:40 PM
profile picture

cravens

#1

I am looking to use a BUY LIMIT DAY order that is cancelled at the end of the day if not filled. Can anyone suggest a way to add it to the 3x2 System in the examples?

Thanks


Rob
profile picture

Eugene

#2
For daily scale, an order that wasn't filled - be it limit, stop or market - is canceled at end-of-bar.

Or are you looking to add a limit order at an intraday bar scale that is installed once (e.g. at open) and ceases at the end of that day?
profile picture

cravens

#3

I was back testing daily strategies and wanted to put in a buy limit day order for tomorrow (bar+1). I want
that order to be in place for only tomorrow. If it gets filled then I will wait for the exit condition.
If it does not get filled then it should be cancelled as if it were a buy limit day order at a broker.

My strategy is waiting for an entry condition to be met based on a daily close price. If the entry condition
is met at today's close I want to buy tomorrow with a 5% limit below today's close.
profile picture

Cone

#4
The order is valid on the bar that you execute it on. If you don't execute on the next bar, then it is canceled. Simple as that -

CODE:
Please log in to see this code.
profile picture

cravens

#5
Thank you.

profile picture

cravens

#6

I understand that the BuyAtLimit will be executed on every bar where my if condition tells it to
be executed. Is there a way to tell if the BuyAtLimit was executed or not executed on that bar via
the data structure and then that flag in my if condition to make sure it is only executed once?
profile picture

Eugene

#7
Each Buy*/Short* call creates a Position object. If it's not null, the Position was created:
CODE:
Please log in to see this code.
profile picture

Nadja

#8
Hi all

I have the same situation as Cravens, but on intraday scale. My strategy should put a limit order in the market on the opening of the session and cancel it at the end of the session if it was not filled. The problem is that my limit order is cancelled after the first bar of the session. How is it possible to keep it for the whole day in the market?

Any help would be greatly appreciated!

This is the Entry Script, bbL corresponds to the synchronized Lower Bollinger Band from the daily scale.

CODE:
Please log in to see this code.


Kind regards

Andreas
profile picture

Eugene

#9
Hi Andreas,

This design pattern is going to help:

Tutorial: Setups, Triggers, Delays, and Timeouts
profile picture

Cone

#10
Keep in mind that you have to execute the signal on every bar that you want the signal to be "live". Not executing a signal means that the order is canceled. This interaction occurs "naturally" if you follow the standard conventions for programming strategies. If you show an example of the rest of your code, we can be more specific.
profile picture

Nadja

#11
Hi Cone and Eugene

Thank you for the link and the explanations, it helped me a lot.

The entry code from above now looks as follows, if any forum member needs annother example how to implement the timeout.

It seems to work correctly, but I need to have a closer look at the trades.

setupValid is a bool, which declares if the entry condition is true or false, while myLimit is a double, declaring the limit buy price.

Kind regards and and enjoy the weekend

Andreas

CODE:
Please log in to see this code.
profile picture

Cone

#12
Re: Bars.IsLastBarOfDay(bar+1)
Using bar + 1 in anything except a trading signal will generate an error when processed on the last bar of the chart because the next bar does not exist.

It seems to me that the pattern you're after is simply to allow only one trade per day, right? If that's the case, the logic can be simplified a lot:

CODE:
Please log in to see this code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).