Almost Done, SuperTrend for TradeScript

Hello,

I have almost done formula for supertrend script. Still can't get it done.

SET FACTOR = 2
SET PERIOD = 10

SET HL2 =  (HIGH + LOW) / 2

#TODO: Instead of True Range, we need Avg. True range * periods
SET UP = HL2 - (FACTOR * TR(PERIOD) )
SET DOWN = HL2 - (FACTOR * TR(PERIOD) )

SET TRENDUP  = ( REF(CLOSE, 1) > REF(TRENDUP,1)  )
SET MAX = MAXOF(UP, REF(TRENDUP, 1))

SET TRENDDOWN  = ( REF(CLOSE, 1) > REF(TRENDDOWN,1)  )
SET MIN = MINOF(UP, REF(TRENDUP, 1))

SET UPTREND  = IF(TRENDUP    , MAX  , UP)
SET DOWNTREND  = IF(  TRENDDOWN   , MIN  , DOWN)

SET TRENDUPCONF = IF( CLOSE > DOWNTREND, 1, 0 )
SET TRENDDOWNCONF = IF( CLOSE < UPTREND, -1, 0 )

#TODO: SET ALL VALUES. HOW TO ENABLE SIGNAL IF ITS TRUE?
TRENDUPCONF = 1 AND TRENDDOWNCONF = 0

Any Help to finish it, Algo Geek? 

2 Likes

Super Trend indicator is already available in pi by default under chart study and super trend is not possible to code with tradescript language.

1 Like

How can we scan for SuperTrend cross overs ? is there a code for that ?

1 Like

Yes pls, I am also in need of details of crossover function use for my script.

thnx

1 Like

Yes. I’m trying to get a closest match. Can you edit the above and make it work? I think I’m missing something.

@AlgoGeek Any tweaks you can think of for the above code to make it work perfectly?

http://www.freebsensetips.com/blog/detail/7/What-is-supertrend-indicator-its-calculation

BASIC UPPERBAND = (HIGH + LOW) / 2 + Multiplier * ATR
BASIC LOWERBAND = (HIGH + LOW) / 2 - Multiplier * ATR

FINAL UPPERBAND = IF( (Current BASICUPPERBAND < Previous FINAL UPPERBAND) and (Previous Close > Previous FINAL UPPERBAND)) THEN (Current BASIC UPPERBAND) ELSE Previous FINALUPPERBAND)

FINAL LOWERBAND = IF( (Current BASIC LOWERBAND > Previous FINAL LOWERBAND) and (Previous Close < Previous FINAL LOWERBAND)) THEN (Current BASIC LOWERBAND) ELSE Previous FINAL LOWERBAND)

SUPERTREND = IF(Current Close <= Current FINAL UPPERBAND ) THEN Current FINAL UPPERBAND ELSE Current FINAL LOWERBAND

I don’t mean to revive a dead thread, but I have been trying to create an algorithm using the Excel file on this site, I mean if excel can do it, why not trade script

My only problem Pi starts crying and crashes on simple If functions too, I’m new to coding on Pi, is it always this buggy?

I see the major problem being passing the previous Final UpperBand but even calculation of IF condition is a pain right now.

BTW I did solve the ATR part was pretty simple. Just used the inbuilt AVG function with TR.

You can get Supertrend screener here: http://chartink.com/screener/supertrend-positive-breakout

And modify the parameters as per your needs

HI Mehul,

Can u share the Transcript arrvied to calcuate the SuperTrend in ‘Pi’ - itself - ?

Thanks.

Hi Thomas,

Sorry for the late reply, my attempt though logically correct and working in parts would only result in Pi crashing, even though I have a pretty great config. Either way I’ll share it with you if I can find it, haven’t used Pi from a long time as I am not allowed to trade anymore due to my job.

As per Super trend formula, ea can be as below. open for suggestion.

For buy signal.
PRICE= ((HIGH + LOW) / 2 )+ 2* SMA(TR,7)

For sell Signal
PRICE= ((HIGH + LOW) / 2) - 2* SMA(TR,7)

hi @HITESH_HANOTIA
I ve backtested it but getting buy and sell signal on same candle