I can’t code same supertrend as PRT
Forums › ProRealTime English forum › ProBuilder support › I can’t code same supertrend as PRT
- This topic has 4 replies, 2 voices, and was last updated 3 years ago by Ben3211.
Tagged: atr, average true range, st, supertrend, tr, true range
Viewing 5 posts - 1 through 5 (of 5 total)
-
-
10/31/2021 at 6:34 PM #180689
Hi everyone!
I’m trying to code the prorealtime supertrend in python with the native tws api.
I noticed my ATR which is essential for calculating the supertrend it sometimes very far from the PRT indicator.
I have tried several different functions for calculating ATR but nothing helps.Is it possible to find the source code for ATR or supertrend?
Perhaps have you another way of thinking ?Thanks everyone
Regards,
Ben10/31/2021 at 6:57 PM #180694There you go:
1234567891011121314151617181920212223242526272829303132333435// Super Trend custom//// https://stackoverflow.com/questions/44935269/supertrend-code-using-pandas-python////Multiplier = 3//Periods = 10Multiplier = Max(1,Min(999,Multiplier))Periods = Max(1,Min(999,Periods))IF BarIndex > Max(Periods,Multiplier) THENMyATR = AverageTrueRange[Periods](close) * MultiplierBasicUPPER = MedianPrice + MyATRBasicLOWER = MedianPrice - MyATRIF (BasicUPPER < FinalUPPER[1]) OR (close[1] > FinalUPPER[1]) THENFinalUPPER = BasicUPPERENDIFIF (BasicLOWER > FinalLOWER[1]) OR (close[1] < FinalLOWER[1]) THENFinalLOWER = BasicLOWERENDIFIF (ST[1] = FinalUPPER[1]) AND (close <= FinalUPPER) THENST = FinalUPPERELSEIF (ST[1] = FinalUPPER[1]) AND (close > FinalUPPER) THENST = FinalLOWERELSEIF (ST[1] = FinalLOWER[1]) AND (close >= FinalLOWER) THENST = FinalLOWERELSEIF (ST[1] = FinalLOWER[1]) AND (close < FinalLOWER) THENST = FinalUPPERENDIFENDIFENDIFENDIFENDIFRETURN ST AS "Super Trend"11/01/2021 at 9:19 AM #18072411/01/2021 at 10:17 AM #180733Atr (and TR):
1234567891011121314151617181920212223242526// ATR formula//// https://en.wikipedia.org/wiki/Average_true_range// https://www.investopedia.com/terms/a/atr.asp//// TR calculations://// MyTR = max(Range,max(abs (high − close[1]),abs (low − close[1])))//// The true range is the largest of the:// - Most recent period's high minus the most recent period's low// - Absolute value of the most recent period's high minus the// previous close// - Absolute value of the most recent period's low minus the// previous close//// Calculation of ATR (of P periods)://p = 10p = max(2,min(999,p)) //range 2 - 999MyTR = max(Range,max(abs(high - close[1]),abs(low - close[1])))IF BarIndex < p THENMyATR = MyTRELSEMyATR = ((MyATR[1] * (p - 1)) + MyTR) / pENDIFRETURN MyATR1 user thanked author for this post.
11/01/2021 at 1:58 PM #180743 -
AuthorPosts
Viewing 5 posts - 1 through 5 (of 5 total)