Example of strategy in Pine script anyone?

Does anyone have a tutorial or a basic example of using the new pine script feature - strategies. Using strategy one can build a sort of an automated robot that can be used in TV for backtesting your ideas in Pine script. Any examples? The doc is extensive but an explanation of the generic flow or a tutor would be very useful on this subject.
4 people have
this question
+1
Reply
  • Would really love to see a sample too if anyone would oblige...

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

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

  • admin (Company Admin) October 06, 2015 07:14
    We're working in this direction. Follow our blog and updates on the site.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

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

  • I am sure there are some great features in TV which I am not able to access due to lack of guidance/understanding. I am not a geek , yet have some trading ideas that have developed over a few years that I am keen to automate.
    Is anyone developing a simple UI to make and test strategy? Or do we find someone via this website for instance who could be paid to script/explain?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

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

  • This reply was removed on 2015-11-06.
    see the change log
  • 2
    //@version=2

    strategy("ProfitStrategy01", overlay=true)

    // Simple Profit making strategy by joinfree

    Phigh = (open>close?open:close)

    Plow = (open>close?close:open)

    longC = (strategy.position_size <= 0) and (Phigh[1] > Phigh[0]) and (Plow[0] > Plow[1]) and (close[0] > open[0])

    strategy.entry("buy", strategy.long, 100000, when=longC)

    strategy.exit("buy", "buy", 100000, profit=200, stop=50)

    shortC = (strategy.position_size <= 0) and (Phigh[1] > Phigh[0]) and (Plow[0] > Plow[1]) and (close[0] < open[0])

    strategy.entry("sell", strategy.short, 100000, when=shortC)

    strategy.exit("sell", "sell", 100000, profit=200, stop=50)
    • Well, is this really 100000 shares? contracts? dollars?
      The doc indicates you can load all of the above, even use a percent of equity, but I see no one loading the method properly to say shares for example.

      Discrepancy is if you go to Settings of your Strategy and observe the Order Size dropdown, you will only see contracts, dollars, and pct equity.

      Which makes me to believe that Shares really is not an option. Then, on the List Of Trades and Performance it shows P & L as if it was 1 Share instead of 1 Contract (100 shares). Just very inconsistent.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

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

  • A person can bounce all over the internet for hours and hours and still not find enough good examples.
    Here's an example of code not working,

    the point here is to just have .886 written below a candle when its close is an .886 retracement of one of the previous 10 candles (a whole lot of work for something simple)

    //----Begin Fib testing
    data = close == ((close[1] or close [2] or close[3] or close[4] or close[5] or close[6] or close[7] or close[8] or close[9] or close[10])*0.886))
    plotchar(data, char='↑', location=location.belowbar, color=red, text=".886")

    but i get an error saying, "line 24: no viable alternative at input ')'"

    There is no troubleshooting guide for errors that I know of so more examples would be very nice.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

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

  • Hi,

    Is there any way to replicate placing an entry 'Long' 'Call' at the close of a candle that has been marked as 'Buy', and then an exit at the close of the next candle? This would represent placing a call with an expiry time of 60 seconds. Does that make sense?

    For example :

    longC = (Trend == 1 and Trend[1] == -1 and last60bullish and last30bullish)
    strategy.entry("buy", strategy.long, 10000, when=longC)
    strategy.exit("buy", "buy", 10000, "is it possible to replicate a buy at the next candle")

    Any help would be very much appreciated.

    Kind Regards,

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

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