TrendLine Scythes for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
9HTK5EW.png


- Not Exact Conversion
Author Message :
Trendline Scythes is a script designed to automatically detect and draw special curved trendlines, resembling scythes or blades, based on pivotal points in price action. These trendlines adapt to the volatility of the market, providing a unique perspective on trend dynamics.
More Details : https://www.tradingview.com/v/aehvh10O/

CSS:
# https://www.tradingview.com/v/aehvh10O/
#// This Pine Script™ code is subject to the terms of the Attribution-NonCommercial-ShareAlike 4.0
#// © EliCobra
#indicator("TrendLine Scythes", "[?] - TL Scythes", true, max_polylines_count = 100, max_lines_count =
# converted by Sam4Cok@Samer800 - 02/2024     - not exact conversion

input timeframe = {Default "Chart", "Cusotm"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input plotStyle = {Default "Lines", "Curved"};
input PivotLength   = 40;
input ScytheLength  = 80;    # "Scythe Length"
input showBreaks = yes;

def na = Double.NaN;      # non-numeric values
def ext = ScytheLength;
def curve = plotStyle==plotStyle."Curved";
def last = isNaN(close);
def bar = if !last then BarNumber() else bar[1];
def H; def L; def C; def O;
Switch (timeframe) {
Case "Cusotm" :
    H   = high(period = customTimeframe);            # high price
    L   = low(period = customTimeframe);             # low price
    C   = close(period = customTimeframe);           # close price
    O   = open(period = customTimeframe);            # open price
Default :
    H   = high;            # high price
    L   = low;             # low price
    C   = close;           # close price
    O   = open;            # open price
}
#pivots(float src, float length, bool isHigh) =>
script FindPivots {
    input src  = close; # default data or study being evaluated
    input lbL_  = 5;    # default Pivot Lookback Left
    input lbR_  = 1;    # default Pivot Lookback Right
    input HL   = yes;     # default high or low pivot designation, -1 low, +1 high
    def _V;
    ##############
    def _BN  = BarNumber();
    def _nan = Double.NaN;
    def lbL = floor(lbL_); def lbR = floor(lbR_);
    def _pivotRange = lbL + lbL;
    def _VStop = if !IsNaN(src[_pivotRange]) and lbR > 0 and lbL > 0 then
                 fold a = 1 to lbR + 1 with b=1 while b do
                 if HL then src > GetValue(src, -a) else src < GetValue(src, -a) else _nan;
    if (HL) {
        _V = if _BN > lbL and src == Highest(src, lbL + 1) and _VStop
            then src else _nan;
    } else {
        _V = if _BN > lbL and src == Lowest(src, lbL + 1) and _VStop
            then src else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}

def phPvt = findpivots(h, PivotLength, PivotLength, yes);
def plPvt = findpivots(l, PivotLength, PivotLength, no);
def nzPh = !isNaN(phPvt);
def nzPl = !isNaN(plPvt);
def tr = TrueRange(H, C, L);
def nATR = WildersAverage(tr, PivotLength);
def ph = if nzPh then phPvt else ph[1];
def pl = if nzPl then plPvt else pl[1];
def atrH = if nzPh then nATR else atrH[1];
def atrL = if nzPl then nATR else atrL[1];
def atrH50 = atrH / 2;
def atrL50 = atrL / 2;
def cntHi = if nzPh then 0 else if cntHi[1] > ext then ext else cntHi[1] + 1;
def cntLo = if nzPl then 0 else if cntLo[1] > ext then ext else cntLo[1] + 1;
def multiH = if curve then Power(cntHi, 2) / cntHi else ext;
def multiL = if curve then Power(cntLo, 2) / cntLo else ext;
def ph1 = ph - (atrH / PivotLength) * multiH * 2;
def ph2 = ph - (atrH / PivotLength) * ext * 2;
def pl1 = pl + (atrL / PivotLength) * multiL * 2;
def pl2 = pl + (atrL / PivotLength) * ext * 2;
def InxH = if nzPh then bar else InxH[1];
def InxL = if nzPl then bar else InxL[1];

def slpH1 = (ph - ph1 - atrH50) / (ext);
def slpH2 = (ph - ph2 - atrH) / (ext);
def slpL1 = (pl1 - pl - atrL50) / (ext);
def slpL2 = (pl2 - pl - atrL) / (ext);
def HiL1 =  if ph!=ph[-1] then na else ph - (bar - InxH) * slpH1;
def HiL2 =  if ph!=ph[-1] then na else ph - atrH50 - (bar - InxH) * slpH2;
def LoL1 =  if pl!=pl[-1] then na else pl + (bar - InxL) * slpL1;
def LoL2 =  if pl!=pl[-1] then na else pl + atrL50 + (bar - InxL) * slpL2;

plot hhLine1 = if HiL1 and !last and HiL1 >= HiL2 then HiL1 else na;
plot hhLine2 = if HiL2 and !last and HiL1 >= HiL2 then HiL2 else na;
plot llLine1 = if LoL1 and !last and LoL2 >= LoL1 then LoL1 else na;
plot llLine2 = if LoL2 and !last and LoL2 >= LoL1 then LoL2 else na;
#---- Signals
def HCrossUp = C Crosses Above hhLine1;
def LCrossUp = C Crosses Above llLine2;
def LCrossDn = C Crosses Below llLine1;
def HCrossDn = C Crosses Below hhLine2;
def breakUp = if cntHi <= ext/2 then 0 else
              if HCrossUp[1] then breakUp[1] + 1 else breakUp[1];
def breakDn = if cntLo <= ext/2 then 0 else
              if LCrossDn[1] then breakDn[1] + 1 else breakDn[1];
def RvsDn = if cntHi <= 5 then 0 else
            if HCrossDn[1] then RvsDn[1] + 1 else RvsDn[1];
def RvsUp = if cntLo <= 5 then 0 else
            if LCrossUp[1] then RvsUp[1] + 1 else RvsUp[1];

hhLine1.AssignValueColor(if RvsDn > 0 then Color.GREEN else Color.DARK_GREEN);
llLine1.AssignValueColor(if RvsUp > 0 then Color.RED else Color.DARK_RED);
hhLine2.AssignValueColor(if RvsDn > 0 then Color.GREEN else Color.DARK_GREEN);
llLine2.AssignValueColor(if RvsUp > 0 then Color.RED else Color.DARK_RED);

AddCloud(hhLine1, hhLine2, Color.DARK_GREEN);
AddCloud(llLine2, llLine1, Color.DARK_RED);

AddChartBubble(showBreaks and breakUp!=breakUp[1] and breakUp ==2, l, "Break", Color.GREEN, no);
AddChartBubble(showBreaks and breakDn!=breakDn[1] and breakDn ==2, h, "Break", Color.RED);

#AddChartBubble(showReversals and RvsUp!=RvsUp[1] and RvsUp ==2 and c[1]>o[1], low, "test", Color.CYAN, no);
#AddChartBubble(showReversals and RvsDn!=RvsDn[1] and RvsDn ==2 and o[1]>c[1], high, "test", Color.MAGENTA);

#-- END of CODE
 
Does this repaint?? @samer800
9HTK5EW.png


- Not Exact Conversion
Author Message :
Trendline Scythes is a script designed to automatically detect and draw special curved trendlines, resembling scythes or blades, based on pivotal points in price action. These trendlines adapt to the volatility of the market, providing a unique perspective on trend dynamics.
More Details : https://www.tradingview.com/v/aehvh10O/

CSS:
# https://www.tradingview.com/v/aehvh10O/
#// This Pine Script™ code is subject to the terms of the Attribution-NonCommercial-ShareAlike 4.0
#// © EliCobra
#indicator("TrendLine Scythes", "[?] - TL Scythes", true, max_polylines_count = 100, max_lines_count =
# converted by Sam4Cok@Samer800 - 02/2024     - not exact conversion

input timeframe = {Default "Chart", "Cusotm"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input plotStyle = {Default "Lines", "Curved"};
input PivotLength   = 40;
input ScytheLength  = 80;    # "Scythe Length"
input showBreaks = yes;

def na = Double.NaN;      # non-numeric values
def ext = ScytheLength;
def curve = plotStyle==plotStyle."Curved";
def last = isNaN(close);
def bar = if !last then BarNumber() else bar[1];
def H; def L; def C; def O;
Switch (timeframe) {
Case "Cusotm" :
    H   = high(period = customTimeframe);            # high price
    L   = low(period = customTimeframe);             # low price
    C   = close(period = customTimeframe);           # close price
    O   = open(period = customTimeframe);            # open price
Default :
    H   = high;            # high price
    L   = low;             # low price
    C   = close;           # close price
    O   = open;            # open price
}
#pivots(float src, float length, bool isHigh) =>
script FindPivots {
    input src  = close; # default data or study being evaluated
    input lbL_  = 5;    # default Pivot Lookback Left
    input lbR_  = 1;    # default Pivot Lookback Right
    input HL   = yes;     # default high or low pivot designation, -1 low, +1 high
    def _V;
    ##############
    def _BN  = BarNumber();
    def _nan = Double.NaN;
    def lbL = floor(lbL_); def lbR = floor(lbR_);
    def _pivotRange = lbL + lbL;
    def _VStop = if !IsNaN(src[_pivotRange]) and lbR > 0 and lbL > 0 then
                 fold a = 1 to lbR + 1 with b=1 while b do
                 if HL then src > GetValue(src, -a) else src < GetValue(src, -a) else _nan;
    if (HL) {
        _V = if _BN > lbL and src == Highest(src, lbL + 1) and _VStop
            then src else _nan;
    } else {
        _V = if _BN > lbL and src == Lowest(src, lbL + 1) and _VStop
            then src else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}

def phPvt = findpivots(h, PivotLength, PivotLength, yes);
def plPvt = findpivots(l, PivotLength, PivotLength, no);
def nzPh = !isNaN(phPvt);
def nzPl = !isNaN(plPvt);
def tr = TrueRange(H, C, L);
def nATR = WildersAverage(tr, PivotLength);
def ph = if nzPh then phPvt else ph[1];
def pl = if nzPl then plPvt else pl[1];
def atrH = if nzPh then nATR else atrH[1];
def atrL = if nzPl then nATR else atrL[1];
def atrH50 = atrH / 2;
def atrL50 = atrL / 2;
def cntHi = if nzPh then 0 else if cntHi[1] > ext then ext else cntHi[1] + 1;
def cntLo = if nzPl then 0 else if cntLo[1] > ext then ext else cntLo[1] + 1;
def multiH = if curve then Power(cntHi, 2) / cntHi else ext;
def multiL = if curve then Power(cntLo, 2) / cntLo else ext;
def ph1 = ph - (atrH / PivotLength) * multiH * 2;
def ph2 = ph - (atrH / PivotLength) * ext * 2;
def pl1 = pl + (atrL / PivotLength) * multiL * 2;
def pl2 = pl + (atrL / PivotLength) * ext * 2;
def InxH = if nzPh then bar else InxH[1];
def InxL = if nzPl then bar else InxL[1];

def slpH1 = (ph - ph1 - atrH50) / (ext);
def slpH2 = (ph - ph2 - atrH) / (ext);
def slpL1 = (pl1 - pl - atrL50) / (ext);
def slpL2 = (pl2 - pl - atrL) / (ext);
def HiL1 =  if ph!=ph[-1] then na else ph - (bar - InxH) * slpH1;
def HiL2 =  if ph!=ph[-1] then na else ph - atrH50 - (bar - InxH) * slpH2;
def LoL1 =  if pl!=pl[-1] then na else pl + (bar - InxL) * slpL1;
def LoL2 =  if pl!=pl[-1] then na else pl + atrL50 + (bar - InxL) * slpL2;

plot hhLine1 = if HiL1 and !last and HiL1 >= HiL2 then HiL1 else na;
plot hhLine2 = if HiL2 and !last and HiL1 >= HiL2 then HiL2 else na;
plot llLine1 = if LoL1 and !last and LoL2 >= LoL1 then LoL1 else na;
plot llLine2 = if LoL2 and !last and LoL2 >= LoL1 then LoL2 else na;
#---- Signals
def HCrossUp = C Crosses Above hhLine1;
def LCrossUp = C Crosses Above llLine2;
def LCrossDn = C Crosses Below llLine1;
def HCrossDn = C Crosses Below hhLine2;
def breakUp = if cntHi <= ext/2 then 0 else
              if HCrossUp[1] then breakUp[1] + 1 else breakUp[1];
def breakDn = if cntLo <= ext/2 then 0 else
              if LCrossDn[1] then breakDn[1] + 1 else breakDn[1];
def RvsDn = if cntHi <= 5 then 0 else
            if HCrossDn[1] then RvsDn[1] + 1 else RvsDn[1];
def RvsUp = if cntLo <= 5 then 0 else
            if LCrossUp[1] then RvsUp[1] + 1 else RvsUp[1];

hhLine1.AssignValueColor(if RvsDn > 0 then Color.GREEN else Color.DARK_GREEN);
llLine1.AssignValueColor(if RvsUp > 0 then Color.RED else Color.DARK_RED);
hhLine2.AssignValueColor(if RvsDn > 0 then Color.GREEN else Color.DARK_GREEN);
llLine2.AssignValueColor(if RvsUp > 0 then Color.RED else Color.DARK_RED);

AddCloud(hhLine1, hhLine2, Color.DARK_GREEN);
AddCloud(llLine2, llLine1, Color.DARK_RED);

AddChartBubble(showBreaks and breakUp!=breakUp[1] and breakUp ==2, l, "Break", Color.GREEN, no);
AddChartBubble(showBreaks and breakDn!=breakDn[1] and breakDn ==2, h, "Break", Color.RED);

#AddChartBubble(showReversals and RvsUp!=RvsUp[1] and RvsUp ==2 and c[1]>o[1], low, "test", Color.CYAN, no);
#AddChartBubble(showReversals and RvsDn!=RvsDn[1] and RvsDn ==2 and o[1]>c[1], high, "test", Color.MAGENTA);

#-- END of CODE
 
Does this repaint?? @samer800

If you are using the timeframe setting on its default:
input timeframe = {Default "Chart", "Cusotm"};
There is nothing in this code to indicate any repainting.
This forum uses a prefix of REPAINTS on indicators that repaint.

Keep in mind, that the current bar of this indicator, along with most indicators on this forum, will update every tick until the current candle is closed.
As there is no way to predict the final close of the candle ahead of time.
 
Last edited:
  • Like
Reactions: sum
Thank you for your contribution @samer800

I am not sure how to utilize this indicator as part of my swing trading?
What group this tool belongs to?
Perhaps someone can explain?
 

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