• Get $40 off VIP by signing up for a free account! Sign Up

Repaints MTF Hourly Trading System (Zeiierman) for ThinkOrSwim

Repaints

samer800

Moderator - Expert
VIP
Lifetime
y1PzKrX.png


Author Message - I added 2 hours trading option:

Overview
The Hourly Trading System (Zeiierman) is designed to enhance your trading by highlighting critical price levels and trends on an hourly basis. This indicator plots the open prices of hourly and 4-hour candles, visualizes retests, displays average price lines, and overlays higher timeframe candlesticks. It is particularly beneficial for intraday traders seeking to capitalize on short-term price movements and volume patterns.
How to Use
Quickly gauge where the current price stands relative to key hourly and 4-hour levels. The plotted lines and zones serve as potential support and resistance areas, helping traders identify crucial points for entry or exit.

Read more: https://www.tradingview.com/v/LjuoM8aq/

CODE:

CSS:
#// Indicator for TOS
#// © Zeiierman
#indicator("Hourly Trading System (Zeiierman)"
# Converted by Sam4Cok@Samer800    - 07/2024
#hint NbrOfCandles: Limited to 10 HTF Candles.
input barColor  = no;         # "BarColor"
input showInfoLabels = yes;
input showPreviousDayCloseLine = yes;
input selectTradingSystem = {Default "1 Hour System", "2 Hours System"};
input displayOptions = {"Line", default "Zone"};
input ZoneWidth    = 1.0;     # "Zone width"
input ShowRetests = no;       # "Show Retests"
input NbrOfRetest = 2;        # "Nbr of Retest"
input VolumeFilter = no;      # "Volume Filter"
input filterLength = 20;
input showAverageLine = yes;  # "1 hour average"
input showHighLowLabels = no; # "Hourly High & Low Labels"
input CandleTimeframe = AggregationPeriod.FIFTEEN_MIN; # "60","Timeframe"
input NbrOfCandles = 3;       # "Nbr of Candles"
input CandlesOffset = 1;

def na = Double.NaN;
def last = !IsNaN(close);
def numb = Min(Max(NbrOfCandles, 0), 10);
def loc = CandlesOffset + numb;
def zoneDev = ZoneWidth / 10000;
def hr = selectTradingSystem==selectTradingSystem."1 Hour System";
def line = displayOptions == displayOptions."Line";
def current = GetAggregationPeriod();
def mint = AggregationPeriod.MIN;
def hour4 = AggregationPeriod.FOUR_HOURS;
def tf = Max(CandleTimeframe, current);
def hour;
Switch (selectTradingSystem) {
Case "2 Hours System" :
    hour = AggregationPeriod.TWO_HOURS;
Default :
    hour = AggregationPeriod.HOUR;
}
#def b = BarNumber();
def time = GetTime();
def time1 = if !IsNaN(close) then time else time1[1];
def bars_per_hour = hour / current;
def newDay = GetYYYYMMDD()!= GetYYYYMMDD()[1];
#-- Color
DefineGlobalColor("lime", CreateColor(105, 255, 190));
DefineGlobalColor("box", CreateColor(189, 0, 189));
DefineGlobalColor("cloud", Color.PLUM);
DefineGlobalColor("dn", CreateColor(255, 82, 82));
DefineGlobalColor("candleUp", Color.CYAN);
DefineGlobalColor("candleDn", Color.DOWNTICK); #CreateColor(239,83,80));
DefineGlobalColor("blue", CreateColor(33,150,243));
#// ~~ Time {
def minutetime = (time % mint);
def hourtime   = (time % hour);
def hour4time  = (time % hour4);
def time_hour  = (minutetime == 0 and hourtime == 0);
def time_4hour = (minutetime == 0 and hour4time == 0);
def newHour  = CompoundValue(1, time_hour and !time_hour[1], yes);
def new4Hour = CompoundValue(1, time_4hour and !time_4hour[1], yes);

def line1;def boxTop1; def boxBot1; def cnt1;  def cnt;
def start_point;def line2; def boxTop; def boxBot; def count; def count1; def count2;
def end; def pos; def pos1; def pos2; def ma;def hrHigh; def hrLow;

if newDay {
    line1 = if showPreviousDayCloseLine then close[1] else na;
    line2 = na;
    ma    = close;
    start_point = close;
    boxTop1 = open * (1 + zoneDev);
    boxBot1 = open * (1 - zoneDev);
    boxTop = na;
    boxBot = na;
    cnt1   = 0;
    cnt    = na;
    count = count2[1];
    end   = Time;
    pos   = no;
    hrHigh = na;
    hrLow = na;
} else if newHour {
    line1 = if new4Hour then open else line1[1];
    ma    = close;
    start_point = open;
    line2   = open;
    cnt     = 0;
    cnt1    = if cnt1[1] > bars_per_hour then na else cnt1[1] + 1;
    boxTop1 = if cnt1[1] > bars_per_hour then na else boxTop1[1];
    boxBot1 = if cnt1[1] > bars_per_hour then na else boxBot1[1];
    boxTop = open * (1 + zoneDev);
    boxBot = open * (1 - zoneDev);
    count = 0;
    end   = if new4Hour then Time + hour4 else time + hour;
    pos   = yes;
    hrHigh = if showHighLowLabels then high else na;
    hrLow  = if showHighLowLabels then low else na;
     } else {
    line1 = line1[1];
    ma = ma[1] + close;
    start_point = start_point[1];
    line2 = line2[1];
    cnt   = cnt[1] + 1;
    cnt1  = if cnt1[1] > bars_per_hour then na else cnt1[1] + 1;
    boxTop1 = if cnt1 > bars_per_hour then na else boxTop1[1];
    boxBot1 = if cnt1 > bars_per_hour then na else boxBot1[1];
    boxTop = boxTop[1];
    boxBot = boxBot[1];
    count  = count2[1];
    end    = end[1];
    pos    = pos2[1];
    hrHigh = Max(high, hrHigh[1]);
    hrLow  = Min(low, hrLow[1]);
}
#// ~~ Direction {
def timeHi = if hrHigh!=hrHigh[1] then time1 else timeHi[1];
def timeLo = if hrLow!=hrLow[1] then time1 else timeLo[1];
def dir = if close >= start_point then 1 else -1;
def len = if (newHour or newDay) then 1 else len[1] + 1;
def ma_hour = if showAverageLine then (ma / len) else na;
def linePrice1 = if line2 then line2 else linePrice1[1];
def hour4Col = if newDay then 0 else if line1!=line1[1] then 1 else hour4Col[1];
#-- plots
plot Avg = if count then ma_hour else na; #ma / count;
plot line_Hour = if line then linePrice1 else na;
plot hour4Line = if last and line1 then line1 else na;
plot HourTop = if !line and boxTop then boxTop else na;
plot HourBot = if !line and boxBot then boxBot else na;
plot HourTop1 = if line then (boxTop1 + boxBot1) / 2  else boxTop1;
plot HourBot1 = if !line and boxBot1 then boxBot1 else na;

Avg.AssignValueColor(if dir==1 then Color.CYAN else COlor.DOWNTICK);
hour4Line.SetPaintingStrategy(PaintingStrategy.DASHES);
line_Hour.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HourTop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HourBot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line_Hour.SetDefaultColor(GlobalColor("box"));
hour4Line.AssignValueColor(if hour4Col then GlobalColor("box") else GlobalColor("blue"));
HourTop.SetDefaultColor(GlobalColor("box"));
HourBot.SetDefaultColor(GlobalColor("box"));
HourTop1.SetDefaultColor(GlobalColor("box"));
HourBot1.SetDefaultColor(GlobalColor("box"));

AddCloud(if HourTop==HourTop[1] then HourTop else na, HourBot, GlobalColor("cloud"));
AddCloud(HourTop1, HourBot1, GlobalColor("cloud"));

#-- Bar Color

AssignPriceColor(if !barColor then Color.CURRENT else
                 if dir > 0 then Color.VIOLET else Color.DARK_ORANGE);

#//Current High & Low Labels
Script Pivots {
    input series    = close;
    input leftBars  = 10;
    input rightBars = 10;
    input isHigh = yes;
    input Cond = no;
    def na = Double.NaN;
    def pvtCond = !isNaN(Cond) and !isNaN(leftBars) and !isNaN(rightBars) and Cond;
    def HH = if !pvtCond then 0 else
             series == (fold ii = 0 to leftBars with pp = series do
                       if pp > GetValue(series, ii) then pp else GetValue(series, ii));
    def LL = if !pvtCond then 0 else
             series == (fold jj = 0 to leftBars with qq = series do
                       if qq < GetValue(series, jj) then qq else  GetValue(series, jj));
    def barIndexH = if !pvtCond then na else
                    fold i = 1 to rightBars + 1 with p=1 while p do
                    series > GetValue(series, - i);
    def barIndexL = if !pvtCond then na else
                    fold j = 1 to rightBars + 1 with q=1 while q do
                    series < GetValue(series, - j);
    def PivotPoint;
if pvtCond {
if isHigh {
    PivotPoint = if (pvtCond and HH and barIndexH) then series else na;
    } else {
    PivotPoint = if (pvtCond and LL and barIndexL) then series else na;
    }
} else {
    PivotPoint = na;
}
    plot pvt = PivotPoint;
}
def rightBar  = AbsValue(bars_per_hour - cnt);
def rightBar1 = AbsValue(bars_per_hour - cnt1);
def leftBar = cnt;
def leftBar1 = cnt1;
def hourHigh = if showHighLowLabels and boxTop then Pivots(high, leftBar, rightBar, yes, cnt>0) else na;
def hourLow  = if showHighLowLabels and boxTop then Pivots(low, leftBar, rightBar, no, cnt>0) else na;
def hourHigh1 = if showHighLowLabels and boxTop1 then Pivots(high, leftBar1, rightBar1, yes, cnt1>0) else na;
def hourLow1  = if showHighLowLabels and boxTop1 then Pivots(low, leftBar1, rightBar1, no, cnt1>0) else na;

AddChartBubble(hourHigh, high, cnt, Color.GREEN);
AddChartBubble(hourLow, low, cnt, Color.RED, no);
AddChartBubble(hourHigh1 and isNaN(hourHigh), high, cnt1, Color.DARK_GREEN);
AddChartBubble(hourLow1  and isNaN(hourLow), low, cnt1, Color.DARK_RED, no);
AddChartBubble(highestAll(timeHi)==time1, high, "H", color.GREEN);
AddChartBubble(highestAll(timeLo)==time1, low, "L", color.RED, no);

#// ~~  Retest condition for 1-Hour Open Line {
def filter = if VolumeFilter then volume > wma(volume, filterLength) else yes;
def retest_count_1h;
def repos_1; # = false
def reneg_1; # = false

if pos and count > 1 and count <= bars_per_hour and retest_count_1h[1] < NbrOfRetest and
     (if line then low[1] > linePrice1 and low <= linePrice1 and
     close >= linePrice1 else low[1] > boxTop and low <= boxTop
     and close >= boxBot) {
    repos_1 = yes;
    reneg_1 = no;
    pos1 = no;
    count1 = 0;
    retest_count_1h = retest_count_1h[1] + 1;
} else if pos and count > 1 and count <= bars_per_hour  and retest_count_1h[1] < NbrOfRetest and
     (if Line then high[1] < linePrice1 and high >= linePrice1 and
     close <= linePrice1 else high[1] < boxBot and high >= boxBot
     and close <= boxTop) {
    repos_1 = no;
    reneg_1 = yes;
    pos1 = no;
    count1 = 0;
    retest_count_1h = retest_count_1h[1] + 1;
    } else {
    repos_1 = no;
    reneg_1 = no;
    pos1 = pos;
    count1 = count;
    retest_count_1h = if linePrice1!=linePrice1[1] then 0 else retest_count_1h[1];
}
count2 = count1 + 1;
pos2 = if (count2 > 1) then yes else pos1;
def HourPosRetest = filter and ShowRetests and repos_1;
def HourNegRetest = filter and ShowRetests and reneg_1;

plot RetPos = HourPosRetest;
plot RetNeg = HourNegRetest;
RetPos.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
RetNeg.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
RetPos.SetDefaultColor(Color.GREEN);
RetNeg.SetDefaultColor(Color.PINK);

#-- HTF Bar

# Plot the new Chart
script getLoc {
    input src = close;
    input offset = 0;
    def na = Double.NaN;
    def last = IsNaN(close);
    def n = offset;
    def n1 = n - 1;
    def result = if !last[n] and last[n1] then src[n] else na;
    plot out = result;
}
# Plot the new Chart
script candle {
    input loc = 0;
    input tf = 0;
    input offset = 0;
    def na = Double.NaN;
    def last = IsNaN(close);
    def o = open (Period = tf)[loc];
    def c = close(Period = tf)[loc];
    def h = high (Period = tf)[loc];
    def l = low  (Period = tf)[loc];
    def n = offset - loc;
    def n1 = n - 1;
    def opTF = if !last[n] and last[n1] then o[n] else na;
    def clTF = if !last[n] and last[n1] then c[n] else na;
    def hiTF = if !last[n] and last[n1] then h[n] else na;
    def loTF = if !last[n] and last[n1] then l[n] else na;
    plot op = opTF;
    plot cl = clTF;
    plot hi = hiTF;
    plot lo = loTF;
}

def op = if numb < 1 then na else candle(0, tf, loc).op;
def cl = if numb < 1 then na else candle(0, tf, loc).cl;
def hi = if numb < 1 then na else candle(0, tf, loc).hi;
def lo = if numb < 1 then na else candle(0, tf, loc).lo;

def op1 = if numb < 2 then na else candle(1, tf, loc).op;
def cl1 = if numb < 2 then na else candle(1, tf, loc).cl;
def hi1 = if numb < 2 then na else candle(1, tf, loc).hi;
def lo1 = if numb < 2 then na else candle(1, tf, loc).lo;

def op2 = if numb < 3 then na else candle(2, tf, loc).op;
def cl2 = if numb < 3 then na else candle(2, tf, loc).cl;
def hi2 = if numb < 3 then na else candle(2, tf, loc).hi;
def lo2 = if numb < 3 then na else candle(2, tf, loc).lo;

def op3 = if numb < 4 then na else candle(3, tf, loc).op;
def cl3 = if numb < 4 then na else candle(3, tf, loc).cl;
def hi3 = if numb < 4 then na else candle(3, tf, loc).hi;
def lo3 = if numb < 4 then na else candle(3, tf, loc).lo;

def op4 = if numb < 5 then na else candle(4, tf, loc).op;
def cl4 = if numb < 5 then na else candle(4, tf, loc).cl;
def hi4 = if numb < 5 then na else candle(4, tf, loc).hi;
def lo4 = if numb < 5 then na else candle(4, tf, loc).lo;

def op5 = if numb < 6 then na else candle(5, tf, loc).op;
def cl5 = if numb < 6 then na else candle(5, tf, loc).cl;
def hi5 = if numb < 6 then na else candle(5, tf, loc).hi;
def lo5 = if numb < 6 then na else candle(5, tf, loc).lo;

def op6 = if numb < 7 then na else candle(6, tf, loc).op;
def cl6 = if numb < 7 then na else candle(6, tf, loc).cl;
def hi6 = if numb < 7 then na else candle(6, tf, loc).hi;
def lo6 = if numb < 7 then na else candle(6, tf, loc).lo;

def op7 = if numb < 8 then na else candle(7, tf, loc).op;
def cl7 = if numb < 8 then na else candle(7, tf, loc).cl;
def hi7 = if numb < 8 then na else candle(7, tf, loc).hi;
def lo7 = if numb < 8 then na else candle(7, tf, loc).lo;

def op8 = if numb < 9 then na else candle(8, tf, loc).op;
def cl8 = if numb < 9 then na else candle(8, tf, loc).cl;
def hi8 = if numb < 9 then na else candle(8, tf, loc).hi;
def lo8 = if numb < 9 then na else candle(8, tf, loc).lo;

def op9 = if numb < 10 then na else candle(9, tf, loc).op;
def cl9 = if numb < 10 then na else candle(9, tf, loc).cl;
def hi9 = if numb < 10 then na else candle(9, tf, loc).hi;
def lo9 = if numb < 10 then na else candle(9, tf, loc).lo;

def green  = if numb < 1 then na else cl  > op;
def green1 = if numb < 2 then na else cl1 > op1;
def green2 = if numb < 3 then na else cl2 > op2;
def green3 = if numb < 4 then na else cl3 > op3;
def green4 = if numb < 5 then na else cl4 > op4;
def green5 = if numb < 6 then na else cl5 > op5;
def green6 = if numb < 7 then na else cl6 > op6;
def green7 = if numb < 8 then na else cl7 > op7;
def green8 = if numb < 9 then na else cl8 > op8;
def green9 = if numb < 10 then na else cl9 > op9;



AddChart(open= if green then cl else na, high= hi, low= lo, close = op,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green then na else op, high= hi, low= lo, close = cl,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green1 then cl1 else na, high= hi1, low= lo1, close = op1,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green1 then na else op1, high= hi1, low= lo1, close = cl1,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green2 then cl2 else na, high= hi2, low= lo2, close = op2,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green2 then na else op2, high= hi2, low= lo2, close = cl2,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green3 then cl3 else na, high= hi3, low= lo3, close = op3,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green3 then na else op3, high= hi3, low= lo3, close = cl3,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green4 then cl4 else na, high= hi4, low= lo4, close = op4,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green4 then na else op4, high= hi4, low= lo4, close = cl4,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green5 then cl5 else na, high= hi5, low= lo5, close = op5,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green5 then na else op5, high= hi5, low= lo5, close = cl5,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green6 then cl6 else na, high= hi6, low= lo6, close = op6,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green6 then na else op6, high= hi6, low= lo6, close = cl6,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green7 then cl7 else na, high= hi7, low= lo7, close = op7,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green7 then na else op7, high= hi7, low= lo7, close = cl7,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green8 then cl8 else na, high= hi8, low= lo8, close = op8,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green8 then na else op8, high= hi8, low= lo8, close = cl8,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

AddChart(open= if green9 then cl9 else na, high= hi9, low= lo9, close = op9,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleUp"));
AddChart(open= if green9 then na else op9, high= hi9, low= lo9, close = cl9,
         type = ChartType.CANDLE, growcolor =  GlobalColor("candleDn"));

#-- Labels

#// Retrieve the previous 1-hour, 4-hour, and daily close prices
def prev_hour_close  = close(Period = hour)[1];
def prev_4hour_close = close(Period = hour4)[1];
def prev_daily_close = close(Period = "DAY")[1];

def hourly_change = if !isNaN(prev_hour_close) then
                    (close - prev_hour_close) / prev_hour_close else hourly_change[1];
def four_hour_change = if !isNaN(prev_4hour_close) then
                    (close - prev_4hour_close) / prev_4hour_close else four_hour_change[1];
def daily_change = if !isNaN(prev_daily_close) then
                    (close - prev_daily_close) / prev_daily_close else daily_change[1];

AddLabel(showInfoLabels, "Period closes in (" + (bars_per_hour-cnt) + ")", GlobalColor("blue"));
AddLabel(showInfoLabels, (if hr then "1Hr (" else "2Hr (") + AsPercent(hourly_change) + ")",
            if hourly_change>0 then Color.GREEN else Color.RED);
AddLabel(showInfoLabels, "4Hr (" + AsPercent(four_hour_change) + ")",
            if four_hour_change>0 then Color.GREEN else Color.RED);
AddLabel(showInfoLabels, "Daily (" + AsPercent(daily_change) + ")",
            if daily_change>0 then Color.GREEN else Color.RED);

#-- END of CODE
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
187 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top