Hi Wayne,
Hmmm - mixed results - Either I've stuffed something in the formula (new at Amibroker) or I'm missing some of the subleties in the parameters...... It's a start I guess.
The buy signals in the attached screenshot seem ok but the sells aren't so good - Corcoran's example (in the first link I posted) looks a lot better so I'll keep at it.
Anyway, here's the code :
_SECTION_BEGIN("All");
f = (C > 0.5) AND ((V*C) > 400000); //optional filter
AccumWindow = Param("Accumulation Window (days)", 20, 1, 50);
LowerBias = Param("Lower Bias", -0.5, -1, 0, 0.05);
UpperBias = Param("Upper Bias", 0.5, 0, 1, 0.05);
LowerQuantile = Param("Lower Quantile", 10, 0, 50);
UpperQuantile = Param("Upper Quantile", 90, 50, 100);
SellWindow= Param("Sell Window (days)", 10, 1, 50);
BuyWindow= Param("Buy Window (days)", 10, 1, 50);
ClosingDifference = Close - Ref(Close, -1);
ClosingPositionBias = ( ClosingDifference / ATR(1) );
SignValue = IIf ( ClosingPositionBias < LowerBias , -1, IIf ( ClosingPositionBias > UpperBias, 1, 0 ) );
TrueRangeAccumulator = IIf ( ATR(1) > Percentile ( ATR(1), AccumWindow, UpperQuantile ), Close * Volume * signValue * ATR(1), 0 );
AccumulatorLine = Sum(TrueRangeAccumulator , AccumWindow );
SellAccumulator = IIf ( Close > Percentile ( Close, AccumWindow, UpperQuantile ), Close * Volume * signValue * ATR(1), 0 );
SellLine = Sum(SellAccumulator , AccumWindow );
Sell = Cross ( 0, AccumulatorLine ) AND ( BarsSince ( SellLine <= 0 ) > SellWindow); //need to improve this
Sell = ExRemSpan(Sell, 8);
BuyAccumulator = IIf ( Close < Percentile ( Close, AccumWindow, LowerQuantile ), Close * Volume * signValue * ATR(1), 0 );
BuyLine = Sum(BuyAccumulator , AccumWindow );
Buy = Cross ( AccumulatorLine , 0 ) AND ( BarsSince ( Buyline > 0 ) > BuyWindow); //need to improve this
Buy = ExRemSpan(Buy, 8) AND f;
PositionSize = -100 / GetOption("MaxOpenPositions");
PositionScore = 100 - RSI(14);
Filter = Buy;
AddColumn( Volume, "Volume");
arrows = ParamToggle("Plot Trade Arrows", "HIDE|SHOW", 1);
if (arrows)
{
PlotShapes( Buy*shapeSmallUpTriangle+ Sell*shapeSmallDownTriangle, IIf(Buy, colorLime, colorRed), 0 );
}
_SECTION_END();
_SECTION_BEGIN("Indicators");
Plot( AccumulatorLine , "AccumulatorLine ", ColorRGB(255,0,0), styleNoTitle | styleNoLabel);
Plot( SellLine , "SellLine ", ColorRGB(100,0,0), styleNoTitle | styleNoLabel | styleArea );
Plot( BuyLine, "BuyLine", ColorRGB(0,0,100), styleNoTitle | styleNoLabel | styleArea );
_SECTION_END();