Coding of treading view stratge

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #241433 quote
    Fahad
    Participant
    New

    Hi,

    Appreacte your support to coding the below strategy:

     

     

     

    SOURCE = input(hlc3)
    RSILENGTH = input(14, title = “RSI LENGTH”)
    RSICENTERLINE = input(52, title = “RSI CENTER LINE”)
    MACDFASTLENGTH = input(7, title = “MACD FAST LENGTH”)
    MACDSLOWLENGTH = input(12, title = “MACD SLOW LENGTH”)
    MACDSIGNALSMOOTHING = input(12, title = “MACD SIGNAL SMOOTHING”)
    a = input(10, title = “Key Vaule. ‘This changes the sensitivity'”)
    SmoothK = input(3)
    SmoothD = input(3)
    LengthRSI = input(14)
    LengthStoch = input(14)
    RSISource = input(close)
    c = input(10, title=”ATR Period”)
    xATR = atr(c)
    nLoss = a * xATR
    xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close – nLoss),
    iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
    iff(close > nz(xATRTrailingStop[1], 0), close – nLoss, close + nLoss)))
    pos = iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
    iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
    color = pos == -1 ? red: pos == 1 ? green : blue
    ema= ema(close,1)
    above = crossover(ema,xATRTrailingStop )
    below = crossover(xATRTrailingStop,ema)
    buy = close > xATRTrailingStop and above
    sell = close < xATRTrailingStop and below
    barbuy = close > xATRTrailingStop
    barsell = close < xATRTrailingStop
    plotshape(buy, title = “Buy”, text = ‘Buy’, style = shape.labelup, location = location.belowbar, color= green,textcolor = white, transp = 0, size = size.tiny)
    plotshape(sell, title = “Sell”, text = ‘Sell’, style = shape.labeldown, location = location.abovebar, color= red,textcolor = white, transp = 0, size = size.tiny)
    barcolor(barbuy? green:na)
    barcolor(barsell? red:na)
    //alertcondition(buy, title=’Buy’, message=’Buy’)
    //alertcondition(sell, title=’Sell’, message=’Sell’)

    if (buy)
    strategy.entry(“UTBotBuy”,strategy.long, when=testPeriod)
    if (sell)
    strategy.entry(“UTBotSell”,strategy.short, when=testPeriod)

    #241465 quote
    Iván González
    Moderator
    Legend

    Hi!
    Could you please share the complete code and screenshots? thanks

    #241489 quote
    Fahad
    Participant
    New

    Below , Thanks

     

    //@version=2
    strategy(title=”UTBot Strategy”, overlay = true, initial_capital = 300, pyramiding = 100, calc_on_order_fills = false, calc_on_every_tick = false,
    default_qty_type = strategy.cash, default_qty_value = 1000, commission_value = 0.075)

    // CREDITS to @HPotter for the orginal code.
    // CREDITS to @Yo_adriiiiaan for recently publishing the UT Bot study based on the original code –
    // CREDITS to @TradersAITradingPlans for making this Strategy.
    // Strategy fixed with Time period by Kirk65.
    // I am using this UT bot with 2 hours time frame with god resultss. Alert with “Once per bar” and stoploss 1.5%. If Alerts triggered and price goes against Alert. Stoploss will catch it. Wait until next Alert.
    // While @Yo_adriiiiaan mentions it works best on a 4-hour timeframe or above, witch is a lot less risky, but less profitable.

    testStartYear = input(2019, “BACKTEST START YEAR”, minval = 1980, maxval = 2222)
    testStartMonth = input(01, “BACKTEST START MONTH”, minval = 1, maxval = 12)
    testStartDay = input(01, “BACKTEST START DAY”, minval = 1, maxval = 31)
    testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
    testStopYear = input(2222, “BACKTEST STOP YEAR”, minval=1980, maxval = 2222)
    testStopMonth = input(12, “BACKTEST STOP MONTH”, minval=1, maxval=12)
    testStopDay = input(31, “BACKTEST STOP DAY”, minval=1, maxval=31)
    testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)

    testPeriod = time >= testPeriodStart and time <= testPeriodStop ? true : false

    SOURCE = input(hlc3)
    RSILENGTH = input(14, title = “RSI LENGTH”)
    RSICENTERLINE = input(52, title = “RSI CENTER LINE”)
    MACDFASTLENGTH = input(7, title = “MACD FAST LENGTH”)
    MACDSLOWLENGTH = input(12, title = “MACD SLOW LENGTH”)
    MACDSIGNALSMOOTHING = input(12, title = “MACD SIGNAL SMOOTHING”)
    a = input(10, title = “Key Vaule. ‘This changes the sensitivity'”)
    SmoothK = input(3)
    SmoothD = input(3)
    LengthRSI = input(14)
    LengthStoch = input(14)
    RSISource = input(close)
    c = input(10, title=”ATR Period”)
    xATR = atr(c)
    nLoss = a * xATR
    xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close – nLoss),
    iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
    iff(close > nz(xATRTrailingStop[1], 0), close – nLoss, close + nLoss)))
    pos = iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1,
    iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
    color = pos == -1 ? red: pos == 1 ? green : blue
    ema= ema(close,1)
    above = crossover(ema,xATRTrailingStop )
    below = crossover(xATRTrailingStop,ema)
    buy = close > xATRTrailingStop and above
    sell = close < xATRTrailingStop and below
    barbuy = close > xATRTrailingStop
    barsell = close < xATRTrailingStop
    plotshape(buy, title = “Buy”, text = ‘Buy’, style = shape.labelup, location = location.belowbar, color= green,textcolor = white, transp = 0, size = size.tiny)
    plotshape(sell, title = “Sell”, text = ‘Sell’, style = shape.labeldown, location = location.abovebar, color= red,textcolor = white, transp = 0, size = size.tiny)
    barcolor(barbuy? green:na)
    barcolor(barsell? red:na)
    //alertcondition(buy, title=’Buy’, message=’Buy’)
    //alertcondition(sell, title=’Sell’, message=’Sell’)

    if (buy)
    strategy.entry(“UTBotBuy”,strategy.long, when=testPeriod)
    if (sell)
    strategy.entry(“UTBotSell”,strategy.short, when=testPeriod)

    #241494 quote
    Iván González
    Moderator
    Legend

    Hi. Here you have the indicator:

    //-----------------------------------------------//
    //PRC_UTBot trailingStop
    //version = 0
    //17.12.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-----------------------------------------------//
    //Inputs
    //-----------------------------------------------//
    a=10 //
    c=10 //atr period
    p=1 //ema period
    colorCandle=0
    //-----------------------------------------------//
    //Exponential moving average
    //-----------------------------------------------//
    ema=average[p,1](close)
    //-----------------------------------------------//
    //Average True Range
    //-----------------------------------------------//
    atr=averagetruerange[c](close)
    nLoss=a*atr
    //-----------------------------------------------//
    //Trailing Stop
    //-----------------------------------------------//
    once trailingStop=close
    if close>trailingStop[1] and close[1]>trailingStop[1] then
    trailingStop=max(trailingStop,close-nLoss)
    elsif close<trailingStop[1] and close[1]<trailingStop[1] then
    trailingStop=min(trailingStop,close+nLoss)
    elsif close>trailingStop[1] then
    trailingStop=close-nLoss
    else
    trailingStop=close+nLoss
    endif
    //-----------------------------------------------//
    //Plot Signals
    //-----------------------------------------------//
    above=ema crosses over trailingStop
    below=ema crosses under trailingStop
    
    if close>trailingStop and above then
    drawarrowup(barindex,low-atr)coloured("green")
    elsif close<trailingStop and below then
    drawarrowdown(barindex,high+atr)coloured("red")
    endif
    //-----------------------------------------------//
    //Color Candles and trailStop
    //-----------------------------------------------//
    if close>trailingStop then
    if colorCandle then
    drawcandle(open,high,low,close)coloured("green")
    endif
    r=0
    g=255
    b=0
    else
    if colorCandle then
    drawcandle(open,high,low,close)coloured("red")
    endif
    r=255
    g=0
    b=0
    endif
    //-----------------------------------------------//
    return trailingStop coloured(r,g,b)style(point)

    And the strategy:

    //-----------------------------------------------//
    //PRC_UTBot trailingStop
    //version = 0
    //17.12.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-----------------------------------------------//
    //Inputs
    //-----------------------------------------------//
    a=10 //
    c=10 //atr period
    p=1 //ema period
    //-----------------------------------------------//
    //Exponential moving average
    //-----------------------------------------------//
    ema=average[p,1](close)
    //-----------------------------------------------//
    //Average True Range
    //-----------------------------------------------//
    atr=averagetruerange[c](close)
    nLoss=a*atr
    //-----------------------------------------------//
    //Trailing Stop
    //-----------------------------------------------//
    once trailingStop=close
    if close>trailingStop[1] and close[1]>trailingStop[1] then
    trailingStop=max(trailingStop,close-nLoss)
    elsif close<trailingStop[1] and close[1]<trailingStop[1] then
    trailingStop=min(trailingStop,close+nLoss)
    elsif close>trailingStop[1] then
    trailingStop=close-nLoss
    else
    trailingStop=close+nLoss
    endif
    //-----------------------------------------------//
    //Plot Signals
    //-----------------------------------------------//
    above=ema crosses over trailingStop
    below=ema crosses under trailingStop
    
    if close>trailingStop and above then
    buy 1 contract at market
    elsif close<trailingStop and below then
    sellshort 1 contract at market
    endif
    //-----------------------------------------------//
    //Color Candles and trailStop
    //-----------------------------------------------//
    if close>trailingStop then
    r=0
    g=255
    b=0
    else
    r=255
    g=0
    b=0
    endif
    //-----------------------------------------------//
    graphonprice trailingStop coloured(r,g,b)
    #241929 quote
    Fahad
    Participant
    New

    Thanks , Appreciate it

Viewing 5 posts - 1 through 5 (of 5 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

Coding of treading view stratge


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Fahad @doo23559 Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Fahad
1 year, 8 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/15/2024
Status: Active
Attachments: No files
Logo Logo
Loading...