Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-08-06· OpenAIAi2 WildChat-4.8M (AI2)

//@version=5 indicator('LeProfessor RSI/MA kesişimi taraması 1', shorttitle='Le…

  1. User

    //@version=5 indicator('Le_Professor RSI/MA kesişimi taraması 1', shorttitle='Le Professor Tarama 1', overlay=false)

    // RSI Params rsi_length = input.int(14, title='Length', inline='RSI', group='RSI') timePeriod = input.timeframe('D', "Resolution", options=['D', 'W', 'M', '1', '3', '5', '10', '15', '30', '45', '60', '120', '240']) bars_apart = input.int(40, title='Labels Bars Apart', inline='Style', group='Style')

    // Liste Seçimi list_selection = input.string('Liste 1', title="Liste Seçimi", options=['Liste 1', 'Liste 2', 'Liste 3'], group='Liste Seçimi')

    // Hisse listeleri var string[] symbol_list = na if list_selection == 'Liste 1' symbol_list := array.new_string(5) array.set(symbol_list, 0, 'BIST:A1CAP') array.set(symbol_list, 1, 'BIST:ACSEL') array.set(symbol_list, 2, 'BIST:ADEL') array.set(symbol_list, 3, 'BIST:ADESE') array.set(symbol_list, 4, 'BIST:ADGYO')

    if list_selection == 'Liste 2' symbol_list := array.new_string(5) array.set(symbol_list, 0, 'BIST:ARCLK') array.set(symbol_list, 1, 'BIST:AEFES') array.set(symbol_list, 2, 'BIST:AFYON') array.set(symbol_list, 3, 'BIST:AGESA') array.set(symbol_list, 4, 'BIST:AGHOL')

    if list_selection == 'Liste 3' symbol_list := array.new_string(5) array.set(symbol_list, 0, 'BIST:AGROT') array.set(symbol_list, 1, 'BIST:AGYO') array.set(symbol_list, 2, 'BIST:AHGAZ') array.set(symbol_list, 3, 'BIST:AKBNK') array.set(symbol_list, 4, 'BIST:AKCNS')

    // Verileri hesaplama Var_Func(source, len) => valpha = 2 / (len + 1) vud1 = source > source[1] ? source - source[1] : 0 vdd1 = source < source[1] ? source[1] - source : 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) * source) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1]) VAR

    ma(source, len, type) => switch type "SMA" => ta.sma(source, len) "EMA" => ta.ema(source, len) "SMMA (RMA)" => ta.rma(source, len) "WMA" => ta.wma(source, len) "VWMA" => ta.vwma(source, len) "VAR" => Var_Func(source, len) len1=input.int(20, title="RSI Divergence length", maxval=500) len = input.int(14, minval=1, title='Length') src= close src2 = input(close, 'Source') maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA", "VAR"], group="MOST Settings") maLengthInput = input.int(5, title="MA Length", group="MOST Settings") percent = input.float(9.0, 'STOP LOSS Percent', step=0.1, minval=0, group="MOST Settings") up = ta.rma(math.max(ta.change(src), 0), len) down = ta.rma(-math.min(ta.change(src), 0), len) rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down) rsiMA = ma(rsi, maLengthInput, maTypeInput)

    exMov = rsiMA fark = exMov * percent * 0.01 longStop = exMov - fark longStopPrev = nz(longStop[1], longStop) longStop := exMov > longStopPrev ? math.max(longStop, longStopPrev) : longStop shortStop = exMov + fark shortStopPrev = nz(shortStop[1], shortStop) shortStop := exMov < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop dir = 1 dir := nz(dir[1], dir) dir := dir == -1 and exMov > shortStopPrev ? 1 : dir == 1 and exMov < longStopPrev ? -1 : dir MOST = dir == 1 ? longStop : shortStop cro= ta.crossover(exMov, MOST) cru= ta.crossunder(exMov, MOST) direction = 0 direction := cro ? 1 : cru ? -1 : direction[1]

    drawLine(X1, Y1, X2, Y2, ExtendType, Color, LineStyle) => var line Line = na Line := line.new(X1, Y1, X2, Y2, xloc.bar_index, ExtendType, Color, LineStyle, 1) line.delete(Line[1])

    rsdcr2(PeriodMinusOne, Deviations, Estimate) => var period = PeriodMinusOne + 1 var devDenominator = Estimate == 'Unbiased' ? PeriodMinusOne : period Ex = 0.0 Ex2 = 0.0 Exy = 0.0 Ey = 0.0 for i = 0 to PeriodMinusOne by 1 closeI = nz(rsi[i]) Ex := Ex + i Ex2 := Ex2 + i * i Exy := Exy + closeI * i Ey := Ey + closeI Ey ExEx = Ex * Ex slope = Ex2 == ExEx ? 0.0 : (period * Exy - Ex * Ey) / (period * Ex2 - ExEx) linearRegression = (Ey - slope * Ex) / period intercept = linearRegression + bar_index * slope deviation = 0.0 for i = 0 to PeriodMinusOne by 1 deviation := deviation + math.pow(nz(rsi[i]) - (intercept - bar_index[i] * slope), 2.0) deviation deviation := Deviations * math.sqrt(deviation / devDenominator) correlate = ta.correlation(rsi, bar_index, period) r2 = math.pow(correlate, 2.0) [linearRegression, slope, deviation, correlate, r2] periodTrend = input.int(89, 'Trend Period', minval=4) deviationsAmnt = input.float(1.5, ' Deviation', minval=0.1, step=0.1) estimatorType = input.string('tarafsız', ' Estimator', options=['taraflı', 'tarafsız']) var extendType = input.string('Right', 'Extend', options=['Right', 'Segment']) == 'Right' ? extend.right : extend.none periodMinusOne = periodTrend - 1 [linReg, slope, deviation, correlate, r2] = rsdcr2(periodMinusOne, deviationsAmnt, estimatorType) endPointBar = bar_index - periodTrend + 1 endPointY = linReg + slope * periodMinusOne

    screenerFunc(sym) => ///rsi_value1 = (ta.crossover(rsi, rsiMA) and (-0.2 < correlate) and ( +0.6 > correlate) and(rsi< 50)) rsi_value1 = (ta.crossover(rsi, rsiMA) and ta.crossover(rsi, MOST) and (-0.2 < correlate) and ( +0.6 > correlate)),

      [rsi_value1]
    

    // Ekran etiketi var string scr_label1 = 'RSİ-MA YUKARI KESEN: \n-------------------------\n'

    // Hisse listelerini kontrol et for i = 0 to array.size(symbol_list) - 1 sym = array.get(symbol_list, i) rsi = request.security(sym, timePeriod, ta.rsi(close, rsi_length)) rsiMA = request.security(sym, timePeriod, ma(rsi, 14, "SMA")) rsi_value1 = (ta.crossover(rsi, rsiMA) and rsi < 50) scr_label1 := rsi_value1 ? scr_label1 + sym + ' ' + '\n' : scr_label1

    label.new(bar_index, 0, scr_label1, color=color(na), textcolor=#4fff49, style=label.style_label_down, textalign=text.align_left)

    // Uyarı mesajı alert_message = scr_label1 alert(alert_message, freq=alert.freq_once_per_bar_close)

  2. Assistant

    This script is written in Pine Script, which is used for creating custom technical indicators and strategies on TradingView. Here's a breakdown of its main components:

    Indicator Setup

    • Indicator Name: The script starts by defining an indicator titled 'Le_Professor RSI/MA kesişimi taraması 1'.
    • Parameters: Inputs for RSI length (rsi_length), timeframe resolution (timePeriod), and label appearance (bars_apart) are set, among others.

    Stock Lists

    • List Selection: A list_selection input allows the user to select from three lists of stocks (Liste 1, Liste 2, Liste 3). Each list contains five stock symbols.

    Calculations

    • MA and RSI Calculation: Functions are created to calculate different types of moving averages (ma) and a custom Var_Func. The RSI is calculated, and a moving average is applied to the RSI values.
    • Stop Loss Logic: Using the moving average of the RSI, the script calculates stop loss levels (longStop and shortStop) and determines the direction (dir) for signals.
    • Regression and Deviation: Linear regression and deviation calculations are done to create additional filters for the signals.

    Screener Logic

    • Signal Screening: A function screenerFunc is declared, which includes conditions to determine crossover events (ta.crossover) between RSI and its moving average or other custom levels (like MOST).

    Output and Alerts

    • Label Display: The script generates a label displaying symbols of stocks that meet the RSI crossover condition and are below RSI value 50.
    • Alert Message: An alert is set up to notify the user when the conditions specified in scr_label1 are met for any stock in the selected list. The alert frequency is set to trigger once per bar close.

    This script is designed to help traders identify points where the RSI of a list of stocks crosses above its moving average from below 50, which could be indicative of a potential upward trend. The script adds more technical filtering and sends alerts, which can assist in making informed trading decisions based on user-defined lists.

  3. User

    Cannot call 'request.security' with argument 'symbol'='sym'. An argument of 'series string' type was used but a 'simple string' is expected.

  4. Assistant

    The error you're encountering is due to the fact that Pine Script expects a simple string for the symbol argument in the request.security function, but the current implementation uses sym, which is of the type series string. To resolve this issue, you need to ensure that sym is a simple string at the time of calling request.security.

    Here’s a step-by-step approach to solve this problem:

    1. Store the Static Symbol String: Instead of using sym directly (which can be a series), use a static string for each iteration. You can achieve this by creating another variable that holds the stock symbol as a simple string inside the loop.

    2. Modify the Loop: When iterating over the symbol_list, convert each symbol into a simple string and then pass it to request.security.

    Here's how you can alter the loop to ensure sym is a simple string:

    // Iterate over the symbol list
    for i = 0 to array.size(symbol_list) - 1
        // Get the symbol as a simple string
        string current_symbol = array.get(symbol_list, i)
        // Use 'request.security' with the simple string
        rsi = request.security(current_symbol, timePeriod, ta.rsi(close, rsi_length))
        rsiMA = request.security(current_symbol, timePeriod, ma(rsi, 14, "SMA"))
        rsi_value1 = (ta.crossover(rsi, rsiMA) and rsi < 50)
        scr_label1 := rsi_value1 ? scr_label1 + current_symbol + ' ' + '\n' : scr_label1
    

    Explanation:

    • current_symbol: This variable stores the symbol retrieved from symbol_list as a simple string for each iteration.
    • request.security Adjustments: You then use current_symbol within the request.security function to ensure it has the correct data type.

    This change should resolve the error and allow the script to function correctly by fetching the RSI and moving average data for the correct stock symbols.