有一個舊的程式碼,很早以前有朋友托我作測試並協助修改,但我一直沒有時間幫他處理;現在"有女萬事足"後,更沒時間測試了,為了不浪費,經過朋友同意,在這裡開放給版上各位對撰寫策略程式碼有興趣的人研究。如果在修改語法之後,測試結果很不錯的話,記得要跟我分享唷!! *ps: 希望八月中之後能有更多的時間寫文章。
程式碼為TS格式
Inputs: Ceil(60), Flr(20),
{Additional inputs}
TStop1(0), StopB1(999), StopV1(0),
TStop2(0), StopB2(999), StopV2(0),
TAdd3(0), AddB3(999), TStop3(0), StopB3(999), Alpha3(0), Beta3(0),
TAdd4(0), AddV4(0), TStop4(0), StopV4(0), Alpha4(0), Beta4(0);
Var: X(0), Y(0), ZDelta(0), VarA(0), VarB(0), OldVarA(0), Pos(0), OpLoss(0), OpPro(0), BottDay(0), PeakDay(0),
{Additional variables}
Trigger(0), MaxReg(0);
Y = X;
X = Stddev(Close, 30);
ZDelta = (X - Y) / X;
If CurrentBar =1 then
VarA = 20;
OldVarA = VarA;
VarA = OldVarA * (1 + ZDelta);
VarA = MaxList(VarA, Flr);
VarA = MinList(VarA, Ceil);
VarB = VarA * 0.5;
Buy ("Go Long") tomorrow at Highest(High, VarA) Stop;
Sell ("Go Short") tomorrow at Lowest(Low, VarA) Stop;
ExitLong ("Exit Long") tomorrow at Lowest(Low, VarB) Stop;
ExitShort ("Exit Short") tomorrow at Highest(High, VarB) Stop;
{Additional trading}
If BigPointValue <> 0 and EntryPrice <> 0 Then Begin
Trigger = (PositionProfit/BigPointValue) * 100 / EntryPrice;
MaxReg = (MaxPositionProfit/BigPointValue) * 100 / EntryPrice;
End;
If TStop1 = 1 Then Begin
If BarsSinceEntry >= StopB1 and Trigger < StopV1 Then Begin
If MarketPosition = 1 Then
ExitLong ("Stop Long 1") tomorrow at Open Stop;
If MarketPosition = -1 Then
ExitShort ("Stop Short 1") tomorrow at Open Stop;
End;
End;
If TStop2 = 1 Then Begin
If BarsSinceEntry >= StopB2 and Trigger < StopV2 Then Begin
If MarketPosition = 1 Then
ExitLong ("Stop Long 2") tomorrow at Open Stop;
If MarketPosition = -1 Then
ExitShort ("Stop Short 2") tomorrow at Open Stop;
End;
End;
If TAdd3 = 1 Then Begin
If BarsSinceEntry >= AddB3 and
Trigger Crosses Over (Alpha3 + Beta3 * BarsSinceEntry) Then Begin
If MarketPosition = 1 Then
Buy ("Add Long 3") tomorrow at Open Stop;
If MarketPosition = -1 Then
Sell ("Add Short 3") tomorrow at Open Stop;
End;
End;
If TStop3 = 1 Then Begin
If BarsSinceEntry >= StopB3 and
Trigger Crosses Under (Alpha3 + Beta3 * BarsSinceEntry) Then Begin
If MarketPosition = 1 Then
ExitLong ("Stop Long 3") tomorrow at Open Stop;
If MarketPosition = -1 Then
ExitShort ("Stop Short 3") tomorrow at Open Stop;
End;
End;
If TAdd4 = 1 Then Begin
If MaxReg >= AddV4 and
Trigger Crosses Over (Alpha4 + Beta4 * MaxReg) Then Begin
If MarketPosition = 1 Then
Buy ("Add Long 4") tomorrow at Open Stop;
If MarketPosition = -1 Then
Sell ("Add Short 4") tomorrow at Open Stop;
End;
End;
If TStop4 = 1 Then Begin
If MaxReg >= StopV4 and
Trigger Crosses Under (Alpha4 + Beta4 * MaxReg) Then Begin
If MarketPosition = 1 Then
ExitLong ("Stop Long 4") tomorrow at Open Stop;
If MarketPosition = -1 Then
ExitShort ("Stop Short 4") tomorrow at Open Stop;
End;
End;
{End additional trading}
Pos = MarketPosition;
OpLoss = MaxPositionLoss;
OpPro = MaxPositionProfit;
If OpLoss < OpLoss[1] And Pos <> 0 Then
BottDay = BarsSinceEntry;
If OpPro > OpPro[1] And Pos <> 0 Then
PeakDay = BarsSinceEntry;
{Percentage export}
If CurrentBar = 1 Then
Print(File("c:\Ua\Systems\Exam.txt"),"EntryDate",",","EntryPrice",",",
"MarketPosition",",","MaxPositionLoss",",","BottomDay",",",
"MaxPositionProfit",",","PeakDay",",","PositionProfit",",","LengthOfTrade");
If Pos <> Pos[1] And Pos[1] <> 0 Then
Print(File("c:\Ua\Systems\Exam.txt"),EntryDate(1),",",EntryPrice(1),",",
MarketPosition(1),",",(MaxPositionLoss(1)/BigPointValue)*100/EntryPrice(1),
",",BottDay,",",(MaxPositionProfit(1)/BigPointValue)*100/EntryPrice(1),
",",PeakDay,",",(PositionProfit(1)/BigPointValue)*100/EntryPrice(1),",",
BarsSinceEntry(1));
{End percentage export}