• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Turn bottom ZigZag into an MTF indicator


Active member
I cannot seem to figure out how to add the bottom code MTF, its great for direction.

declare lower;

input method = {default average, high_low};

def percentamount = .01;
def revAmount = .05;
def atrreversal = 1.68;
def atrlength = 5;
def pricehigh = high;
def pricelow = low;
def averagelength = 5;
def averagetype = AverageType.WEIGHTED;
def mah = MovingAverage(averagetype, pricehigh, averagelength);
def mal = MovingAverage(averagetype, pricelow, averagelength);
def priceh2 = if method == method.high_low then pricehigh else mah;
def pricel2 = if method == method.high_low then pricelow else mal;
def EI = ZigZagHighLow("price h" = priceh2, "price l" = pricel2, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);

rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);
def chg = (if EISave == priceh2 then priceh2 else pricel2) - GetValue(EISave, 1);
def isUp = chg > 0;
def isDown = chg < 0;

plot Bullish = isUp;
plot Bearish = isDown;

# Alerts:
rec counter;
if (Bullish) {
    counter = 1;
} else {
    if (counter[1] == 1 or counter[1] < 10) {
        counter = counter[1] + 1;
    } else {
        counter = 1;

rec counterd;
if (Bearish) {
    counterd = 1;
} else {
    if (counterd[1] == 1 or counterd[1] < 10) {
        counterd = counterd[1] + 1;
    } else {
        counterd = 1;

def LongSignal = counterd == 3;
def ShortSignal = counter == 3;

input AlertSoundUP = {default “Bell”, “Chimes”, “Ding”, “NoSound”, “Ring”};
input AlertSoundDOWN = {“Bell”, “Chimes”, “Ding”, “NoSound”, default “Ring”};
Alert(LongSignal , text = "UP UP UP", Alert.BAR, AlertSoundUP);
Alert(ShortSignal , text = "DOWN DOWN DOWN", Alert.BAR, AlertSoundDOWN);

Last edited by a moderator:


Well-known member
Well, I haven't had much time to look into this but I did run a test by simply duplicating the indicator so there are three iterations with different average lengths by changing atrlength and averagelength just to see what that would show... Here was the result... Do you see any benefit from this...??? That was the best I could do for a quick test... I'm not sure if I'll have time later so perhaps someone else can dig deeper...



Active member
Thank you so much I do think it helps visualize what how the trend changes on with different lengths, I have not tested this indicator to this extent. I know someone else who can help and simplify the indicator into a binary code, however I do not want to give him homework lol, but I know henry1224 is great with these type of indicators from what I've seen, I even believe he might have codes like these.


New member
hi, can anyone help me with making a scanner with this study? i tried to disable everything below the "def chg = (if EISave == priceh2 then priceh2 else pricel2) - GetValue(EISave, 1);" and then added the "plot = datachg = chg;". then i went to scan and created a new scan. added the study "MTF_plotchg" then selected greater than value "0". but i get the error "folding: 'from' cannot be greater than 'to': 1>0". i figured this would work, since i am essentially using the "def isUp = chg > 0 and def isDown = chg < 0" outside into the scan. Any suggestions on how i can create a scan?
also what does " if !IsNaN(EI) then EI else GetValue(EISave, 1);" does this mean (!IsNaN(EI)?


Well-known member
@taipanaz You may or may not be able to get a scan to work based on the code above... The issue at hand is the inclusion and complexity of the reference to the ZigZagHighLow indicator, which also contributes to repainting issues... It may throw "Too Complex" errors...

Similar threads