Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

  • Forums
  • Pinescript
  • Cannot use a mutable variable as an argument of the request.security function.

Cannot use a mutable variable as an argument of the request.security function.

May 17, 2022 - 7:08 PM

Viewed 1348 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/57023 COPY
  • Greetings, I am working on a scanning program, but it gives the error you see in the title, I could not solve it, I would appreciate if you could help.

    my codes are below

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © egemynet

    //@version=5

    indicator('ertekin rend Magic + ema', overlay=true, format=format.price, precision=2)

    colorred = #ff0404
    colorblue = #298cff
    colorgreen = #008f06
    colorblack = #000000
    colorbrown = #b40b00

    ////////////////////////////////////////////////////// fibo ///////////////////////////////////////////////////////////

    FPeriod = input(144, title='Fibo Period', tooltip=Bu şartları listeler\n alis = k > k [1] and kb > kb[1] and tpl== 3 and up1 \n satis = k < k [1] and kb < kb[1] and tpl== 0 and down1, group='Auto Fibo')
    plotF1618 = input(title='Plot 1.618 Level?', defval=false, group='Auto Fibo')

    Fhigh = ta.highest(FPeriod)
    Flow = ta.lowest(FPeriod)
    FH = ta.highestbars(high, FPeriod)
    FL = ta.lowestbars(low, FPeriod)
    downfibo = FH < FL

    F0 = downfibo ? Flow : Fhigh
    F236 = downfibo ? (Fhigh - Flow) * 0.236 + Flow : Fhigh - (Fhigh - Flow) * 0.236
    F382 = downfibo ? (Fhigh - Flow) * 0.382 + Flow : Fhigh - (Fhigh - Flow) * 0.382
    F500 = downfibo ? (Fhigh - Flow) * 0.500 + Flow : Fhigh - (Fhigh - Flow) * 0.500
    F618 = downfibo ? (Fhigh - Flow) * 0.618 + Flow : Fhigh - (Fhigh - Flow) * 0.618
    F786 = downfibo ? (Fhigh - Flow) * 0.786 + Flow : Fhigh - (Fhigh - Flow) * 0.786
    F1000 = downfibo ? (Fhigh - Flow) * 1.000 + Flow : Fhigh - (Fhigh - Flow) * 1.000
    F1618 = downfibo ? (Fhigh - Flow) * 1.618 + Flow : Fhigh - (Fhigh - Flow) * 1.618

    Fcolor = downfibo ? #6A1B9A : #6A1B9A //#00b300 : #E41019
    Foffset = downfibo ? FH : FL

    up_ = ta.crossover(close[1],F236) or ta.crossover(close[1],F382) or ta.crossover(close[1],F500) or ta.crossover(close[1],F618) or ta.crossover(close[1],F786)
    down_ = ta.crossunder(close[1],F236) or ta.crossunder(close[1],F382) or ta.crossunder(close[1],F500) or ta.crossunder(close[1],F618) or ta.crossunder(close[1],F786)
    alertcondition(up_ or down_, title = Alarm, message = Beklenen oldu...)

    plot(F0, color=Fcolor, linewidth=2, style=plot.style_circles, trackprice=true, show_last=1, title='0', transp=0)
    plot(F236, color=Fcolor, linewidth=2, style=plot.style_circles, trackprice=true, show_last=1, title='0.236', transp=0)
    plot(F382, color=Fcolor, linewidth=2, style=plot.style_circles, trackprice=true, show_last=1, title='0.382', transp=0)
    plot(F500, color=Fcolor, linewidth=2, style=plot.style_circles, trackprice=true, show_last=1, title='0.5', transp=0)
    plot(F618, color=Fcolor, linewidth=2, style=plot.style_circles, trackprice=true, show_last=1, title='0.618', transp=0)
    plot(F786, color=Fcolor, linewidth=2, style=plot.style_circles, trackprice=true, show_last=1, title='0.786', transp=0)
    plot(F1000, color=Fcolor, linewidth=2, style=plot.style_circles, trackprice=true, show_last=1, title='1', transp=0)
    plot(plotF1618 and F1618 ? F1618 : na, color=Fcolor, linewidth=3, trackprice=true,show_last=1, title='1.618', transp=0)

    ///////////////////////////////////////////////// trend magic ///////////////////////////////////////////////////

    period = input(20, 'CCI period', group=Trend Magic)
    coeff = input(1, 'ATR Multiplier', group=Trend Magic)
    AP = input(5, 'ATR Period', group=Trend Magic)
    ATR = ta.sma(ta.tr, AP)
    src_ = input(close, group=Trend Magic)
    upT = low - ATR * coeff
    downT = high + ATR * coeff
    MagicTrend = 0.0
    MagicTrend := ta.cci(src_, period) >= 0 ? upT < nz(MagicTrend[1]) ? nz(MagicTrend[1]) : upT : downT > nz(MagicTrend[1]) ? nz(MagicTrend[1]) : downT
    color1 = ta.cci(src_, period) >= 0 ? #0022FC : #FC0400
    plot(MagicTrend, color=color1, linewidth=3)

    ///////////////////////////////////////////////// ema ///////////////////////////////////////////////////

    ema = ta.ema(close, 100)
    plot(ema, ema 100, color= color.green, linewidth=2)

    ///////////////////////////////////////////////// tarama ///////////////////////////////////////////////////

    up = ta.crossover(MagicTrend, ema) and close > ema
    down = ta.crossunder(MagicTrend, ema) and close < ema

    ////////////////////////////////////////////////// fonksiyon /////////////////////////////////////////////////////////////

    customFunc() => (up or down)
    sure = '15'

    s1 = request.security(ticker.heikinashi('BTCUSDTPERP '), sure, customFunc())
    s2 = request.security(ticker.heikinashi('ETHUSDTPERP '), sure, customFunc())
    s3 = request.security(ticker.heikinashi('BNBUSDTPERP '), sure, customFunc())
    s4 = request.security(ticker.heikinashi('ADAUSDTPERP '), sure, customFunc())
    s5 = request.security(ticker.heikinashi('SOLUSDTPERP '), sure, customFunc())
    s6 = request.security(ticker.heikinashi('XRPUSDTPERP '), sure, customFunc())
    s7 = request.security(ticker.heikinashi('LUNAUSDTPERP '), sure, customFunc())
    s8 = request.security(ticker.heikinashi('DOGEUSDTPERP '), sure, customFunc())
    s9 = request.security(ticker.heikinashi('DOTUSDTPERP '), sure, customFunc())
    s10= request.security(ticker.heikinashi('AVAXUSDTPERP '), sure, customFunc())
    s11= request.security(ticker.heikinashi('MATICUSDTPERP '), sure, customFunc())
    s12= request.security(ticker.heikinashi('ATOMUSDTPERP '), sure, customFunc())
    s13= request.security(ticker.heikinashi('LTCUSDTPERP '), sure, customFunc())
    s14= request.security(ticker.heikinashi('LINKUSDTPERP '), sure, customFunc())
    s15= request.security(ticker.heikinashi('NEARUSDTPERP '), sure, customFunc())
    s16= request.security(ticker.heikinashi('UNIUSDTPERP '), sure, customFunc())
    s17= request.security(ticker.heikinashi('ALGOUSDTPERP '), sure, customFunc())
    s18= request.security(ticker.heikinashi('TRXUSDTPERP '), sure, customFunc())
    s19= request.security(ticker.heikinashi('BCHUSDTPERP '), sure, customFunc())
    s20= request.security(ticker.heikinashi('FTMUSDTPERP '), sure, customFunc())
    s21= request.security(ticker.heikinashi('XLMUSDTPERP '), sure, customFunc())
    s22= request.security(ticker.heikinashi('MANAUSDTPERP '), sure, customFunc())
    s23= request.security(ticker.heikinashi('ICPUSDTPERP '), sure, customFunc())
    s24= request.security(ticker.heikinashi('HBARUSDTPERP '), sure, customFunc())
    s25= request.security(ticker.heikinashi('VETUSDTPERP '), sure, customFunc())
    s26= request.security(ticker.heikinashi('SANDUSDTPERP '), sure, customFunc())
    s27= request.security(ticker.heikinashi('ETCUSDTPERP '), sure, customFunc())
    s28= request.security(ticker.heikinashi('KLAYUSDTPERP '), sure, customFunc())
    s29= request.security(ticker.heikinashi('FILUSDTPERP '), sure, customFunc())
    s30= request.security(ticker.heikinashi('EGLDUSDTPERP '), sure, customFunc())
    s31= request.security(ticker.heikinashi('HNTUSDTPERP '), sure, customFunc())
    s32= request.security(ticker.heikinashi('THETAUSDTPERP '), sure, customFunc())
    s33= request.security(ticker.heikinashi('AXSUSDTPERP '), sure, customFunc())
    s34= request.security(ticker.heikinashi('XMRUSDTPERP '), sure, customFunc())
    s35= request.security(ticker.heikinashi('XTZUSDTPERP '), sure, customFunc())
    s36= request.security(ticker.heikinashi('EOSUSDTPERP '), sure, customFunc())
    s37= request.security(ticker.heikinashi('ONEUSDTPERP '), sure, customFunc())
    s38= request.security(ticker.heikinashi('AAVEUSDTPERP '), sure, customFunc())
    s39= request.security(ticker.heikinashi('GRTUSDTPERP '), sure, customFunc())

    src_label = 'TM + ema 1\n------------\n'
    src_label := s1 ? src_label + '01- BTC \n' : src_label

    src_label := s2 ? src_label + '02- ETH \n' : src_label

    src_label := s3 ? src_label + '03- BNB \n' : src_label

    src_label := s4 ? src_label + '04- ADA \n' : src_label

    src_label := s5 ? src_label + '05- SOL \n' : src_label

    src_label := s6 ? src_label + '06- XRP \n' : src_label

    src_label := s7 ? src_label + '07- LUNA \n' : src_label

    src_label := s8 ? src_label + '08- DOGE \n' : src_label

    src_label := s9 ? src_label + '09- DOT \n' : src_label

    src_label := s10 ? src_label + '10- AVAX \n' : src_label

    src_label := s11 ? src_label + '11- MATIC \n' : src_label

    src_label := s12 ? src_label + '12- ATOM \n' : src_label

    src_label := s13 ? src_label + '13- LTC \n' : src_label

    src_label := s14 ? src_label + '14- LINK \n' : src_label

    src_label := s15 ? src_label + '15- NEAR \n' : src_label

    src_label := s16 ? src_label + '16- UNI \n' : src_label

    src_label := s17 ? src_label + '17- ALGO \n' : src_label

    src_label := s18 ? src_label + '18- TRX \n' : src_label

    src_label := s19 ? src_label + '19- BCH \n' : src_label

    src_label := s20 ? src_label + '20- FTM \n' : src_label

    src_label := s21 ? src_label + '21- XLM \n' : src_label

    src_label := s22 ? src_label + '22- MANA \n' : src_label

    src_label := s23 ? src_label + '23- ICP \n' : src_label

    src_label := s24 ? src_label + '24- HBAR \n' : src_label

    src_label := s25 ? src_label + '25- VET \n' : src_label

    src_label := s26 ? src_label + '26- SAND \n' : src_label

    src_label := s27 ? src_label + '27- ETC \n' : src_label

    src_label := s28 ? src_label + '28- KLAY \n' : src_label

    src_label := s29 ? src_label + '29- FIL \n' : src_label

    src_label := s30 ? src_label + '30- EGLD \n' : src_label

    src_label := s31 ? src_label + '31- HNT \n' : src_label

    src_label := s32 ? src_label + '32- THETA \n' : src_label

    src_label := s33 ? src_label + '33- AXS \n' : src_label

    src_label := s34 ? src_label + '34- XMR \n' : src_label

    src_label := s35 ? src_label + '35- XTZ \n' : src_label

    src_label := s36 ? src_label + '36- EOS \n' : src_label

    src_label := s37 ? src_label + '37- ONE \n' : src_label

    src_label := s38 ? src_label + '38- AAVE \n' : src_label

    src_label := s39 ? src_label + '39- GRT \n' : src_label

    aaa = label.new(time, close, src_label, color=colorgreen, textcolor=color.white, size=size.normal, style=label.style_label_left, textalign=text.align_left, xloc=xloc.bar_time)
    label.set_x(id=aaa, x=label.get_x(id=aaa) + 1110000)
    label.delete(aaa[1])

    0
  • Anonymous:
    Maybe this will help: https://quantnomad.com/faq-cannot-use-a-mutable-variable-as-an-argument-of-the-security-function-how-to-fix/

    yes i saw that but i couldn't apply it to my project dude

    0
  • Check out this scanner as a guide and you can decrease the size of that code tremendously as it really boggs down TV on these scanner type scripts. https://www.tradingview.com/script/yhEM8KVI-Counting-Stars-Overlay-Market-Overview-Series/

    0
CONTENTS