DateTimeToBar for Intraday scales (5min)
Author: kendalab
Creation Date: 12/31/2015 1:46 PM
profile picture

kendalab

#1
I'm trying to add a position that was created outside the parameters of my script. I can do this on a daily scale with the following code.

CODE:
Please log in to see this code.


^Shamelessly stolen from the DateTimeToBar QuickRef with slight mods.
But how do I do this for a scale of say 5 minutes or 60 minutes if the position needs to be at 10:05 AM or 10:30 AM?
profile picture

Eugene

#2
No need to reinvent the wheel, it's already implemented:

Import real (historical) trades

As to your question in general, DateTime supports several overloads that accept hours, minutes etc. Just invoke IntelliSense to see them.
profile picture

kendalab

#3
I managed to get

this.SimTradeFile2(@"C:\Data\Trades2.csv", @"dd-MM-yyyy HH:mm:ss");

to work with stock symbols, but it doesn't seem to like option symbols like Fidelity's -DIA160115P176. It doesn't seem to like the dash.
profile picture

Eugene

#4
When it does not seem to like, how is it expressed? Type in the error message text if you've got it. A symbol name may not start with a tab, comma or ";". Other chars including the dash are fine.

profile picture

kendalab

#5
Thanks for the tip on IntelliSense, I was able to get a position opened using the code in my first post. It works, but is not my preferred method.

The Robert Sucher (SimTradeFile2) method is giving me the following error, which is ,as you mentioned, not because of the dash.

"Runtime error: Bar number must be 1194 or greater"
" at WealthLab.Strategies.MyStrategy.Execute()
at WealthLab.WealthScript.SellAtLimit(Int32 bar, Position pos, Double limitPrice, String signalName)
at WealthLab.WealthScript.SellAtLimit(Int32 bar, Position pos, Double limitPrice, String signalName)
at WealthLab.WealthScript.a(Int32 A_0, Int32 A_1, Int32 A_2)"

The file content is a single line "-DIA160115P175;29-12-2015 15:05:00;Buy;1.35"

I added "using Community.Components;"
and I added:
CODE:
Please log in to see this code.


Getting the position open using my code from the first post works fine now that I have the DateTime hours & minutes in. The Sucher method opens the position (shows on the chart tab), but my SellAtLimit doesn't work with it, where it does work with my 1st post code.

My sellatlimit:
CODE:
Please log in to see this code.


There were two lines referencing the importing of the file and I only have the second line in my code. Is that the problem? The history isn't completely loaded?
CODE:
Please log in to see this code.

profile picture

Eugene

#6
This error may be caused by not having loaded enough data (so that the bar is missing) or due to absense of this bar in the -DIA160115P175 data.

QUOTE:
I added "using Community.Components;"

Not even necessary since these all are "extension methods".

QUOTE:
There were two lines referencing the importing of the file and I only have the second line in my code. Is that the problem?

No, this is just the actual (ImportHistoricalTrades) and the legacy syntax (SimTradeFile).
profile picture

kendalab

#7
Thanks, I removed Community.Components.

It would be the same data, -DIA160115P175, just two methods of opening the same position.

Method 1, that works. Opens the position and completes the SellAtLimit.
CODE:
Please log in to see this code.


and Method 2, SimTradeFile2
using file data "-DIA160115P175;29-12-2015 15:05:00;Buy;1.35" has the missing bar problem.

Same data, trying to open the same position.
I can live with Method 1. I just thought I must be doing something wrong with my use of the SimTradeFile2 approach.
profile picture

Eugene

#8
SimTradeFile2 does not have a problem as it correctly opens the Position for you. One line in the file = one open position. Its duty is finished. Case closed.

The problem is either in the SellAtLimit usage or in something else you aren't showing. Note that from your postings it's not evident how you've integrated the SellAtLimit line and why Position.AllPositions must be employed in what appears a single-position code.
profile picture

kendalab

#9
It's multi-position, but I'm curious what single-position code I'm using? lol at myself

My code allows for an average down trade, so it's not single position exactly.

With SimTradeFile2, it looks like ActivePositions.Count is set prior to my
CODE:
Please log in to see this code.

loop starts, so having an open position counter set to include a position that isn't open at the start of my loop is what I'm not handling correctly.
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).