Stoch Divergence Conversion

Forums ProRealTime English forum ProBuilder support Stoch Divergence Conversion

Viewing 10 posts - 1 through 10 (of 10 total)
  • #126458

    Hi,

    I am converting below code from tradingview (https://uk.tradingview.com/scripts/search/stochastic%20divergence/) to PRT 10.3 (IG).

    //@version=4
    //@author=lucemanb
    study(title=”Plain Stochastic Divergence ✂️ “, overlay=false)

    periodK = input(14, title=”K”, minval=1)
    periodD = input(3, title=”D”, minval=1)
    smoothK = input(3, title=”Smooth”, minval=1)

    Dinput1 = sma(stoch(close, high, low, periodK), smoothK)
    SD = sma(Dinput1, periodD)

    plot(title = ‘K’, series = Dinput1 , color = #FF7F00CA,linewidth = 2 )
    plot(title = “D”, series = SD , color = #1E90FF, linewidth = 1)

    f_top_fractal(_src)=>_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and _src[2] > _src[0]
    f_bot_fractal(_src)=>_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and _src[2] < _src[0]
    f_fractalize(_src)=>f_top_fractal(_src) ? 1 : f_bot_fractal(_src) ? -1 : 0

    fractal_top1 = f_fractalize(Dinput1) > 0 ? Dinput1[2] : na
    fractal_bot1 = f_fractalize(Dinput1) < 0 ? Dinput1[2] : na

    high_prev1 = valuewhen(fractal_top1, Dinput1[2], 0)[2]
    high_price1 = valuewhen(fractal_top1, high[2], 0)[2]
    low_prev1 = valuewhen(fractal_bot1, Dinput1[2], 0)[2]
    low_price1 = valuewhen(fractal_bot1, low[2], 0)[2]

    regular_bearish_div1 = fractal_top1 and high[2] > high_price1 and Dinput1[2] < high_prev1
    hidden_bearish_div1 = fractal_top1 and high[2] < high_price1 and Dinput1[2] > high_prev1
    regular_bullish_div1 = fractal_bot1 and low[2] < low_price1 and Dinput1[2] > low_prev1
    hidden_bullish_div1 = fractal_bot1 and low[2] > low_price1 and Dinput1[2] < low_prev1

    col1 = regular_bearish_div1 ? color.red : hidden_bearish_div1 ? color.maroon : na
    col2 = regular_bullish_div1 ? #00FF00EB : hidden_bullish_div1 ? color.green : na

    plot(title=’Bearish Divergence’, series = fractal_top1 ? Dinput1[2] : na, color=col1, linewidth=3, offset=-2)
    plot(title=’Bullish Divergence’, series = fractal_bot1 ? Dinput1[2] : na, color=col2, linewidth=3, offset=-2)

    plotshape(fractal_top1 and (regular_bearish_div1 or hidden_bearish_div1), “spot top”, shape.diamond, location.top, color.blue)
    plotshape(fractal_bot1 and (regular_bullish_div1 or hidden_bullish_div1), “spot bottom”, shape.diamond, location.bottom, color.blue)

    I am trying but unsure about “valuewhen(condition, source, occurance)[2] ” containing extra “[2]” at the end.

    Below is my try but need to fix it and make it work.

     

    Please help.

    Thanks,

    Ash

     

     

    #135365

    valuewhen(condition, source, occurance)[2] ” containing extra “[2]” at the end, means that a reference to the second previous value of the result is to be taken into account, so you have to calculate “valuewhen(condition, source, occurance)”, then use the value retained the 2nd previous bar.

    But I don’t know how to convert it into PRT code.

    #135379

    There is no instruction that replace the ValueWhen, you have to make a loop to find the value you want for that particular barindex.

    #135483

    Thanks.

    Actually the objective is to find hidden bearish and bullish divergences. I’ve code for normal divergence but not for hidden.

    Let me know as when i tried to find hidden divergences on prt, i failed.

    #135561

    If you have coded something to find normal divergences, you would be able to find the hidden ones?

    #135607

    I’d be very interested in this if you manage to get it coded Ashehzi

    #135611
    #135701

    That indicator shows on the price chart but sadly it doesn’t show in a separate pane – from the comments it seems others were finding the same.

    #135770

    This should do, it will return 2=dd, 1=hd (long), -2=dd,-1,hd (short) and 0 if none.

    Line 15 can be modified (withiut even changing the name of variables) to accomodate for other indicators:

    of course you will have to add further parameters to the indicator if you need to use Macd or Stochastic.

     

     

    #139409

    I’ve used https://www.prorealcode.com/prorealtime-indicators/rsi-classical-hidden-divergences-indicator/ before but it doesn’t serve the purpose. I will try to convert the hidden part of this code (rsi-divergences-2.itf) to stoch hidden and will let you know if it serves the purpose.

Viewing 10 posts - 1 through 10 (of 10 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login