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

Superstar X V2

This document is a Pine Script code for a trading indicator called 'Trend Signals with TP & SL [SUPERSTAR X V1]'. It includes various inputs for customizing sensitivity, ATR calculation methods, and stop loss percentages, along with calculations for buy/sell signals based on trends. The script also generates visual signals and labels on a trading chart to assist in decision-making.

Uploaded by

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

Superstar X V2

This document is a Pine Script code for a trading indicator called 'Trend Signals with TP & SL [SUPERSTAR X V1]'. It includes various inputs for customizing sensitivity, ATR calculation methods, and stop loss percentages, along with calculations for buy/sell signals based on trends. The script also generates visual signals and labels on a trading chart to assist in decision-making.

Uploaded by

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

//@version=5

indicator("Trend Signals with TP & SL [SUPERSTAR X V1]", shorttitle = "Trend Signals with TP & SL
[SUPERSTAR X V1]", overlay = true)

src = input(hl2, title="Source", group = "Trend Continuation Signals with TP & SL")

Multiplier = input.float(2, title="Sensitivity (0.5 - 5)", step=0.1, defval=2, minval=0.5, maxval=5, group
= "Trend Continuation Signals with TP & SL")

atrPeriods = input.int(14, title="ATR Length", defval=10, group = "Trend Continuation Signals with TP
& SL")

atrCalcMethod = input.string("Method 1", title="ATR Calculation Methods", options = ["Method 1",


"Method 2"], group = "Trend Continuation Signals with TP & SL")

cloud_val = input.int(10, title="Cloud Moving Average Length", defval = 10, minval = 5, maxval = 500,
group = "Trend Continuation Signals with TP & SL")

stopLossVal = input.float(2.0, title="Stop Loss Percent (0 for Disabling)", minval=0, group = "Trend
Continuation Signals with TP & SL")

showBuySellSignals = input.bool(true, title="Show Buy/Sell Signals", defval=true, group = "Trend


Continuation Signals with TP & SL")

showMovingAverageCloud = input.bool(true, title="Show Cloud MA", group = "Trend Continuation


Signals with TP & SL")

percent(nom, div) =>

100 * nom / div

// Calculations

src1 = ta.hma(open, 5)[1]

src2 = ta.hma(close, 12)

momm1 = ta.change(src1)

momm2 = ta.change(src2)

f1(m, n) => m >= n ? m : 0.0

f2(m, n) => m >= n ? 0.0 : -m

m1 = f1(momm1, momm2)

m2 = f2(momm1, momm2)

sm1 = math.sum(m1, 1)

sm2 = math.sum(m2, 1)
cmoCalc = percent(sm1 - sm2, sm1 + sm2)

hh = ta.highest(2)

h1 = ta.dev(hh, 2) ? na : hh

hpivot = fixnan(h1)

ll = ta.lowest(2)

l1 = ta.dev(ll, 2) ? na : ll

lpivot = fixnan(l1)

rsiCalc = ta.rsi(close, 9)

lowPivot = lpivot

highPivot = hpivot

sup = rsiCalc < 25 and cmoCalc > 50 and lowPivot

res = rsiCalc > 75 and cmoCalc < -50 and highPivot

atr2 = ta.sma(ta.tr, atrPeriods)

atr = atrCalcMethod == "Method 1" ? ta.atr(atrPeriods) : atr2

up = src - (Multiplier * atr)

up1 = nz(up[1], up)

up := close[1] > up1 ? math.max(up, up1) : up

dn = src + (Multiplier * atr)

dn1 = nz(dn[1], dn)

dn := close[1] < dn1 ? math.min(dn, dn1) : dn

trend = 1

trend := nz(trend[1], trend)

trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

buySignal = trend == 1 and trend[1] == -1

sellSignal = trend == -1 and trend[1] == 1


pos = 0.0

pos := buySignal ? 1 : sellSignal ? -1 : pos[1]

longCond = buySignal and pos[1] != 1

shortCond = sellSignal and pos[1] != -1

entryOfLongPosition = ta.valuewhen(longCond, close, 0)

entryOfShortPosition = ta.valuewhen(shortCond, close, 0)

sl = stopLossVal > 0 ? stopLossVal / 100 : 99999

stopLossForLong = entryOfLongPosition * (1 - sl)

stopLossForShort = entryOfShortPosition * (1 + sl)

takeProfitForLong1R = entryOfLongPosition * (1 + sl)

takeProfitForShort1R = entryOfShortPosition * (1 - sl)

takeProfitForLong2R = entryOfLongPosition * (1 + sl * 2)

takeProfitForShort2R = entryOfShortPosition * (1 - sl * 2)

takeProfitForLong3R = entryOfLongPosition * (1 + sl * 3)

takeProfitForShort3R = entryOfShortPosition * (1 - sl * 3)

long_sl = low < stopLossForLong and pos[1] == 1

short_sl = high > stopLossForShort and pos[1] == -1

takeProfitForLongFinal = high > takeProfitForLong3R and pos[1] == 1

takeProfitForShortFinal = low < takeProfitForShort3R and pos[1] == -1

if long_sl or short_sl or takeProfitForLongFinal or takeProfitForShortFinal

pos := 0
lindex = ta.valuewhen(longCond, bar_index, 0)

sindex = ta.valuewhen(shortCond, bar_index, 0)

entryColor = pos == 1 ? color.blue : color.purple

// Only create a line and label if we are entering a trade and it doesn't already exist

var line entryLine = na

var line stopLine = na

var line tpLine1 = na

var line tpLine2 = na

var line tpLine3 = na

var label labelEntry = na

var label labelStop = na

var label labelTp1 = na

var label labelTp2 = na

var label labelTp3 = na

if barstate.islast and pos != 0

line.delete(entryLine)

line.delete(stopLine)

line.delete(tpLine1)

line.delete(tpLine2)

line.delete(tpLine3)

label.delete(labelEntry)

label.delete(labelStop)

label.delete(labelTp1)

label.delete(labelTp2)

label.delete(labelTp3)
entryLine := line.new(bar_index, pos > 0 ? entryOfLongPosition : entryOfShortPosition, pos > 0 ?
lindex : sindex, pos > 0 ? entryOfLongPosition : entryOfShortPosition, color=entryColor)

stopLine := line.new(bar_index, pos > 0 ? stopLossForLong : stopLossForShort, pos > 0 ? lindex :


sindex, pos > 0 ? stopLossForLong : stopLossForShort, color=color.red)

tpLine1 := line.new(bar_index, pos > 0 ? takeProfitForLong1R : takeProfitForShort1R, pos > 0 ?


lindex : sindex, pos > 0 ? takeProfitForLong1R : takeProfitForShort1R, color=color.green)

tpLine2 := line.new(bar_index, pos > 0 ? takeProfitForLong2R : takeProfitForShort2R, pos > 0 ?


lindex : sindex, pos > 0 ? takeProfitForLong2R : takeProfitForShort2R, color=color.green)

tpLine3 := line.new(bar_index, pos > 0 ? takeProfitForLong3R : takeProfitForShort3R, pos > 0 ?


lindex : sindex, pos > 0 ? takeProfitForLong3R : takeProfitForShort3R, color=color.green)

labelEntry := label.new(bar_index, pos > 0 ? entryOfLongPosition : entryOfShortPosition,


color=entryColor, textcolor=#000000, style=label.style_label_left, text="Entry Price: " +
str.tostring(pos > 0 ? entryOfLongPosition : entryOfShortPosition))

labelStop := label.new(bar_index, pos > 0 ? stopLossForLong : stopLossForShort, color=color.red,


textcolor=#000000, style=label.style_label_left, text="Stop Loss Price: " +
str.tostring(math.round((pos > 0 ? stopLossForLong : stopLossForShort) * 100) / 100))

labelTp1 := label.new(bar_index, pos > 0 ? takeProfitForLong1R : takeProfitForShort1R,


color=color.green, textcolor=#000000, style=label.style_label_left, text="(1-1) Take Profit: " +
str.tostring(math.round((pos > 0 ? takeProfitForLong1R : takeProfitForShort1R) * 100) / 100))

labelTp2 := label.new(bar_index, pos > 0 ? takeProfitForLong2R : takeProfitForShort2R,


color=color.green, textcolor=#000000, style=label.style_label_left, text="(2-1) Take Profit: " +
str.tostring(math.round((pos > 0 ? takeProfitForLong2R : takeProfitForShort2R) * 100) / 100))

labelTp3 := label.new(bar_index, pos > 0 ? takeProfitForLong3R : takeProfitForShort3R,


color=color.green, textcolor=#000000, style=label.style_label_left, text="(3-1) Take Profit: " +
str.tostring(math.round((pos > 0 ? takeProfitForLong3R : takeProfitForShort3R) * 100) / 100))

// Plots for buy/sell signals

plotshape(longCond and showBuySellSignals ? up : na, title="Buy", text="Buy",


location=location.belowbar, style=shape.labelup, size=size.small, color=color.new(color.teal, 0),
textcolor=color.white)

plotshape(shortCond and showBuySellSignals ? dn : na, title="Sell", text="Sell",


location=location.abovebar, style=shape.labeldown, size=size.small, color=color.new(color.red, 0),
textcolor=color.white)

//

You might also like