Force a date of purchase
Author: BCode
Creation Date: 1/26/2017 7:29 PM
profile picture

BCode

#1
As a rule I try and be very strict about following my buy and sell signals, but there are occasions when the stock climbs/falls that my code doesn't catch. As such I decide to make a purchase or sale that isn't reflected in my back testing. In the past I have just forced the purchase with code by indicating the bar at which I want to make the purchase as indicated below:

CODE:
Please log in to see this code.

This of course allows my code to look for the next buy/sell point and my action can be taken into account in the trade history and NET Profit. However this only works if I don't ever change the date range or the scale. What I would prefer to do is instead of indicating the bar at which to make the purchase, I would like to specify the date and time at which the purchase should occur. I can't seem to figure out how to do this though.
Any one out there been down this road before? Any help would be much appreciated.

Thanks,
Brian
profile picture

Eugene

#2
Hi Brian,
Here you go:

CODE:
Please log in to see this code.


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

BCode

#3
Eugene,
Thanks, that is great.

Is there a way I can also specify the price I paid or sold the stock for at that date and time?

Brian
profile picture

Eugene

#4
Yes, that's also possible. Simply call this method from Community Components:

Import real (historical) trades
profile picture

BCode

#5
Oops,
I thought the code wasn't working but I figured out the issue. Thus the reason I deleted the text of this post.

Thanks again for all your help. The code works perfectly.

Brian
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).