## 2014年6月16日 星期一

### 三連發交易策略 Three In a Row [程式碼]

Three in a Row
You might be surprised at how well very simple ideas work. The principle of three in a row sounds simple, yet the results are very powerful. We buy when three conditions are met:
• Today’s close is greater than the close five days ago.
• The close 5 days ago is greater than the close 10 days ago.
• The close 10 days ago is greater than the close 15 days ago.
Short entries are similar, also requiring three conditions:
• Today’s close is less than the close five days ago.
• The close 5 days ago is less than the close 10 days ago.
• The close 10 days ago is less than the close 15 days ago.

inputs: ATRs_L(2),ATRs_S(2);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0);

MP = MarketPosition ;

if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;

if Close > Close[BarNo] and Close[BarNo] > Close[BarNo*2] and Close[BarNo*2] > Close[BarNo*3] then Buy next bar at Market ;

if Close < Close[BarNo] and Close[BarNo] < Close[BarNo*2] and Close[BarNo*2] < Close[BarNo*3] then Sell next bar at Market ;

if ExitType = 1 then SetStopLoss(PL * BigPointValue) ;

if ExitType = 2 then Begin
SetStopLoss(PL * BigPointValue) ;
SetProfitTarget(PF * BigPointValue) ;
end;

if ExitType = 3 then Begin
if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market ;
end;

if ExitType = 4 then Begin
SetStopLoss(PL * BigPointValue) ;
SetProfitTarget(PF * BigPointValue) ;
if MP > 0 and BarsSinceEntry = NBarL then Sell {ExitLong} next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then Buy {ExitShort} next bar at Market ;
end;

if ExitType = 5 then Begin

{Inputs: ATRs_L(3);}
Variables: PosHigh(0), ATRVal_L(0);
ATRVal_L = AvgTrueRange(10) * ATRs_L;

If BarsSinceEntry = 0 Then PosHigh = High;
If MarketPosition = 1 Then Begin
If High > PosHigh Then PosHigh = High;
ExitLong ("ATR") Next Bar at PosHigh - ATRVal_L Stop;
End else ExitLong ("ATR eb") Next bar at High - ATRVal_L Stop;
{Inputs: ATRs_S(3);}
Variables: PosLow(0), ATRVal_S(0);
ATRVal_S = AvgTrueRange(10) * ATRs_S;

If BarsSinceEntry = 0 Then PosLow = Low;

If MarketPosition = -1 Then Begin
If Low < PosLow Then PosLow = Low;
ExitShort ("ATR_1") Next Bar at PosLow + ATRVal_S Stop;
End else ExitShort ("ATR_1 eb") Next bar at Low + ATRVal_S Stop;
end;

if IsBalanceDay then setExitonClose ;   MagicQS084