# Mobius PSAR Help

#### HighBredCloud

##### Well-known member
VIP
I found this cool PSAR by Mobius...I would like to have the traditional POINTS display above and below the candles instead of coloring the candles themselves so that I can use with other SuperTrends...What needs to be changed in the code below to achieve that? I tried and no avail...
Code:
``````# Parabolic SAR modified with fractal dimension index

# Mobius

# V01.01.2010 V02.09.2013 V03.07.2014  V04.2014 Altered calculations for Fractal dimensions

#hint:<b>Parabolic Stop and Reverse:</b>\n This version is adjusted using a fractal dimension index.\n When price is trending the index will move lower compressing the PSAR's scaling factor and limit factor so that trend reversals are picked up quicker and when the market becomes more balanced and trading the scaling factor and limit factor will widen to lesson whipsaw.\n This same process could be accomplished with ADX or Implied Volatility.

# User Inputs

input n = 8;

input AscaleLow = .01;  #hint AscaleLow: Typical range from .01 to .03

input AscaleHigh = .0618;#hint AscaleHigh: Typical range from .03 to .09

input BscaleLow = .1;   #hint BscaleLow: Typical range from .1 to .3

input BscaleHigh = .99; #hint BscaleHigh: Typical range from .3 to .9

input Labels = yes;

# Variables

def o;

def h;

def l;

def c;

def TR;

#def A;

def B;

def Ascaled;

def Bscaled;

# Internal Script

script Scale {

input c = close;

input Min = .01;

input Max =   1;

def hh = HighestAll(c);

def ll   = LowestAll(c);

plot Range = (((Max - Min) * (c - ll)) /  (hh - ll)) + Min;

}

# Calculations

o = (open[1] + close[1]) / 2;

h = Max(high, close[1]);

l = Min(low, close[1]);

c = (o + h + l + close) / 4;

TR = Max(h, c[1]) - Min(l, c[1]);

# A = Log(Sum(TR, n)) / (Highest(c, n) - Lowest(c, n)) / Log(n);

# Ascaled = Round(Scale(c = A, min = AscaleLow, max = AscaleHigh), 3);

B = (Log(Sum(TR, n) / (Highest(h, n) - Lowest(l, n)))

/ Log(10)) / (Log(n) / Log(10));

Ascaled = Round(Scale(c = B, min = AscaleLow, max = AscaleHigh), 3);

Bscaled = Round(Scale(c = B, min = BscaleLow, max = BscaleHigh), 2);

AddLabel(Labels, "A Factor Scaled: " + Ascaled, Color.WHITE);

AddLabel(Labels, "B Factor Scaled: " + Bscaled, Color.WHITE);

AddLabel(Labels, if Bscaled > Bscaled[1] and Bscaled > .5

else if Bscaled < Bscaled[1] and Bscaled < .618

then "Trending"

else if Bscaled > .618

else if Bscaled < .382

then "Trending"

else "",

if Bscaled < Bscaled[1] and Bscaled < .618

then Color.Green

else if Bscaled < .382

then Color.Green

else if Bscaled > .382 and Bscaled > Bscaled[1]

then Color.Red

else if Bscaled > .618

then Color.Red

else Color.Yellow);

def state = {default init, long, short};

def extreme;

def SAR;

def acc;

switch (state[1]) {

case init:

state = state.long;

acc = Ascaled;

extreme = h;

SAR = l;

case short:

if (SAR[1] < h)

then {

state = state.long;

acc = Ascaled;

extreme = h;

SAR = extreme[1];

} else {

state = state.short;

if (l < extreme[1])

then {

acc = Min(acc[1] + Ascaled, Bscaled);

extreme = l;

} else {

acc = acc[1];

extreme = extreme[1];

}

SAR = Max(Max(h, h[1]), SAR[1] + acc * (extreme - SAR[1]));

}

case long:

if (SAR[1] > l)

then {

state = state.short;

acc = Ascaled;

extreme = l;

SAR = extreme[1];

} else {

state = state.long;

if (h > extreme[1])

then {

acc = Min(acc[1] + Ascaled, Bscaled);

extreme = h;

} else {

acc = acc[1];

extreme = extreme[1];

}

SAR = Min(Min(l, l[1]), SAR[1] + acc * (extreme - SAR[1]));

}

}

# Chart Management

AssignPriceColor(if SAR > h then Color.RED else Color.GREEN);

#### horserider

##### Well-known member
VIP
Just plot it like ToS psar. My guess it is very very close.

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

#### hockeycoachdoug

##### Member
2019 Donor
VIP
Do you mean replace this code-
# Chart Management

AssignPriceColor(if SAR > h then Color.RED else Color.GREEN);

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

In the original code in post 1

#### HighBredCloud

##### Well-known member
VIP
Just plot it like ToS psar. My guess it is very very close.

plot parSAR = SAR;
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.SetDefaultColor(GetColor(5));
I tried that before and I was able to get PSAR to work it just wasn't accurate...The candles still painted differently than PSAR using that code...Hence why I made the post.

#### HighBredCloud

##### Well-known member
VIP
@hockeycoachdoug I think the SAR > h is the key to how the candles are painted...and I don't know how to make the POINTS of PSAR reflect that...

#### horserider

##### Well-known member
VIP
I gave you the solution.
hockeycoachdoug -- yep

#### HighBredCloud

##### Well-known member
VIP
@horserider I appreciate your solution...but that's not it...Take a closer look on different days for a given stock and you will see that the solution you provided is not correct. There are days where what you suggested plots correctly but there are also days where its 1 candle late... As I mentioned before...I already tried that prior to making this post. This PSAR is a bit more complex than regular PSAR the code you gave corresponds to...

#### horserider

##### Well-known member
VIP
My guess is candle colors are sar >h while dots are close. Change sar > c and see if dots and candles align.

Hope so or I will need to plot it all and see. NAH do not feel like bothering for one candle. If that is not true maybe someone else can help you.

#### HighBredCloud

##### Well-known member
VIP
My guess is candle colors are sar >h while dots are close. Change sar > c and see if dots and candles align.

Hope so or I will need to plot it all and see. NAH do not feel like bothering for one candle. If that is not true maybe someone else can help you.
Thanks I will try that...But remember 1 candle on a 15 minute is 3 candles on a 5 minute...and 15 candles on a 1 minute...This is a bigger deal than what you make of it.

##### Active member
This plots the points above/below the candles in the right colors, but you will get a dot still in wrong position. BUT what is important is the color without having to paint the candles right?! That's my best attempt
Code:
``````input offset = 0;
plot parSAR = SAR[offset];
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.AssignValueColor(if SAR > h then Color.RED else Color.GREEN);``````

#### HighBredCloud

##### Well-known member
VIP
@tradebyday byday Yeah...I don't know if that was just an anomaly...everything else seems to plot the right way...By any chance is the slope of the points above the candles correct as far as you can tell? Reason being is you can tell the Stop and Reverse is approaching based on how close the dots are to the actual candles...IF that is correct than you have addressed the issue. Thank You!

##### Active member
@tradebyday byday Yeah...I don't know if that was just an anomaly...everything else seems to plot the right way...By any chance is the slope of the points above the candles correct as far as you can tell? Reason being is you can tell the Stop and Reverse is approaching based on how close the dots are to the actual candles...IF that is correct than you have addressed the issue. Thank You!
Ya as far as I can tell it seems correct, as the issue does not occur every time. But if you react to the color change, this will at least allow you to not make any mistakes reading the indicator, even when it doesn't put the dot on the correct side of the candle

#### HighBredCloud

##### Well-known member
VIP
Ya as far as I can tell it seems correct, as the issue does not occur every time. But if you react to the color change, this will at least allow you to not make any mistakes reading the indicator, even when it doesn't put the dot on the correct side of the candle
Personally the color change is the bonus for more visual representation to what is going on...The slope is the most important aspect of the dots as it tells you how close to possible reversal. I will test this out tomorrow but from looking at previous days it also seems to be working...its hard to tell for sure as to why certain candles would paint the dot a different color yet not switch the position. PSAR is a good study especially when trading a trending stock...

#### horserider

##### Well-known member
VIP
plot parSAR = SAR; This was not plotting correctly.

input offset = 0;
plot parSAR = SAR[offset]; But this is plotting correctly.

Must be my eyes are bad. No idea. Anyway if you change the h to c you will get a one candle advanced warning of some trend changes.

#### HighBredCloud

##### Well-known member
VIP
plot parSAR = SAR; This was not plotting correctly.

input offset = 0;
plot parSAR = SAR[offset]; But this is plotting correctly.

Must be my eyes are bad. No idea. Anyway if you change the h to c you will get a one candle advanced warning of some trend changes.
So...since I am not a coder and it takes me 4x as long to figure things out...are you implying that I use this line of code?

input offset = 0;
plot parSAR = SAR[offset];
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.AssignValueColor(if SAR > c then Color.RED else Color.GREEN);

#### HighBredCloud

##### Well-known member
VIP
@horserider So I changed to SAR > C as you suggested...the pic below shows the plotting...Your suggestion being on the left and @tradebyday on the right...same slope on both but the dots on the right reflect the candle color...yours don't. Mobius must be one hell of a coder because I am stumped...but I am not a coder either.

Last edited:

#### horserider

##### Well-known member
VIP
No I was saying those are exactly the same. Yet you claimed one was not plotting correctly and the other was. From the first code I mentioned it plots the same. You did not originally ask for the dots to be colored. Dots colored now it plots correctly,,hahaha guess colors are very powerful.

The suggestion to change the sar > c was for the candle colors not the dot colors. Look back that suggestion was made before the dots were being colored.

#### HighBredCloud

##### Well-known member
VIP
No I was saying those are exactly the same. Yet you claimed one was not plotting correctly and the other was. From the first code I mentioned it plots the same. You did not originally ask for the dots to be colored. Dots colored now it plots correctly,,hahaha guess colors are very powerful.

The suggestion to change the sar > c was for the candle colors not the dot colors. Look back that suggestion was made before the dots were being colored.

@horserider Assuming you're referring to this particular portion of the script:

input offset = 0;
plot parSAR = SAR[offset];
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.AssignValueColor(if SAR > c then Color.RED else Color.GREEN);

Then the two plot the same and look the same...except for the dot color. I just did that last night at like 2:30 AM...What I was referring to was your previous suggestion in post #2 using this script:

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

My original post was to replicate the dots in the same fashion as how the candle is painted. Nothing changed. It would be much easier if you actually looked at the code instead of a none coder trying to explain to a coder what is going on and what my intention is...There's other people here that might find this helpful...not just me.

#### horserider

##### Well-known member
VIP
"Nothing changed. It would be much easier if you actually looked at the code instead of a none coder trying to explain to a coder what is going on and what my intention is "
Wow! Really! Hmmm guess I looked at the code to be able to modify it, don't you think. And now it is expected the coder knows your intention by looking at the code. What I know is that the code I gave you was correct for what you requested.

"I would like to have the traditional POINTS display above and below the candles instead of coloring the candles themselves "
That is what you said. "traditional points" so I did traditional points. Then you complain it is incorrect plotting and when someone gives you the exact same plot but with colors you say it plots correctly.

As far as the sar > c that was stated before coloring the dots and thus could only be referring to this.
AssignPriceColor(if SAR > h then Color.RED else Color.GREEN);

Before you ask for further help on studies please take the time to decide exactly what you want and then state it precisely. To get the correct coding the requests must be precisely stated. Then all this continued "it is wrong" or "one more thing" stuff can be avoided.

My belief is you should be grateful for the help given freely here. The ungrateful may not find help as easily.

#### HighBredCloud

##### Well-known member
VIP
"Nothing changed. It would be much easier if you actually looked at the code instead of a none coder trying to explain to a coder what is going on and what my intention is "
Wow! Really! Hmmm guess I looked at the code to be able to modify it, don't you think. And now it is expected the coder knows your intention by looking at the code. What I know is that the code I gave you was correct for what you requested.

"I would like to have the traditional POINTS display above and below the candles instead of coloring the candles themselves "
That is what you said. "traditional points" so I did traditional points. Then you complain it is incorrect plotting and when someone gives you the exact same plot but with colors you say it plots correctly.

As far as the sar > c that was stated before coloring the dots and thus could only be referring to this.
AssignPriceColor(if SAR > h then Color.RED else Color.GREEN);

Before you ask for further help on studies please take the time to decide exactly what you want and then state it precisely. To get the correct coding the requests must be precisely stated. Then all this continued "it is wrong" or "one more thing" stuff can be avoided.

My belief is you should be grateful for the help given freely here. The ungrateful may not find help as easily.

@horserider Refer to your post #8. You make a comment that you don't feel like plotting the code just for one candle...and that someone else should help out with this...Your words not mine. So my assumption is you didn't plot the study...and guessed what the solution might be because your solution DID NOT WORK. I informed you of that but then you say that I complain? Letting you know it doesn't work is not complaining...its letting you know it DID NOT WORK...nothing more.

I NEVER changed my request...it stayed the same. Like I said before nothing changed with my request! I don't know where you read what you read. But reread it again.

I even explained to you that your suggestion from post #2 did not work as I already tried that prior to making this thread. The PSAR dots should reflect the candle color. Am I wrong to assume that when the candle is GREEN the dots should be below the candle and when the candle is RED the dots should be above the candle? I never even asked about "one more thing" in addition to my original request not to complicate anything.

And what is up with this you should be grateful for help given freely comment? When was I disrespectful to you or anyone else here? By stating your suggestion didn't work? Really?

I spend just as much time on this site as you...I may not be coding things like you or others but I do other things like testing the indicators that you coders make.. IF you think you have EVERYTHING figured out then by all means please make thread with your strategy so that the rest can follow.