Weekly Supertrend in a daily timeframe

Category: Indicators By: Fer666 Created: April 11, 2019, 8:49 AM
April 11, 2019, 8:49 AM
Indicators
3 Comments

This SuperTrend indicator is to be used in the daily timeframe.

This script plots the weekly Supertrend (parameters to be defined) in the daily chart.

Parameters to calculate the supertrend: Multiplier and Period. Recommendend values: Multiplier = 3; Period = 10;

rem ********************* Weekly ST in daily timeframe  *******************

rem ***********************    Created by F. Sacristan   ******************

rem to be used in the daily timeframe

rem this script plots the weekly Supertrend (parameters to be defined) in the daily chart

rem Parameters to calculate the supertrend: Multiplier and Period. REcommendend values: Multiplier = 3; Period = 10

period=10
multiplier=3

WeekNo = dayofWeek

if barindex = 0 then
 WeekStart = 1
else
 if WeekNo < WeekNo[1] then
  WeekStart = 1
 else
  WeekStart = 0
 endif
endif


if WeekNo < WeekNo[1] then

 WClosePrev = close[1]
 WLow = low
 WHigh = high
 WLowPrev = WLow[1]
 WHighPrev = WHigh[1]

else

 WClosePrev = WClosePrev[1]
 if low > WLow[1] then
  WLow = WLow[1]
 else
  WLow = low
 endif
 if high > WHigh[1] then
  WHigh = High
 else
  WHigh = WHigh[1]
 endif
 WLowPrev = WLowPrev[1]
 WHighPrev = WHighPrev[1]
endif

WMid = 0.5*(WHighPrev + WLowPrev)

if barindex < Period then

 STUp = 0
 STDown = 0

else

 if WeekStart = 1 then
  TR1 = abs(WLowPrev - WClosePrev[1])
  TR2 = abs(WHighPrev - WClosePrev[1])
  TR3 = abs(WHighPrev - WLowPrev)
 else
  TR1 = TR1[1] 
  TR2 = TR2[1]
  TR3 = TR3[1]
 endif

 TR4 = max(TR1,TR2)
 TRX = max(TR3,TR4)

 if WeekStart = 1 then
  TRTrigger = TRX
  Counter = Counter[1]+1
 else
  TRTrigger = 0
  Counter = Counter[1]
 endif

 if Counter < Period then
  SumTR = TRTrigger + SumTR[1]
 else
  SumTR = 0
 endif

 ATRAverage = SumTR/Counter

 if Counter < Period then
  ATR = ATRAverage
 else
  if WeekStart = 1 then
   ATR = (ATR[1]*(Period-1)+TRTrigger)/Period
  else
   ATR = ATR[1]
  endif
 endif

 STUpBasic = WMid + Multiplier*ATR
 STDownBasic = WMid - Multiplier*ATR

 if WeekStart = 1 then

 if (STUpBasic < STUp[1]) or (WClosePrev[1]>STUp[1]) then
  STUp = STUpBasic
 else
  STUp = STUp[1]
 endif
else
 STUp = STUp[1]
endif

 if WeekStart = 1 then

  if (STDownBasic > STDown) or (WClosePrev[1]< STDown[1]) then
   STDown = STDownBasic
  else
   STDown = STDown[1]
  endif
   else
    STDown = STDown[1]
  endif
 endif
if barindex < Period then
 WeeklyST = STDown
endif

if barindex >= Period and WeekStart = 1 and WClosePrev[1] <= STDown[1] then

 WeeklyST = STUp[1]
 Trend = -1

elsif barindex >= Period and WeekStart =1 and WClosePrev[1] >= STUp[1] then

 WeeklyST = STDown[1]
 Trend = 1
elsif Trend = 1 then
 WeeklyST = STDown[1]
elsif Trend = -1 then
 WeeklyST = STUp[1]
endif
return WeeklyST as "Weekly ST"

Download
Filename: Weekly-SuperTrend-on-Daily-TF.itf
Downloads: 99
Fer666 New
Operating in the shadows, I hack problems one by one. My bio is currently encrypted by a complex algorithm. Decryption underway...
Author’s Profile

Comments

Logo Logo
Loading...