Parabolic SAR - How to smooth Parabolic - How to pass DataSeries intead of just Bars
Author: cs96ai
Creation Date: 4/20/2010 10:46 AM
profile picture

cs96ai

#1
Hi,

Just wondering if anyone has had any luck smoothing the Parabolic SAR.

I can plot graph using something like this...
CODE:
Please log in to see this code.


But what I'd like to do is something like...

CODE:
Please log in to see this code.



From the above snippet the EMA.Series is returning an EMA DataSeries which I'm trying to plug in to to Parabolic plot in order to smooth the indicator.

But plot only takes "Bars".

Is there a way to convert the dataseries in to bar data?
Is there there another Parabolic that accepts DataSeries intead of only "Bars"?


Thanks all!

CS
profile picture

Eugene

#2
No, there does not exist another Parabolic because this the original formula by Welles Wilder takes the highest high reached in a bullish trend, or the lowest low in a bearish trend.

You can create a fake Bars object - see SaveToFile in the QuickRef. Note: you don't have to save the Bars object to a disk file like in that example, your goal is to create and fill it on-the-fly (with an EMA value at the current bar for O, H, L, and C) and pass this Bars object to the Parabolic.Series. With the help of the QuickRef example, this should be very simple to accomplish but you'll have not a true Parabolic, for sure.
profile picture

Cone

#3
How about this?
CODE:
Please log in to see this code.
profile picture

Eugene

#4
Interesting. Using the same default settings, this modified indicator seems to have a smoother ride in trends than Wilder's, making it a more consistent trailing exit. However, where Wilder's SAR shines is at reaping profits from violent moves. Unfortunately, the modified Parabolic isn't that responsive.
profile picture

Cone

#5
I smell a new TSL strategy in the works ;)
profile picture

cs96ai

#6
What I really seemed to notice was the parabolic became less sensitive to horizontal movement inside the major trend.

I was finding that once the trend was indicated I would often get a false indication of a stop and reverse if the price went sideways.

By pumping EMA smoothed data in to the parabolic the sideways movement didn't have as much of an impact.

The down side to this is that the top and bottom of the parabolic slides two or three bars out. (depending on the market could be a huge problem)

The top dotted line shows a break in the parabolic. Parabolic(0.02,0.02,0.2)
The bottom dotted line shows a solid trend (no breaks) through the duration of uptrend.
Parabolic(0.02,0.02,0.2) - Smoothed by EMA(15)
The solid dark blue line is just for reference it is EMA(30)

Thanks for the help everyone!
profile picture

cs96ai

#7
Just out of curiosity what is TSL?

=D
profile picture

Cone

#8
The regular Trading Systems Lab article in Active Trader magazine.
profile picture

csprings

#9
How do I get from the Parabolic.Series when the dot switches from long to short?

The code snippet in the reference manual is switching based on a calculated stop being hit, not the dot flipping sides?

I have been playing with weekly series vs. daily which stays in the trend longer with fewer whipsaws, but acceleration factor has to be tweaked.
profile picture

Eugene

#10
The code snippet in the Wiki is switching based on a Parabolic level. It's time to go long when the current bar's price is above the Parabolic, vice versa for short trades.
profile picture

csprings

#11
Never mind.
CODE:
Please log in to see this code.

profile picture

csprings

#12
I plugged in the code above and am switching the trade when the dot flips above or below the candle bar. I am executing the trade at the bar, not bar+1 for Parabolic SAR because, as I understand it, the calculation is using the data from bars before, not the current bar to plot the dot. So you have the dot to make the trade decision on at market open. That's how it works in real life, the dot is plotted at the beginning of the period, at least on thinkorswim, and doesn't change. I'm not accounting for slippage of the first few minutes of trading where I don't get the indicator until the opening bell rings, but otherwise I don't think this is peeking, for this indicator...comments?

Also I did a bunch of monte carlo simulations with the EMA stuff above and unfortunately it didn't add to the bottom line. However, the monte carlo runs showed that much higher values than Wilder's .02 for acceleration/deceleration produced better results.

Anyway, I spent a bunch of time last week tediously entering data into Excel off parabolic sar graphs, then I remembered I had this program that I had never used so I opened it up today, did thousands of runs where I was spending many minutes per 'run' before. way cool.

the bar vs bar+1 question is key though, it isn't a profitable strategy if you don't enter the trade on the morning the dot flips over.

CODE:
Please log in to see this code.


profile picture

Eugene

#13
QUOTE:
I am executing the trade at the bar, not bar+1 for Parabolic SAR because, as I understand it, the calculation is using the data from bars before, not the current bar to plot the dot.

You're getting it wrong. This code is bluntly peeking into the future.

Take a look at this tutorial in the Wealth-Lab Wiki: Introductory | Bars, Loops, and Bar + 1, and make sure you've went through Programming Trading Strategies > Peeking in the WealthScript Guide.

Further down the road, "emaPeriod" of 1 (by default) is simply the price itself. The whole point of smoothing got lost with this change of a parameter's value.

Finally, starting the trading loop at bar 20 even when your EMA would be a 20-period one, is not correct, since EMA is one of so called "unstable" indicators. See WealthScript Programming Guide > Indicators > Stability of indicators for an in deep discussion and recommendations.
profile picture

csprings

#14
Thanks for your review, Eugene.
I was just showing in the code that I tested the EMA approach. The monte carlo simulator plugged in values for EMA from 1 to 20, and with few exceptions, 1 worked better, meaning it was an interesting idea that didn't pan out. I went back to the straight parabolic series.

I changed high low to open. At the open, the current parabolic stop is known, and should be calculated from previous data, not the current bar. This period's stop value should be usable at the open of this period.

The stop dot plotted today should be calculated from previous data. This is how it works in other plotting programs- the stop point is plotted at the beginning of the period and does not change throughout the period.

The manual says you must use bar+1 if the indicator uses any data in bar. I'm saying if you calculate paraboic sar like everyone else, the stop in bar is from bar-1 data.
Thanks!

profile picture

Eugene

#15
While your reasoning is correct, your code is dead wrong. You're not calculating from the previous bar, what the code is doing is using today's high, low and closing prices to buy/short at the open of today. Don't waste any more time on Monte Carlo runs and Excel spreadsheets - can't make a supersonic jet fly when its chassis are broken. ;)
profile picture

cs96ai

#16
I ran in to the same problem when first starting out with PSAR and some of the other indicators as well.
There is a huge huge huge difference buy[bar] versus buy[bar+1].

I was running 1 month test data doing future contracts and when I did buy[bar+1] my returns were very often negative even when running with optimization.
Now switch to buy[bar] and the returns were in the positive thousand range.
Just goes to show how peeking even only 1 bar in to the future can change expected returns.

Of course this begs the question....
Are there other tools available to peek in to the future.
(Decision tree, Bayes learning, Nearest Neighbour, Bagging ect...)

=D
profile picture

csprings

#17
I misunderstood how/when the PSAR algorithm decides to flip over. Rats. Sorry for being so dense.
Now that I understand it, I don't see how to make it a profitable strategy.
Another one on the scrap heap of indicators that look nice but are eventually not profitable to trade, unless I'm missing something.

I did a web search of different ways people are using it- with MACD, ADXR, DMI, DMI + ADX, SMA...each of them has a flaw that makes it unprofitable, as far as I can tell, which isn't much.

Has anyone here gotten a profitable strategy out of Parabolic SAR?
profile picture

Eugene

#18
QUOTE:
Has anyone here gotten a profitable strategy out of Parabolic SAR?

In that Trading System Lab article (see above), we'll try ;)
profile picture

cs96ai

#19
WOW!!!!!
This just got published in Active Trader Magazine!!!!!!
August 2010, Volume 11 No 8.
Smoothed Parabolic system!!!
WHOO HOOOOO!!!!!

profile picture

Cone

#20
I must be psychic (see 4/20/2010) :)
profile picture

cs96ai

#21
YOU TOTALLY CALLED IT!!!!!!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).