Translating code from Traderstudio What are GValues?

Quote from JaiSreeram:

Please may I know the answer?

Here an example we have two systems which use marketvars. They share this information with a tradeplan.

' 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



' 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


' 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 VirtualTradePlan()
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
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")="off"
Else
S1.Market(i).MarketVar("TurnOff")="on"
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
 
Back
Top