Quote from fundjunkie:
Hi,
I have a need to do some testing against a series of individual contracts (not the usual back-adjusted stuff). Can you tell me if Tradersstudio, or the Pro version I should say, can do that? If so, how?
I'm not aware that this is something that is possible for a lone gunman like me, although it is very desirable. And that, quite frankly, is a pain in the ass...
Thx
D
Yes, it can be done in TradersStudio by treating the individual contracts like markets in a portfiolo. So you create a session which is made up of the individual contracts. Then you need to use a little special code. First we need a function which tell us if the current date is between two different dates
' TradersStudio(r) copyright 2004-2011, All rights reserved
' This function return true if the "TheDate" passed is between the From Day and month and the DayTo day and month
' It is used in calculating which contract to trade.
Function BetweenDates(TheDate, monthFrom, dayFrom, monthTo, DayTo) As Boolean
Dim dMonth As Integer
Dim dDay As Integer
Dim bOK As Boolean
Dim corrDate As Integer
Dim corrFrom As Integer
Dim corrTo As Integer
dMonth = Month(TheDate)
dDay = DayOfMonth(TheDate)
corrDate = dMonth * 100 + dDay
corrFrom = monthFrom * 100 + dayFrom
corrTo = monthTo * 100 + DayTo
If corrFrom > corrTo Then
Print "wrong input for BetweenDates"
StopRun
End If
BetweenDates = (corrFrom <= corrDate) And (corrDate <= corrTo)
End Function
The we use this function as follows
' TradersStudio(r) copyright 2004-2011, All rights reserved
' This example uses portfiolo capablities of TradersStudio to trade indivdual contracts in for the SP500
Sub SP500SingleContracts()
Dim lastChar As String
Dim fileYear As Integer
Dim bOK As Boolean
Dim CleanSymbol As String
CleanSymbol=thismarket.Symbol(0)
If InStr(thisMarket.Symbol(0),".") Then
CleanSymbol=Left(CleanSymbol,Len(CleanSymbol)-4)
End If
lastChar = Ucase(Right(CleanSymbol, 1))
fileYear = CInt(Mid(CleanSymbol, 2, 4))
If fileYear = Year(Date) + 1 Then
If lastChar = "H" Then
If BetweenDates(Date, 12, 9, 12, 31) Then
'Print CDate(Date), " : H (1)"
bOK = True
End If
End If
End If
If fileYear = Year(Date) Then
If lastChar = "H" Then
If BetweenDates(Date, 1, 1, 3, 9) Then
'Print CDate(Date), " : H (2)"
bOK = True
End If
End If
If lastChar = "M" Then
If betweenDates(Date, 3, 10, 6, 9) Then
'Print CDate(Date), " : M"
bOK = True
End If
End If
If lastChar = "U" Then
If betweenDates(Date, 6, 10, 9, 9) Then
'Print CDate(Date), " : U"
bOK = True
End If
End If
If lastChar = "Z" Then
If betweenDates(Date, 9, 10, 12, 9) Then
'Print CDate(Date), " : Z"
bOK = True
End If
End If
End If
If bOK Then
' call your original system here
ChanBreakOut(20)
Else
ExitAllTrades
End If
End Sub
You can see we use the symbol name and see if the current date is one in which that contract should of been active. If that is the case we run our system which could be anything inside the
If bOK then statement.
This current implementation has a weakness. We only use the current active contract. We could use the active contract as mom series and the previous contract as independent1. Then we could deal with having active data for longer lookback periods.