You are on page 1of 2

//@version=4

study("Patternz", overlay=true)
risk=input(2, title="Risk per Trade %")
capital=input(100000, title="Capital per Trade")

signalB=(((high<high[1] and low>low[1] and high[1]<max(high[2],high[3]) and


low[1]>min(low[2],low[3]) )))
signalA=((high<high[3] and high[1]<high[3] and high[2]<high[3] and low>low[3] and
low[1]>low[3] and low[2]>low[3]))
signalC = ((((high<high[1] and low>low[1] and high[1]<max(high[2],high[3]) and
low[1]>min(low[2],low[3]) ))) ) or (((high<high[3] and high[1]<high[3] and
high[2]<high[3] and low>low[3] and low[1]>low[3] and low[2]>low[3])))
rf=1.5*atr(4)

SignalcloseC=valuewhen(signalC,close,0)

factorsC=valuewhen(signalC,rf,0)

risk1=risk/100
//capital=100000
stop=factorsC
Size=((risk1*capital)/stop)

signalplus=SignalcloseC+factorsC
signalminus=SignalcloseC-factorsC
signalExit = 2 * (signalplus - SignalcloseC) + signalplus
signalExitS = signalminus - 2 * (SignalcloseC - signalminus)

plot(signalplus,color=color.blue)
plot(SignalcloseC,color=color.black)
plot(signalminus,color=color.red)
plot(signalExit, color=color.aqua, linewidth=2)
plot(signalExitS, color=color.lime, linewidth=2)

plotchar(signalA==true, color=color.yellow, text="C", textcolor=color.black)


plotchar(signalB==true, color=color.blue, text="A", textcolor=color.black)

var line ul=na


if signalB==true or signalA==true
ul:=line.new(bar_index,high, bar_index[3],high[3], color=color.black, width=2)
else
ul:=na

var line bl=na


if signalB==true or signalA==true
bl:=line.new(bar_index, low, bar_index[3], low[3], color=color.black, width=2)
else
bl:=na

// 3. Determine long trading conditions


enterLong = crossover(close, signalplus) and
barssince(signalA == true or signalB == true) <= 6

exitLong = crossover(close, signalExit) or low <= SignalcloseC

// 4. Code short trading conditions


enterShort = crossunder(close, signalminus) and
barssince(signalA == true or signalB == true) <= 6

exitShort = crossunder(close, signalExitS) or high >= SignalcloseC

plotshape(enterLong==true, location=location.belowbar, text="Long",


textcolor=color.black, style=shape.arrowup, size=size.small, color=color.green)
plotshape(enterShort==true, location=location.abovebar, text="Short",
textcolor=color.black, style=shape.arrowdown, size=size.small, color=color.red)

labelText =
"========================" +
"\n" +
"Position Calculator " +
"\n" +
"========================" +
"\n" + "\n" +
"Long Entry : " + tostring(int(signalplus)) +
"\n" + "\n" +
"Short Entry : " + tostring(int(signalminus)) +
"\n" + "\n" +
"Long Exit : " + tostring(int(signalExit)) +
"\n" + "\n" +
"Short Exit : " + tostring(int(signalExitS)) +
"\n" + "\n" +
"=> Stop Loss : " + tostring(int(SignalcloseC)) +
"\n" + "\n" +
"=> Position : " + tostring(int(Size))

var label _label = label.new(


x=na,
y=na,
text="",
textalign=text.align_left,
textcolor=color.white,
color=#1235ad,
style=label.style_label_left,
size=size.normal,
xloc = xloc.bar_time,
yloc = yloc.price
)

label.set_text(_label, labelText)
//label.set_xy(_label, timenow + round(change(time)*30), high)
label.set_xy(_label, time_close, high)

You might also like