Multi-Time Frame Parabolic SAR for ThinkorSwim

tradegeek

Active member
2019 Donor
Here is my attempt to put together a multi time-frame parabolic sar indicator using my copy-and-paste coding ability 😂. I had some trouble trying to get it to do a few things so if someone could jump in and give a hand, that would be great. If anyone has anything to add or whatever, please feel free.

If three or more of the time frame is above the psar then the MTF PSAR line (top line #6) is green otherwise it will be red. The candles are colored the same as this line.

* EDITED *

I've actually posted the wrong indicator which is actually the MTF ATR Trailing Stop indicator. I've updated the post to reflect the MTF Parabolic SAR indicator.

2rUzZP.png



MTF PSAR for time-based charts...
Code:
# Multi time-frame Parabolic SAR indicator by tradegeek.
# Master PSAR line(top line, #6) is green when 3+ of the 5 time-frames are cyan and red when 3+ of the 5 time-frame are magenta.
# MTF_PSAR

declare lower;

input TimeFrame1 = AggregationPeriod.MIN;
input TimeFrame2 = AggregationPeriod.TWO_MIN;
input TimeFrame3 = AggregationPeriod.FIVE_MIN;
input TimeFrame4 = AggregationPeriod.TEN_MIN;
input TimeFrame5 = AggregationPeriod.FIFTEEN_MIN;
input PaintBars = {default "yes", "no"};

def close1 = Close(Period = TimeFrame1);
def close2 = Close(Period = TimeFrame2);
def close3 = Close(Period = TimeFrame3);
def close4 = Close(Period = TimeFrame4);
def close5 = Close(Period = TimeFrame5);

def low1 = Low(Period = TimeFrame1);
def low2 = Low(Period = TimeFrame2);
def low3 = Low(Period = TimeFrame3);
def low4 = Low(Period = TimeFrame4);
def low5 = Low(Period = TimeFrame5);

def high1 = High(Period = TimeFrame1);
def high2 = High(Period = TimeFrame2);
def high3 = High(Period = TimeFrame3);
def high4 = High(Period = TimeFrame4);
def high5 = High(Period = TimeFrame5);

input accelerationFactor = 0.02;
input accelerationLimit = 0.2;

assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

##### Chart Time-frame (Time-frame 1)
def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
    state = state.long;
    acc = accelerationFactor;
    extreme = high;
    SAR = low;
case short:
    if (SAR[1] < high)
    then {
        state = state.long;
        acc = accelerationFactor;
        extreme = high;
        SAR = extreme[1];
    } else {
        state = state.short;
        if (low < extreme[1])
        then {
            acc = min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = low;
        } else {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = max(max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
case long:
    if (SAR[1] > low)
    then {
        state = state.short;
        acc = accelerationFactor;
        extreme = low;
        SAR = extreme[1];
    } else {
        state = state.long;
        if (high > extreme[1])
        then {
            acc = min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = high;
        } else {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = min(min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
}

##### Time-frame 2
def state2 = {default init, long, short};
def extreme2;
def SAR2;
def acc2;

switch (state2[1]) {
case init:
    state2 = state2.long;
    acc2 = accelerationFactor;
    extreme2 = high2;
    SAR2 = low2;
case short:
    if (SAR2[1] < high2)
    then {
        state2 = state2.long;
        acc2 = accelerationFactor;
        extreme2 = high2;
        SAR2 = extreme2[1];
    } else {
        state2 = state2.short;
        if (low2 < extreme2[1])
        then {
            acc2 = min(acc2[1] + accelerationFactor, accelerationLimit);
            extreme2 = low2;
        } else {
            acc2 = acc2[1];
            extreme2 = extreme2[1];
        }
        SAR2 = max(max(high2, high2[1]), SAR2[1] + acc2 * (extreme2 - SAR2[1]));
    }
case long:
    if (SAR2[1] > low2)
    then {
        state2 = state2.short;
        acc2 = accelerationFactor;
        extreme2 = low2;
        SAR2 = extreme2[1];
    } else {
        state2 = state2.long;
        if (high2 > extreme2[1])
        then {
            acc2 = min(acc2[1] + accelerationFactor, accelerationLimit);
            extreme2 = high2;
        } else {
            acc2 = acc2[1];
            extreme2 = extreme2[1];
        }
        SAR2 = min(min(low2, low2[1]), SAR2[1] + acc2 * (extreme2 - SAR2[1]));
    }
}

##### Time-frame 3
def state3 = {default init, long, short};
def extreme3;
def SAR3;
def acc3;

switch (state3[1]) {
case init:
    state3 = state3.long;
    acc3 = accelerationFactor;
    extreme3 = high3;
    SAR3 = low3;
case short:
    if (SAR3[1] < high3)
    then {
        state3 = state3.long;
        acc3 = accelerationFactor;
        extreme3 = high3;
        SAR3 = extreme3[1];
    } else {
        state3 = state3.short;
        if (low3 < extreme3[1])
        then {
            acc3 = min(acc3[1] + accelerationFactor, accelerationLimit);
            extreme3 = low3;
        } else {
            acc3 = acc3[1];
            extreme3 = extreme3[1];
        }
        SAR3 = max(max(high3, high3[1]), SAR3[1] + acc3 * (extreme3 - SAR3[1]));
    }
case long:
    if (SAR3[1] > low3)
    then {
        state3 = state3.short;
        acc3 = accelerationFactor;
        extreme3 = low3;
        SAR3 = extreme3[1];
    } else {
        state3 = state3.long;
        if (high3 > extreme3[1])
        then {
            acc3 = min(acc3[1] + accelerationFactor, accelerationLimit);
            extreme3 = high3;
        } else {
            acc3 = acc3[1];
            extreme3 = extreme3[1];
        }
        SAR3 = min(min(low3, low3[1]), SAR3[1] + acc3 * (extreme3 - SAR3[1]));
    }
}

##### Time-frame 4
def state4 = {default init, long, short};
def extreme4;
def SAR4;
def acc4;

switch (state4[1]) {
case init:
    state4 = state4.long;
    acc4 = accelerationFactor;
    extreme4 = high4;
    SAR4 = low4;
case short:
    if (SAR4[1] < high4)
    then {
        state4 = state4.long;
        acc4 = accelerationFactor;
        extreme4 = high4;
        SAR4 = extreme4[1];
    } else {
        state4 = state4.short;
        if (low4 < extreme4[1])
        then {
            acc4 = min(acc4[1] + accelerationFactor, accelerationLimit);
            extreme4 = low4;
        } else {
            acc4 = acc4[1];
            extreme4 = extreme4[1];
        }
        SAR4 = max(max(high4, high4[1]), SAR4[1] + acc4 * (extreme4 - SAR4[1]));
    }
case long:
    if (SAR4[1] > low4)
    then {
        state4 = state4.short;
        acc4 = accelerationFactor;
        extreme4 = low4;
        SAR4 = extreme4[1];
    } else {
        state4 = state4.long;
        if (high4 > extreme4[1])
        then {
            acc4 = min(acc4[1] + accelerationFactor, accelerationLimit);
            extreme4 = high4;
        } else {
            acc4 = acc4[1];
            extreme4 = extreme4[1];
        }
        SAR4 = min(min(low4, low4[1]), SAR4[1] + acc4 * (extreme4 - SAR4[1]));
    }
}

##### time-frame 5
def state5 = {default init, long, short};
def extreme5;
def SAR5;
def acc5;

switch (state5[1]) {
case init:
    state5 = state5.long;
    acc5 = accelerationFactor;
    extreme5 = high5;
    SAR5 = low5;
case short:
    if (SAR5[1] < high5)
    then {
        state5 = state5.long;
        acc5 = accelerationFactor;
        extreme5 = high5;
        SAR5 = extreme5[1];
    } else {
        state5 = state5.short;
        if (low5 < extreme5[1])
        then {
            acc5 = min(acc5[1] + accelerationFactor, accelerationLimit);
            extreme5 = low5;
        } else {
            acc5 = acc5[1];
            extreme5 = extreme5[1];
        }
        SAR5 = max(max(high5, high5[1]), SAR5[1] + acc5 * (extreme5 - SAR5[1]));
    }
case long:
    if (SAR5[1] > low5)
    then {
        state5 = state5.short;
        acc5 = accelerationFactor;
        extreme5 = low5;
        SAR5 = extreme5[1];
    } else {
        state5 = state5.long;
        if (high5 > extreme5[1])
        then {
            acc5 = min(acc5[1] + accelerationFactor, accelerationLimit);
            extreme5 = high5;
        } else {
            acc5 = acc5[1];
            extreme5 = extreme5[1];
        }
        SAR5 = min(min(low5, low5[1]), SAR5[1] + acc5 * (extreme5 - SAR5[1]));
    }
}

##### Plots
plot PSAR = if IsNaN(SAR) then Double.NaN else 1;
PSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR.SetLineWeight(lineWeight = 3);
PSAR.DefineColor("Buy", GetColor(0));
PSAR.DefineColor("Sell", GetColor(1));
PSAR.AssignValueColor(if state == state.long
    then PSAR.Color("Sell")
    else PSAR.Color("Buy"));

plot PSAR2 = if IsNaN(SAR2) then Double.NaN else 2;
PSAR2.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR2.SetLineWeight(lineWeight = 3);
PSAR2.DefineColor("Buy", GetColor(0));
PSAR2.DefineColor("Sell", GetColor(1));
PSAR2.AssignValueColor(if state2 == state2.long
    then PSAR2.Color("Sell")
    else PSAR2.Color("Buy"));

plot PSAR3 = if IsNaN(SAR3) then Double.NaN else 3;
PSAR3.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR3.SetLineWeight(lineWeight = 3);
PSAR3.DefineColor("Buy", GetColor(0));
PSAR3.DefineColor("Sell", GetColor(1));
PSAR3.AssignValueColor(if state3 == state3.long
    then PSAR3.Color("Sell")
    else PSAR3.Color("Buy"));

plot PSAR4 = if IsNaN(SAR4) then Double.NaN else 4;
PSAR4.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR4.SetLineWeight(lineWeight = 3);
PSAR4.DefineColor("Buy", GetColor(0));
PSAR4.DefineColor("Sell", GetColor(1));
PSAR4.AssignValueColor(if state4 == state4.long
    then PSAR4.Color("Sell")
    else PSAR4.Color("Buy"));

plot PSAR5 = if IsNaN(SAR5) then Double.NaN else 5;
PSAR5.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR5.SetLineWeight(lineWeight = 3);
PSAR5.DefineColor("Buy", GetColor(0));
PSAR5.DefineColor("Sell", GetColor(1));
PSAR5.AssignValueColor(if state5 == state5.long
    then PSAR5.Color("Sell")
    else PSAR5.Color("Buy"));

def PSAR_TF1 = if state == state.long then 0 else 1;
def PSAR_TF2 = if state2 == state2.long then 0 else 1;
def PSAR_TF3 = if state3 == state3.long then 0 else 1;
def PSAR_TF4 = if state4 == state4.long then 0 else 1;
def PSAR_TF5 = if state5 == state5.long then 0 else 1;


plot MTF_PSAR = 6;
MTF_PSAR.SetPaintingStrategy(PaintingStrategy.SQUARES);
MTF_PSAR.SetLineWeight(lineWeight = 3);
MTF_PSAR.DefineColor("Buy", GetColor(5));
MTF_PSAR.DefineColor("Sell", GetColor(6));
MTF_PSAR.AssignValueColor ( if (PSAR_TF1 + PSAR_TF2 + PSAR_TF3 + PSAR_TF4 + PSAR_TF5) >= 3 then MTF_PSAR.Color("Buy") else MTF_PSAR.Color("Sell"));

AssignPriceColor ( if PaintBars is false and (PSAR_TF1 + PSAR_TF2 + PSAR_TF3 + PSAR_TF4 + PSAR_TF5) >= 3 then MTF_PSAR.Color("Buy") else if PaintBars is false and (PSAR_TF1 + PSAR_TF2 + PSAR_TF3 + PSAR_TF4 + PSAR_TF5) < 3 then MTF_PSAR.Color("Sell") else Color.CURRENT);

Ok, nobody seems to know how to come up with a MTF indicator for tick and range charts and the consensus among thinkscripters is that tick and range charts does not support "multi time-frames". Well, I've figured out a way to do that with some functionality. It does have some limitations in that you cannot specify the exact tick. However, the "multi time-frames" will be a multiple of the current tick/range chart. So if you are using a 100 tick chart then a multiplier of 5 would mean a 500 tick chart. And if you were on a 5-range chart, a multiplier of 5 would mean a 25-range "time -frame". I did try to see if the same indicator can be used on both time-based and tick/range-based charts by using a multiple of the time (ie: 1min x 60 = 1hour), but it doesn't quite come out right. So you just have to us the correct indicator for the specific type of chart for now. I'm not a coder (at best copy and paste) so if anyone can improve this, please feel free. This template could be used to applied to other indicators to support "multi-tick/range" charts.

Here it is. MTF PSAR for tick/range charts...

Code:
# A multi time frame parabolic sar for tick_count and range charts by tradegeek
# The "tickMultiplier" is a multiple of the current chart.  If you're on a 100 tick chart, a multiplier of 1, 5, 10, and 20, would mean a 100 tick, 500 tick, 1000 tick, and 2000 tick chart, respectively.
# MTF_PSAR_TICK

declare lower;

input tickMultiplier1 = 1;
input tickMultiplier2 = 10;
input tickMultiplier3 = 20;
input tickMultiplier4 = 30;
input tickMultiplier5 = 40;
input PaintBars = {default "yes", "no"};

def close1 = Lowest(close,tickMultiplier1);
def close2 = Lowest(close,tickMultiplier2);
def close3 = Lowest(close,tickMultiplier3);
def close4 = Lowest(close,tickMultiplier4);
def close5 = Lowest(close,tickMultiplier5);

def low1 = Lowest(low,tickMultiplier1);
def low2 = Lowest(low,tickMultiplier2);
def low3 = Lowest(low,tickMultiplier3);
def low4 = Lowest(low,tickMultiplier4);
def low5 = Lowest(low,tickMultiplier5);

def high1 = Highest(high,tickMultiplier1);
def high2 = Highest(high,tickMultiplier2);
def high3 = Highest(high,tickMultiplier3);
def high4 = Highest(high,tickMultiplier4);
def high5 = Highest(high,tickMultiplier5);

input accelerationFactor = 0.02;
input accelerationLimit = 0.2;

assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

##### Chart Time-frame (Time-frame 1)
def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
    state = state.long;
    acc = accelerationFactor;
    extreme = high;
    SAR = low;
case short:
    if (SAR[1] < high)
    then {
        state = state.long;
        acc = accelerationFactor;
        extreme = high;
        SAR = extreme[1];
    } else {
        state = state.short;
        if (low < extreme[1])
        then {
            acc = min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = low;
        } else {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = max(max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
case long:
    if (SAR[1] > low)
    then {
        state = state.short;
        acc = accelerationFactor;
        extreme = low;
        SAR = extreme[1];
    } else {
        state = state.long;
        if (high > extreme[1])
        then {
            acc = min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = high;
        } else {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = min(min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
}

##### Time-frame 2
def state2 = {default init, long, short};
def extreme2;
def SAR2;
def acc2;

switch (state2[1]) {
case init:
    state2 = state2.long;
    acc2 = accelerationFactor;
    extreme2 = high2;
    SAR2 = low2;
case short:
    if (SAR2[1] < high2)
    then {
        state2 = state2.long;
        acc2 = accelerationFactor;
        extreme2 = high2;
        SAR2 = extreme2[1];
    } else {
        state2 = state2.short;
        if (low2 < extreme2[1])
        then {
            acc2 = min(acc2[1] + accelerationFactor, accelerationLimit);
            extreme2 = low2;
        } else {
            acc2 = acc2[1];
            extreme2 = extreme2[1];
        }
        SAR2 = max(max(high2, high2[1]), SAR2[1] + acc2 * (extreme2 - SAR2[1]));
    }
case long:
    if (SAR2[1] > low2)
    then {
        state2 = state2.short;
        acc2 = accelerationFactor;
        extreme2 = low2;
        SAR2 = extreme2[1];
    } else {
        state2 = state2.long;
        if (high2 > extreme2[1])
        then {
            acc2 = min(acc2[1] + accelerationFactor, accelerationLimit);
            extreme2 = high2;
        } else {
            acc2 = acc2[1];
            extreme2 = extreme2[1];
        }
        SAR2 = min(min(low2, low2[1]), SAR2[1] + acc2 * (extreme2 - SAR2[1]));
    }
}

##### Time-frame 3
def state3 = {default init, long, short};
def extreme3;
def SAR3;
def acc3;

switch (state3[1]) {
case init:
    state3 = state3.long;
    acc3 = accelerationFactor;
    extreme3 = high3;
    SAR3 = low3;
case short:
    if (SAR3[1] < high3)
    then {
        state3 = state3.long;
        acc3 = accelerationFactor;
        extreme3 = high3;
        SAR3 = extreme3[1];
    } else {
        state3 = state3.short;
        if (low3 < extreme3[1])
        then {
            acc3 = min(acc3[1] + accelerationFactor, accelerationLimit);
            extreme3 = low3;
        } else {
            acc3 = acc3[1];
            extreme3 = extreme3[1];
        }
        SAR3 = max(max(high3, high3[1]), SAR3[1] + acc3 * (extreme3 - SAR3[1]));
    }
case long:
    if (SAR3[1] > low3)
    then {
        state3 = state3.short;
        acc3 = accelerationFactor;
        extreme3 = low3;
        SAR3 = extreme3[1];
    } else {
        state3 = state3.long;
        if (high3 > extreme3[1])
        then {
            acc3 = min(acc3[1] + accelerationFactor, accelerationLimit);
            extreme3 = high3;
        } else {
            acc3 = acc3[1];
            extreme3 = extreme3[1];
        }
        SAR3 = min(min(low3, low3[1]), SAR3[1] + acc3 * (extreme3 - SAR3[1]));
    }
}

##### Time-frame 4
def state4 = {default init, long, short};
def extreme4;
def SAR4;
def acc4;

switch (state4[1]) {
case init:
    state4 = state4.long;
    acc4 = accelerationFactor;
    extreme4 = high4;
    SAR4 = low4;
case short:
    if (SAR4[1] < high4)
    then {
        state4 = state4.long;
        acc4 = accelerationFactor;
        extreme4 = high4;
        SAR4 = extreme4[1];
    } else {
        state4 = state4.short;
        if (low4 < extreme4[1])
        then {
            acc4 = min(acc4[1] + accelerationFactor, accelerationLimit);
            extreme4 = low4;
        } else {
            acc4 = acc4[1];
            extreme4 = extreme4[1];
        }
        SAR4 = max(max(high4, high4[1]), SAR4[1] + acc4 * (extreme4 - SAR4[1]));
    }
case long:
    if (SAR4[1] > low4)
    then {
        state4 = state4.short;
        acc4 = accelerationFactor;
        extreme4 = low4;
        SAR4 = extreme4[1];
    } else {
        state4 = state4.long;
        if (high4 > extreme4[1])
        then {
            acc4 = min(acc4[1] + accelerationFactor, accelerationLimit);
            extreme4 = high4;
        } else {
            acc4 = acc4[1];
            extreme4 = extreme4[1];
        }
        SAR4 = min(min(low4, low4[1]), SAR4[1] + acc4 * (extreme4 - SAR4[1]));
    }
}

##### time-frame 5
def state5 = {default init, long, short};
def extreme5;
def SAR5;
def acc5;

switch (state5[1]) {
case init:
    state5 = state5.long;
    acc5 = accelerationFactor;
    extreme5 = high5;
    SAR5 = low5;
case short:
    if (SAR5[1] < high5)
    then {
        state5 = state5.long;
        acc5 = accelerationFactor;
        extreme5 = high5;
        SAR5 = extreme5[1];
    } else {
        state5 = state5.short;
        if (low5 < extreme5[1])
        then {
            acc5 = min(acc5[1] + accelerationFactor, accelerationLimit);
            extreme5 = low5;
        } else {
            acc5 = acc5[1];
            extreme5 = extreme5[1];
        }
        SAR5 = max(max(high5, high5[1]), SAR5[1] + acc5 * (extreme5 - SAR5[1]));
    }
case long:
    if (SAR5[1] > low5)
    then {
        state5 = state5.short;
        acc5 = accelerationFactor;
        extreme5 = low5;
        SAR5 = extreme5[1];
    } else {
        state5 = state5.long;
        if (high5 > extreme5[1])
        then {
            acc5 = min(acc5[1] + accelerationFactor, accelerationLimit);
            extreme5 = high5;
        } else {
            acc5 = acc5[1];
            extreme5 = extreme5[1];
        }
        SAR5 = min(min(low5, low5[1]), SAR5[1] + acc5 * (extreme5 - SAR5[1]));
    }
}

##### Plots
plot PSAR = if IsNaN(SAR) then Double.NaN else 1;
PSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR.SetLineWeight(lineWeight = 3);
PSAR.DefineColor("Buy", GetColor(0));
PSAR.DefineColor("Sell", GetColor(1));
PSAR.AssignValueColor(if state == state.long
    then PSAR.Color("Sell")
    else PSAR.Color("Buy"));

plot PSAR2 = if IsNaN(SAR2) then Double.NaN else 2;
PSAR2.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR2.SetLineWeight(lineWeight = 3);
PSAR2.DefineColor("Buy", GetColor(0));
PSAR2.DefineColor("Sell", GetColor(1));
PSAR2.AssignValueColor(if state2 == state2.long
    then PSAR2.Color("Sell")
    else PSAR2.Color("Buy"));

plot PSAR3 = if IsNaN(SAR3) then Double.NaN else 3;
PSAR3.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR3.SetLineWeight(lineWeight = 3);
PSAR3.DefineColor("Buy", GetColor(0));
PSAR3.DefineColor("Sell", GetColor(1));
PSAR3.AssignValueColor(if state3 == state3.long
    then PSAR3.Color("Sell")
    else PSAR3.Color("Buy"));

plot PSAR4 = if IsNaN(SAR4) then Double.NaN else 4;
PSAR4.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR4.SetLineWeight(lineWeight = 3);
PSAR4.DefineColor("Buy", GetColor(0));
PSAR4.DefineColor("Sell", GetColor(1));
PSAR4.AssignValueColor(if state4 == state4.long
    then PSAR4.Color("Sell")
    else PSAR4.Color("Buy"));

plot PSAR5 = if IsNaN(SAR5) then Double.NaN else 5;
PSAR5.SetPaintingStrategy(PaintingStrategy.POINTS);
PSAR5.SetLineWeight(lineWeight = 3);
PSAR5.DefineColor("Buy", GetColor(0));
PSAR5.DefineColor("Sell", GetColor(1));
PSAR5.AssignValueColor(if state5 == state5.long
    then PSAR5.Color("Sell")
    else PSAR5.Color("Buy"));

def PSAR_TF1 = if state == state.long then 0 else 1;
def PSAR_TF2 = if state2 == state2.long then 0 else 1;
def PSAR_TF3 = if state3 == state3.long then 0 else 1;
def PSAR_TF4 = if state4 == state4.long then 0 else 1;
def PSAR_TF5 = if state5 == state5.long then 0 else 1;


plot MTF_PSAR = 6;
MTF_PSAR.SetPaintingStrategy(PaintingStrategy.SQUARES);
MTF_PSAR.SetLineWeight(lineWeight = 3);
MTF_PSAR.DefineColor("Buy", GetColor(5));
MTF_PSAR.DefineColor("Sell", GetColor(6));
MTF_PSAR.AssignValueColor ( if (PSAR_TF1 + PSAR_TF2 + PSAR_TF3 + PSAR_TF4 + PSAR_TF5) >= 3 then MTF_PSAR.Color("Buy") else MTF_PSAR.Color("Sell"));

AssignPriceColor ( if PaintBars is false and (PSAR_TF1 + PSAR_TF2 + PSAR_TF3 + PSAR_TF4 + PSAR_TF5) >= 3 then MTF_PSAR.Color("Buy") else if PaintBars is false and (PSAR_TF1 + PSAR_TF2 + PSAR_TF3 + PSAR_TF4 + PSAR_TF5) < 3 then MTF_PSAR.Color("Sell") else Color.CURRENT);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@pkcfc Well, if you are familiar with the PSAR then you know it may flip above or below the candle if the candle wick pass the threshold so it may flip back and forth while the candle is forming. Also since it's MTF and main PSAR is based on three out of the five time-frames, you may experience "repainting" when one of the three time-frame is the larger time-frame and if it flips and that may "repaint" the candles on the small time-frame chart.
 
Since this is a recent MTF indicator, I will ask the question here. In terms of coding, is is just not feasible to produce a "Multi-tick frame" based indicator? Or is it simply a TOS (thinkscript) limitation?
 
Since this is a recent MTF indicator, I will ask the question here. In terms of coding, is is just not feasible to produce a "Multi-tick frame" based indicator? Or is it simply a TOS (thinkscript) limitation?
The problem is, for TOS at least, that Tick Charts are not Time based at all... And without the Time parameter there really is no MTF capability...
 
What if it is derived from candle lookback, so instead of using specific settings for the "tick value" much like we'd choose the different time frames, but rather select #candles required to derive the answer? For example, staying on topic with PSAR, in its original form it has dots that sort of follow price as a "stop-loss" mechanism in its original creation for trend trading, in which PSAR forms its dots each candle when not in a MTF format. So say I use a 500tick chart, forming a PSAR dot every 500tick candle, then an other PSAR that derives its dots per every two 500tick candles (equivalent to 1000ticks), then a third derived on four candles (2000ticks), and so on. Obviously this is a very specific example, but if you understand kind of where I am going with this, would such a thing be possible @rad14733 ? But the goal would be to have settings to pick the specific #candles of lookback to derive the individual "MTF" components which would then create an "MTF" based indicator that works on ALL possible charts from time, range, renk, and tick charts. More or less thinking outloud on this concept but since I am not well versed in coding, I welcome any comments to both the feasibility of the idea, and if i am just overcomplicating a problem that has a very simple solution (just running multiple charts side by side) haha
 
@tradebyday @rad14733

What @tradebyday stated above makes sense. However, I've searched Google and read several "pro" thinkscripters stated that MTF for tick and range chart isn't possible. I'm not a coder but I think I'm pretty good at solving problems and sometimes what seems like something that can't be done could very well be done with a very simple solution.

I just altered the indicator to support tick and range charts. Yes, it can be done and I've done it! That means other MTF indicators could be made to support tick and range charts the same way. It's so ridiculously simple. :) I'm so proud of myself and my "copy and paste" abilities...LOL!


(I'll post it soon! Meanwhile here are some screenshots.)

2rMpWl.png


2rVJ07.png
 
Last edited:
@tradegeek I eagerly await your discovery as I have switched back from using Renko Bars, for the most part, because of the whole MTF limitation...
 
@rad14733 @tradebyday

In my original post, I accidentally posted the MTF of the ATR Trailing Stop instead of the PSAR. I've updated the post along with the MTF PSAR for tick/range charts.
 
Last edited:
@tradegeek Glad I could spur some inspiration, look forward to seeing the transformation that could occur with other MTF indicators. I will be testing this one out on several situations and will share if I find anything truly ground breaking
 
For any day traders, what are the time friends you guys recommend? Especially ones that'll keep its color without it changing to much. Thanks :)
 
One thing I have noticed is that MTF_PSAR_Tick paints a lot faster than the Time based MTF_PSAR... Looking forward to see hw it performs in realtime trading...
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
433 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top