Buy and Sell by Dates
Author: zozzy
Creation Date: 11/19/2013 3:54 PM
profile picture

zozzy

#1
How would I write a short program to buy and sell by specific dates?
For Example:
Buy on 11-01-2014
Sell on 05-01-2014
profile picture

Eugene

#2
Simlar question got raised just last week:

Buy stock on given date with Trailing stop

It can be made even simpler, the key is in comparing a supplied DateTime with the current bar's DateTime e.g.

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

zozzy

#3
Thanks for the prompt response. I'll try it.

Update

Eugene,

I tried to simplify your strategy above to buy just 1 stock on 1 date and then sell that stock on a later date. I obviously don't know enough to make it work successfully. I got several compile errors.

I'll try to attach my code below:

CODE:
Please log in to see this code.

Would you please look it over and suggest how I might fix it. Or if it's hopeless, please provide a better simple version.

Thank you.

profile picture

Eugene

#4
Robert,

Here's a version of the code that buys just 1 stock on 1 date and then sell that stock on a later date:

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