SENTIMENT RANGE MA

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #244198 quote
    Bertoli Riccardo
    Participant
    Junior

    Buongiorno,
    Chiedo di voler cortesemente tradurre in linguaggio PRT questo codice che sembra interessante in quanto evidenzia molto chiaramente le fasi di stallo del mercato
    Grazie
    Cordiali saluti
    SENTIMENT RANGE MA
    fornisce ai trader una prospettiva dinamica sull’attività di mercato, enfatizzando sia la stabilità nelle zone di chop sia la rapida adattabilità al di fuori di esse.
    https://www.tradingview.com/v/LVsNPKBe/
    CODICE CSS
    # https://www.tradingview.com/v/LVsNPKBe/
    #/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://moz
    #// © ChartPrime
    #indicator(“Sentiment Range MA [ChartPrime]”, overlay = true, timeframe = “”, timeframe_gaps = false)
    # Converted and Mod by Sam4Cok@Samer800 – 11/2023

    input showSignals = no;
    input colorBars = no;
    input showBand = yes;
    input timeframe = {Default “Chart”, “Custom”};
    input customTimeframe = AggregationPeriod.DAY;
    input source = FundamentalType.CLOSE; # “Source”
    input Length = 20; # “Length”
    input DoubleFilter = yes; # “Double Filter”
    input trueRangeType = {Default “Candle High/Low”, “Volatility Adjustment”};
    input CandleSmoothing = 4; # “Trigger Smoothing”
    input atrLength = 200; # “ATR Length”
    input RangeMultiplier = 6.00; # “Range Multiplier”
    input RangeStyle = {default “Body”, “Wick”}; # “Range Style”
    input LineColorStyle = {default “MA Direction”, “MA Cross”, “Solid”}; # “Color Style”

    def na = Double.NaN;
    def last = isNaN(close);
    def useAtr = trueRangeType == trueRangeType.”Volatility Adjustment”;
    def mtf = timeframe == timeframe.”Custom”;
    def dir = LineColorStyle == LineColorStyle.”MA Direction”;
    def cross = LineColorStyle == LineColorStyle.”MA Cross”;
    def len = Length + 1;
    def smoothing = CandleSmoothing + 1;
    def multi = RangeMultiplier;
    #– Color
    DefineGlobalColor(“bull”, CreateColor(33, 255, 120)); # “Bullish Color”
    DefineGlobalColor(“bear”, CreateColor(255, 33, 33)); # “Bearish Color”
    DefineGlobalColor(“neut”, CreateColor(137, 137, 137)); # “Neutral Color”
    DefineGlobalColor(“dbull”, CreateColor(1, 50, 32)); # “Bullish Color”
    DefineGlobalColor(“dbear”, CreateColor(63, 0, 0)); # “Bearish Color”
    DefineGlobalColor(“dneut”, CreateColor(42, 42, 42)); # “Neutral Color”
    #- MTF
    def tfS = Fundamental(FundamentalType = source);
    def tfO = Fundamental(FundamentalType = FundamentalType.OPEN);
    def tfC = Fundamental(FundamentalType = FundamentalType.CLOSE);
    def tfH = Fundamental(FundamentalType = FundamentalType.HIGH);
    def tfL = Fundamental(FundamentalType = FundamentalType.LOW);
    def mtfS = Fundamental(FundamentalType = source, Period = customTimeframe);
    def mtfO = Fundamental(FundamentalType = FundamentalType.OPEN, Period = customTimeframe);
    def mtfC = Fundamental(FundamentalType = FundamentalType.CLOSE, Period = customTimeframe);
    def mtfH = Fundamental(FundamentalType = FundamentalType.HIGH, Period = customTimeframe);
    def mtfL = Fundamental(FundamentalType = FundamentalType.LOW, Period = customTimeframe);

    def s = if mtf then mtfS else tfC;
    def o = if mtf then mtfO else tfO;
    def c = if mtf then mtfC else tfC;
    def h = if mtf then mtfH else tfH;
    def l = if mtf then mtfL else tfL;

    #sr_ma(float source, output_smoothing, trigger_smoothing, atr_length = 50, multiplier, string
    script sr_ma {
    input source = close;
    input output_smoothing = 3;
    input smoothing = 1;
    input atr_length = 50;
    input multiplier = 1;
    input range_switch = “Body”;
    input duel_filter = no;
    input useAtr = no;
    input o = open;
    input c = close;
    input h = high;
    input l = low;
    def ntr = TrueRange(h, c, l);
    def nATR = WildersAverage(ntr, atr_length);
    def minVol = Min(nATR * 0.5, c * (0.3 / 100));
    def volAdj = minVol[20];
    def max = Max(o, c);
    def min = Min(o, c);
    def candle_top = if range_switch != “Body” then h else max;
    def candle_bot = if range_switch != “Body” then l else min;
    def smooth_top = Average(candle_top, smoothing);
    def smooth_bot = Average(candle_bot, smoothing);
    def tr = candle_top – candle_bot;
    def avgTr = Average(tr, atr_length);
    def atr = if useAtr then volAdj else avgTr;
    def sr_ma;
    def cur_range;
    def top_range;
    def bot_range;
    def flag = smooth_top > top_range[1] or smooth_bot sr_ma and l sr_ma;
    def plot_bearish = h 0;
    def ma_delta_bearish = (sr_ma – nzSr_ma) 0 then GlobalColor(“bull”) else
    if ma_col 0 then halfTop else na, halfBot, GlobalColor(“dbull”));
    AddCloud(if ma_col 0 then Top else na, Bot, GlobalColor(“dbull”));
    AddCloud(if ma_col 0 and ma_delta > 0 then 2 else
    if ma_cross>0 or ma_delta > 0 then 1 else
    if ma_cross<0 and ma_delta < 0 then -2 else
    if ma_cross<0 or ma_delta < 0 then -1 else 0;
    AssignPriceColor(if !colorBars then Color.CURRENT else
    if barColor == 2 then Color.GREEN else
    if barColor == 1 then Color.DARK_GREEN else
    if barColor ==-2 then Color.RED else
    if barColor ==-1 then Color.DARK_RED else Color.GRAY);
    #– Signals
    def Bull = if barColor== 2 then Bull[1] + 1 else 0;
    def Bear = if barColor==-2 then Bear[1] + 1 else 0;

    AddChartBubble(showSignals and Bull==2, low, "B", Color.GREEN, no);
    AddChartBubble(showSignals and Bear==2, high, "S", Color.RED);
    #– END of CODE
    Ultima modifica da un moderatore:18 febbraio 2024

    TRADINGVIEW-Screenshot-2025-02-22-123002.jpg TRADINGVIEW-Screenshot-2025-02-22-123002.jpg
    #244303 quote
    Iván González
    Moderator
    Master

    Ecco qui:

    //-----------------------------------------------------//
    // PRC_Sentiment Range MA Indicator
    // Version: 0
    // Date: 24.02.2025
    // Author: Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //-----------------------------------------------------//
    
    //-----------------------------------------------------//
    // INPUT PARAMETERS
    //-----------------------------------------------------//
    source = close           // Source price used for calculations
    outputSmoothing = 20     // Smoothing period for the output
    useDouble = 1            // Apply double smoothing (1 = Yes, 0 = No)
    smoothing = 4            // Smoothing period for range calculations
    atrLength = 200          // ATR length for volatility calculation
    multiplier = 6           // ATR multiplier for range calculation
    rangeSwitch = 1          // Determines the range type (1 = Body, 0 = Wick)
    MaType = 1               // Moving Average method (1 = MA direction, 0 = MA Cross)
    //-----------------------------------------------------//
    
    //-----------------------------------------------------//
    // CANDLE RANGE SELECTION
    //-----------------------------------------------------//
    // Define the range based on the selected method (wick or body)
    IF rangeSwitch = 0 THEN
    candleTop = high
    candleBottom = low
    ELSE
    candleTop = max(open, close)  // Highest value of body (open/close)
    candleBottom = min(open, close) // Lowest value of body (open/close)
    ENDIF
    
    // Apply smoothing to the top and bottom of the candle range
    smoothTop = average[smoothing](candleTop)
    smoothBottom = average[smoothing](candleBottom)
    //-----------------------------------------------------//
    
    //-----------------------------------------------------//
    // ATR-BASED RANGE CALCULATION
    //-----------------------------------------------------//
    IF barindex <= atrLength THEN
    outSrMa = undefined
    outTopRange = undefined
    outBottomRange = undefined
    ELSE
    itr = candleTop - candleBottom  // Intrinsic range of the candle
    atr = average[atrLength](itr)   // ATR-based range calculation
    
    once currentRange = undefined   // Initial range value
    
    // Check if the smoothed range exceeds the current range bounds
    flag = smoothTop > topRange OR smoothBottom < bottomRange OR currentRange = undefined
    
    // If range exceeds limits, update the main values
    IF flag THEN
    srMa = source
    currentRange = atr * multiplier
    topRange = srMa + currentRange
    bottomRange = srMa - currentRange
    ENDIF
    
    // Apply optional double smoothing to the output values
    IF useDouble THEN
    outSrMa = average[outputSmoothing, 2](average[outputSmoothing, 0](srMa))
    outTopRange = average[outputSmoothing, 2](average[outputSmoothing, 0](topRange))
    outBottomRange = average[outputSmoothing, 2](average[outputSmoothing, 0](bottomRange))
    ELSE
    outSrMa = average[outputSmoothing, 2](srMa)
    outTopRange = average[outputSmoothing, 2](topRange)
    outBottomRange = average[outputSmoothing, 2](bottomRange)
    ENDIF
    ENDIF
    //-----------------------------------------------------//
    
    //-----------------------------------------------------//
    // TREND DETECTION LOGIC
    //-----------------------------------------------------//
    IF MaType = 1 THEN
    // Define trend based on MA direction
    plotNeutral = outSrMa = outSrMa[1]  // No trend change
    plotBullish = outSrMa > outSrMa[1]  // Uptrend
    plotBearish = outSrMa < outSrMa[1]  // Downtrend
    ELSE
    // Define trend based on price relation to MA
    plotNeutral = high > outSrMa AND low < outSrMa   // Price crosses MA
    plotBullish = low > outSrMa   // Price is above MA
    plotBearish = high < outSrMa  // Price is below MA
    ENDIF
    
    // Assign colors based on trend direction
    IF plotBullish THEN
    r = 33
    g = 255
    b = 120  // Green for bullish trend
    ELSIF plotBearish THEN
    r = 255
    g = 33
    b = 33   // Red for bearish trend
    ELSIF plotNeutral THEN
    r = 137
    g = 137
    b = 137  // Gray for neutral trend
    ENDIF
    //-----------------------------------------------------//
    
    //-----------------------------------------------------//
    // GRAPHICAL REPRESENTATION
    //-----------------------------------------------------//
    // Fill the area between MA and upper/lower range with the trend color
    colorbetween(outSrMa, outTopRange, r, g, b, 10)
    colorbetween(outSrMa, outBottomRange, r, g, b, 10)
    
    //-----------------------------------------------------//
    // Plot the smoothed moving average with the determined trend color
    //-----------------------------------------------------//
    RETURN outSrMa COLOURED(r, g, b) STYLE(LINE, 3)
    //-----------------------------------------------------//
    robertogozzi thanked this post
    #245398 quote
    Bertoli Riccardo
    Participant
    Junior

    E’ proprio quello che cercavo.

    Complimenti vivissimi, fornite un supporto veramente eccezionale.

    Grazie mille

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

SENTIMENT RANGE MA


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Author
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Bertoli Riccardo
1 year, 1 month ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 02/22/2025
Status: Active
Attachments: 1 files
Logo Logo
Loading...