Vars: MVal(0), MAvg(0), MDif(0),counter(0), MVunter(0), TotalBars(0), HighestHi(0), LowestLo(0);
Array: MV[2,50](0);
MVal = MACD(FastMA,SlowMA);
MAvg = ema(MACD(FastMA,SlowMA),MacdMA);
MDif = MVal - MAvg;
// MA array and macd cross, High, low SAVE
counter = 0;
If CrossUp(MDif , 0) OR CrossDown(MDIF , 0) Then Begin
For counter = 0 to 49 Begin
MV[ 0 , 50 - Counter ] = MV[ 0 , 49 - Counter ];
MV[ 1 , 50 - Counter ] = MV[ 1 , 49 - Counter ];
MV[ 2 , 50 - Counter ] = MV[ 2 , 49 - Counter ];
End;
MV[ 0 , 0 ] = Index;
MV[ 1, 0 ] = High;
MV[ 2, 0 ] = Low;
End;
// Finding the highest corss and lowest cross when MACD Crosses over
HighestHi = -1;
LowestLo = 9999;
For counter = 0 to NCOs-1 Begin
If MV[ 1 , counter ] > HighestHi then
HighestHi = MV[ 1 , counter ];
If MV[ 2 , counter ] < LowestLo then
LowestLo = MV[ 2 , counter ];
End;
Totalbars = Index - MV[ 0 , NCOs - 1];
if date <> date[1] then var1 = date[1];
If TotalBars < NBars and exitdate(1) != var1 and stime < 150000 then Begin
Buy("B",atstop, HighestHi + ATR(30)*AtrMult) ;
Sell("S",atstop, LowestLo - ATR(30)*AtrMult) ;
End;
ExitLong("EL", atstop, Lowest( Low , TrailBar ));
ExitShort("ES", atstop, Highest( High , TrailBar));
SetStopLoss(StopPer);
SetStopEndofday(150000);
-Charles Sin

No comments:
Post a Comment