#code #Bullish Engulfing and Bearish Engulfing #TradingView #PineScript #//@version=4…
- User
#code #Bullish Engulfing and Bearish Engulfing #TradingView #PineScript #//@version=4 #strategy() #color=color.red #Function Definitions
- Assistant
Here's a TradingView Pine Script that defines functions for Bullish Engulfing and Bearish Engulfing patterns and uses them in a strategy. This script will plot the patterns on the chart and execute a simple strategy based on them.
pinescript//@version=4 study("Engulfing Patterns Strategy", shorttitle="EP", overlay=true) // Function to check if the current bar is a bullish engulfing pattern bool isBullishEngulfing() => close > high[1] and close < low[1] and open < close[1] and close > high[1] // Function to check if the current bar is a bearish engulfing pattern bool isBearishEngulfing() => close < low[1] and close > high[1] and open > close[1] and close < low[1] // Plot bullish engulfing patterns on the chart plotshape(isBullishEngulfing(), title="Bullish Engulfing", style=shape.labelup, color=color.green, textcolor=color.white, text="BE", location=location.belowbar) // Plot bearish engulfing patterns on the chart plotshape(isBearishEngulfing(), title="Bearish Engulfing", style=shape.labeldown, color=color.red, textcolor=color.white, text="BE", location=location.abovebar) // Simple strategy: Buy on bullish engulfing and sell on bearish engulfing strategy("Engulfing Patterns Strategy", shorttitle="EP", overlay=false) // Buy signal on bullish engulfing if (isBullishEngulfing()) strategy.entry("Buy", strategy.long) // Sell signal on bearish engulfing if (isBearishEngulfing()) strategy.close("Buy")This script will:
- Plot Bullish Engulfing (BE) patterns with a green label below the bar.
- Plot Bearish Engulfing (BE) patterns with a red label above the bar.
- Generate a buy signal (long entry) when a Bullish Engulfing pattern is detected.
- Close any open long positions when a Bearish Engulfing pattern is detected.
- User
give me the full code with the follow conditions.
#//@version=4 #strategy() #color=color.red #Function Definitions
- Assistant
Here's the full Pine Script code with the given conditions and additional improvements, such as stop loss and take profit levels, and a simple moving average (SMA) filter to reduce false signals.
pinescript - User
. I adjusted the code above like this.
//@version=4 strategy("Bullish and Bearish Engulfing", overlay=true)
// Define the bullish and bearish engulfing patterns bool bullishEngulfing = close[1] < open[1] and close > open and close > open[1] and open <= close[1] bool bearishEngulfing = close[1] > open[1] and close < open and close < open[1] and close[1] <= open
// Plot the bullish and bearish signals on the chart plot(bullishEngulfing ? close : na, style=plot.style_circles, color=color.green, linewidth=10, title="Bullish Engulfing") plot(bearishEngulfing ? close : na, style=plot.style_circles, color=color.red, linewidth=10, title="Bearish Engulfing")
- I want arrow style not style=plot.style_circles
- Assistant
Sure, I can help you modify the code to use arrow style instead of circles. Here's the updated code:
pinescript//@version=4 strategy("Bullish and Bearish Engulfing", overlay=true) // Define the bullish and bearish engulfing patterns bool bullishEngulfing = close[1] < open[1] and close > open and close > open[1] and open <= close[1] bool bearishEngulfing = close[1] > open[1] and close < open and close < open[1] and close[1] <= open // Plot the bullish and bearish signals on the chart with arrow style plotshape(bullishEngulfing, style=shape.arrowup, location=location.belowbar, color=color.green, size=size.small, title="Bullish Engulfing") plotshape(bearishEngulfing, style=shape.arrowdown, location=location.abovebar, color=color.red, size=size.small, title="Bearish Engulfing")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.