100% found this document useful (1 vote)
513 views5 pages

Combined Trading Strategy Script

Uploaded by

Dipankar Biswas
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
100% found this document useful (1 vote)
513 views5 pages

Combined Trading Strategy Script

Uploaded by

Dipankar Biswas
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

//@version=4

strategy("Combined Strategy", overlay=true)

// --- Script 1: 2 Moving Average Exponential ---

len = input(5, minval=1, title="Length")


src = input(close, title="Source")
out = ema(src, len)
plot(out, title="EMA", color=[Link])

len2 = input(20, minval=1, title="Length2")


src2 = input(close, title="Source2")
out2 = ema(src2, len2)
plot(out2, title="EMA2", color=[Link])

if (crossover(out, out2))
[Link]("MacdLE", [Link], when=strategy.position_size <= 0,
comment="MacdLE")

[Link]("MacdLE", when=crossunder(out2, out))

// --- Script 2: Order Block Finder ---

colors = input(title="Color Scheme", defval="DARK", options=["DARK", "BRIGHT"])


periods = input(5, "Relevant Periods to identify OB")
threshold = input(0.0, "Min. Percent move to identify OB", step=0.1)
usewicks = input(false, "Use whole range [High/Low] for OB marking?")
showbull = input(true, "Show latest Bullish Channel?")
showbear = input(true, "Show latest Bearish Channel?")
showdocu = input(false, "Show Label for documentation tooltip?")
info_pan = input(false, "Show Latest OB Panel?")

ob_period = periods + 1
absmove = ((abs(close[ob_period] - close[1]))/close[ob_period]) * 100
relmove = absmove >= threshold

bullcolor = colors == "DARK" ? [Link] : [Link]


bearcolor = colors == "DARK" ? [Link] : [Link]

bullishOB = close[ob_period] < open[ob_period]


int upcandles = 0
for i = 1 to periods
upcandles := upcandles + (close[i] > open[i] ? 1 : 0)

OB_bull = bullishOB and (upcandles == (periods)) and relmove


OB_bull_high = OB_bull ? usewicks ? high[ob_period] : open[ob_period] : na
OB_bull_low = OB_bull ? low[ob_period] : na
OB_bull_avg = (OB_bull_high + OB_bull_low)/2

bearishOB = close[ob_period] > open[ob_period]


int downcandles = 0
for i = 1 to periods
downcandles := downcandles + (close[i] < open[i] ? 1 : 0)

OB_bear = bearishOB and (downcandles == (periods)) and relmove


OB_bear_high = OB_bear ? high[ob_period] : na
OB_bear_low = OB_bear ? usewicks ? low[ob_period] : open[ob_period] : na
OB_bear_avg = (OB_bear_low + OB_bear_high)/2

plotshape(OB_bull, title="Bullish OB", style=[Link], color=bullcolor,


textcolor=bullcolor, size=[Link], location=[Link], offset=-ob_period,
text="Bullish OB")
bull1 = plot(OB_bull_high, title="Bullish OB High", style=plot.style_linebr,
color=bullcolor, offset=-ob_period, linewidth=3)
bull2 = plot(OB_bull_low, title="Bullish OB Low", style=plot.style_linebr,
color=bullcolor, offset=-ob_period, linewidth=3)
fill(bull1, bull2, color=bullcolor, transp=0, title="Bullish OB fill")
plotshape(OB_bull_avg, title="Bullish OB Average", style=[Link],
color=bullcolor, size=[Link], location=[Link], offset=-ob_period)

plotshape(OB_bear, title="Bearish OB", style=[Link], color=bearcolor,


textcolor=bearcolor, size=[Link], location=[Link], offset=-ob_period,
text="Bearish OB")
bear1 = plot(OB_bear_low, title="Bearish OB Low", style=plot.style_linebr,
color=bearcolor, offset=-ob_period, linewidth=3)
bear2 = plot(OB_bear_high, title="Bearish OB High", style=plot.style_linebr,
color=bearcolor, offset=-ob_period, linewidth=3)
fill(bear1, bear2, color=bearcolor, transp=0, title="Bearish OB fill")
plotshape(OB_bear_avg, title="Bearish OB Average", style=[Link],
color=bearcolor, size=[Link], location=[Link], offset=-ob_period)

var line linebull1 = na


var line linebull2 = na
var line linebull3 = na
var line linebear1 = na
var line linebear2 = na
var line linebear3 = na

if OB_bull and showbull


[Link](linebull1)
linebull1 := [Link](x1=bar_index, y1=OB_bull_avg, x2=bar_index-1,
y2=OB_bull_avg, extend=[Link], color=bullcolor, style=line.style_solid, width=1)

[Link](linebull2)
linebull2 := [Link](x1=bar_index, y1=OB_bull_high, x2=bar_index-1,
y2=OB_bull_high, extend=[Link], color=bullcolor, style=line.style_dashed,
width=1)

[Link](linebull3)
linebull3 := [Link](x1=bar_index, y1=OB_bull_low, x2=bar_index-1,
y2=OB_bull_low, extend=[Link], color=bullcolor, style=line.style_dashed,
width=1)

if OB_bear and showbear


[Link](linebear1)
linebear1 := [Link](x1=bar_index, y1=OB_bear_avg, x2=bar_index-1,
y2=OB_bear_avg, extend=[Link], color=bearcolor, style=line.style_solid, width=1)

[Link](linebear2)
linebear2 := [Link](x1=bar_index, y1=OB_bear_high, x2=bar_index-1,
y2=OB_bear_high, extend=[Link], color=bearcolor, style=line.style_dashed,
width=1)

[Link](linebear3)
linebear3 := [Link](x1=bar_index, y1=OB_bear_low, x2=bar_index-1,
y2=OB_bear_low, extend=[Link], color=bearcolor, style=line.style_dashed,
width=1)

// Alerts for Order Blocks Detection


alertcondition(OB_bull, title='New Bullish OB detected', message='New Bullish OB
detected - This is NOT a BUY signal!')
alertcondition(OB_bear, title='New Bearish OB detected', message='New Bearish OB
detected - This is NOT a SELL signal!')

// Print latest Order Blocks in Data Window


var latest_bull_high = 0.0
var latest_bull_avg = 0.0
var latest_bull_low = 0.0
var latest_bear_high = 0.0
var latest_bear_avg = 0.0
var latest_bear_low = 0.0

if OB_bull_high > 0
latest_bull_high := OB_bull_high

if OB_bull_avg > 0
latest_bull_avg := OB_bull_avg

if OB_bull_low > 0
latest_bull_low := OB_bull_low

if OB_bear_high > 0
latest_bear_high := OB_bear_high

if OB_bear_avg > 0
latest_bear_avg := OB_bear_avg

if OB_bear_low > 0
latest_bear_low := OB_bear_low

plotchar(latest_bull_high, char=' ', location=[Link], color=#777777,


transp=100, size=[Link], title="Latest Bull High")
plotchar(latest_bull_avg, char=' ', location=[Link], color=#777777,
transp=100, size=[Link], title="Latest Bull Avg")
plotchar(latest_bull_low, char=' ', location=[Link], color=#777777,
transp=100, size=[Link], title="Latest Bull Low")
plotchar(latest_bear_high, char=' ', location=[Link], color=#777777,
transp=100, size=[Link], title="Latest Bear High")
plotchar(latest_bear_avg, char=' ', location=[Link], color=#777777,
transp=100, size=[Link], title="Latest Bear Avg")
plotchar(latest_bear_low, char=' ', location=[Link], color=#777777,
transp=100, size=[Link], title="Latest Bear Low")

// InfoPanel for latest Order Blocks


draw_InfoPanel(_text, _x, _y, font_size) =>
var label la_panel = na
[Link](la_panel)
la_panel := [Link](
x=_x, y=_y,
text=_text, xloc=xloc.bar_time, yloc=[Link],
color=[Link](#383838, 5), style=label.style_label_left,
textcolor=[Link], size=font_size)

info_panel_x = time_close + round(change(time) * 100)


info_panel_y = close

title = "LATEST ORDER BLOCKS"


row0 = "-----------------------------------------------------"
row1 = ' Bullish - High: ' + tostring(latest_bull_high, '#.##')
row2 = ' Bullish - Avg: ' + tostring(latest_bull_avg, '#.##')
row3 = ' Bullish - Low: ' + tostring(latest_bull_low, '#.##')
row4 = "-----------------------------------------------------"
row5 = ' Bearish - High: ' + tostring(latest_bear_high, '#.##')
row6 = ' Bearish - Avg: ' + tostring(latest_bear_avg, '#.##')
row7 = ' Bearish - Low: ' + tostring(latest_bear_low, '#.##')

panel_text = '\n' + title + '\n' + row0 + '\n' + row1 + '\n' + row2 + '\n' + row3 +
'\n' + row4 + '\n\n' + row5 + '\n' + row6 + '\n' + row7 + '\n'

if info_pan
draw_InfoPanel(panel_text, info_panel_x, info_panel_y, [Link])

// Tooltip and Documentation Label


chper = time - time[1]
chper := change(chper) > 0 ? chper[1] : chper

var vartooltip = "Indicator to help identifying institutional Order Blocks. Often


these blocks signal the beginning of a strong move, but there is a high probability,
that these prices will be revisited at a later point in time again and therefore are
interesting levels to place limit orders. \nBullish Order block is the last down
candle before a sequence of up candles. \nBearish Order Block is the last up candle
before a sequence of down candles. \nIn the settings the number of required
sequential candles can be adjusted. \nFurthermore a %-threshold can be entered which
the sequential move needs to achieve in order to validate a relevant Order Block. \
nChannels for the last Bullish/Bearish Block can be shown/hidden."

var label l_docu = na


[Link](l_docu)

if showdocu
l_docu := [Link](x=time + chper * 35, y=close, text="DOCU OB",
color=[Link], textcolor=[Link], style=label.style_label_center,
xloc=xloc.bar_time, yloc=[Link], size=[Link], textalign=text.align_left,
tooltip=vartooltip)

You might also like