Strategy · Pine Script v5 · On the chart

AC- MY SCRIPT1

by hasnocool· code credited to arjunji4u

This strategy plots an Optimized Trend Tracker and a selectable moving-average support line on the price chart.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code539
Settings40inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

539 lines of Pine Script v5 from AC- MY SCRIPT1.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

AC- MY SCRIPT1.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © arjunji4u
//@version=5
strategy('AC- MY SCRIPT1', 'AC- MS1', overlay=true)
src = input(close, title='Source')
length = input.int(4, 'OTT Period', minval=1)
percent = input.float(4.2, 'OTT Percent', step=0.1, minval=0)
showsupport = input(title='Show Support Line?', defval=true)
showsignalsk = input(title='Show Support Line Crossing Signals?', defval=true)
showsignalsc = input(title='Show Price/OTT Crossing Signals?', defval=false)
highlight = input(title='Show OTT Color Changes?', defval=false)
showsignalsr = input(title='Show OTT Color Change Signals?', defval=false)
highlighting = input(title='Highlighter On/Off ?', defval=true)
mav = input.string(title='Moving Average Type', defval='VAR', options=['SMA', 'EMA', 'WMA', 'TMA', 'VAR', 'WWMA', 'ZLEMA', 'TSF'])
Var_Func(src, length) =>
    valpha = 2 / (length + 1)
    vud1 = src > src[1] ? src - src[1] : 0
    vdd1 = src < src[1] ? src[1] - src : 0
    vUD = math.sum(vud1, 9)
    vDD = math.sum(vdd1, 9)
    vCMO = nz((vUD - vDD) / (vUD + vDD))
    VAR = 0.0
    VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1])
    VAR
VAR = Var_Func(src, length)
Wwma_Func(src, length) =>
    wwalpha = 1 / length
    WWMA = 0.0
    WWMA := wwalpha * src + (1 - wwalpha) * nz(WWMA[1])
    WWMA
WWMA = Wwma_Func(src, length)
Zlema_Func(src, length) =>
    zxLag = length / 2 == math.round(length / 2) ? length / 2 : (length - 1) / 2
    zxEMAData = src + src - src[zxLag]
    ZLEMA = ta.ema(zxEMAData, length)
    ZLEMA
ZLEMA = Zlema_Func(src, length)
Tsf_Func(src, length) =>
    lrc = ta.linreg(src, length, 0)
    lrc1 = ta.linreg(src, length, 1)
    lrs = lrc - lrc1
    TSF = ta.linreg(src, length, 0) + lrs
    TSF
TSF = Tsf_Func(src, length)
getMA(src, length) =>
    ma = 0.0
    if mav == 'SMA'
        ma := ta.sma(src, length)
        ma
    if mav == 'EMA'
        ma := ta.ema(src, length)
        ma
    if mav == 'WMA'
        ma := ta.wma(src, length)
        ma
    if mav == 'TMA'
        ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)
        ma
    if mav == 'VAR'
        ma := VAR
        ma
    if mav == 'WWMA'
        ma := WWMA
        ma
    if mav == 'ZLEMA'
        ma := ZLEMA
        ma
    if mav == 'TSF'
        ma := TSF
        ma
    ma
MAvg = getMA(src, length)
fark = MAvg * percent * 0.01
longStop = MAvg - fark
longStopPrev = nz(longStop[1], longStop)
longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = MAvg + fark
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir
MT = dir == 1 ? longStop : shortStop
OTT = MAvg > MT ? MT * (200 + percent) / 200 : MT * (200 - percent) / 200
plot(showsupport ? MAvg : na, color=color.new(#0585E1, 0), linewidth=2, title='Support Line')
OTTC = highlight ? OTT[2] > OTT[3] ? color.green : color.red : #B800D9
pALL = plot(nz(OTT[2]), color=OTTC, linewidth=2, title='OTT', transp=0)
alertcondition(ta.cross(OTT[2], OTT[3]), title='Color ALARM', message='OTT Has Changed Color!')
alertcondition(ta.crossover(OTT[2], OTT[3]), title='GREEN ALERT', message='OTT GREEN BUY SIGNAL!')
alertcondition(ta.crossunder(OTT[2], OTT[3]), title='RED ALERT', message='OTT RED SELL SIGNAL!')
alertcondition(ta.cross(MAvg, OTT[2]), title='Cross Alert', message='OTT - Support Line Crossing!')
alertcondition(ta.crossover(MAvg, OTT[2]), title='Crossover Alarm', message='Support Line BUY SIGNAL!')
alertcondition(ta.crossunder(MAvg, OTT[2]), title='Crossunder Alarm', message='Support Line SELL SIGNAL!')
alertcondition(ta.cross(src, OTT[2]), title='Price Cross Alert', message='OTT - Price Crossing!')
alertcondition(ta.crossover(src, OTT[2]), title='Price Crossover Alarm', message='PRICE OVER OTT - BUY SIGNAL!')
alertcondition(ta.crossunder(src, OTT[2]), title='Price Crossunder Alarm', message='PRICE UNDER OTT - SELL SIGNAL!')
buySignalk = ta.crossover(MAvg, OTT[2])
plotshape(buySignalk and showsignalsk ? OTT * 0.995 : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0))
sellSignallk = ta.crossunder(MAvg, OTT[2])
plotshape(sellSignallk and showsignalsk ? OTT * 1.005 : na, title='Sell', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))
buySignalc = ta.crossover(src, OTT[2])
plotshape(buySignalc and showsignalsc ? OTT * 0.995 : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0))
sellSignallc = ta.crossunder(src, OTT[2])
plotshape(sellSignallc and showsignalsc ? OTT * 1.005 : na, title='Sell', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))
mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0, display=display.none)
longFillColor = highlighting ? MAvg > OTT ? color.green : na : na
shortFillColor = highlighting ? MAvg < OTT ? color.red : na : na
fill(mPlot, pALL, title='UpTrend Highligter', color=longFillColor, transp=90)
fill(mPlot, pALL, title='DownTrend Highligter', color=shortFillColor, transp=90)
buySignalr = ta.crossover(OTT[2], OTT[3])
plotshape(buySignalr and showsignalsr ? OTT * 0.995 : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0))
sellSignallr = ta.crossunder(OTT[2], OTT[3])
plotshape(sellSignallr and showsignalsr ? OTT * 1.005 : na, title='Sell', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))
showscr = input(true, title='Show Screener Label')
posX_scr = input(20, title='Pos. Label x-axis')
posY_scr = input(1, title='Pos. Size Label y-axis')
colinput = input.string(title='Label Color', defval='Blue', options=['White', 'Black', 'Red', 'Green', 'Yellow', 'Blue'])
col = color.gray
if colinput == 'White'
    col := color.white
    col
if colinput == 'Black'
    col := color.black
    col
if colinput == 'Red'
    col := color.red
    col
if colinput == 'Green'
    col := color.green
    col
if colinput == 'Yellow'
    col := color.yellow
    col
if colinput == 'Blue'
    col := color.blue
    col
dummy0 = input(true, title='=Backtest Inputs=')
FromDay = input.int(defval=1, title='From Day', minval=1, maxval=31)
FromMonth = input.int(defval=1, title='From Month', minval=1, maxval=12)
FromYear = input.int(defval=2005, title='From Year', minval=2005)
ToDay = input.int(defval=1, title='To Day', minval=1, maxval=31)
ToMonth = input.int(defval=1, title='To Month', minval=1, maxval=12)
ToYear = input.int(defval=9999, title='To Year', minval=2006)
Start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
Finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
Timerange() =>
    time >= Start and time <= Finish ? true : false
if buySignalk
    strategy.entry('Long', strategy.long, when=Timerange())
if sellSignallk
    strategy.entry('Short', strategy.short, when=Timerange())
t1 = input.symbol('NIFTY', title='Symbol 01')
t2 = input.symbol('S68', title='Symbol 02')
t3 = input.symbol('1000SHIBUSDTPERP', title='Symbol 03')
t4 = input.symbol('1INCHUSDTPERP', title='Symbol 04')
t5 = input.symbol('ALGOUSDTPERP', title='Symbol 05')
t6 = input.symbol('ALICEUSDTPERP', title='Symbol 06')
t7 = input.symbol('ALPHAUSDTPERP', title='Symbol 07')
t8 = input.symbol('ANTUSDTPERP', title='Symbol 08')
t9 = input.symbol('API3USDTPERP', title='Symbol 09')
t10 = input.symbol('ARUSDTPERP', title='Symbol 10')
t11 = input.symbol('ARPAUSDTPERP', title='Symbol 11')
t12 = input.symbol('AUDIOUSDTPERP', title='Symbol 12')
t13 = input.symbol('', title='Symbol 13')
t14 = input.symbol('', title='Symbol 14')
t15 = input.symbol('', title='Symbol 15')
t16 = input.symbol('', title='Symbol 16')
t17 = input.symbol('', title='Symbol 17')
t18 = input.symbol('', title='Symbol 18')
t19 = input.symbol('', title='Symbol 19')
t20 = input.symbol('', title='Symbol 20')
t21 = input.symbol('', title='Symbol 21')
t22 = input.symbol('', title='Symbol 22')
t23 = input.symbol('', title='Symbol 23')
t24 = input.symbol('', title='Symbol 24')
t25 = input.symbol('', title='Symbol 25')
t26 = input.symbol('', title='Symbol 26')
t27 = input.symbol('', title='Symbol 27')
t28 = input.symbol('', title='Symbol 28')
t29 = input.symbol('', title='Symbol 29')
t30 = input.symbol('', title='Symbol 30')
t31 = input.symbol('', title='Symbol 31')
t32 = input.symbol('', title='Symbol 32')
t33 = input.symbol('', title='Symbol 33')
t34 = input.symbol('', title='Symbol 34')
t35 = input.symbol('', title='Symbol 35')
t36 = input.symbol('', title='Symbol 36')
t37 = input.symbol('', title='Symbol 37')
t38 = input.symbol('', title='Symbol 38')
t39 = input.symbol('', title='Symbol 39')
t40 = input.symbol('', title='Symbol 40')
OTTs(percent, length) =>
    Up = MAvg - MAvg * percent * 0.01
    Dn = MAvg + MAvg * percent * 0.01
    TrendUp = 0.0
    TrendUp := MAvg[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up
    TrendDown = 0.0
    TrendDown := MAvg[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn
    Trend = 0.0
    Trend := MAvg > TrendDown[1] ? 1 : MAvg < TrendUp[1] ? -1 : nz(Trend[1], 1)
    Tsl = Trend == 1 ? TrendUp : TrendDown
    S_Buy = Trend == 1 ? 1 : 0
    S_Sell = Trend != 1 ? 1 : 0
    [Trend, Tsl]
[Trend, Tsl] = OTTs(percent, length)
TrendReversal = Trend != Trend[1]
[t01, s01] = request.security(t1, timeframe.period, OTTs(percent, length))
[t02, s02] = request.security(t2, timeframe.period, OTTs(percent, length))
[t03, s03] = request.security(t3, timeframe.period, OTTs(percent, length))
[t04, s04] = request.security(t4, timeframe.period, OTTs(percent, length))
[t05, s05] = request.security(t5, timeframe.period, OTTs(percent, length))
[t06, s06] = request.security(t6, timeframe.period, OTTs(percent, length))
[t07, s07] = request.security(t7, timeframe.period, OTTs(percent, length))
[t08, s08] = request.security(t8, timeframe.period, OTTs(percent, length))
[t09, s09] = request.security(t9, timeframe.period, OTTs(percent, length))
[t010, s010] = request.security(t10, timeframe.period, OTTs(percent, length))
[t011, s011] = request.security(t11, timeframe.period, OTTs(percent, length))
[t012, s012] = request.security(t12, timeframe.period, OTTs(percent, length))
[t013, s013] = request.security(t13, timeframe.period, OTTs(percent, length))
[t014, s014] = request.security(t14, timeframe.period, OTTs(percent, length))
[t015, s015] = request.security(t15, timeframe.period, OTTs(percent, length))
[t016, s016] = request.security(t16, timeframe.period, OTTs(percent, length))
[t017, s017] = request.security(t17, timeframe.period, OTTs(percent, length))
[t018, s018] = request.security(t18, timeframe.period, OTTs(percent, length))
[t019, s019] = request.security(t19, timeframe.period, OTTs(percent, length))
[t020, s020] = request.security(t20, timeframe.period, OTTs(percent, length))
[t021, s021] = request.security(t21, timeframe.period, OTTs(percent, length))
[t022, s022] = request.security(t22, timeframe.period, OTTs(percent, length))
[t023, s023] = request.security(t23, timeframe.period, OTTs(percent, length))
[t024, s024] = request.security(t24, timeframe.period, OTTs(percent, length))
[t025, s025] = request.security(t25, timeframe.period, OTTs(percent, length))
[t026, s026] = request.security(t26, timeframe.period, OTTs(percent, length))
[t027, s027] = request.security(t27, timeframe.period, OTTs(percent, length))
[t028, s028] = request.security(t28, timeframe.period, OTTs(percent, length))
[t029, s029] = request.security(t29, timeframe.period, OTTs(percent, length))
[t030, s030] = request.security(t30, timeframe.period, OTTs(percent, length))
[t031, s031] = request.security(t31, timeframe.period, OTTs(percent, length))
[t032, s032] = request.security(t22, timeframe.period, OTTs(percent, length))
[t033, s033] = request.security(t33, timeframe.period, OTTs(percent, length))
[t034, s034] = request.security(t34, timeframe.period, OTTs(percent, length))
[t035, s035] = request.security(t35, timeframe.period, OTTs(percent, length))
[t036, s036] = request.security(t36, timeframe.period, OTTs(percent, length))
[t037, s037] = request.security(t37, timeframe.period, OTTs(percent, length))
[t038, s038] = request.security(t38, timeframe.period, OTTs(percent, length))
[t039, s039] = request.security(t39, timeframe.period, OTTs(percent, length))
[t040, s040] = request.security(t40, timeframe.period, OTTs(percent, length))
tr01 = t01 != t01[1]
up01 = t01 == 1
dn01 = t01 == -1
tr02 = t02 != t02[1]
up02 = t02 == 1
dn02 = t02 == -1
tr03 = t03 != t03[1]
up03 = t03 == 1
dn03 = t03 == -1
tr04 = t04 != t04[1]
up04 = t04 == 1
dn04 = t04 == -1
tr05 = t05 != t05[1]
up05 = t05 == 1
dn05 = t05 == -1
tr06 = t06 != t06[1]
up06 = t06 == 1
dn06 = t06 == -1
tr07 = t07 != t07[1]
up07 = t07 == 1
dn07 = t07 == -1
tr08 = t08 != t08[1]
up08 = t08 == 1
dn08 = t08 == -1
tr09 = t09 != t09[1]
up09 = t09 == 1
dn09 = t09 == -1
tr010 = t010 != t010[1]
up010 = t010 == 1
dn010 = t010 == -1
tr011 = t011 != t011[1]
up011 = t011 == 1
dn011 = t011 == -1
tr012 = t012 != t012[1]
up012 = t012 == 1
dn012 = t012 == -1
tr013 = t013 != t013[1]
up013 = t013 == 1
dn013 = t013 == -1
tr014 = t014 != t014[1]
up014 = t014 == 1
dn014 = t014 == -1
tr015 = t015 != t015[1]
up015 = t015 == 1
dn015 = t015 == -1
tr016 = t016 != t016[1]
up016 = t016 == 1
dn016 = t016 == -1
tr017 = t017 != t017[1]
up017 = t017 == 1
dn017 = t017 == -1
tr018 = t018 != t018[1]
up018 = t018 == 1
dn018 = t018 == -1
tr019 = t019 != t019[1]
up019 = t019 == 1
dn019 = t019 == -1
tr020 = t020 != t020[1]
up020 = t020 == 1
dn020 = t020 == -1
tr021 = t021 != t021[1]
up021 = t021 == 1
dn021 = t021 == -1
tr022 = t022 != t022[1]
up022 = t022 == 1
dn022 = t022 == -1
tr023 = t023 != t023[1]
up023 = t023 == 1
dn023 = t023 == -1
tr024 = t024 != t024[1]
up024 = t024 == 1
dn024 = t024 == -1
tr025 = t025 != t025[1]
up025 = t025 == 1
dn025 = t025 == -1
tr026 = t026 != t026[1]
up026 = t026 == 1
dn026 = t026 == -1
tr027 = t027 != t027[1]
up027 = t027 == 1
dn027 = t027 == -1
tr028 = t028 != t028[1]
up028 = t028 == 1
dn028 = t028 == -1
tr029 = t029 != t029[1]
up029 = t029 == 1
dn029 = t029 == -1
tr030 = t030 != t030[1]
up030 = t030 == 1
dn030 = t030 == -1
tr031 = t031 != t031[1]
up031 = t031 == 1
dn031 = t031 == -1
tr032 = t032 != t032[1]
up032 = t032 == 1
dn032 = t032 == -1
tr033 = t033 != t033[1]
up033 = t033 == 1
dn033 = t033 == -1
tr034 = t034 != t034[1]
up034 = t034 == 1
dn034 = t034 == -1
tr035 = t035 != t035[1]
up035 = t035 == 1
dn035 = t035 == -1
tr036 = t036 != t036[1]
up036 = t036 == 1
dn036 = t036 == -1
tr037 = t037 != t037[1]
up037 = t037 == 1
dn037 = t037 == -1
tr038 = t038 != t038[1]
up038 = t038 == 1
dn038 = t038 == -1
tr039 = t039 != t039[1]
up039 = t039 == 1
dn039 = t039 == -1
tr040 = t040 != t040[1]
up040 = t040 == 1
dn040 = t040 == -1
pot_label = 'Potential Reversal: \n'
pot_label := tr01 ? pot_label + t1 + '\n' : pot_label
pot_label := tr02 ? pot_label + t2 + '\n' : pot_label
pot_label := tr03 ? pot_label + t3 + '\n' : pot_label
pot_label := tr04 ? pot_label + t4 + '\n' : pot_label
pot_label := tr05 ? pot_label + t5 + '\n' : pot_label
pot_label := tr06 ? pot_label + t6 + '\n' : pot_label
pot_label := tr07 ? pot_label + t7 + '\n' : pot_label
pot_label := tr08 ? pot_label + t8 + '\n' : pot_label
pot_label := tr09 ? pot_label + t9 + '\n' : pot_label
pot_label := tr010 ? pot_label + t10 + '\n' : pot_label
pot_label := tr011 ? pot_label + t11 + '\n' : pot_label
pot_label := tr012 ? pot_label + t12 + '\n' : pot_label
pot_label := tr013 ? pot_label + t13 + '\n' : pot_label
pot_label := tr014 ? pot_label + t14 + '\n' : pot_label
pot_label := tr015 ? pot_label + t15 + '\n' : pot_label
pot_label := tr016 ? pot_label + t16 + '\n' : pot_label
pot_label := tr017 ? pot_label + t17 + '\n' : pot_label
pot_label := tr018 ? pot_label + t18 + '\n' : pot_label
pot_label := tr019 ? pot_label + t19 + '\n' : pot_label
pot_label := tr020 ? pot_label + t20 + '\n' : pot_label
pot_label := tr021 ? pot_label + t21 + '\n' : pot_label
pot_label := tr022 ? pot_label + t22 + '\n' : pot_label
pot_label := tr023 ? pot_label + t23 + '\n' : pot_label
pot_label := tr024 ? pot_label + t24 + '\n' : pot_label
pot_label := tr025 ? pot_label + t25 + '\n' : pot_label
pot_label := tr026 ? pot_label + t26 + '\n' : pot_label
pot_label := tr027 ? pot_label + t27 + '\n' : pot_label
pot_label := tr028 ? pot_label + t28 + '\n' : pot_label
pot_label := tr029 ? pot_label + t29 + '\n' : pot_label
pot_label := tr030 ? pot_label + t30 + '\n' : pot_label
pot_label := tr031 ? pot_label + t31 + '\n' : pot_label
pot_label := tr032 ? pot_label + t32 + '\n' : pot_label
pot_label := tr033 ? pot_label + t33 + '\n' : pot_label
pot_label := tr034 ? pot_label + t34 + '\n' : pot_label
pot_label := tr035 ? pot_label + t35 + '\n' : pot_label
pot_label := tr036 ? pot_label + t36 + '\n' : pot_label
pot_label := tr037 ? pot_label + t37 + '\n' : pot_label
pot_label := tr038 ? pot_label + t38 + '\n' : pot_label
pot_label := tr039 ? pot_label + t39 + '\n' : pot_label
pot_label := tr040 ? pot_label + t40 + '\n' : pot_label
scr_label = 'Confirmed Reversal: \n'
scr_label := tr01[1] ? scr_label + t1 + '\n' : scr_label
scr_label := tr02[1] ? scr_label + t2 + '\n' : scr_label
scr_label := tr03[1] ? scr_label + t3 + '\n' : scr_label
scr_label := tr04[1] ? scr_label + t4 + '\n' : scr_label
scr_label := tr05[1] ? scr_label + t5 + '\n' : scr_label
scr_label := tr06[1] ? scr_label + t6 + '\n' : scr_label
scr_label := tr07[1] ? scr_label + t7 + '\n' : scr_label
scr_label := tr08[1] ? scr_label + t8 + '\n' : scr_label
scr_label := tr09[1] ? scr_label + t9 + '\n' : scr_label
scr_label := tr010[1] ? scr_label + t10 + '\n' : scr_label
scr_label := tr011[1] ? scr_label + t11 + '\n' : scr_label
scr_label := tr012[1] ? scr_label + t12 + '\n' : scr_label
scr_label := tr013[1] ? scr_label + t13 + '\n' : scr_label
scr_label := tr014[1] ? scr_label + t14 + '\n' : scr_label
scr_label := tr015[1] ? scr_label + t15 + '\n' : scr_label
scr_label := tr016[1] ? scr_label + t16 + '\n' : scr_label
scr_label := tr017[1] ? scr_label + t17 + '\n' : scr_label
scr_label := tr018[1] ? scr_label + t18 + '\n' : scr_label
scr_label := tr019[1] ? scr_label + t19 + '\n' : scr_label
scr_label := tr020[1] ? scr_label + t20 + '\n' : scr_label
scr_label := tr021[1] ? scr_label + t21 + '\n' : scr_label
scr_label := tr022[1] ? scr_label + t22 + '\n' : scr_label
scr_label := tr023[1] ? scr_label + t23 + '\n' : scr_label
scr_label := tr024[1] ? scr_label + t24 + '\n' : scr_label
scr_label := tr025[1] ? scr_label + t25 + '\n' : scr_label
scr_label := tr026[1] ? scr_label + t26+ '\n' : scr_label
scr_label := tr027[1] ? scr_label + t27 + '\n' : scr_label
scr_label := tr028[1] ? scr_label + t28 + '\n' : scr_label
scr_label := tr029[1] ? scr_label + t29 + '\n' : scr_label
scr_label := tr030[1] ? scr_label + t30 + '\n' : scr_label
scr_label := tr031[1] ? scr_label + t31 + '\n' : scr_label
scr_label := tr032[1] ? scr_label + t32 + '\n' : scr_label
scr_label := tr033[1] ? scr_label + t33 + '\n' : scr_label
scr_label := tr034[1] ? scr_label + t34 + '\n' : scr_label
scr_label := tr035[1] ? scr_label + t35 + '\n' : scr_label
scr_label := tr036[1] ? scr_label + t36 + '\n' : scr_label
scr_label := tr037[1] ? scr_label + t37 + '\n' : scr_label
scr_label := tr038[1] ? scr_label + t38 + '\n' : scr_label
scr_label := tr039[1] ? scr_label + t39 + '\n' : scr_label
scr_label := tr040[1] ? scr_label + t40 + '\n' : scr_label
up_label = 'Uptrend: \n'
up_label := up01[1] ? up_label + t1 + '\n' : up_label
up_label := up02[1] ? up_label + t2 + '\n' : up_label
up_label := up03[1] ? up_label + t3 + '\n' : up_label
up_label := up04[1] ? up_label + t4 + '\n' : up_label
up_label := up05[1] ? up_label + t5 + '\n' : up_label
up_label := up06[1] ? up_label + t6 + '\n' : up_label
up_label := up07[1] ? up_label + t7 + '\n' : up_label
up_label := up08[1] ? up_label + t8 + '\n' : up_label
up_label := up09[1] ? up_label + t9 + '\n' : up_label
up_label := up010[1] ? up_label + t10 + '\n' : up_label
up_label := up011[1] ? up_label + t11 + '\n' : up_label
up_label := up012[1] ? up_label + t12 + '\n' : up_label
up_label := up013[1] ? up_label + t13 + '\n' : up_label
up_label := up014[1] ? up_label + t14 + '\n' : up_label
up_label := up015[1] ? up_label + t15 + '\n' : up_label
up_label := up016[1] ? up_label + t16 + '\n' : up_label
up_label := up017[1] ? up_label + t17 + '\n' : up_label
up_label := up018[1] ? up_label + t18 + '\n' : up_label
up_label := up019[1] ? up_label + t19 + '\n' : up_label
up_label := up020[1] ? up_label + t20 + '\n' : up_label
up_label := up021[1] ? up_label + t21 + '\n' : up_label
up_label := up022[1] ? up_label + t22 + '\n' : up_label
up_label := up023[1] ? up_label + t23 + '\n' : up_label
up_label := up024[1] ? up_label + t24 + '\n' : up_label
up_label := up025[1] ? up_label + t25 + '\n' : up_label
up_label := up026[1] ? up_label + t26 + '\n' : up_label
up_label := up027[1] ? up_label + t27 + '\n' : up_label
up_label := up028[1] ? up_label + t28 + '\n' : up_label
up_label := up029[1] ? up_label + t29 + '\n' : up_label
up_label := up030[1] ? up_label + t30 + '\n' : up_label
up_label := up031[1] ? up_label + t31 + '\n' : up_label
up_label := up032[1] ? up_label + t32 + '\n' : up_label
up_label := up033[1] ? up_label + t33 + '\n' : up_label
up_label := up034[1] ? up_label + t34 + '\n' : up_label
up_label := up035[1] ? up_label + t35 + '\n' : up_label
up_label := up036[1] ? up_label + t36 + '\n' : up_label
up_label := up037[1] ? up_label + t37 + '\n' : up_label
up_label := up038[1] ? up_label + t38 + '\n' : up_label
up_label := up039[1] ? up_label + t39 + '\n' : up_label
up_label := up040[1] ? up_label + t40 + '\n' : up_label
dn_label = 'Downtrend: \n'
dn_label := dn01[1] ? dn_label + t1 + '\n' : dn_label
dn_label := dn02[1] ? dn_label + t2 + '\n' : dn_label
dn_label := dn03[1] ? dn_label + t3 + '\n' : dn_label
dn_label := dn04[1] ? dn_label + t4 + '\n' : dn_label
dn_label := dn05[1] ? dn_label + t5 + '\n' : dn_label
dn_label := dn06[1] ? dn_label + t6 + '\n' : dn_label
dn_label := dn07[1] ? dn_label + t7 + '\n' : dn_label
dn_label := dn08[1] ? dn_label + t8 + '\n' : dn_label
dn_label := dn09[1] ? dn_label + t9 + '\n' : dn_label
dn_label := dn010[1] ? dn_label + t10 + '\n' : dn_label
dn_label := dn011[1] ? dn_label + t11 + '\n' : dn_label
dn_label := dn012[1] ? dn_label + t12 + '\n' : dn_label
dn_label := dn013[1] ? dn_label + t13 + '\n' : dn_label
dn_label := dn014[1] ? dn_label + t14 + '\n' : dn_label
dn_label := dn015[1] ? dn_label + t15 + '\n' : dn_label
dn_label := dn016[1] ? dn_label + t16 + '\n' : dn_label
dn_label := dn017[1] ? dn_label + t17 + '\n' : dn_label
dn_label := dn018[1] ? dn_label + t18 + '\n' : dn_label
dn_label := dn019[1] ? dn_label + t19 + '\n' : dn_label
dn_label := dn020[1] ? dn_label + t20 + '\n' : dn_label
dn_label := dn021[1] ? dn_label + t21 + '\n' : dn_label
dn_label := dn022[1] ? dn_label + t22 + '\n' : dn_label
dn_label := dn023[1] ? dn_label + t23 + '\n' : dn_label
dn_label := dn024[1] ? dn_label + t24 + '\n' : dn_label
dn_label := dn025[1] ? dn_label + t25 + '\n' : dn_label
dn_label := dn026[1] ? dn_label + t26 + '\n' : dn_label
dn_label := dn027[1] ? dn_label + t27 + '\n' : dn_label
dn_label := dn028[1] ? dn_label + t28 + '\n' : dn_label
dn_label := dn029[1] ? dn_label + t29 + '\n' : dn_label
dn_label := dn030[1] ? dn_label + t30 + '\n' : dn_label
dn_label := dn031[1] ? dn_label + t31 + '\n' : dn_label
dn_label := dn032[1] ? dn_label + t32 + '\n' : dn_label
dn_label := dn033[1] ? dn_label + t33 + '\n' : dn_label
dn_label := dn034[1] ? dn_label + t34 + '\n' : dn_label
dn_label := dn035[1] ? dn_label + t35 + '\n' : dn_label
dn_label := dn036[1] ? dn_label + t36 + '\n' : dn_label
dn_label := dn037[1] ? dn_label + t37 + '\n' : dn_label
dn_label := dn038[1] ? dn_label + t38 + '\n' : dn_label
dn_label := dn039[1] ? dn_label + t39 + '\n' : dn_label
dn_label := dn040[1] ? dn_label + t40 + '\n' : dn_label
f_colorscr(_valscr) =>
    _valscr ? #00000000 : na
f_printscr(_txtscr) =>
    var _lblscr = label(na)
    label.delete(_lblscr)
    _lblscr := label.new(time + (time - time[1]) * posX_scr, ohlc4[posY_scr], _txtscr, xloc.bar_time, yloc.price, f_colorscr(showscr), textcolor=showscr ? col : na, size=size.normal, style=label.style_label_center)
    _lblscr
f_printscr(scr_label + '\n' + pot_label + '\n' + up_label + '\n' + dn_label)
Expand (554 lines)

Overview

AC- MY SCRIPT1 builds the average as SMA, EMA, WMA, TMA, VAR, WWMA, ZLEMA, or TSF, then offsets long and short stops by a percent of that average. Optional markers flag support-line crosses, price crosses of the tracker, and tracker color changes, and a label can screen several symbols. Period, percent, colors, and a backtest date window are adjustable. The supplied code shows no stop loss and does not show exit rules.

Details

Published by

hasnocool on GitHub

Code credit

arjunji4u, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Moving averages, Screeners & dashboards

Markets

Crypto, Indices

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Sourcesourceclosesrc
OTT Periodint4length
OTT Percentfloat4.2percent
Show Support Line?booltrueshowsupport
Show Support Line Crossing Signals?booltrueshowsignalsk
Show Price/OTT Crossing Signals?boolfalseshowsignalsc
Show OTT Color Changes?boolfalsehighlight
Show OTT Color Change Signals?boolfalseshowsignalsr
Highlighter On/Off ?booltruehighlighting
Moving Average TypestringVARmav
Show Screener Labelbooltrueshowscr
Pos. Label x-axisint20posX_scr
Show all 40 settings
SettingTypeDefaultVariable
Pos. Size Label y-axisint1posY_scr
Label ColorstringBluecolinput
=Backtest Inputs=booltruedummy0
From Dayint1FromDay
From Monthint1FromMonth
From Yearint2005FromYear
To Dayint1ToDay
To Monthint1ToMonth
To Yearint9999ToYear
Symbol 01symbolNIFTYt1
Symbol 02symbolS68t2
Symbol 03symbol1000SHIBUSDTPERPt3
Symbol 04symbol1INCHUSDTPERPt4
Symbol 05symbolALGOUSDTPERPt5
Symbol 06symbolALICEUSDTPERPt6
Symbol 07symbolALPHAUSDTPERPt7
Symbol 08symbolANTUSDTPERPt8
Symbol 09symbolAPI3USDTPERPt9
Symbol 10symbolARUSDTPERPt10
Symbol 11symbolARPAUSDTPERPt11
Symbol 12symbolAUDIOUSDTPERPt12
Symbol 13symbolt13
Symbol 14symbolt14
Symbol 15symbolt15
Symbol 16symbolt16
Symbol 17symbolt17
Symbol 18symbolt18
Symbol 19symbolt19
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Calculates a custom moving average (MaMA) by modifying the source price with price momentum, acceleration, and psychological win-rate probability before applying an EMA or SMA. Plots the adjusted moving average directly on the price chart alongside optional re

Strategy v5 Moving averagesTrend
Updated 4 years ago · None stated GitHub repository of Momentum Adjusted Moving Average by DGT

This long-only trend-following strategy combines Ichimoku Kinko Hyo components with higher timeframe moving average filters. It triggers long entries when price trades above a higher timeframe EMA and a bullish Tenkan-Sen cross above Kijun-Sen occurs under fav

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · MPL-2.0 GitHub repository of Ichimoku Kinko Hyo Momentum Strategy

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers