Conversion of strategy tester from pinescript T.view

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #222630 quote
    HottoSenpaiHottoSenpai
    Participant
    New

    Hello so i was using tradingview and i have gotten en script for backtesting my strategy but i want to move to prorealtime.
    Strategy is Simple. Trading begine after specific candle open for example lets use 9:15 – 9:20. lets call it main bar It will be at 5min chart always.

    Entry point will be closing of prior bar that was created between 9:15-9:20. Trade buy will be when the price will cross high of prior (main) bar + 2 points after 9:20.

    Trade sell will be when the price will cross low of prior (main) bar + 2 points.

    SL will be size of the main bar + 2 points ,TP will be 2RR ( double size of specific SL) It will trade till first win but not more that 4 trades in one day. Each trade need to be open from main bar levels for buy and sell. I will insert here the code from pinescript.
    //@version=5

    strategy(title=”Custom Session Strategy”, overlay=true, default_qty_value=100, initial_capital=100000, max_lines_count=500, default_qty_type=strategy.percent_of_equity, pyramiding=0, process_orders_on_close=true)
    tz = input.string(“UTC+2”, title=’TimeZone’)
    // Trading Session
    in_session(sess) =>
        t = time(timeframe.period, sess, tz)
        r = na(t) ? false : true
        r
    session = input.session(“1415-1500″, title=”Trading Session”) + “:1234567”
    sessionx = input.session(“1415-1550″, title=”Exit Trades after this”) + “:1234567”
    inSess = in_session(session)
    inSessx = in_session(sessionx)
    bgcolor(inSess ? color.new(color.orange, 90) : na)
    start = inSess and not inSess[1]
    h = ta.valuewhen(start, high[0], 0)
    l = ta.valuewhen(start, low[0], 0)
    r = h – l
    e = input(2.0, title=’Entry Points’)
    sl = input(2.0, title=’SL Points’)
    plot(inSess ? h + e : na, color=color.orange, style=plot.style_linebr)
    plot(inSess ? l – e : na, color=color.orange, style=plot.style_linebr)
    sl_long = (h + e) – (r + sl)
    sl_short = (l – e) + (r + sl)
    tp = input.float(2.0, title=”Take Profit R:R”, minval=0, step=0.1)
    tp_long = (h + e) + math.abs((h + e) – sl_long) * tp
    tp_short = (l – e) – math.abs((l – e) – sl_short) * tp
    // Calculate the 1% profit threshold
    initial_risk = math.abs(h – (h + e))  // Initial risk for a long trade
    profit_threshold = initial_risk * 1.01  // 1% profit threshold
    // NEWDAY
    is_newbar(res) =>
        t = time(res)
        not na(t) and (na(t[1]) or t > t[1])
    newDay = is_newbar(“D”)
    newTrade = ta.change(strategy.closedtrades) > 0
    newWin = ta.change(strategy.wintrades) > 0
    trades_per_day = 0
    trades_per_day := newDay ? 0 : newTrade ? trades_per_day[1] + 1 : trades_per_day[1]
    wins_per_day = 0
    wins_per_day := newDay ? 0 : newWin ? wins_per_day[1] + 1 : wins_per_day[1]
    // Strategy Backtest Limiting Algorithm
    i_startTime = input.time(defval=timestamp(“01 Sep 2002 13:30 +0000″), title=”Backtesting Start Time”)
    i_endTime = input.time(defval=timestamp(“30 Sep 2099 19:30 +0000″), title=”Backtesting End Time”)
    timeCond = (time > i_startTime) and (time < i_endTime)
    equity = strategy.initial_capital + strategy.netprofit
    if inSess and equity > 0 and timeCond and strategy.opentrades == 0 and trades_per_day < 4
        strategy.entry(“long”, strategy.long, comment=’Long’, stop=h + e)
        strategy.exit(“SL/TPL”, from_entry=”long”, stop=sl_long, limit=tp_long, comment_profit=’TP’, comment_loss=’SL’)
        if (close >= (h + e) + profit_threshold)
            strategy.exit(“Move SL to BE”, from_entry=”long”, stop=h + e)
    if strategy.position_size > 0 and strategy.position_size[1] <= 0
        line.new(bar_index – 1, sl_long, bar_index + 2, sl_long, color=color.red)
    if inSess and equity > 0 and timeCond and strategy.opentrades == 0 and wins_per_day == 0
        strategy.entry(“short”, strategy.short, comment=’Short’, stop=l – e)
        strategy.exit(“SL/TPS”, from_entry=”short”, stop=sl_short, limit=tp_short, comment_profit=’TP’, comment_loss=’SL’)
        if (close <= (l – e) – profit_threshold)
            strategy.exit(“Move SL to BE”, from_entry=”short”, stop=l – e)
    if not inSess or trades_per_day == 4 or wins_per_day > 0 or equity < 0
        strategy.cancel(“long”)
        strategy.cancel(“short”)
        if not inSessx
            strategy.close_all(comment=’Exit’)
    pinescript.txt
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Conversion of strategy tester from pinescript T.view


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 1 voice and has 0 replies.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/18/2023
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...