BuyAtLimit order over a period of time
Author: novemberindiakilo
Creation Date: 7/9/2019 2:28 AM
profile picture

novemberindiakilo

#1
I am new to WealthLab and so apologies if this question sounds too naive.

I am trying to set a BuyAtLimit order over a period of time that spans multiple bars and not just one bar. However the BuyAtLimit format doesn't seem to allow for that. So I tried to come up with the following code (that tries to set up a limit order over a period of 10 bars) but it throws up errors.

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

Eugene

#2
Nikith, welcome to the forum. Please clarify on why you intend to make an order active over a period of time that spans multiple bars. In WealthScript, a signal is processed on each bar already. If you expand on the trading system logic you're trying to accomplish, there may be a design pattern for you.
profile picture

novemberindiakilo

#3
Thanks for the response.

BuyAtLimit may or may not execute based on the limit price. If I set the limit price too low, chances are high that the order doesn't fill. In such a case, I would like to set the BuyAtLimit across multiple bars and continue searching until it results in a fill in the period spanning multiple bars.
profile picture

novemberindiakilo

#4
In other words, how to simulate a BuyAtLimit order that is Good Till Canceled (GTC) ?
profile picture

Eugene

#5
As I understand it, if the cntMultiCondition1 has been triggered you'd want to issue an entry order valid for the next 10 bars? If it's true then here's a tutorial explaining how to code it: Setups, Triggers, Delays, and Timeouts. Feel free to ask if any assistance is required in getting it done in WealthScript.
profile picture

novemberindiakilo

#6
Yes, that is exactly what I am looking for. The link was helpful and I tweaked my code as follows to include a timeout. But I am not still not sure whether this code is correct since the resultant trades seem to differ from my objective. Thanks again!

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

Eugene

#7
You're making good progress. At first glance I spotted an issue and it is the placement of the boolean variable declaration inside the main (trading) loop:
CODE:
Please log in to see this code.

This way it gets reset on every bar which is the opposite of what you intend to do. So if you move this outside of the loop you should see a difference:
CODE:
Please log in to see this code.

profile picture

novemberindiakilo

#8
Awesome ! thanks, it worked.
profile picture

Eugene

#9
You're welcome.
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).