Murray Ruggiero
Sponsor
Letâs look at the following example. We have two different systems. The first one is a simple channel breakout. You can see the VirtualBuy and VirtualSell. These use the virtual backtester and will be used to turn the system on and off. The filtering is done at the tradeplan level. When MarketVar TurnOff is set that system is turned off so we exit any trades we are in. The real buy and sells are disabled at the tradeplan level.
' TradersStudio(r) copyright 2004-2011, All rights reserved
Sub Virtual1(SLen)
Dim MinMove
Dim S As String
MinMove=GetActiveMinMove()
VirtualBuy("ChanBuy",1,Highest(High,SLen,0)+MinMove ,Stop,Day)
VirtualSell("ChanSell",1,Lowest(Low,SLen,0)-MinMove,Stop,Day)
Buy("ChanBuy",1,Highest(High,SLen,0)+MinMove ,Stop,Day)
Sell("ChanSell",1,Lowest(Low,SLen,0)-MinMove,Stop,Day)
S = MarketVar("TurnOff")
If Len(S)>0 Then
ExitLong("","",1,0,Market,Day)
ExitShort("","",1,0,Market,Day)
End If
End Sub
Here is an opening range breakout system which is the second system in our example
' TradersStudio(r) copyright 2004-2011, All rights reserved
' System which communicates with
Sub Virtual2(Mult)
Dim AveTr
Dim Nxtopen
Dim S As String
If BarNumber<LastBar Then
Nxtopen=NextOpen(0)
Else
Nxtopen=0
End If
If Close>Open Then
Sell("SellBrk",1,Nxtopen-Mult*TrueRange,Stop,Day)
VirtualSell("SellBrk",1,Nxtopen-Mult*TrueRange,Stop,Day)
End If
If Close<Open Then
Buy("BuyBrk",1,Nxtopen+Mult*TrueRange,Stop,Day)
VirtualBuy("BuyBrk",1,Nxtopen+Mult*TrueRange,Stop,Day)
End If
S = MarketVar("TurnOff")
If Len(S)>0 Then
ExitLong("","",1,0,Market,Day)
ExitShort("","",1,0,Market,Day)
End If
End Sub
Below is the virtual tradeplan. At the session level within the tradeplan we check the equity curve for both of the systems above. We turn on the system which has a higher equity curve and turn off the one with a lower equity value. When the system is turned off we set entrynumunits to 0, -1 means that we take position sizing from the session level. If we set entrynumunits to 0, we will set MarketVar(âTurnOffâ) to âExitâ and this flag will be used by the systems at the session level to exit any exiting positions.
' TradersStudio(r) copyright 2004-2011, All rights reserved
' This trade plan switchs between systems. It sets variables based on Virtual trading channel
' to trade the system which are performing best currently.
Sub VirtualTradePlan01()
Dim i As Integer
Dim S1 As TSProcessor.ISession
Dim S2 As TSProcessor.ISession
Dim n1 As Integer
Dim n2
If SessionCount <> 2 Then
MsgBox("This trade plan must have 2 sessions")
StopRun
End If
S1 = TradePlan.Session(0)
S2 = TradePlan.Session(1)
If S1.VirCurEquity > S2.VirCurEquity Then
n1 = -1
n2 = 0
Else
print "System 2 is the best"
n1 = 0
n2 = -1
End If
'Print S1.VirCurEquity & " / " & S2.VirCurEquity
For i = 0 To S1.MarketCount - 1
S1.Market(i).EntryNumUnits = n1
Next
For i = 0 To S2.MarketCount - 1
S2.Market(i).EntryNumUnits = n2
Next
For i = 0 To S1.MarketCount - 1
If n1=0 Then
S1.Market(i).MarketVar("TurnOff")="Exit"
Else
S1.Market(i).MarketVar("TurnOff")=""
End If
Next
For i = 0 To S2.MarketCount - 1
If n2=0 Then
S2.Market(i).MarketVar("TurnOff")="Exit"
Else
S2.Market(i).MarketVar("TurnOff")=""
End If
Next
End Sub
' TradersStudio(r) copyright 2004-2011, All rights reserved
Sub Virtual1(SLen)
Dim MinMove
Dim S As String
MinMove=GetActiveMinMove()
VirtualBuy("ChanBuy",1,Highest(High,SLen,0)+MinMove ,Stop,Day)
VirtualSell("ChanSell",1,Lowest(Low,SLen,0)-MinMove,Stop,Day)
Buy("ChanBuy",1,Highest(High,SLen,0)+MinMove ,Stop,Day)
Sell("ChanSell",1,Lowest(Low,SLen,0)-MinMove,Stop,Day)
S = MarketVar("TurnOff")
If Len(S)>0 Then
ExitLong("","",1,0,Market,Day)
ExitShort("","",1,0,Market,Day)
End If
End Sub
Here is an opening range breakout system which is the second system in our example
' TradersStudio(r) copyright 2004-2011, All rights reserved
' System which communicates with
Sub Virtual2(Mult)
Dim AveTr
Dim Nxtopen
Dim S As String
If BarNumber<LastBar Then
Nxtopen=NextOpen(0)
Else
Nxtopen=0
End If
If Close>Open Then
Sell("SellBrk",1,Nxtopen-Mult*TrueRange,Stop,Day)
VirtualSell("SellBrk",1,Nxtopen-Mult*TrueRange,Stop,Day)
End If
If Close<Open Then
Buy("BuyBrk",1,Nxtopen+Mult*TrueRange,Stop,Day)
VirtualBuy("BuyBrk",1,Nxtopen+Mult*TrueRange,Stop,Day)
End If
S = MarketVar("TurnOff")
If Len(S)>0 Then
ExitLong("","",1,0,Market,Day)
ExitShort("","",1,0,Market,Day)
End If
End Sub
Below is the virtual tradeplan. At the session level within the tradeplan we check the equity curve for both of the systems above. We turn on the system which has a higher equity curve and turn off the one with a lower equity value. When the system is turned off we set entrynumunits to 0, -1 means that we take position sizing from the session level. If we set entrynumunits to 0, we will set MarketVar(âTurnOffâ) to âExitâ and this flag will be used by the systems at the session level to exit any exiting positions.
' TradersStudio(r) copyright 2004-2011, All rights reserved
' This trade plan switchs between systems. It sets variables based on Virtual trading channel
' to trade the system which are performing best currently.
Sub VirtualTradePlan01()
Dim i As Integer
Dim S1 As TSProcessor.ISession
Dim S2 As TSProcessor.ISession
Dim n1 As Integer
Dim n2
If SessionCount <> 2 Then
MsgBox("This trade plan must have 2 sessions")
StopRun
End If
S1 = TradePlan.Session(0)
S2 = TradePlan.Session(1)
If S1.VirCurEquity > S2.VirCurEquity Then
n1 = -1
n2 = 0
Else
print "System 2 is the best"
n1 = 0
n2 = -1
End If
'Print S1.VirCurEquity & " / " & S2.VirCurEquity
For i = 0 To S1.MarketCount - 1
S1.Market(i).EntryNumUnits = n1
Next
For i = 0 To S2.MarketCount - 1
S2.Market(i).EntryNumUnits = n2
Next
For i = 0 To S1.MarketCount - 1
If n1=0 Then
S1.Market(i).MarketVar("TurnOff")="Exit"
Else
S1.Market(i).MarketVar("TurnOff")=""
End If
Next
For i = 0 To S2.MarketCount - 1
If n2=0 Then
S2.Market(i).MarketVar("TurnOff")="Exit"
Else
S2.Market(i).MarketVar("TurnOff")=""
End If
Next
End Sub
Yes Please Murray