PineScript indi

MPTM's new home
Post Reply
Nerozki
Posts: 1
Joined: Sun Mar 22, 2020 12:50 pm

PineScript indi

Post by Nerozki »

Hello everyone

This is my first post here on the Forum

I am not a coder or programmer nor have I a lot of expierence and English is not my first language so please excuse the grammar.

I have been working on a pinescript code for a little while that is slowly making progress and I hope that it could be something in the future that we can all use.

I am sure there is already indicators doing basicly the same thing.

In short it uses bollingerbands, Ema 180 and so on.

Code: Select all

//@version=5
strategy("Bollinger Bands Long and Short Strategy with Optional Regime Filter", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// Define the input parameters for moving average period and standard deviations
length = input(180, title="Moving Average Length")
stdDevUpper = input(3.0, title="Upper Bollinger Band Std Dev")
stdDevLower = input(1.0, title="Lower Bollinger Band Std Dev")
spxSymbol = input("SP:SPX", title="S&P 500 Symbol")
useRegimeFilter = input(true, title="Use S&P 500 Regime Filter")

// Calculate the Bollinger Bands
basis = ta.sma(close, length)
upperBand = basis + stdDevUpper * ta.stdev(close, length)
lowerBand = basis - stdDevLower * ta.stdev(close, length)

// Plot Bollinger Bands
plot(basis, color=color.blue, title="Central Moving Average", linewidth=2)
plot(upperBand, color=color.green, title="Upper Band")
plot(lowerBand, color=color.red, title="Lower Band")

// Regime Filter: S&P 500 above its 180-period moving average
spxPrice = request.security(spxSymbol, "D", close)
spxMovingAverage = ta.sma(spxPrice, length)
regimeFilter = spxPrice > spxMovingAverage

// Generate buy and sell signals with optional regime filter
longCondition = close < lowerBand and (regimeFilter or not useRegimeFilter)
exitLongCondition = close > upperBand

// Adjusted to ensure the entire candle is above the upper band
shortCondition = open > upperBand and close > upperBand and (regimeFilter or not useRegimeFilter)
exitShortCondition = close < lowerBand

// Execute trading orders based on conditions
if (longCondition)
    strategy.entry("Long", strategy.long)
if (exitLongCondition)
    strategy.close("Long")

if (shortCondition)
    strategy.entry("Short", strategy.short)
if (exitShortCondition)
    strategy.close("Short")


What I would like to add is the Super trend indi so that the buy and sell signals only occur below the lower band when the supertrend starts to indicate it is bullish, I would also like the signal only to print when there is a engulfing candle

so when these 3 criteria's are met

Price below lower BB
Super trend is below lower BB and signals up trend
A engulfing candle forms

and the exact opposite for Short positions

Again I am no professional traded I am no professional coder but i have been dabbling with trading for a little while now and Just a shoutout to all the creators of HGI you truly have something wonderful going on there.

I would like to add screenshots but it is not allowing me to



Thanks
Nerozki
Post Reply

Return to “Utilities Indicators and Scripts”