Help get this topic noticed by sharing it on Twitter, Facebook, or email.
I’m happy

Volume indicator

Hi,

I would like to create an indicator based on volume.
My idea is the following :

Change the color of the current volume if it is the inverse and two times the size of the previous volume size.

Some one help me ?
3 people have
this question
+1
Reply
  • I am trying that :

    //@version=3
    study("VOL x2 RG")
    v1 = volume
    v2 = volume[1]
    c = v2 < v1/2
    plot(c, style=columns, color=black)

    But create error message :

    root_data expression of plot_0 has invalid type: series__bool expected series
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

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

  • Pine script won't plot raw booleans, so you will have to convert boolean to numbers. Here is one method of doing so:

    //@version=3
    study("VOL x2 RG")
    v1 = volume
    v2 = nz(volume[1]) // nz()
    c = v2 < v1 / 2
    booleanToBinary = c==true ? 1.0 : 0.0
    plot(booleanToBinary, style=columns, color=red)

    When referencing historical values (somevariable[1+]), consider using it in nz(). That way it will avoid NaN and at least provide 0.0.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

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

  • Thanks a lot midtown !

    I have adapted your solution at my requirement, works greet :) :

    //@version=3
    study("VOL x2 RG")

    //Volume is two times higher or lower and in opposite direction of the precendent volume/bar
    CurrentCloseGreen = open < close
    CurrentCloseRed = open > close
    BarPrecGreen = open[1] < close[1]
    BarPrecRed = open[1] > close[1]
    v1 = volume
    v2 = nz(volume[1]) // nz()
    c1 = CurrentCloseGreen and BarPrecRed and v2 < v1 / 2
    c2 = CurrentCloseRed and BarPrecGreen and v2 < v1 / 2
    booleanToBinary1 = c1==true ? 1.0 : 0.0
    booleanToBinary2 = c2==true ? 1.0 : 0.0
    plot(booleanToBinary1, style=columns, color=green)
    plot(booleanToBinary2, style=columns, color=red)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

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