Looking for Parabolic SAR MTF (Multi Time Frame)

F

flyer01

New member
Would anyone be willing to share code for a MTF PSAR script. For example, on a 1 hour chart I would like to see the Parabolic SAR plotted from a 4 hour aggregation. Is this possible?
 
horserider

horserider

Well-known member
VIP
@flyer01 Here is 4 hour agg. Can input agg of your choice to display PSAR at a different agg than chart.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2019 ParabolicSAR
# Changed to 4 hour aggregation by Horserider 12/13/2019

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 + ")");

def state = {default init, long, short};
def extreme;
def SAR;
def acc;
input agg = AggregationPeriod.FOUR_HOURS;
def high = high (period = agg);
def low = low (period = agg);
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]));
}
}

plot parSAR = SAR;
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.SetDefaultColor(GetColor(5));
 
F

flyer01

New member
@horserider, that is exactly what I was looking for. Thank you so much!
 
S

stockminion

New member
VIP
Can we make this work in Mobile @horserider .
 
BenTen

BenTen

Administrative
Staff
VIP
@stockminion MTF doesn’t work in the mobile app.
 
D

Dazeinhjk

New member
VIP
@flyer01 Here is 4 hour agg. Can input agg of your choice to display PSAR at a different agg than chart.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2019 ParabolicSAR
# Changed to 4 hour aggregation by Horserider 12/13/2019

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 + ")");

def state = {default init, long, short};
def extreme;
def SAR;
def acc;
input agg = AggregationPeriod.FOUR_HOURS;
def high = high (period = agg);
def low = low (period = agg);
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]));
}
}

plot parSAR = SAR;
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.SetDefaultColor(GetColor(5));

Nice study. Im using, is so useful. Do you know any study with a Parabolic SAR but crossover MTF? Im looking an arrow to see the trend within parabolicSAR. For example, in lower timeframe I would like to know when the price crossover parabolic in higher timeframe.
 

Similar threads

Top