(程式碼) Spread System


[LegacyColorValue = TRUE];

{ *****************************************************************************************
   
Study : Spread System


*******************************************************************************************}


Inputs: Length(10), OBLevel(108), OSLevel(92), TrailBar(6), LowProf(100);
Vars:  PctChange1(0), PctChange2(0), Spread(0), ExtraMeasure(0);

{ Percent Change of Data1 and Data2 }
If Close[Length] of Data1 <> 0 then
PctChange1 = ( Close of Data1 / Close[Length] of Data1 ) * 100;
If Close[Length] of Data2 <> 0 then
PctChange2 = ( Close of Data2 / Close[Length] of Data2 ) * 100;

{ Strength of Data1 versus Data2 }
If ( PctChange2 ) <> 0 then
Spread = ( PCtChange1 / PctChange2 ) * 100;

{ Entry orders }
If Spread < OSLevel Then
Buy this bar at Close;

If Spread > OBLevel Then
SellShort this bar at Close;

{ Trailing stop }
If PositionProfit > 0 then Begin
If MarketPosition = 1 then
Sell ("LongTrailStop") next bar at Lowest( Low , TrailBar ) - ExtraMeasure stop;
If MarketPosition = -1 then
BuytoCover ("ShortTrailStop")next bar at Highest( High , TrailBar ) + ExtraMeasure stop; 
End;

{ Stale position exit }
If BarsSinceEntry > 6 AND PositionProfit < LowProf then Begin
Sell this bar on Close;
BuytoCover this bar on Close;
End;