0% found this document useful (0 votes)
63 views6 pages

Nifty Trend Rider

great pdf for algo

Uploaded by

Hathque sandy
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)
63 views6 pages

Nifty Trend Rider

great pdf for algo

Uploaded by

Hathque sandy
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/ 6

//@version=5

// @maashardatrading07
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/

indicator("Maa Sharda Trading", overlay=true, precision=0,


explicit_plot_zorder=true, max_labels_count=500)
// Get user input
emaEnergy = input.bool(true, "EMA Energy")
sensitivity = input.float(10, " Sensitivity (0.5 - 10)", 0.5, 10, step=0.1)
keltner_length = input(10, "Keltner Channel Length")
atrPeriod = input(10, "ATR Length")
factor = input.float(3.5, "Factor", step = 0.01)

// Keltner Channel function


keltner_channel(src, length) =>
ma = ta.sma(src, length)
rangec = high - low
upper = ma + rangec
lower = ma - rangec
[upper, lower]

// Modified Supertrend function using Keltner Channel


supertrend(_src, factor, atrLen, kel_length) =>
[upperKeltner, lowerKeltner] = keltner_channel(_src, kel_length)
rangec = upperKeltner - lowerKeltner
upperBand = _src + factor * rangec
lowerBand = _src - factor * rangec
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ?
lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ?
upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]

if na(rangec[1])
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
[superTrend, direction]
// Get Components
ema1 = ta.ema(high, 9)
ema2 = ta.ema(high, 12)
ema3 = ta.ema(high, 15)
ema4 = ta.ema(high, 18)
ema5 = ta.ema(high, 21)
ema6 = ta.ema(high, 24)
ema7 = ta.ema(high, 27)
ema8 = ta.ema(high, 30)
ema9 = ta.ema(high, 33)
ema10 = ta.ema(high, 36)
ema11 = ta.ema(high, 39)
ema12 = ta.ema(high, 42)
ema13 = ta.ema(high, 45)
ema14 = ta.ema(high, 48)
ema15 = ta.ema(high, 51)

// Colors
green = #2BBC4D, red = #C51D0B
emaEnergyColor(ma) => emaEnergy ? (close >= ma ? green : red) : na

// Plots
plot(ema1, "", emaEnergyColor(ema1), editable=false)
plot(ema2, "", emaEnergyColor(ema2), editable=false)
plot(ema3, "", emaEnergyColor(ema3), editable=false)
plot(ema4, "", emaEnergyColor(ema4), editable=false)
plot(ema5, "", emaEnergyColor(ema5), editable=false)
plot(ema6, "", emaEnergyColor(ema6), editable=false)
plot(ema7, "", emaEnergyColor(ema7), editable=false)
plot(ema8, "", emaEnergyColor(ema8), editable=false)
plot(ema9, "", emaEnergyColor(ema9), editable=false)
plot(ema10, "", emaEnergyColor(ema10), editable=false)
plot(ema11, "", emaEnergyColor(ema11), editable=false)
plot(ema12, "", emaEnergyColor(ema12), editable=false)
plot(ema13, "", emaEnergyColor(ema13), editable=false)
plot(ema14, "", emaEnergyColor(ema14), editable=false)
plot(ema15, "", emaEnergyColor(ema15), editable=false)
[supertrend, direction] = supertrend(close, sensitivity, 11, keltner_length)
bull = ta.crossover(close, supertrend)
bear = ta.crossunder(close, supertrend)

y1 = low - (ta.atr(30) * 2)
y2 = high + (ta.atr(30) * 2)

buy = bull ? label.new(bar_index, y1, "BUY", xloc.bar_index, yloc.price, green,


label.style_label_up, color.white, size.normal) : na
sell = bear ? label.new(bar_index, y2, "SELL", xloc.bar_index, yloc.price, red,
label.style_label_down, color.white, size.normal) : na

[supertrends, directions] = ta.supertrend(factor, atrPeriod)


bodyMiddle = plot((open + close) / 2, display=display.none)
// Trend Catcher Indicator (Example)
ema100 = ta.ema(close, 10)
ema200 = ta.ema(close, 20)
trendCatcher = ta.crossover(ema100, ema200) ? 1 : ta.crossunder(ema100, ema200) ? -
1 : 0
trendColor = trendCatcher == 1 ? color.rgb(90, 23, 102) : na
barcolor(trendColor)
// Colored candles
barcolor(color = close > supertrends ? color.rgb(102, 255, 0) : color.rgb(255, 0,
0))
///...... TP & SL TOOLS ........
price=close
//entryPrice = input.float(price, title = 'Entry Price', group = 'Trade Levels')
//manualStopLoss = input.float(3351.2, title = 'Stop Loss (Manual)', group = 'Trade
Levels')
useFractal = input.bool(true, title = 'Use Fractal for Stop Loss', group = 'Trade
Levels')
//tradeSide = isUptrend1?"Buy":"Sell"//input.string('Buy', title = 'Trade
Direction', options = ['Buy', 'Sell'], group = 'Trade Levels')

// ==== ‫ مجموعة‬:‫ إعدادات العرض‬TP&SL STYLE ====


showLabels = input.bool(true, title = 'Show TP&SL Labels?', group = 'TP&SL STYLE')
offset = input.int(5, title = 'Offset from Last Bar', minval = 1, maxval = 100,
group = 'TP&SL STYLE')
len = input.int(5, title = 'Line Length', minval = 1, maxval = 100, group = 'TP&SL
STYLE')
labelSizeOption = input.string('Normal', title = 'Label Size', options = ['Tiny',
'Small', 'Normal', 'Large'], group = 'TP&SL STYLE')
lineWidth = input.int(1, title = 'Line Width', minval = 1, maxval = 5, group =
'TP&SL STYLE')
lineStyleOption = input.string('Solid', title = 'Line Style', options = ['Solid',
'Dotted', 'Dashed'], group = 'TP&SL STYLE')

// ==== ‫==== تحويل الإعدادات‬


labelSize = switch labelSizeOption
'Tiny' => size.tiny
'Small' => size.small
'Normal' => size.normal
'Large' => size.large

lineStyle = switch lineStyleOption


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

// ==== ‫ حساب‬fractals ====


fractalLow = low[2] < low[1] and low[2] < low[3] and low[2] < low[0] ? low[2] : na
fractalHigh = high[2] > high[1] and high[2] > high[3] and high[2] > high[0] ?
high[2] : na

var float lastFractalLow = na


var float lastFractalHigh = na
if not na(fractalLow)
lastFractalLow := fractalLow
lastFractalLow
if not na(fractalHigh)
lastFractalHigh := fractalHigh
lastFractalHigh

// ==== ‫وقف الخسارة‬: fractal ‫==== أو يدوي‬


stopLoss = useFractal ? bull ? lastFractalLow : lastFractalHigh : na

// ==== ‫==== حساب الأهداف التلقائية‬


slDistance = math.abs(close - stopLoss)
tp1 = bull ? close + slDistance * 1 : close - slDistance * 1
tp2 = bull ? close+ (tp1 - close) * 2 : close - (close - tp1) * 2
tp3 = bull ? close + (tp2 - close) * 1.5 : close - (close - tp2) * 1.5

// ==== ‫==== الموضع الأفقي‬


int lastBar = bar_index + offset

// ==== ‫==== الخطوط‬


var line entryLine = na
var line slLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na

//...........

var float newtp1 =na


var float newtp2 = na
var float newtp3 = na
var float newSl=na
var float avv=na
//if (buySignal or strongBuy_signals or greatBuySignals or sellSignal or
strongSell_signals or greatSellSignals)

if (bull or bear)
newtp1:= tp1
newtp2:=tp2
newtp3:=tp3
newSl:=stopLoss
avv:=close
line.delete(entryLine)
line.delete(slLine)
line.delete(tp1Line)
line.delete(tp2Line)
line.delete(tp3Line)
entryLine := line.new(lastBar - len, close, lastBar, close, color =
color.orange, width = lineWidth, style = lineStyle)
slLine := line.new(lastBar - len, stopLoss, lastBar, stopLoss, color =
color.red, width = lineWidth, style = lineStyle)
tp1Line := line.new(lastBar - len, tp1, lastBar, tp1, color = color.green,
width = lineWidth, style = lineStyle)
tp2Line := line.new(lastBar - len, tp2, lastBar, tp2, color = color.green,
width = lineWidth, style = lineStyle)
tp3Line := line.new(lastBar - len, tp3, lastBar, tp3, color = color.green,
width = lineWidth, style = lineStyle)

// ==== ‫==== الليبالت‬


var label entryLabel = na
var label slLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na

//label.delete(entryLabel)
//label.delete(slLabel)
//label.delete(tp1Label)
//label.delete(tp2Label)
//label.delete(tp3Label)

// float newtp1=na
//r float newtp2=na
//if (showLabels and (buySignal or strongBuy_signals or greatBuySignals or
sellSignal or strongSell_signals or greatSellSignals))

if (bull or bear)
avv:=close
label.delete(entryLabel)
label.delete(slLabel)
label.delete(tp1Label)
label.delete(tp2Label)
label.delete(tp3Label)
entryLabel := label.new(lastBar, close, 'Entry : ' + str.tostring(close), style
= label.style_label_left, color = color.orange, textcolor = color.white, size =
labelSize)
slLabel := label.new(lastBar, stopLoss, 'SL : ' + str.tostring(stopLoss), style
= label.style_label_left, color = color.red, textcolor = color.white, size =
labelSize)
tp1Label := label.new(lastBar, tp1, 'TP1 : ' + str.tostring(tp1), style =
label.style_label_left, color = color.green, textcolor = color.white, size =
labelSize)
tp2Label := label.new(lastBar, tp2, 'TP2 : ' + str.tostring(tp2), style =
label.style_label_left, color = color.green, textcolor = color.white, size =
labelSize)
tp3Label := label.new(lastBar, tp3, 'TP3 : ' + str.tostring(tp3), style =
label.style_label_left, color = color.green, textcolor = color.white, size =
labelSize)
tp3Label

if not na(slLabel)
label.delete(slLabel)
slLabel := label.new(bar_index + offset, newSl, "SL :
"+str.tostring(newSl),style = label.style_label_left,color=color.red,textcolor =
color.white,size = labelSize )

if not na(entryLabel)
label.delete(entryLabel)
entryLabel := label.new(bar_index + offset, avv, "Entry:
"+str.tostring(avv),style = label.style_label_left,color=color.orange,textcolor =
color.white,size = labelSize )

if not na(tp1Label)
label.delete(tp1Label)
tp1Label:= label.new(bar_index+offset,newtp1,"TP1 :
"+str.tostring(newtp1),style =label.style_label_left,color=color.green,textcolor =
color.white,size = labelSize )

if not na(tp2Label)
label.delete(tp2Label)
tp2Label:= label.new(bar_index+offset,newtp2,"TP2 :
"+str.tostring(newtp2),style =label.style_label_left,color=color.green,textcolor =
color.white,size = labelSize )
if not na(tp3Label)
label.delete(tp3Label)
tp3Label:= label.new(bar_index+offset,newtp3,"TP3 :
"+str.tostring(newtp3),style =label.style_label_left,color=color.green,textcolor =
color.white,size = labelSize )

if not na(entryLine)
line.delete(entryLine)
entryLine := line.new(bar_index+offset-
len,avv,bar_index+offset,avv,color=color.orange,width = lineWidth,style =
lineStyle)

if not na(slLine)
line.delete(slLine)
slLine := line.new(bar_index+offset-
len,newSl,bar_index+offset,newSl,color=color.red,width = lineWidth,style =
lineStyle)

if not na(tp1Line)
line.delete(tp1Line)
tp1Line := line.new(bar_index+offset-
len,newtp1,bar_index+offset,newtp1,color=color.green,width = lineWidth,style =
lineStyle)

if not na(tp2Line)
line.delete(tp2Line)
tp2Line := line.new(bar_index+offset-
len,newtp2,bar_index+offset,newtp2,color=color.green,width = lineWidth,style =
lineStyle)

if not na(tp3Line)
line.delete(tp3Line)
tp3Line := line.new(bar_index+offset-
len,newtp3,bar_index+offset,newtp3,color=color.green,width = lineWidth,style =
lineStyle)

You might also like