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
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.
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.