0% found this document useful (0 votes)
29 views

cop2

The document contains a Pine Script code for a trading indicator called 'Smart Money Breakouts' which identifies potential buy and sell signals based on price action and volume analysis. It also includes a strategy for the 'RMI ADPRO Strategy' that utilizes the Relative Momentum Index (RMI) to determine market conditions and execute trades. The code features various settings for risk management, visual elements, and trade execution logic.

Uploaded by

amsshk1993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

cop2

The document contains a Pine Script code for a trading indicator called 'Smart Money Breakouts' which identifies potential buy and sell signals based on price action and volume analysis. It also includes a strategy for the 'RMI ADPRO Strategy' that utilizes the Relative Momentum Index (RMI) to determine market conditions and execute trades. The code features various settings for risk management, visual elements, and trade execution logic.

Uploaded by

amsshk1993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

//@version=5

indicator("Smart Money Breakouts [ChartPrime]", overlay=true, max_labels_count=500,


max_lines_count=500)
color GREEN = color.rgb(2, 133, 69)
color TAIL = color.rgb(20, 141, 154)
color RED = color.rgb(246, 7, 7)
color _Green = color.rgb(2, 106, 89)
color OFF = color.new(color.red,100)
string DYNAMICSLG = "➞ Risk To Reward Settings 🔸"
string CORE = "➞ Core Settings 🔸"
var array<int> score = array.new_int(2,0)
//
var float UpdatedHigh = na
var float UpdatedLow = na
var bool ShortTrade = false
var bool TradeisON = false
var bool LongTrade = false
var int HighIndex = na
var bool phActive = false
var bool plActive = false
var int LowIndex = na
var bool HBreak = false
var line tpLine = na
var line SLLine = na
var label LAB = na
var float TP = 0.0
var float SL = 0.0
int Sync = bar_index
bool BUY = false
bool SELL = false

type Vol
array<float> Total
array<float> Green
array<float> Red
array<float> SCR

Volume = Vol.new(
array.new_float(),
array.new_float(),
array.new_float(),
array.new_float()

int period = input.int(20, 'Length',group = CORE,tooltip = "Swing


Length")
bool CandleType = input.string(title = "Type ➞",
defval='Wicks',
options=['Wicks', 'Body'],
group = CORE,
tooltip = "Calculation Price : Wicks or Body of the candle")
== 'Wicks'
float RR1 = input.float(1.1,"RR Ratio",step = 0.1 , tooltip = "Risk to
reward Ratio",group = CORE)
bool SLType = input.string('Close',
'SL Type', ['Close', 'High/Low'], group=CORE,tooltip = "Activate SL on candle
close or high/low") == 'Close'
bool ShowSL = input.bool(false,"Show SL",group = CORE)
string Linestyle = input.string('Dashed',
'Line Style', ['Solid', 'Dashed', 'Dotted'], group=CORE,inline= "Line")

color Bull = input.color(GREEN,"",group=CORE,inline= "Line")


color Bear = input.color(RED,"",group=CORE,inline= "Line")

//----- { SL Calculation
// -- ATR
x2 = low - ta.rma(ta.tr(true), 14) * 1.5
xz = ta.rma(ta.tr(true), 14) * 1.5 + high
longDiffSL2 = math.abs(close - xz)
longDiffSL = math.abs(close - x2)
// }

StyleSwitch = switch Linestyle


'Dashed' => line.style_dashed ,
'Dotted' => line.style_dotted ,
=> line.style_solid

method volAdj(int len)=>


math.min(ta.atr(len) * 0.3, close * (0.3/100)) [20] /2

Adj = volAdj(30)

VolCal(Index,Sync) =>
Bars = math.abs(Index - Sync)
for i = 0 to Bars -1
Volume.SCR.push(close[i])

for i = 0 to Volume.SCR.size() -1

if Volume.SCR.get(i) > open[i]


Volume.Green.push(volume[i])

if Volume.SCR.get(i) < open[i]


Volume.Red.push(volume[i])

Volume.Total.push(volume[i])

GreenRatio = math.round(Volume.Green.sum() / Volume.Total.sum()* 100,2)


RedRatio = math.round(Volume.Red.sum() / Volume.Total.sum()* 100,2)
Out = GreenRatio > 55 ? "🟢" : RedRatio > 55 ? "🔴" : "🟡"
Out

PH = ta.pivothigh(high, period, period)


PL = ta.pivotlow(low, period, period)
ScrHigh = CandleType ? high : close
ScrLow = CandleType ? low : close

if ta.change(fixnan(PH)) != 0
UpdatedHigh := PH
phActive := true
HighIndex := Sync - period

if ta.change(fixnan(PL)) != 0
UpdatedLow := PL
plActive := true
LowIndex := Sync - period

// LONG
if ScrHigh > UpdatedHigh and phActive
BUY := true
phActive := false

//Sell
if ScrLow < UpdatedLow and plActive
SELL := true
plActive := false

// lets Draw

if BUY and not TradeisON


sign = VolCal(HighIndex,Sync)
line.new(HighIndex,
UpdatedHigh,
Sync,
UpdatedHigh,
color=Bull,
style=StyleSwitch,
width=2)
label.new(math.floor(Sync - (Sync - HighIndex) / 2),
UpdatedHigh,
not HBreak ? 'CHoCH\n' + sign : 'BOS\n' + sign,
color=OFF,
textcolor=color.white,
size=size.tiny)
label.new(Sync,
low,
"",
yloc = yloc.belowbar,
color = color.lime,
size = size.small,
style = label.style_label_up)
HBreak := true

if SELL and not TradeisON


sign = VolCal(LowIndex,Sync)
line.new(LowIndex,
UpdatedLow,
Sync,
UpdatedLow,
color=Bear,
style=StyleSwitch,
width=2)
label.new(math.floor(Sync - (Sync - LowIndex) / 2),
UpdatedLow,
HBreak ? 'CHoCH\n' + sign : 'BOS\n' + sign,
color=OFF,
textcolor=color.white,
style=label.style_label_up,
size=size.tiny)
label.new(Sync,
low,
"",
yloc = yloc.abovebar,
color =RED,
size = size.small,
style = label.style_label_down)
HBreak := false

Long = BUY and not TradeisON


Short = SELL and not TradeisON

TradeFire = Long or Short

if Long and not TradeisON


LongTrade:= true
ShortTrade:= false

if Short and not TradeisON


LongTrade:= false
ShortTrade:= true

if true
if TradeFire and not TradeisON
TP := switch
Long => close + (RR1 * longDiffSL)
Short => close - (RR1 * longDiffSL2)

SL := switch
Long => close - longDiffSL
Short => close + longDiffSL2

TradeisON:= true
if true
line.new(bar_index,
Long ? high : low,
bar_index,
TP,
width=2,
color = TAIL,
style= line.style_dashed)

tpLine:= line.new(bar_index,
TP,
bar_index+2,
TP,
style= line.style_dashed,
color = TAIL
)
if ShowSL
SLLine:= line.new(bar_index,
SL,
bar_index+2,
SL,
style= line.style_dashed,
color = RED
)
LAB:=label.new(bar_index,
TP,
"Target",
color = TAIL,
style= label.style_label_left,
size=size.small,
textcolor = color.white
)
if TradeisON
line.set_x2(tpLine,bar_index)
label.set_x(LAB,bar_index+1)
if ShowSL
line.set_x2(SLLine,bar_index)

if LongTrade and TradeisON


if high >= TP
label.set_color(LAB,GREEN)
score.set(0,score.get(0)+1)
TradeisON:=false
if (SLType ? close : low) <= SL
score.set(1,score.get(1)+1)
label.set_color(LAB,color.new(RED,70))
label.set_tooltip(LAB,"Stoploss Hit : "+
str.tostring(math.round_to_mintick(SL)))
TradeisON:=false

else if ShortTrade and TradeisON


if low <= TP
label.set_color(LAB,GREEN)
score.set(0,score.get(0)+1)
TradeisON:=false

if (SLType ? close : high) >= SL


score.set(1,score.get(1)+1)
label.set_color(LAB,color.new(RED,70))
label.set_tooltip(LAB,"Stoploss Hit : "+
str.tostring(math.round_to_mintick(SL)))
TradeisON:=false

BearCon = TradeisON and ShortTrade


BullCon = TradeisON and LongTrade

barcolor(BearCon ? RED : BullCon ? _Green : color.rgb(52, 52, 54) )

plotcandle(open, high, low, close, color = BearCon ? RED : BullCon ? _Green :


color.rgb(52, 52, 54),
wickcolor = color.rgb(103, 99, 99),bordercolor = BearCon ? RED : BullCon ?
_Green : color.rgb(52, 52, 54))

bgcolor(BearCon ? color.rgb(136, 4, 15, 90) : BullCon ? color.rgb(8, 191, 158,90) :


na )

// where is my table ?!
var tb = table.new(position.top_right, 3, 3,
bgcolor= color.new(color.gray,80))

if barstate.islast

table.cell(tb, 0, 0, "Winning Trades"


, text_color = #a3a3b1)
table.cell(tb, 1, 0, str.tostring(score.get(0))
, text_color = #08c09b)
table.cell(tb, 0, 1, "Losing Trades"
, text_color = #a3a3b1)
table.cell(tb, 1, 1, str.tostring(score.get(1))
, text_color = #cd0202)

alertcondition(Long,"BUY")
alertcondition(Short,"Sell")

combine this indicator with below

//@version=5
strategy('RMI ADPRO Strategy', overlay=true, max_labels_count=500,
currency=currency.USD)

// ** ---> Inputs ------------- {


var bool positive = false
var bool negative = false
string RSI_group = "RMI Settings"
string mom_group = "Range Values"
string visual = "Visuals"
string grid_group = "Grid Bot Settings"
int Length = input(14, "RMI Length ", inline="RMI",
group=RSI_group)
int pmom = input(66, "Positive above", inline="rsi1",
group=RSI_group)
int nmom = input(30, "Negative below", inline="rsi1",
group=RSI_group)
bool filleshow = input(true, "Show Range MA ", inline="002",
group=visual)
color bull = input(#00bcd4, "", inline="002",
group=visual)
color bear = input(#ff5252, "", inline="002",
group=visual)
float grid_lines = input.float(30, "Grid Lines", minval=1,
group=grid_group)
float grid_spacing = input.float(2.5, "Grid Spacing %",
minval=0.1, group=grid_group)

// ** ---> RMI Calculations ------------- {


float BarRange = high - low
up = ta.rma(math.max(ta.change(close), 0), Length)
down = ta.rma(-math.min(ta.change(close), 0), Length)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
mf = ta.mfi(hlc3, Length)
rsi_mfi = math.avg(rsi, mf)
// ** ---> Momentum Conditions ------------- {
bool p_mom = rsi_mfi[1] < pmom and rsi_mfi > pmom and rsi_mfi > nmom and
ta.change(ta.ema(close, 5)) > 0
bool n_mom = rsi_mfi < nmom and ta.change(ta.ema(close, 5)) < 0

if p_mom
positive := true
negative := false

if n_mom
positive := false
negative := true

// ** ---> Range Weighted MA and Bands ------------- {


method _Band(int len)=>
math.min(ta.atr(len) * 0.3, close * (0.3 / 100))[20] / 2 * 8

Band = _Band(30)

method rangeMA(float Range, Prd)=>


weight = Range / math.sum(Range, Prd)
sum = math.sum(close * weight, Prd)
tw = math.sum(weight, Prd)
sum / tw

rwma = rangeMA(BarRange, 20)


colour = positive ? bull : bear
RWMA = positive ? rwma - Band : negative ? rwma + Band : na
alpha = color.new(color.black, 100)

center = plot(filleshow ? RWMA : na, "RRTH", colour, editable=true)


plot(filleshow ? RWMA : na, "RRTH", color.new(colour, 70), 2, editable=true)
plot(filleshow ? RWMA : na, "RRTH", color.new(colour, 80), 3, editable=true)
plot(filleshow ? RWMA : na, "RRTH", color.new(colour, 90), 4, editable=true)

max = RWMA + Band


min = RWMA - Band

top = plot(filleshow ? max : na, "RRTH", alpha)


bottom = plot(filleshow ? min : na, "RRTH", alpha)
fill(top, center, top_value=max, bottom_value=RWMA, bottom_color=color.new(colour,
75), top_color=alpha, editable=true)
fill(center, bottom, top_value=RWMA, bottom_value=min, bottom_color=alpha,
top_color=color.new(colour, 75), editable=true)

// ** ---> Visuals and Labels ------------- {


Barcol = positive ? color.green : color.red

if negative and not negative[1]


label.new(bar_index, max + (Band / 2), "Close Long / Start Grid",
color=color.red, size=size.small, textcolor=color.white)
if positive and not positive[1]
label.new(bar_index, min - (Band / 2), "Buy Long 100%", color=color.green,
size=size.small, style=label.style_label_up, textcolor=color.white)

plotcandle(open, high, low, close, color=Barcol, wickcolor=Barcol,


bordercolor=Barcol)
barcolor(color=Barcol)
// ** ---> Strategy Logic ------------- {
// Calculate equity-based quantities
float long_qty = strategy.equity / close // 100% of equity for long position
float grid_qty = (strategy.equity / grid_lines) / close // Equity per grid line
(e.g., 100/30 ≈ 3.333% per line)

// Long Position: Full amount on green (buy) signal, close on red (sell) signal
if positive and not positive[1]
// Close any existing long positions (including grid positions) to ensure we
can open a new "Long" position
strategy.close_all(comment="Close All Before Long")
strategy.entry("Long", strategy.long, qty=long_qty)
// Debug label to confirm the long position entry attempt
label.new(bar_index, close, "Long Entry Attempt: " + str.tostring(long_qty) + "
contracts", color=color.green, style=label.style_label_down, textcolor=color.white)

if negative and not negative[1]


strategy.close("Long", comment="Close Long")

// Grid Bot: On red (sell) signal, place 30 grid lines, 2.5% apart
var float grid_base_price = 0.0
var float[] grid_prices = array.new_float(0)
var line[] grid_lines_array = array.new_line(0) // Array to store grid lines for
removal

// Function to remove existing grid lines


f_removeLines() =>
if array.size(grid_lines_array) > 0
for i = 0 to array.size(grid_lines_array) - 1
line.delete(array.get(grid_lines_array, i))
array.clear(grid_lines_array) // Clear the array in place instead of
reassigning

if negative and not negative[1]


// Remove old grid lines
f_removeLines()

// Calculate new grid prices


grid_base_price := close
grid_prices := array.new_float(0)
for i = 0 to grid_lines - 1
grid_price = grid_base_price * (1 - (i * grid_spacing / 100))
array.push(grid_prices, grid_price)
strategy.entry("Grid" + str.tostring(i), strategy.long, qty=grid_qty,
limit=grid_price, comment="Grid Buy " + str.tostring(i))
// Draw a horizontal line using line.new()
new_line = line.new(bar_index, grid_price, bar_index + 1, grid_price,
color=color.yellow, style=line.style_dashed)
array.push(grid_lines_array, new_line)

// Close all grid positions and remove grid lines when signal changes to positive
if positive and not positive[1]
f_removeLines()
for i = 0 to grid_lines - 1
strategy.close("Grid" + str.tostring(i), comment="Close Grid " +
str.tostring(i))

// ** ---> Alerts ------------- {


alertcondition(positive and not positive[1], "BUY", "Buy Signal")
alertcondition(negative and not negative[1], "SELL", "Sell Signal")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy