Perfect Trading System for Fut
Rules : Intraday
1. Chart time frame 5 min
2. For best results trade buy signals after intra buy active and vice versa for sell signal
3. Manage risk as per SL mentioned and trail SL accordingly or book when 1:1 minimum
Rules : Positional
1. Chart time frame 30 min
2. For best results trade buy signals after intra buy active and vice versa for sell signal
3. Manage risk as per SL mentioned and trail SL accordingly or book when 1:1 minimum
//@version=5
indicator("Perfect Trading system for Fut", overlay=true)
// Input option to enable/disable the stop loss text boxes
showStopLossLabels = input.bool(true, title="Show Stop Loss Labels")
// Function to calculate the height of the candle body
body_height(open, close) =>
math.abs(close - open)
// Function to calculate the total height of the candle (high to low)
candle_height(high, low) =>
high - low
// Calculate body height and candle height for the current candle
bodyHeight = body_height(open, close)
candleHeight = candle_height(high, low)
// Conditions for body height percentage
greaterThan50Percent = bodyHeight > (candleHeight * 0.5)
lessThan50Percent_prev = body_height(open[1], close[1]) < (candle_height(high[1], low[1]) * 0.5)
// Buy Signal: A candle with body height > 50% closes above the high of the previous candle with body
height < 50%
buySignal = close[1] < high[1] and close > high[1] and greaterThan50Percent and
lessThan50Percent_prev
// Sell Signal: A candle with body height > 50% closes below the low of the previous candle with body
height < 50%
sellSignal = close[1] > low[1] and close < low[1] and greaterThan50Percent and lessThan50Percent_prev
// Plot a star above the candle when body height is >= 50% of candle height
plotchar(greaterThan50Percent, char="★", location=location.abovebar, color=color.yellow, size=size.tiny)
// Highlight candles based on body height condition
bgcolor(greaterThan50Percent ? color.new(color.red, 90) : na, title="MC")
// Long Entry and Stop Loss
var float long_entry_price = na
var float long_stop_loss = na
// Function to calculate vertical offset for signals
verticalOffset = ta.atr(14) * 0.5
if (buySignal)
long_entry_price := close
long_stop_loss := low[1] - low[1] * 0.001
if showStopLossLabels
label.new(bar_index, low - verticalOffset, "Long: " + str.tostring(long_entry_price, "#.##") + "\nSL: " +
str.tostring(long_stop_loss, "#.##"),
color=color.green, style=label.style_label_up, yloc=yloc.price)
// Short Entry and Stop Loss
var float short_entry_price = na
var float short_stop_loss = na
if (sellSignal)
short_entry_price := close
short_stop_loss := high[1] + high[1] * 0.001
if showStopLossLabels
label.new(bar_index, high + verticalOffset, "Short: " + str.tostring(short_entry_price, "#.##") + "\nSL: "
+ str.tostring(short_stop_loss, "#.##"),
color=color.red, style=label.style_label_down, yloc=yloc.price)
// Plot entries and stop losses
plot(long_entry_price, title="Long Entry", color=color.green, style=plot.style_linebr, linewidth=2)
plot(long_stop_loss, title="Long Stop Loss", color=color.red, style=plot.style_linebr, linewidth=2)
plot(short_entry_price, title="Short Entry", color=color.red, style=plot.style_linebr, linewidth=2)
plot(short_stop_loss, title="Short Stop Loss", color=color.red, style=plot.style_linebr, linewidth=2)
// Plot buy and sell signals on the chart with offset
plotshape(buySignal, location=location.belowbar, color=color.blue, style=shape.labelup, text="Buy",
offset=0)
plotshape(sellSignal, location=location.abovebar, color=color.orange, style=shape.labeldown, text="Sell",
offset=0)
// Calculate EMAs
ema5 = ta.ema(close, 5)
ema13 = ta.ema(close, 13)
ema34 = ta.ema(close, 34)
// Plot EMAs
plot(ema5, color=color.red, title="EMA 5")
plot(ema13, color=color.green, title="EMA 13")
plot(ema34, color=color.blue, title="EMA 34")
// Calculate the ratio
ema_diff_ratio = (ema34 - ema13) / (ema13 - ema5)
// Display the ratio value on the chart as a label
var label_ratio = label.new(x=bar_index, y=high, text="EMA Diff Ratio: " + str.tostring(ema_diff_ratio,
format.percent), color=color.purple, textcolor=color.white, style=label.style_label_down, size=size.small)
// Display the ratio in a table
var table ema_table = table.new(position.bottom_right, 1, 1, border_width=1)
if (bar_index == 0)
table.cell(ema_table, 0, 0, "EMA Diff Ratio: " + str.tostring(ema_diff_ratio, format.percent))
else
table.cell(ema_table, 0, 0, str.tostring(ema_diff_ratio, format.percent))
// Fetch CCI values for specific timeframes
cci34_30min = request.security(syminfo.tickerid, "30", ta.cci(close, 34),
lookahead=barmerge.lookahead_on)
cci8_5min = request.security(syminfo.tickerid, "5", ta.cci(close, 8), lookahead=barmerge.lookahead_on)
cci34_5min = request.security(syminfo.tickerid, "5", ta.cci(close, 34), lookahead=barmerge.lookahead_off)
// Determine crossing conditions for positional signals
crossBelow110 = cci34_30min < -110 and cci34_30min[1] >= -110
crossAbove110 = cci34_30min > 110 and cci34_30min[1] <= 110
// Track active positional signals
var bool posShortActive = na
var bool posLongActive = na
if crossBelow110
posShortActive := true
posLongActive := false
else if crossAbove110
posShortActive := false
posLongActive := true
// Modified: Plot positional signals with adjusted positions and larger offset
plotshape(series=crossBelow110, location=location.abovebar, color=color.red, style=shape.triangledown,
title="Pos.Short", offset=-2, size=size.small)
plotshape(series=crossAbove110, location=location.belowbar, color=color.green, style=shape.triangleup,
title="Pos.Long", offset=-2, size=size.small)
// Modified: Add labels with adjusted positions and increased vertical offset
if crossBelow110
label.new(bar_index, high + 5 * verticalOffset, "Pos_Short", color=color.red,
style=label.style_label_down, yloc=yloc.price, size=size.small)
if crossAbove110
label.new(bar_index, low - 5 * verticalOffset, "Pos_Long", color=color.green, style=label.style_label_up,
yloc=yloc.price, size=size.small)
// Initialize exit signal flags
var bool pos_short_exit_plotted = false
var bool pos_long_exit_plotted = false
// Determine pos_short_exit condition
pos_short_exit = posShortActive and cci34_30min > 60
// Determine pos_long_exit condition
pos_long_exit = posLongActive and cci34_30min < -60
// Plot pos_short_exit signal only once
if pos_short_exit and not pos_short_exit_plotted
pos_short_exit_plotted := true
// Plot pos_long_exit signal only once
if pos_long_exit and not pos_long_exit_plotted
pos_long_exit_plotted := true
// Reset pos_short_exit_plotted flag when not in a short position
if not posShortActive
pos_short_exit_plotted := false
// Reset pos_long_exit_plotted flag when not in a long position
if not posLongActive
pos_long_exit_plotted := false
// Initialize flags to track if signals have been plotted
var bool imtraBuySignalPlotted = false
var bool imtraSellSignalPlotted = false
var bool imtraBuyExitPlotted = false
var bool imtraSellExitPlotted = false
// Define buy and sell signal conditions for CCI
imtraBuySignal = ta.crossover(cci34_5min, 100)
imtraSellSignal = ta.crossunder(cci34_5min, -100)
// Define exit conditions for buy and sell signals for CCI
imtraBuyExit = ta.crossunder(cci34_5min, -60)
imtraSellExit = ta.crossover(cci34_5min, 60)
// Plot buy signal for CCI if it hasn't been plotted already
if (imtraBuySignal and not imtraBuySignalPlotted)
label.new(bar_index, low - 3 * verticalOffset, "Intra Buy", color=color.green, style=label.style_label_up,
yloc=yloc.price)
imtraBuySignalPlotted := true
imtraSellSignalPlotted := false
// Plot sell signal for CCI if it hasn't been plotted already
if (imtraSellSignal and not imtraSellSignalPlotted)
label.new(bar_index, high + 3 * verticalOffset, "Intra Sell", color=color.red,
style=label.style_label_down, yloc=yloc.price)
imtraSellSignalPlotted := true
imtraBuySignalPlotted := false
// Plot buy exit signal for CCI if it hasn't been plotted already
if (imtraBuyExit and not imtraBuyExitPlotted)
label.new(bar_index, low - 4 * verticalOffset, "Intra Buy Exit", color=color.blue,
style=label.style_label_down, yloc=yloc.price)
imtraBuyExitPlotted := true
imtraBuySignalPlotted := false
// Plot sell exit signal for CCI if it hasn't been plotted already
if (imtraSellExit and not imtraSellExitPlotted)
label.new(bar_index, high + 4 * verticalOffset, "Intra Sell Exit", color=color.blue,
style=label.style_label_up, yloc=yloc.price)
imtraSellExitPlotted := true
imtraSellSignalPlotted := false
// Modify pullback conditions to consider intra buy/sell signals
pullbackShort = posShortActive and cci8_5min > 135 and not pos_short_exit_plotted and not
imtraBuySignalPlotted
pullbackLong = posLongActive and cci8_5min < -135 and not pos_long_exit_plotted and not
imtraSellSignalPlotted
// Plot pullback signals with offset
plotshape(series=pullbackShort, location=location.belowbar, color=color.blue, style=shape.triangledown,
title="Pullback Short", offset=1)
plotshape(series=pullbackLong, location=location.abovebar, color=color.blue, style=shape.triangleup,
title="Pullback Long", offset=1)
// Plot exit signals with offset
plotshape(series=pos_short_exit and pos_short_exit_plotted, location=location.belowbar,
color=color.blue, style=shape.triangledown, title="pos_short_exit", offset=2)
plotshape(series=pos_long_exit and pos_long_exit_plotted, location=location.abovebar, color=color.blue,
style=shape.triangleup, title="pos_long_exit", offset=2)
Indicator Settings….