Parabolic SAR on AccDist

NEKSUS

New member
Hi All !
Can anyone make Parabolic SAR on AccDist?
 

BenTen

Administrative
Staff
VIP
@tomsk Take a look at another indicator called AccumDistBuyPr. It should be in ThinkorSwim by default. This study only takes into account the closing price (no volume involved). Maybe you can use that as an alternative if you already have a solution to make the indicator.
 

tomsk

Well-known member
VIP
@tomsk Take a look at another indicator called AccumDistBuyPr. It should be in ThinkorSwim by default. This study only takes into account the closing price (no volume involved). Maybe you can use that as an alternative if you already have a solution to make the indicator.

@BenTen Yep AccumDistBuyPr is indeed a standard TOS indicator based on the close. However the computation for PSAR is based on the relationship between each data point's high and low. I definitely concur that PSAR is a powerful signal. Not sure if anyone has done this yet but it would be a relatively simple matter to generate a signal whenever the PSAR transitioned from a negative state to a positive state or vice versa. Let me know, this is a relatively quick fix. In my view that would be a good workaround for @NEKSUS

EDIT: As a matter of fact just to amuse myself, I programmed a scan real quick and ran some tests this morning on the S&P 500
Bullish Transition: 25 hits
Bearish Transition: 20 hits

EDIT: The realm of possibilities are endless!
 
Last edited:

tomsk

Well-known member
VIP
Here is the scan for a PSAR for EITHER a transition from bullish to bearish OR from bearish to bullish
I have listed two plot statements. Please comment out the one you don't want as the scanner only accepts a single plot statement

Code:
# PSAR Scan
# tomsk
# 11.20.2019

# Scans for a PSAR state transition from bullish to bearish or from bearish to bullish

#
# TD Ameritrade IP Company, Inc. (c) 2008-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;

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]));
    }
}

def transitionBull = state[1] == state.short and state == state.long;
def transitionBear = state[1] == state.long and state == state.short;

# Comment out (#) the ONE not needed
plot scan = transitionBull;
#plot scan = transitionBear;
 

Schminga

New member
tomsk: Can you (pretty please) send the scrip to add this to a thinkorswim Watchlist with "1" = Dark_Green otherwise Dark_Red?
 

GhostNet117

New member
Would it be possible to do this without the recursive functions? The recursive functions are making it so I cannot do a conditional order or alert based on this indicator. Any ideas? I have tried making temp variables to hold last accessed values in each case even.
 

laketrader

New member
2019 Donor
VIP
I liked the scan for a PSAR for EITHER a transition from bullish to bearish OR from bearish to bullish . I tried to make a label for PSR study. But I found on some symbols that the value was incorrect.
e.g WKHS - The correct label should be 5 but the label displayed 15.

I am not sure why. Any help is always appreciated.

Code:
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;

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]));
    }
}

def transitionBull = state[1] == state.short and state == state.long;
def transitionBear = state[1] == state.long and state == state.short;
def count1 = if transitionBull  then 1 else count1[1]+1;
def count2 = if transitionBear  then 1 else count2[1]+1;
input label_text = "PSAR";
AddLabel(1, label_text + " - " + if transitionBull then count1 else count2,
     if transitionBull then color.green
     else color.red);
 

Thomas

Active member
VIP
@tomsk After reading this post I ask why cannot PSAR be added to "Hi_Low," as it's measured from so.....stated in message #8
 

Similar threads

Top