Code: Select all
{STAD13: LinReg - Mom}
[LegacyColorValue = TRUE];
Inputs:
Price(Close), Regress(20), XMALen(15), MomLen(10), EntryPct(.25),
EntryCnt(4), BigProfs(8), ExitBars(4), BKeven(3), Protect(3), Trailing(5), Volatile(3), Length(10);
Variables:
XLRAverage(0), Moment(0), BuySetup(False), SellSetup(False), BuyPrice(0), SellPrice(0),
LongCounter(0), ShortCounter(0), ATR(0);
XLRAverage = XAverage(LinearRegValue(Price, Regress, 0), XMALen);
Moment = Momentum(Price, MomLen);
ATR = AvgTrueRange(10);
LongCounter = LongCounter + 1;
ShortCounter = ShortCounter + 1;
BuySetup = XLRAverage > XLRAverage[1] AND Close > XLRAverage AND Moment < 0 AND Moment > Moment[1];
SellSetup = XLRAverage < XLRAverage[1] AND Close < XLRAverage AND Moment > 0 AND Moment < Moment[1];
If BuySetup Then Begin
BuyPrice = High + ( EntryPct * ATR );
LongCounter = 1;
End;
If SellSetup Then Begin
SellPrice = Low - ( EntryPct * ATR );
ShortCounter = 1;
End;
If LongCounter <= EntryCnt Then
Buy next bar at BuyPrice Stop;
If ShortCounter <= EntryCnt Then
Sell next bar at SellPrice Stop;
IncludeSystem:"ATR Big Profit Stop", BIGPROFS, LENGTH, EXITBARS;
IncludeSystem:"ATR Breakeven Stop", BKEVEN, LENGTH;
IncludeSystem:"ATR Protective Stop", PROTECT, LENGTH;
IncludeSystem:"ATR Trailing Stop", TRAILING, LENGTH;
IncludeSystem:"ATR Volatility Stop", VOLATILE, LENGTH;
{For Backtesting Purposes}
If LastBaronChart Then Begin
Sell this bar on Close;
BuyToCover this bar on Close;
End;