Creating and Backtesting Tradingview Pinescript Trading Strategy

For Complete Course: Practical Approach to Tradingview Pinescript Programming – 20+hours of Pinescript Course to learn …


  1. Hello I am creating an indicator.
    This is how I coded my indicator.

    I coded my indicator as follows

    //@version 5

    Indicator (title =" OBV modified " , overlay = false , timeframe = "" , timeframe_gaps = true)

    var float Obv = na
    var float a = na

    If (volume >0 and ((close>close[1]) or
    ((close=close[1]=close[2])and(close[2]>close[3])) or
    or continue this pattern))

    a := volume

    Else if (volume>0 and ((close<close[1]) or
    ((close=close[1])and(close[1]<close[2])) or
    or continue this pattern )

    a := -volume

    Else if (volume<0 )

    a := 0

    a := 0

    var Anchor = input.string(defval = "Session" , title = "Anchor Period" , option = [" Hour" , "Session" , "Week", "Month"] , group = "OBV Settings")

    Offset = input(0 ,title = "Offset" , group = "OBV Settings")

    timeChange(period) => ta.change(time(period))

    isNew period = switch anchor
    "Hour" => timeChange("60")
    "Session"=> timeChange("D")
    "Week"=> timeChange("W")
    "Month" => timeChange("M")
    computeObv(close, isNewPeriod) =>
    Obv := isNewPeriod ? a : volume + Obv[1]


    Here my conditions contain a sequence .
    If previous condition not holds . We have to check next condition.
    That means .
    If close>close[1] , then volume = positive volume.
    We add this volume with previous volume.
    If close =close[1] , then we have to check whether close[1]>close[2] or not.
    If close[1]>close[2] , then volume = positive volume.
    We can add this volume with previous cumulative sum of volume(like on balance volume calculation and vwap calculation , etc)
    If close=close[1] and close[1]=close[2] , then we have to check whether close[2]>close[3].
    If close[2]>close[3], then volume = positive volume
    We can add this volume with previous cumulative sum volume.
    Continue this sequance till we get an close[n]>close[n+1]
    That is close=close[1]=close[2]=……..=close[n] and close[n]>close[n+1] , then volume equal to positive volume and we can add . This volume with previous cumulative sum volume.

    Can you help me to code this.

  2. This is brilliant and quite captivating as well! Investing in forex has really been favorable to me this season, I make profit from my investment on a weekly basis best regards to Mr. Ray Perkins mentorship/guidance 🇺🇸

  3. Sir ,I do not have any knowledge about coding .With your inspiration I started.When I am writing in my pine editor & when I am putting ,(comma ) it is coming in blue color not in white color.
    And when I try to click on add to chart showing error.
    Please help me sir.

  4. Sir, Signal candle ke high price के उपर next candle पर buy trade लेणे के लिये aur signal candle के low price पर स्टॉप loss लागणा है तो इस के लिये Pinescript मे coding kaise करे. please tell me

  5. I have written one strategy where position will exit after getting 2 close above or below vwap, but can u tell me how to create reenter condition if market reverses, considering above exit as base for reenter.

  6. I have created a backtest but I think it's bugged, on the low timeframes 1 minute – 10 minute it gives a somewhat realistic profit factor of around 1.4 but on the 4 hour time frames it has a win rate over 90 percent, and it will open long trades at the bottom of a candle and sell at the top of the same candle and do the opposite for shorts which seems impossible, do you know how to fix this bug to get more realistic results?

Leave a Reply

Your email address will not be published.