YSPSW

PHOTO EMBED

Sun Oct 08 2023 05:38:48 GMT+0000 (Coordinated Universal Time)

Saved by @Tonyfingh

//@version=4
strategy("Yuvis stock prediction system watch", shorttitle="YSPSW", overlay=true)

// Calculate the Bollinger Bands Length and Standard Deviation based on the chart's time frame
length = input(title="Length", defval=20, minval=1)
mult = input(title="Multiplier", defval=2.0, minval=0.1, maxval=10.0, step=0.1)

basis = sma(close, length)
dev = mult * stdev(close, length)
upper = basis + dev
lower = basis - dev

// Calculate Buy and Sell Conditions
buyCondition = crossover(close, lower)
sellCondition = crossunder(close, upper)

// Define the entry price and holding status
var float entryPrice = na
var bool holding = false

// Strategy Entry and Exit
if (buyCondition)
    if (holding == false) // Only enter if not already holding a position
        entryPrice := close
        strategy.entry("Buy", strategy.long)
        holding := true

if (sellCondition)
    if (holding)
        // Check if the current close is greater than or equal to the entry price
        if (close >= entryPrice)
            strategy.close("Buy") // Close long position
            holding := false
        // If the close is below the entry price, do nothing and continue holding

// Plot entry and exit signals on the chart for visualization
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
content_copyCOPY