-3
//@version=5
// Step 1. Script settings
indicator(title="Donchian Channel", overlay=true)

// Channel settings
dcLen = input.int(96, title="Channel Length", minval=2)

// Visual settings
showMid = input.bool(false, title="Show Midpoint Line?")
fillDc  = input.bool(false, title="Fill Donchian Channel?")

// Signal settings
brkOutFilter = input.int(0, title="Breakout Filter (Ticks)", minval=0) * 
     syminfo.mintick

showBreakouts = input.bool(true, title="Highlight Breakouts?")

// Step 2. Calculate indicator values
hiHighs = ta.highest(high, dcLen)[1]
loLows  = ta.lowest(low, dcLen)[1]

midPoint = (hiHighs + loLows) / 2

// Step 3. Determine indicator signals
// See if prices crossed above/below Donchian Channel
upBrkOut = barstate.isconfirmed and 
     ta.crossover(close, hiHighs + brkOutFilter)

downBrkOut = barstate.isconfirmed and 
     ta.crossunder(close, loLows - brkOutFilter)

// Step 4. Output indicator data
// Plot Donchian Channel
ub = plot(hiHighs, color=color.green, title="DoCh UB")
lb = plot(loLows, color=color.red, title="DoCh LB")

// Fill background between Donchian bands
fill(plot1=ub, plot2=lb, color=fillDc ? color.new(#4169e1, 95) : 
     color.new(color.white, 100))

// Show midpoint line, when enabled
plot(showMid ? midPoint : na, color=color.orange, title="DoCh Mid")

// Highlight breakouts with a coloured background
highlightColour = not showBreakouts ? na :
     upBrkOut ? color.new(color.green, 80) :
     downBrkOut ? color.new(color.red, 80) :
     na

bgcolor(highlightColour)

// Step 5. Create indicator alerts
alertcondition(condition=upBrkOut,
     title="Long Entry",
     message="Price closed above Donchian Channel")

alertcondition(condition=downBrkOut,
     title="Short Entry",
     message="Price closed below Donchian Channel")

indicator("Larry Williams Large Trade Index (LWTI) [Loxx]",
     shorttitle="LWTI [Loxx]",
     overlay = false,
     timeframe="",
     timeframe_gaps = true)


greencolor = #2DD204
redcolor = #D2042D


variant(type, src, len) =>
    sig = 0.0
    if type == "SMA"
        sig := ta.sma(src, len)
    else if type == "EMA"
        sig := ta.ema(src, len)
    else if type == "WMA"
        sig := ta.wma(src, len)  
    else if type == "RMA"
        sig := ta.rma(src, len)  
    sig
   
per = input.int(8, "Period", group = "Basic Settings")
smthit = input.bool(false, "Smooth LWPI?", group = "Basic Settings")
type = input.string("SMA", "Smoothing Type", options = ["EMA", "WMA", "RMA", "SMA"], group = "BasicR Settings")
smthper = input.int(5, "Smoothing Period", group = "Basic Settings")


colorbars = input.bool(false, "Color bars?", group = "UI Options")
showsignals = input.bool(false, "Show signals?", group = "UI Options")


ma = ta.sma(close - nz(close[per]), per)
atr = ta.atr(per)
out = ma/atr * 50 + 50
out := smthit ? variant(type, out, smthper) : out


colorout = out > 50 ? greencolor : redcolor
plot(out, color = colorout, linewidth = 2)
barcolor(colorbars ? colorout : na)


middle = 50


plot(middle, color = bar_index % 2 ? color.gray : na)


goLong = ta.crossover(out, middle)
goShort = ta.crossunder(out, middle)


plotshape(goLong and showsignals, title = "Long", color = greencolor, textcolor = greencolor, text = "L", style = shape.triangleup, location = location.bottom, size = size.auto)
plotshape(goShort and showsignals, title = "Short", color = redcolor, textcolor = redcolor, text = "S", style = shape.triangledown, location = location.top, size = size.auto)


alertcondition(goLong, title="Long", message="Larry Williams Large Trade Index (LWTI) [Loxx]: Long\nSymbol: {{ticker}}\nPrice: {{close}}")
alertcondition(goShort, title="Short", message="Larry Williams Large Trade Index (LWTI) [Loxx]: Short\nSymbol: {{ticker}}\nPrice: {{close}}")

Hey I am developing a strategy that uses the Donchian Channels, the Larry Williams Large Trade Index (LWTI) and a volume indicator.

First setting up the indicators, Donchian Channels on 96 periods, the LWTI, 25 periods and 20 for the smoothing period, and volume to 30 periods with middle line plotted. What the strategy would do is for a long trade, first look if the bar has touched the upper band, if it does then Look at the LWTI and see if it is over 50 and lastly look if the volume is in positive, meaning in green, and it is above the middle line. If everything is set the trade would be set and the stop loss would be where the middle line is, and the take profit would be in a 2:1 ratio. For the short would be, first look if the bar has touched the down band, if it does then Look at the LWTI and see if it is under 50 and lastly look if the volume is in negative, meaning in red, and it is above the middle line. If everything is set the trade would be set and the stop loss would be where the middle line is, and the take profit would be in a 2:1 ratio. I am stuck with the Pine Editor if someone can help woul be awesome.

  • 1
    This site is for **specific questions** related to programming (code) or use of a programmer's tool (IDE, compiler, etc.). *I am stuck with the Pine Editor* is not a question at all, and is clearly not specific in any way. If you want help, you're going to have to clearly explain the actual problem you're having and ask a ***specific*** question that can be answered. For suggestions on writing a good question, see [ask] and the [help]. – Ken White Aug 29 '23 at 23:18
  • Are you using chatGPT? Due to such poor accuracy Stackoverflow has [banned ChatGPT](https://meta.stackoverflow.com/questions/421831/temporary-policy-chatgpt-is-banned). TradingView has also decided [not to provide support](http://tradingview.com/chart/TRAIA/XwwZ70ar-Our-take-on-AI-generated-Pine-Script/) for ChatGPT. – Gu5tavo71 Aug 30 '23 at 13:27

0 Answers0