5m UStech 100 strategy

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #215978 quote
    richmoore123
    Participant
    New

    This is a long only strategy for the 5m US tech 100 . Works well with c.2.5 profit factor.

    I am not a coder so would appreciate if someone could put this in ProRealTime code for me .

    
    //Disbale Signal Repainting
    disableRepainting = input.bool(defval = true, title = "Disable Signal Repainting", group = "Repainting Settings")
    
    
    ////Session Settings Inputs
    useSession = input.bool(defval = true, title = "Use Session", group = "Session Settings")
    closeEverything = input.bool(defval = true, title = "Close all orders/positions if session ends", group = "Session Settings")
    customTimeZone = input.string(defval = "America/New_York", title = "Custom Time Zone", group = "Session Settings", inline = "a1")
    useCustomTimeZone = input.bool(defval = true, title = "On/Off", group = "Session Settings", inline = "a1")
    timeSession = input.session(defval = "0940-1605", title = "Session Time",  group = "Session Settings", tooltip = "Use the checkboxes to select " + 
         "on which days of the week this session is active. The session " +
         "has to be active on at least one day.")
    monSession = input.bool(true, title="Mon ", group = "Session Settings", inline="d1")
    tueSession = input.bool(true, title="Tue ", group = "Session Settings", inline="d1")
    wedSession = input.bool(true, title="Wed ", group = "Session Settings", inline="d1")
    thuSession = input.bool(true, title="Thu ", group = "Session Settings", inline="d1")
    friSession = input.bool(true, title="Fri   ", group = "Session Settings", inline="d2")
    satSession = input.bool(false, title="Sat  ", group = "Session Settings", inline="d2")
    sunSession = input.bool(false, title="Sun ", group = "Session Settings", inline="d2")
    
    
    // Custom Time Zone Logic
    timeZone = useCustomTimeZone ? customTimeZone : syminfo.timezone
    
    
    // Make a days of week string based on the value of the checkboxes
    sessionDays = ""
    
    if sunSession
        sessionDays += "1"
    if monSession
        sessionDays += "2"
    if tueSession
        sessionDays += "3"
    if wedSession
        sessionDays += "4"
    if thuSession
        sessionDays += "5"
    if friSession
        sessionDays += "6"
    if satSession
        sessionDays += "7"
    
    // Make the session string by joining the time with the days
    tradingSession = timeSession + ":" + sessionDays
    
    //Session Logic
    t = time(timeframe.period, tradingSession, timeZone)
    inSession = not na(t) and useSession
    outSession = na(t) and useSession
    bgcolor(inSession ? color.new(color.green, transp = 95) : na)
    
    
    
    ////VWAP indicator
    
    //VWAP Inputs
    vwapSource = input.source(defval = close, title = "VWAP Source", group = "VWAP Settings")
    
    //Calculate Indicator
    vwap = ta.vwap(vwapSource)
    
    
    
    ////EMA Indicator
    
    //EMA Inputs
    emaLength = input.int(defval = 555, title = "EMA Lenght", group = "EMA Settings")
    emaSource = input.source(defval = close, title = "EMA Source", group = "EMA Settings")
    
    //Calculate Indicator
    ema = ta.ema(emaSource, emaLength)
    
    
    ////BB Indicator
    
    //BB Inputs
    bbSource = input.source(defval = close, title = "BBands Source", group = "Bollinger Bands Settings")
    
    bbLength1 = input.int(defval = 20, title = "BBands Lenght 1", minval = 1, group = "BBands 1")
    devUp1 =  input.float(defval = 2, title = "BBands DevUp 1", minval = 1, step = 0.1, group = "BBands 1")
    devDn1 = input.float(defval = 2, title = "BBands DevDown 1", minval = 1, step = 0.1, group = "BBands 1")
    
    bbLength2 = input.int(defval = 10, title = "BBands Lenght 2", minval = 1, group = "BBands 2")
    devUp2 =  input.float(defval = 1.2, title = "BBands DevUp 2", minval = 1, step = 0.1, group = "BBands 2")
    devDn2 = input.float(defval = 1.2, title = "BBands DevDown 2", minval = 1, step = 0.1, group = "BBands 2") 
    
    
    /////////Additional MA
    
    // TEMA
    tema(src, length) =>
        v2 = ta.ema(src, length)
        v = 3 * (v2 - ta.ema(v2, length)) + ta.ema(ta.ema(v2, length), length)  // Triple Exponential
        v
    
    
    // KAMA
    kama(src, length) =>
        k = 0.0
        volatility = math.sum(math.abs(src-src[1]), length)
        change = math.abs(src-src[length-1])
        er = volatility != 0 ? change/volatility : 0
        sc = math.pow((er*(0.666666-0.064516))+0.064516, 2)
        k := nz(k[1])+(sc*(hl2-nz(k[1])))
        k
    
    
    // TRIMA
    trima(src, length) =>
        trima = ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)
        trima
    
    
    //DEMA
    dema(src, length) =>
        e1 = ta.ema(src, length)
        e2 = ta.ema(e1, length)
        dema = 2 * e1 - e2
        dema
    
    
    //MA Switcher
    maType =  input.string(defval = "SMA", title = "BBands MA Type", options = ["EMA", "SMA", "VWMA", "WMA", "TRIMA", "HMA", "KAMA", "TEMA", "DEMA"], group = "Bollinger Bands Settings") 
    
    getMA(src, length) =>
        ma = float(na)
    
        if maType == "EMA"
            ma := ta.ema(src, length)
    
        if maType == "SMA"
            ma := ta.sma(src, length)
    
        if maType == "VWMA"
            ma := ta.vwma(src, length)
    
        if maType == "WMA"
            ma := ta.wma(src, length)
        
        if maType == "TRIMA"
            ma := trima(src, length)
        
        if maType == "HMA"
            ma := ta.hma(src, length)
        
        if maType == "KAMA"
            ma := kama(src, length)
    
        if maType == "T3"
            ma := tema(src, length)
    
        if maType == "DEMA"
            ma := dema(src, length)
        
        ma
    
    
    //Calculate BB Indicator
    
    middleLine1 = getMA(bbSource, bbLength1)
    upperBand1 = (middleLine1 + (devUp1 * (ta.stdev(bbSource, bbLength1))))
    lowerBand1 = (middleLine1 - (devDn1 * (ta.stdev(bbSource, bbLength1))))
    
    
    middleLine2 = getMA(bbSource, bbLength2)
    upperBand2 = (middleLine2 + (devUp2 * (ta.stdev(bbSource, bbLength2))))
    lowerBand2 = (middleLine2 - (devDn2 * (ta.stdev(bbSource, bbLength2))))
    
    
    upperBandDifference = upperBand1 - upperBand2
    maxDifference = 100
    ratio = 100 - (100 * (upperBandDifference / maxDifference))
    
    
    
    ////Condition Logic
    VWAP_condition = vwapSource > vwap
    EMA_condition = emaSource > ema
    above95 = ratio > 89
    closeAboveBothUpperBands = bbSource > upperBand1 and bbSource > upperBand2
    
    
    entryCondition = above95 and VWAP_condition and EMA_condition and closeAboveBothUpperBands
    exitConditionRegular = (upperBand2 - bbSource) / bbSource > 0.006
    
    
    //Define position direction
    isLong = strategy.position_size > 0
    isShort = strategy.position_size < 0
    noPosition = strategy.position_size == 0
    
    
    
    //Strategy Entries
    if entryCondition and (inSession or not useSession) and noPosition and (barstate.isconfirmed or not disableRepainting)
        strategy.entry("Long", strategy.long)
    if exitConditionRegular and (inSession or not useSession) and isLong and (barstate.isconfirmed or not disableRepainting)
        strategy.close("Long")
    
    
    if outSession and closeEverything
        strategy.cancel_all()
        strategy.close_all()
    #217574 quote
    ProRealAlgos
    Participant
    Junior

    This will not get you the whole way there, but I used ChatGPT with the prompt instructions from this ProRealCode thread here to convert it to ProRealTime code.
    https://www.prorealcode.com/topic/create-strategies-codes-with-chatgpt-for-prorealtime/

    You will with 100% certainty have to make some additional adjustments to make it work. However, I hope it got you a couple of steps forward.

    //Disbale Signal Repainting
    disableRepainting = true
     
    ////Session Settings Inputs
    useSession = true
    closeEverything = true
    customTimeZone = "America/New_York"
    useCustomTimeZone = true
    timeSession = "0940-1605"
    monSession = true
    tueSession = true
    wedSession = true
    thuSession = true
    friSession = true
    satSession = false
    sunSession = false
     
    // Custom Time Zone Logic
    timeZone = useCustomTimeZone ? customTimeZone : syminfo.timezone
     
    // Make a days of week string based on the value of the checkboxes
    sessionDays = ""
     
    if sunSession then
        sessionDays = sessionDays + "1"
    endif
    if monSession then
        sessionDays = sessionDays + "2"
    endif
    if tueSession then
        sessionDays = sessionDays + "3"
    endif
    if wedSession then
        sessionDays = sessionDays + "4"
    endif
    if thuSession then
        sessionDays = sessionDays + "5"
    endif
    if friSession then
        sessionDays = sessionDays + "6"
    endif
    if satSession then
        sessionDays = sessionDays + "7"
    endif
     
    // Make the session string by joining the time with the days
    tradingSession = timeSession + ":" + sessionDays
     
    //Session Logic
    t = timeframes(1, tradingSession, timeZone)
    inSession = not na(t) and useSession
    outSession = na(t) and useSession
    bgcolor(inSession, color.new(color.green, 95))
     
    ////VWAP indicator
    vwapSource = close
     
    //Calculate Indicator
    vwap = VWAP[vwapSource]
     
    ////EMA Indicator
    emaLength = 555
    emaSource = close
     
    //Calculate Indicator
    ema = EMA[emaSource, emaLength]
     
    ////BB Indicator
    bbSource = close
     
    bbLength1 = 20
    devUp1 = 2
    devDn1 = 2
     
    bbLength2 = 10
    devUp2 = 1.2
    devDn2 = 1.2
     
    /////////Additional MA
     
    // TEMA
    tema(src, length) =
        v2 = EMA[src, length]
        v = 3 * (v2 - EMA[v2, length]) + EMA[EMA[v2, length], length]  // Triple Exponential
        v
     
    // KAMA
    kama(src, length) =
        k = 0.0
        volatility = sum(abs(src-src[1]), length)
        change = abs(src-src[length-1])
        er = volatility <> 0 ? change/volatility : 0
        sc = pow((er*(0.666666-0.064516))+0.064516, 2)
        k = nz(k[1])+(sc*(hl2-nz(k[1])))
        k
     
    // TRIMA
    trima(src, length) =
        trima = SMA[SMA[src, ceil(length / 2)], floor(length / 2) + 1]
        trima
     
    //DEMA
    dema(src, length) =
        e1 = EMA[src, length]
        e2 = EMA[e1, length]
        dema = 2 * e1 - e2
        dema
     
    //MA Switcher
    maType = "SMA"
     
    getMA(src, length) =
        ma = 0.0
     
        if maType = "EMA" then
            ma = EMA[src, length]
     
        if maType = "SMA" then
            ma = SMA[src, length]
     
        if maType = "VWMA" then
            ma = VWMA[src, length]
     
        if maType = "WMA" then
            ma = WMA[src, length]
        
        if maType = "TRIMA" then
            ma = trima(src, length)
        
        if maType = "HMA" then
            ma = HMA[src, length]
        
        if maType = "KAMA" then
            ma = kama(src, length)
     
        if maType = "T3" then
            ma = tema(src, length)
     
        if maType = "DEMA" then
            ma = dema(src, length)
        
        ma
     
    //Calculate BB Indicator
    middleLine1 = getMA(bbSource, bbLength1)
    upperBand1 = middleLine1 + (devUp1 * (STDEV[bbSource, bbLength1]))
    lowerBand1 = middleLine1 - (devDn1 * (STDEV[bbSource, bbLength1]))
     
    middleLine2 = getMA(bbSource, bbLength2)
    upperBand2 = middleLine2 + (devUp2 * (STDEV[bbSource, bbLength2]))
    lowerBand2 = middleLine2 - (devDn2 * (STDEV[bbSource, bbLength2]))
     
    upperBandDifference = upperBand1 - upperBand2
    maxDifference = 100
    ratio = 100 - (100 * (upperBandDifference / maxDifference))
     
    ////Condition Logic
    VWAP_condition = vwapSource > vwap
    EMA_condition = emaSource > ema
    above95 = ratio > 89
    closeAboveBothUpperBands = bbSource > upperBand1 and bbSource > upperBand2
     
    entryCondition = above95 and VWAP_condition and EMA_condition and closeAboveBothUpperBands
    exitConditionRegular = (upperBand2 - bbSource) / bbSource > 0.006
     
    //Define position direction
    isLong = positionsize > 0
    isShort = positionsize < 0
    noPosition = positionsize = 0
     
    //Strategy Entries
    if entryCondition and (inSession or not useSession) and noPosition and (barnumber[1] > 0 or not disableRepainting) then
        buy at market
    endif
    if exitConditionRegular and (inSession or not useSession) and isLong and (barnumber[1] > 0 or not disableRepainting) then
        sell at market
    endif
     
    if outSession and closeEverything then
        set stop ploss 0
        sell at market
    endif
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

5m UStech 100 strategy


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by ProRealAlgos
2 years, 7 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/11/2023
Status: Active
Attachments: No files
Logo Logo
Loading...