// Constants - Reduced transparency to 60 for brighter colors
var color red_color = color.new(#ff0000, 0) // Brighter red
var color green_color = color.new(#00ff00, 0) // Brighter green (#00FF00 is more vibrant than #32CD32)
// Rest of the code remains the same...
method calc_ma(string type, float src, int length) =>
float sma = ta.sma(src, length)
float ema = ta.ema(src, length)
float rma = ta.rma(src, length)
float wma = ta.wma(src, length)
float vwma = ta.vwma(src, length)
code
float smma = na(sma[1]) ? sma : (sma[1] * (length - 1) + src) / length
float hullma = ta.wma(2 * ta.wma(src, length / 2) - ta.wma(src, length), math.round(math.sqrt(float(length))))
float tma = ta.sma(sma, length)
float dema_ema = ema
float dema = 2 * dema_ema - ta.ema(dema_ema, length)
float tema_ema1 = ema
float tema_ema2 = ta.ema(tema_ema1, length)
float tema_ema3 = ta.ema(tema_ema2, length)
float tema = 3 * (tema_ema1 - tema_ema2) + tema_ema3
result = switch type
"RMA" => rma
"SMA" => sma
"EMA" => ema
"WMA" => wma
"VWMA" => vwma
"SMMA" => smma
"HullMA" => hullma
"TMA" => tma
"DEMA" => dema
"TEMA" => tema
=> sma
result
// Color calculations
method get_color(float dist, float niv_prof, float src, float ma) =>
color col = na
if dist >= niv_prof
if src > ma
col := red_color
if src < ma
col := green_color
col
This is my tradingview indicator it shows green sign for buy and red sign for sell
make a version 6 trading strategy from this
BUY when 1) Indicator shows greenn line or box 2) you get a green candle closure .. then open long with a stoploss of recent low and take profit of RR3 and vice versa for shorts
give me options
to change how much $ i want to risk on trade
to change RR
Assistant
Here's a TradingView Strategy (Pine Script v6) version of your indicator logic, converted into a trading strategy that:
Enters long when:
The background is green (bg_color is green)
A green candle closes (close > open)
Enters short when:
The background is red
A red candle closes (close < open)
Features:
Stop Loss set to recent lowest low (for longs) or recent highest high (for shorts)
Take Profit based on Risk-Reward Ratio (RR) (default 3x)
Inputs:
Risk Amount – How much $ to risk per trade
Risk Reward Ratio – RR for Take Profit
Optional: Enable/Disable long/short trades
✅ Trading Strategy Code (Pine Script v6)
pinescript
//@version=6
strategy("Six AI Algo Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
// Input Settings
risk_amount = input.float(100, title="Risk Amount ($)", minval=0.01)
rr_ratio = input.float(3.0, title="Risk Reward Ratio", minval=0.1)
enable_long = input.bool(true, title="Enable Long Trades")
enable_short = input.bool(true, title="Enable Short Trades")
// Input variables for current timeframe
tf_c = input.bool(title="🔹 Current Timeframe 🔹", defval=true)
ma_type_c = input.string(title="Type of MA=", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "HullMA", "TMA", "DEMA", "TEMA"])
ma_len_c = input.int(defval=200, title="MA Length=", minval=1)
ma_src_c = input.source(close, title="MA Source=")
ma_dsl_c = input.float(defval=0.89, title="Depth Search Level", minval=0.0, step=0.01)
nopbtf_c = input.int(defval=200, title="Number Of Previous Bars To Find Depth", minval=1)
// Input variables for timeframe 1
tf_1 = input.bool(title="🔹 Timeframe 1 🔹", defval=true)
ma_type_1 = input.string(title="Type of MA Timeframe 1", defval="SMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "HullMA", "TMA", "DEMA", "TEMA"])
ma_len_1 = input.int(defval=200, title="MA Length Timeframe 1", minval=1)
ma_src_1 = input.source(close, title="MA Source Timeframe 1")
res1 = input.timeframe("2", title="Timeframe 1")
ma_dsl_1 = input.float(defval=0.89, title="Depth Search Level", minval=0.0, step=0.01)
nopbtf_1 = input.int(defval=200, title="Number Of Previous Bars To Find Depth", minval=1)
// Constants - Brighter colors
var color red_color = color.new(#ff0000, 0)
var color green_color = color.new(#00ff00, 0)
// MA Calculation Function
method calc_ma(string type, float src, int length) =>
float sma = ta.sma(src, length)
float ema = ta.ema(src, length)
float rma = ta.rma(src, length)
float wma = ta.wma(src, length)
float vwma = ta.vwma(src, length)
float smma = na(sma[1]) ? sma : (sma[1] * (length - 1) + src) / length
float hullma = ta.wma(2 * ta.wma(src, length / 2) - ta.wma(src, length), math.round(math.sqrt(float(length))))
float tma = ta.sma(sma, length)
float dema = 2 * ta.ema(src, length) - ta.ema(ta.ema(src, length), length)
float tema = 3 * (ta.ema(src, length) - ta.ema(ta.ema(src, length), length)) + ta.ema(ta.ema(ta.ema(src, length), length), length)
switch type
"RMA" => rma
"SMA" => sma
"EMA" => ema
"WMA" => wma
"VWMA" => vwma
"SMMA" => smma
"HullMA" => hullma
"TMA" => tma
"DEMA" => dema
"TEMA" => tema
=> sma
// Current timeframe calculations
ma_current = calc_ma(ma_type_c, ma_src_c, ma_len_c)
dist_current = math.abs(ma_src_c - ma_current)
niv_prof_current = ta.highest(dist_current, nopbtf_c) * ma_dsl_c
// Timeframe 1 calculations
ma_tf_1 = request.security(syminfo.tickerid, res1, calc_ma(ma_type_1, ma_src_1, ma_len_1))
src_tf_1 = request.security(syminfo.tickerid, res1, ma_src_1)
dist_tf_1 = math.abs(src_tf_1 - ma_tf_1)
niv_prof_tf_1 = ta.highest(dist_tf_1, nopbtf_1) * ma_dsl_1
// Color calculations
method get_color(float dist, float niv_prof, float src, float ma) =>
color col = na
if dist >= niv_prof
if src > ma
col := red_color
if src < ma
col := green_color
col
bg_color = get_color(dist_current, niv_prof_current, ma_src_c, ma_current)
// Entry Conditions
is_green = bg_color == green_color
is_red = bg_color == red_color
green_candle = close > open
red_candle = close < open
long_condition = is_green and green_candle and enable_long
short_condition = is_red and red_candle and enable_short
// Calculate Stop Loss and Take Profit
stop_long = ta.lowest(low, 10) // recent low
stop_short = ta.highest(high, 10) // recent high
risk_long = strategy.position_avg_price - stop_long
risk_short = stop_short - strategy.position_avg_price
tp_long = strategy.position_avg_price + (risk_long * rr_ratio)
tp_short = strategy.position_avg_price - (risk_short * rr_ratio)
// Calculate position size based on risk amount
position_size_long = risk_amount / risk_long
position_size_short = risk_amount / risk_short
// Execute Trades
if long_condition
strategy.entry("Long", strategy.long, qty=position_size_long)
if short_condition
strategy.entry("Short", strategy.short, qty=position_size_short)
// Exit on TP/SL
strategy.exit("Long", "Long", stop=stop_long, limit=tp_long)
strategy.exit("Short", "Short", stop=stop_short, limit=tp_short)
// Plotting
plotshape(long_condition, title="Long Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(short_condition, title="Short Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
bgcolor(bg_color, title="Background Color")
🔧 How to Use
Copy and paste the above code into a new Pine Script v6 strategy in TradingView.
Attach it to any chart.
Use the inputs to:
Adjust how much $ to risk per trade
Set your Risk-Reward Ratio (RR)
Toggle long/short entries
Strategy will automatically:
Enter positions when both conditions are met
Set stop loss and take profit dynamically
Size the position based on risk amount
📌 Notes
The strategy assumes dollar-based risk, but you can change it to % of equity by modifying default_qty_type at the top.
You can add alerts in TradingView for entry/exit signals.
You can backtest this strategy on any market (crypto, forex, stocks, etc.)