Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

Need help with a simple crossover-Strategy

Apr 28, 2023 - 7:35 PM

Viewed 506 times

https://best-trading-indicator.com/community/bti/forums/3953/topics/1685874 COPY
  • Did you get a solution?

    0
  • Hi,

    I'm Dan, new to TradingView and new to coding, so I need your help right away. ;-)

    I started building a strategy that basically consists of a publicly available indicator and a strategy:
    • FLD's - Future Lines of Demarcation by HPotter
    • Bollinger Bands Strategy

    Aim of the strategy:

    • in addition to the standard candlestick price trend in Tradingview, the price trend is to be shifted to the right by a variably adjustable number of time units (default = 40) with the help of the FLD indicator as an orange line.
    • Above and below this FLD line, a Bollinger Band with a variably adjustable standard deviation (default = 1.05) is to be shown - based on the FLD line and not on the SMA (20). (However, the SMS can remain in the script; I can set it to 1).
    • The strategy should: a. generate a buy signal when the actual price (src and not FLD) has crossed the upper Bollinger Band from bottom to top, and b. generate a sell signal when the actual price has crossed the lower Bollinger band from top to bottom.
    • The purpose of the Bollinger band is to reduce the number of (false) signals.
    • The buy and sell signals should be indicated with green and red labels respectively.

    By and large, the script stands, but it does not deliver any signals (Caution! This strategy did not generate any orders throughout the testing range.), although I think the Nasdaq-100 (NDX) should provide enough signals.

    Here is my current draft of the script:


    //@version=5
    strategy(title='FLD with Bollinger Bands', overlay=true)
    src = input(title='Source', defval=hlcc4)
    FLD = src
    Period = input(title='Offset FLD', defval=40)
    offset = Period
    length = input.int(title=SMA BB, minval=1, defval=20)
    mult = input.float(title=StDev BB, minval=0.001, maxval=10, defval=1.05)
    //reverse = input(false, title='Trade reverse') //(Probably not needed.)
    //basis = ta.sma(FLD, length) //(This code generates signals, but wrong ones.)
    dev = mult * ta.stdev(src, length)
    //upper = basis + dev //(This code generates signals, but wrong ones.)
    upper = FLD + dev
    //lower = basis - dev //(This code generates signals, but wrong ones.)
    lower = FLD - dev

    // Entry und Exit
    buyEntry = ta.crossover(src, upper)
    sellEntry = ta.crossunder(src, lower)
    if (buyEntry)
    strategy.entry(buyEntry, strategy.long, comment=buy)
    else
    strategy.cancel(id=buyEntry)
    if (sellEntry)
    strategy.entry(sellEntry, strategy.short, comment=sell)
    else
    strategy.cancel(id=sellEntry)

    // Plotting
    p1 = plot(upper, Upper, color=#2962FF, offset = offset)
    p2 = plot(lower, Lower, color=#2962FF, offset = offset)
    fill(p1, p2, title = Background, color=color.rgb(33, 150, 243, 95))
    plot(FLD, title=FLD, color=color.new(color.orange, 10), linewidth=1, style=plot.style_line, offset = Period)
    //plotshape(buyEntry, title='buyEntry', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), text='Buy', textcolor=color.new(color.black, 0), size=size.tiny)
    //plotshape(sellEntry, title='sellEntry', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), text='Sell', textcolor=color.new(color.black, 0), size=size.tiny)


    May I ask you to check the script and hopefully correct it?

    Thank you in advance for your help!

    0
CONTENTS