TOS – Achilles ES Psar Cross

Back in time series. A program from 2011 for TOS. Originally for the ES, now for $DXY plots.

You just know that I must be running out of ideas to make desperate moves like this.

Or just giving away free stuff. In the shape of tiny, little yellow balls.

# Achilles indicator 2011 
# ver 1.007


input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, default EMA};


input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input smoothingType = {default SMA, EMA};


input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;

def sDev = StDev(data = price[-displace], length = length);
def MidLine = Average(data = price[-displace], length = length);
def LowerBand = MidLine + Num_Dev_Dn * sDev;
def UpperBand = MidLine + Num_Dev_up * sDev;

input Len = 14;
input CIx = {default CI3, CI2};

def CI2 = 100 * Log( Sum( TrueRange(high, close, low), Len)) / ( Highest(close[1], Len) - Lowest(close[1], Len)) / Log(Len);

def CI3 = ( ( Log(Sum(TrueRange(high, close, low), Len) / (Highest(if high >= close[1] then high else close[1], Len) - Lowest( if low <= close[1] then low else close[1], Len))) / Log(10)) / (Log(Len) / Log(10))) * 100;

def CI = if CIx == CIx.CI3 then CI3 else CI2;


def SlowK = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, smoothingType).FullK;



def SlowD = reference StochasticFull(over_bought, over_sold, KPeriod, DPeriod, priceH, priceL, priceC, 3, smoothingType).FullD;


input fsLength = 7;
input medLength = 14;
input slLength = 28;

def trRng = TrueRange(high, close, low);

def trRngFast = Sum(trRng, fastLength);
def trRngMed = Sum(trRng, medLength);
def trRngSlow = Sum(trRng, slowLength);

def diff = close - Min(close[1], low);

def diffFast = Sum(diff, fsLength);
def diffMed = Sum(diff, medLength);
def diffSlow = Sum(diff, slLength);

def factorFast = slLength / fsLength;
def factorMed = slLength / medLength;

def valFast = (diffFast / trRngFast) * factorFast;
def valMed = (diffMed / trRngMed) * factorMed;
def valSlow = (diffSlow / trRngSlow);

def UltOsc = if trRngFast == 0 or trRngMed == 0 or trRngSlow == 0 then 0 
else (valFast + valMed + valSlow) / (factorFast + factorMed + 1);



def NetChgAvg = WildersAverage(price - price[1], 2);
def TotChgAvg = WildersAverage(AbsValue(price - price[1]), 2);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def NetChgAvg14 = WildersAverage(price - price[1], 14);
def TotChgAvg14 = WildersAverage(AbsValue(price - price[1]), 14);
def ChgRatio14 = if TotChgAvg14 != 0 then NetChgAvg14 / TotChgAvg14 else 0;


def RSi2 = (50 * (ChgRatio + 1));


def RSi = (50 * (ChgRatio14 + 1));

def condition65 = RSi >= 65 and RSi <= 75;

def condition27 = RSi <= 27 and RSi >= 15;

Alert(Crosses(RSi, 65, CrossingDirection.BELOW), "RSI 65 65 65!", Alert.BAR, Sound.Ding);
Alert(Crosses(RSi, 27, CrossingDirection.ABOVE), "RSI 27 27 27!", Alert.BAR, Sound.Ding);


def Value = MACD(fastLength, slowLength, MACDLength, AverageType).Value;
def Avg = MACD(fastLength, slowLength, MACDLength, AverageType).Avg;

def MDown = Value[1] > Avg[1] and Value < Avg;
def MUp = Value[1] < Avg[1] and Value > Avg;

def Down = ((SlowK < SlowD and SlowK > 80 and CI > 44) or ((MDown and SlowK > SlowD and SlowD > 40 and CI < 50 and CI > 35) or (MDown and SlowK > 80 and SlowD < 80))) or ((priceH > UpperBand and MUp and SlowK > 80 and CI < 48 )  or (priceH > UpperBand and SlowK > 75 and SlowD < 74 and CI > 49.40));
def Down2 = ((priceH >= UpperBand and MUp and SlowK > 90 and SlowD > 80 and CI < 48 and CI > 38 ) );
def down3 = (UltOsc >= 0.67 and SlowK >= 79);


def down6 = (CI < 27.41);


def Up =  (((SlowK > SlowD and CI < 28.01 and SlowK < 12.50) or ((SlowK  < 15.50 and CI < 35.01 ) and (SlowK > SlowD))) or (SlowK < 19 and priceL <= LowerBand and SlowD > 20 and CI > 39.25 and SlowK < SlowD)) or (MUp and SlowK < 20.18 and SlowD > SlowK and CI > 40) or (SlowK  < 12 and CI < 35.01  and SlowD < 12.50) ;

def up2 = (UltOsc <= 0.2671 and SlowK <= 21);

def up3 = (CI < 33.5);

def up4 = (UltOsc <= 0.43 and UltOsc >= 0.425) or (UltOsc <= 0.28 and UltOsc >= 0.25);

def PercentB = (price - LowerBand) / (UpperBand - LowerBand) * 100;

def up5 = (PercentB <= -22 and CI <= 24.56) or (PercentB < 0 and CI <= 34.50 and CI >= 34.20) or (PercentB < -0.9 and CI > 42 and CI < 42.80) or (PercentB <= 10 and CI > 49 and CI < 50) or (PercentB <= -1 and CI > 37.40 and CI < 37.60)  or (PercentB <= -21 and CI > 56.90 and CI < 57) or (PercentB < 24 and CI > 43.20 and CI < 43.50) or (PercentB < 5 and CI > 52.90 and CI < 53) or (PercentB < -17 and CI > 35.20 and CI < 35.50 or (PercentB < -28 and CI > 47.70 and CI < 48));

def up6 = (RSi2 <= 2);


AddLabel(yes, Concat("",    
if ((PercentB <= -10) and (CI <= 24.56)) then "SLING SHOT!" else 
if ((PercentB < 0) and (CI < 35)) then "BOUNCE TO RESISTANCE" else 
if ((PercentB >= 128) and (CI <= 39.90)) then "TOP SUSPECTED" else
""), 
if ((PercentB <= -10) and (CI <= 24.56)) then Color.ORANGE else 
if ((PercentB < 0) and (CI < 35)) then Color.ORANGE else
if ((PercentB >= 128) and (CI >= 39.90)) then Color.GREEN else
Color.GRAY);


def down4 = ((CI > 40.60) and (CI < 44.61));


def down5 = (PercentB >= 110 and CI >= 41.50 and CI <= 42.50)  or (PercentB > 95 and CI < 34) or (PercentB >= 110 and CI < 44.50 and CI > 44.25) or (PercentB >= 132 and CI < 48)  or (PercentB >= 129 and CI < 56.50 and CI > 56) or (PercentB > 99 and CI > 61);

plot ArrowUp = if Up then low * 1 else Double.NaN;
# Adjust 0.995 according to how close you want the arrow to the price low
# Kudos to Richard for posting how to do this some time ago
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.SetLineWeight(4);


plot ArrowUp2 = if up2 then low * 0.999 else Double.NaN;
# Adjust 0.995 according to how close you want the arrow to the price low
# Kudos to Richard for posting how to do this some time ago
ArrowUp2.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp2.SetDefaultColor(Color.CYAN);
ArrowUp2.SetLineWeight(4);


plot ArrowUp3 = if up3 then low * 0.999 else Double.NaN;
# Adjust 0.995 according to how close you want the arrow to the price low
# Kudos to Richard for posting how to do this some time ago
ArrowUp3.SetPaintingStrategy(PaintingStrategy.SQUARES);
ArrowUp3.SetDefaultColor(Color.WHITE);
ArrowUp3.SetLineWeight(5);


#plot ArrowUp4 = if up4 then low * 0.99 else Double.NaN;
# Adjust 0.995 according to how close you want the arrow to the price low
# Kudos to Richard for posting how to do this some time ago
#ArrowUp4.SetPaintingStrategy(PaintingStrategy.SQUARES);
#ArrowUp4.SetDefaultColor(Color.RED);
#ArrowUp4.SetLineWeight(5);


plot ArrowUp5 = if up5 then low * 0.999 else Double.NaN;
# Adjust 0.995 according to how close you want the arrow to the price low
# Kudos to Richard for posting how to do this some time 
ArrowUp5.SetPaintingStrategy(PaintingStrategy.POINTS);
ArrowUp5.SetDefaultColor(Color.ORANGE);
ArrowUp5.SetLineWeight(5);



plot ArrowUp6 = if up6 then low * 0.998 else Double.NaN;
# Adjust 0.995 according to how close you want the arrow to the price low
# Kudos to Richard for posting how to do this some time ago
ArrowUp6.SetPaintingStrategy(PaintingStrategy.SQUARES);
ArrowUp6.SetDefaultColor(Color.CYAN);
ArrowUp6.SetLineWeight(3);


plot ArrowDn = if Down <> Down2 then high * 1 else Double.NaN;
# Adjust 1.005 according to how close you want the arrow to the price high
# Kudos to Richard for posting how to do this some time ago
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.RED);
ArrowDn.SetLineWeight(4);

plot ArrowDn2 = if Down2 then high * 1 else Double.NaN;
# Adjust 1.005 according to how close you want the arrow to the price high
# Kudos to Richard for posting how to do this some time ago
ArrowDn2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn2.SetDefaultColor(Color.YELLOW);
ArrowDn2.SetLineWeight(4);


plot ArrowDn3 = if down3 then high * 1 else Double.NaN;
# Adjust 1.005 according to how close you want the arrow to the price high
# Kudos to Richard for posting how to do this some time ago
ArrowDn3.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn3.SetDefaultColor(Color.CYAN);
ArrowDn3.SetLineWeight(4);


plot ArrowDn4 = if down4 then high * 1.0002 else Double.NaN;
# Adjust 1.005 according to how close you want the arrow to the price high
# Kudos to Richard for posting how to do this some time ago
ArrowDn4.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
ArrowDn4.SetDefaultColor(Color.WHITE);
ArrowDn4.SetLineWeight(4);


plot ArrowDn5 = if down5 then low * 1.001 else Double.NaN;
# Adjust 0.995 according to how close you want the arrow to the price low
# Kudos to Richard for posting how to do this some time ago
ArrowDn5.SetPaintingStrategy(PaintingStrategy.POINTS);
ArrowDn5.SetDefaultColor(Color.CYAN);
ArrowDn5.SetLineWeight(5);


plot ArrowDn6 = if (down6 and RSi2 > 75) then high * 1 else Double.NaN;
# Adjust 1.005 according to how close you want the arrow to the price high
# Kudos to Richard for posting how to do this some time ago
ArrowDn6.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn6.SetDefaultColor(Color.ORANGE);
ArrowDn6.SetLineWeight(4);


input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};

def HiLo = Min(high - low, 1.5 * Average(high - low, ATRPeriod));
def HRef = if low <= high[1]
    then high - close[1]
    else (high - close[1]) - 0.5 * (low - high[1]);
def LRef = if high >= low[1]
    then close[1] - low
    else (close[1] - low) - 0.5 * (low[1] - high);
def ATRMod = ExpAverage(Max(HiLo, Max(HRef, LRef)), 2 * ATRPeriod - 1);

def loss;
switch (trailType) {
case modified:
    loss = ATRFactor * ATRMod;
case unmodified:
    loss = ATRFactor * Average(TrueRange(high,  close,  low),  ATRPeriod);
}

rec state = {default init, long, short};
rec trail;
switch (state[1]) {
case init:
    if (!IsNaN(loss)) {
        switch (firstTrade) {
        case long:
            state = state.long;
            trail =  close - loss;
        case short:
            state = state.short;
            trail = close + loss;
    }
    } else {
        state = state.init;
        trail = Double.NaN;
    }
case long:
    if (close > trail[1]) {
        state = state.long;
        trail = Max(trail[1], close - loss);
    }
    else {
        state = state.short;
        trail = close + loss;
    }
case short:
    if (close < trail[1]) {
        state = state.short;
        trail = Min(trail[1], close + loss);
    }
    else {
        state = state.long;
        trail =  close - loss;
    }
}

def BuySignal = Crosses(state == state.long, 0, CrossingDirection.ABOVE);
def SellSignal = Crosses(state == state.short, 0, CrossingDirection.ABOVE);

plot TrailingStop = trail;

TrailingStop.SetPaintingStrategy(PaintingStrategy.POINTS);
TrailingStop.DefineColor("Buy", GetColor(0));
TrailingStop.DefineColor("Sell", GetColor(1));
TrailingStop.AssignValueColor(if state == state.long
    then TrailingStop.Color("Sell")
    else TrailingStop.Color("Buy"));

AddLabel(yes, Concat(Concat ("STOCH(10): " , SlowK),  Concat(" ULT:", UltOsc)), if SlowK <= 20 then Color.RED else (if SlowK >= 80 then Color.GREEN else Color.YELLOW));

AddLabel(yes, Concat("RSI2: " , RSi2), if RSi2 <= 2 then Color.RED else (if RSi2 >= 80 then Color.RED else Color.GREEN));

input accelerationFactor = 0.02;
input accelerationLimit = 0.2;

def PSAR_Ref = ParabolicSAR(accelerationFactor, accelerationLimit);

EMAs are 89 and 365.

I guess the Comfort levels, the LEMAs and their fields and the CloseLines (E-36 channel crossback & targets) are almost as old ideas of mine.

Not much has changed.

No change, I can’t change.