Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Is there a way in Pine Script to plot a calculated projected value one bar ahead of the current last bar?

I am calculating a project high, low and midpoint for tomorrow, or the next bar. I want to insert these values into indicators such as the RSI and the DMI which I can do. I would like the final value in the series to plot with the last bar just forming. I don't want to move the whole series forward one bar as that would make the indicator one day last and still not display the last value.

Is there a way in Pine Script to display a projected calculated value for tomorrow or the next bar in an indicator plot so that the indicator will display the results of that projected calculated value concurrent with the last bar still forming?

I can't use [] as that uses previous values, and I don't want to use offset as that moves the whole series backward or forward. I want the data series to stay in place but for the indicator plot to display the results of my calculated projected values. Can this be done in Pine Script?
17 people have
this question
+1
Reply
  • That's an interesting topic. Looks like we still miss such possibility with Pine.
    Moreover there's not even a default tool to compute/estimate/draw indicators based on future price variations.

    For instance I'd like to know where the RSI would be for each of the next 5 bars if I draw 5 new bars in a given direction (assuming the tool would let us play with future bars).

    Please consider adding such feature!!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Hello,
    yes I also see many uses of this feature. I think similarly it would be useful if we could somehow customize the text in alertcondition . I would like to show specific data which generated the alert. For example the last 3 MACD values, or the current ADX value.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Now you may use offset=1 with combination of show_last=1. https://www.tradingview.com/script/P3...

    //@version=3
    study("Calculated projected value one bar ahead", overlay=true)
    calc_proj = (open + high + low + close) / 4 // Doesn't matter the formula
    plot(calc_proj, show_last=1, offset=1) // Unfortunately plotbar/plotcandle doesn't support offset param yet
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • This is a 3 year old question, only answered now. What exactly is the development status of this? I feel that with some more development focus, and involvement, that TV pine-scripting could have the potential to be one of the top platforms to use...

    But I'm in a lot of doubt seeing the slow progress, if any at all.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • necro-posting in this thread.
    need this for K-Nearest Neighbors


    example on meta trader 5
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Old question, but came up in a search for something else, so I'll reply. @mahameru, maybe this will help. if it helps, please go upvote this topic: https://getsatisfaction.com/tradingvi...

    Try using security with lookahead=barmerge.lookahead_on, something like below. Probably a loop to do this would be shorter code, but this was my first figuring it out, so did it like this.

    // Month close data for last 10 months
    mc = security(tickerid, 'M', close,lookahead=barmerge.lookahead_on) // current month close (close of partial month)
    mcnla = security(tickerid, 'M', close) // close of the full month
    mc1 = security(tickerid, 'M', close[1])
    mch1=max(mcnla,mc1) // use current month as the high
    // end of month close shows up at start of month on chart.
    // another option to handle this is using close[1],lookahead=barmerge.lookahead_on for month 0
    // mch1 = mc1 // don't use current month close as high, month not closed yet... pine version changes
    mc2 = security(tickerid, 'M', close[2])
    mch2=max(mch1,mc2)
    mc3 = security(tickerid, 'M', close[3])
    mch3=max(mch2,mc3)
    mc4 = security(tickerid, 'M', close[4])
    mch4=max(mch3,mc4)
    mc5 = security(tickerid, 'M', close[5])
    mch5=max(mch4,mc5)
    mc6 = security(tickerid, 'M', close[6])
    mch6=max(mch5,mc6)
    mc7 = security(tickerid, 'M', close[7])
    mch7=max(mch6,mc7)
    mc8 = security(tickerid, 'M', close[8])
    mch8=max(mch7,mc8)
    mc9 = security(tickerid, 'M', close[9])
    mch9=max(mch8,mc9)
    mc10 = security(tickerid, 'M', close[10])
    mch10=max(mch9,mc10) // monthly close peak within previous 11 months
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • _src = close
    change = (_src[0] - _src[1])/_src[0]
    linear_predicted_price_f1 = (change*_src[0]) + _src[0]

    linear_predicted_price_f2 = (change*linear_predicted_price_f1[0] + linear_predicted_price_f1[0])
    linear_predicted_price_f3 = (change*linear_predicted_price_f2[0] + linear_predicted_price_f2[0])
    linear_predicted_price_f4 = (change*linear_predicted_price_f3[0] + linear_predicted_price_f3[0])
    linear_predicted_price_f5 = (change*linear_predicted_price_f4[0] + linear_predicted_price_f4[0])
    linear_predicted_price_f6 = (change*linear_predicted_price_f5[0] + linear_predicted_price_f5[0])
    linear_predicted_price_f7 = (change*linear_predicted_price_f6[0] + linear_predicted_price_f6[0])
    linear_predicted_price_f8 = (change*linear_predicted_price_f7[0] + linear_predicted_price_f7[0])
    linear_predicted_price_f9 = (change*linear_predicted_price_f8[0] + linear_predicted_price_f8[0])
    linear_predicted_price_f10 = (change*linear_predicted_price_f9[0] + linear_predicted_price_f9[0])
    linear_predicted_price_f11 = (change*linear_predicted_price_f10[0] + linear_predicted_price_f10[0])

    plot(linear_predicted_price_f1, show_last=1, offset=1, linewidth=1, color=red)
    plot(linear_predicted_price_f2, show_last=1, offset=2, linewidth=1, color=red)
    plot(linear_predicted_price_f3, show_last=1, offset=3, linewidth=1, color=red)
    plot(linear_predicted_price_f4, show_last=1, offset=4, linewidth=1, color=red)
    plot(linear_predicted_price_f5, show_last=1, offset=5, linewidth=1, color=red)
    plot(linear_predicted_price_f6, show_last=1, offset=6, linewidth=1, color=red)
    plot(linear_predicted_price_f7, show_last=1, offset=7, linewidth=1, color=red)
    plot(linear_predicted_price_f8, show_last=1, offset=8, linewidth=1, color=red)
    plot(linear_predicted_price_f9, show_last=1, offset=9, linewidth=1, color=red)
    plot(linear_predicted_price_f10, show_last=1, offset=10, linewidth=1, color=red)
    plot(linear_predicted_price_f11, show_last=1, offset=11, linewidth=1, color=red)

    plot(_src)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated