#### BillMurray

##### Member

Code:

```
declare lower;
## KAMA (Kaufman Adaptive Moving Average) Settings
input price = close;
input KAMAfastLength = 2;
input KAMAslowLength = 30;
input effRatioLength = 10;
input mode = {default KAMA, AMA};
Assert(KAMAfastLength > 0, "'fast length' must be positive: " + KAMAfastLength);
Assert(KAMAslowLength > 0, "'slow length' must be positive: " + KAMAslowLength);
def direction;
def volatility;
def ER;
switch (mode) {
case KAMA:
direction = AbsValue(price - price[effRatioLength]);
volatility = Sum(AbsValue(price - price[1]), effRatioLength);
ER = if volatility != 0 then direction / volatility else 0;
case AMA:
direction = Double.NaN;
volatility = Double.NaN;
ER = AbsValue((price - Lowest(low, effRatioLength)) -
(Highest(high, effRatioLength) - price)) / (Highest(high,
effRatioLength) - Lowest(low, effRatioLength));
}
def FastSF = 2 / (KAMAfastLength + 1);
def SlowSF = 2 / (KAMAslowLength + 1);
def ScaledSF = ER * (FastSF - SlowSF) + SlowSF;
def AMA = CompoundValue(1, AMA[1] + Sqr(ScaledSF) * (price - AMA[1]),
price);
def MovAvgAdaptive = AMA;
## EMA Settings
input length = 34;
input displace = 0;
def AvgExp = ExpAverage(price[-displace], length);
##MACD
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;
def diff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;
## Volume
def Vol = volume(period = AggregationPeriod.DAY);
def avg30dayVol = Average(volume, 30);
def today = volume;
def avg30periodVol = Average(volume, 30);
def BuyVolumeSignal = (today / avg30periodVol) * 100;
def SellVolumeSignal = (today / avg30periodVol) * 100;
def condition1 = price > MovAvgAdaptive and price > AvgExp and BuyVolumeSignal > 15 is true;
def condition2 = price < MovAvgAdaptive and price < AvgExp and BuyVolumeSignal > 15;
;
plot trend = if condition1 is true then 1 else if condition2 >0 then -1 else 0;
trend.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
trend.DefineColor("Up", Color.UPTICK);
trend.DefineColor("Down", Color.DOWNTICK);
trend.AssignValueColor(if trend > 0 then trend.Color("Up") else if trend < 0 then trend.Color("Down") else GetColor(1));
#Zero.SetDefaultColor(GetColor(5));
input DoAlerts = Yes;
Alert(condition1, "Cainer Buy", Alert.BAR, Sound.Ring );
Alert(condition2, "Cainer Sell", Alert.BAR, Sound.Bell );
```

Any suggestions would be greatly appreciated, and of course you get to use this. We use it to trade /ES and /NQ futures quite successfully.