
- 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