Conversion of TradingView strategy to PRT Indicator and screener

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #205852 quote
    iambostoniamboston
    Participant
    Average
    Hey there PRT team, I’m hoping for some assistance with converting the daily  High/Low strategy in Tradingview, to an indicator (with buy/sell signals) + screener for Pro Real Time. I’ve made a few attempts and failed miserably, so any assistance would be amazing!  
    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © exlux99
    
    //@version=5
    
    strategy(title='Daily HIGH/LOW strategy', overlay=true, initial_capital=10000, calc_on_every_tick=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
    
    ////////////////////////////GENERAL INPUTS//////////////////////////////////////
    len = input.int(24, minval=1, title='Length MA', group='Optimization paramters')
    src = input.source(close, title='Source MA', group='Optimization paramters')
    out = ta.ema(src, len)
    
    length = input.int(20, minval=1, title='CMF Length', group='Optimization paramters')
    ad = close == high and close == low or high == low ? 0 : (2 * close - low - high) / (high - low) * volume
    mf = math.sum(ad, length) / math.sum(volume, length)
    
    f_secureSecurity(_symbol, _res, _src) =>
        request.security(_symbol, _res, _src[1], lookahead=barmerge.lookahead_on)
    
    pricehigh = f_secureSecurity(syminfo.tickerid, 'D', high)
    pricelow = f_secureSecurity(syminfo.tickerid, 'D', low)
    
    plot(pricehigh, title='Previous Daily High', style=plot.style_linebr, linewidth=2, color=color.new(color.white, 0))
    plot(pricelow, title='Previous Daily Low', style=plot.style_linebr, linewidth=2, color=color.new(color.white, 0))
    
    short = ta.crossunder(low, pricelow) and close < out and mf < 0
    long = ta.crossover(high, pricehigh) and close > out and mf > 0
    
    
    if short and barstate.isconfirmed
        strategy.entry('short', strategy.short, when=barstate.isconfirmed, stop=pricelow[1])
        strategy.close('short', when=close > out)
    
    if long and barstate.isconfirmed
        strategy.entry('long', strategy.long, when=barstate.isconfirmed, stop=pricehigh[1])
        strategy.close('long', when=close < out)
    
    
    
    Screenshot-2022-12-16-112959.png Screenshot-2022-12-16-112959.png
    #205910 quote
    JSJS
    Participant
    Master
    Hi @iamboston The basis of the system is: High > DHigh(1) Low EMA[24](Close) for LONG Close 0 for LONG CMF < 0 for SHORT The exit of the trades is done with: Close Crosses Under EMA[24](Close) (Sell) Close Crosses About EMA[24](Close) (ExitShort)
    DefParam CumulateOrders=False
    
    EMAPeriod=24 //Period of EMA
    S1=ExponentialAverage[EMAPeriod](Close) //EMA signal
    
    CMFPeriod=20 //Period of Chaikin Money Flow
    MFM = ((Close-Low)-(High-Close)) / (High-Low) //Money Flow Multiplier
    MFV = MFM * Volume //Money Flow Volume
    CMF = Summation[CMFPeriod](MFV) / Summation[CMFPeriod-1](Volume) //Chaikin Money Flow
    
    //LONG
    If High Crosses Over DHigh(1) and Close > S1 and CMF > 0 then
    Buy 1 contract at Market
    EndIf
    //Exit LONG
    If Close Crosses Under S1 then
    Sell at Market
    EndIf
    
    //SHORT
    If Low Crosses Under DLow(1) and Close < S1 and CMF < 0 then
    SellShort 1 contract at Market
    EndIf
    //Exit SHORT
    If Close Crosses Over S1 then
    ExitShort at Market
    EndIf
    
    iamboston and robertogozzi thanked this post
    Scherm­afbeelding-2022-12-16-om-14.50.43.png Scherm­afbeelding-2022-12-16-om-14.50.43.png
    #205938 quote
    iambostoniamboston
    Participant
    Average
    Thank you kindly, JS for the explanation and coded translation. Much appreciated.
    JS thanked this post
    #205994 quote
    phoentzsphoentzs
    Participant
    Master
    I’m surprised. For a breakout system it works quite well. At least long, also on Nasdaq or SP500. But then with EMA45. Short would also work, but then with a different exit strategy. The long candles, which should cause the exit in short mode, are usually simply too long in the time unit. Short would need another exit.
    #206006 quote
    iambostoniamboston
    Participant
    Average
    Agreed, I use it manually with a discretionary exit.
    #206009 quote
    iambostoniamboston
    Participant
    Average
    Hi there JS, Hope you had a great weekend. Would it be possible to have the indicator that you created for the system, too? From there I’ll have a go at creating a screener, too. Hope all’s well and thank you again!
    #206014 quote
    JSJS
    Participant
    Master

    Hi @iamboston

    It is a simple indicator, for the CMF you can use the standard indicator from PRT…

     
    EMAPeriod=24 //Period of EMA
    S1=ExponentialAverage[EMAPeriod](Close) //EMA signal
    
    DH=DHigh(1)//Previous Daily High
    DL=DLow(1)//Previous Daily Low
    
    Return DH as "Daily High" Coloured(255,0,0), DL as "Daily Low" Coloured(0,255,0), S1 as "EMA24" Coloured(255,255,0) Style(DottedLine)
    robertogozzi thanked this post
    Scherm­afbeelding-2022-12-19-om-00.39.51.png Scherm­afbeelding-2022-12-19-om-00.39.51.png
    #206110 quote
    JSJS
    Participant
    Master
    Hi @iamboston To complete the trio 😉 hereby the screener… Hope you have fun with it. Regards Jaap
    EMAPeriod=24 //Period of EMA
    S1=ExponentialAverage[EMAPeriod](Close) //EMA signal
    
    CMFPeriod=20 //Period of Chaikin Money Flow
    MFM=((Close-Low)-(High-Close)) / (High-Low) //Money Flow Multiplier
    MFV=MFM * Volume //Money Flow Volume
    CMF=Summation[CMFPeriod](MFV) / Summation[CMFPeriod](Volume)
    
    C1 = High Crosses Over DHigh(1) and Close > S1 and CMF > 0
    C2 = Low Crosses Under DLow(1) and Close < S1 and CMF < 0
    
    If C1 then
    Result=1
    EndIf
    
    If C2 then
    Result=2
    EndIf
    
    Screener[Result](Result as "1=LONG 2=SHORT")
    
    robertogozzi thanked this post
    #206111 quote
    iambostoniamboston
    Participant
    Average
    G’day Jaap, really appreciate you taking the time to help with this, thank you! Cheers, Bos
Viewing 9 posts - 1 through 9 (of 9 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 TradingView strategy to PRT Indicator and screener


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
iamboston @iamboston Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by iambostoniamboston
3 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/16/2022
Status: Active
Attachments: 3 files
ProRealCode ProRealCode
Loading...