Margin Zones[kryptodude]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4
study(title="Margin Zones[kryptodude]", shorttitle="MultiZones", overlay=true)

margin0 = 0
tickCost0 = 0
max0 = 0
min0 = 0
NumberOfDaysAgo=input(defval=1,type=input.integer, minval=0,title="Number of Days Ago")
ShwU = input(defval=true, type=input.bool, title="ShowZonesUp")
ShwD = input(defval=true, type=input.bool, title="ShowZonesDwn")

Show_25 =input(defval=true, type=input.bool, title="＋25      ", inline = "2")
Show_50 =input(defval=true, type=input.bool, title="＋50      ", inline = "2")
Show_100=input(defval=true, type=input.bool, title="＋100", inline = "2")
Show25 = input(defval=true, type=input.bool, title="－25      ", inline = "3")
Show50 = input(defval=true, type=input.bool, title="－50      ", inline = "3")
Show100= input(defval=true, type=input.bool, title="－100", inline = "3")

ticker1 = input(type=input.symbol, defval = "", title = "#1")
margin1 = input(defval=0.0,type=input.float, title="Margin")
tickCost1 = input(defval=0.0,type=input.float,  title="Tick cost")
max1 = input(defval=0.0,type=input.float, title="Price max")
min1 = input(defval=0.0,type=input.float, title="Price min")

ticker2 = input(type=input.symbol, defval = "", title = "#2")
margin2 = input(defval=0.0,type=input.float, title="Margin")
tickCost2 = input(defval=0.0,type=input.float,  title="Tick cost")
max2 = input(defval=0.0,type=input.float, title="Price max")
min2 = input(defval=0.0,type=input.float, title="Price min")

ticker3 = input(type=input.symbol, defval = "", title = "#3")
margin3 = input(defval=0.0,type=input.float, title="Margin")
tickCost3 = input(defval=0.0,type=input.float,  title="Tick cost")
max3 = input(defval=0.0,type=input.float, title="Price max")
min3 = input(defval=0.0,type=input.float, title="Price min")

ticker4 = input(type=input.symbol, defval = "", title = "#4")
margin4 = input(defval=0.0,type=input.float, title="Margin")
tickCost4 = input(defval=0.0,type=input.float,  title="Tick cost")
max4 = input(defval=0.0,type=input.float, title="Price max")
min4 = input(defval=0.0,type=input.float, title="Price min")

ticker5 = input(type=input.symbol, defval = "", title = "#5")
margin5 = input(defval=0.0,type=input.float, title="Margin")
tickCost5 = input(defval=0.0,type=input.float,  title="Tick cost")
max5 = input(defval=0.0,type=input.float, title="Price max")
min5 = input(defval=0.0,type=input.float, title="Price min")

cur_ticker=syminfo.prefix+":"+syminfo.ticker

id = iff(cur_ticker==ticker1, 1, iff(cur_ticker==ticker2, 2, iff(cur_ticker==ticker3,3, iff(cur_ticker==ticker4,4, iff(cur_ticker==ticker5,5,0)))))

isMached = id==0 ? false: true

margin = iff(id==1, margin1, iff(id==2, margin2, iff(id==3,margin3, iff(id==4,margin4, iff(id==5,margin5, margin0)))))
tickCost = iff(id==1, tickCost1, iff(id==2, tickCost2, iff(id==3,tickCost3, iff(id==4,tickCost4, iff(id==5,tickCost5, tickCost0)))))
max = iff(id==1, max1, iff(id==2, max2, iff(id==3,max3, iff(id==4,max4, iff(id==5,max5, max0)))))
min = iff(id==1, min1, iff(id==2, min2, iff(id==3,min3, iff(id==4,min4, iff(id==5,min5, min0)))))


DaysAgo(t) => floor(timenow/1000/60/60/24)-floor(time_close/1000/60/60/24)<=t?floor(timenow/1000/60/60/24)-floor(time_close/1000/60/60/24):0
DateNow = floor(timenow/1000/60/60/24)
DateStart=(DateNow-NumberOfDaysAgo-DaysAgo(2))*1000*60*60*24
ShowAgo=(time>DateStart)?true:false

//calculation of margin zones
pMarg = margin / tickCost 
//100
m100_1Up = min + pMarg * 0.95
m100_2Up = min + pMarg * 1.05
m100_1Dwn = max - pMarg * 0.95
m100_2Dwn =  max - pMarg * 1.05
//50
m50_1Up = min + pMarg / 2 * 0.95
m50_2Up = min + pMarg  / 2 * 1.05
m50_1Dwn = max - pMarg / 2 * 0.95
m50_2Dwn = max - pMarg  / 2 * 1.05
//25
m25_1Up = min + pMarg / 4 * 0.95
m25_2Up = min + pMarg  / 4 * 1.05
m25_1Dwn = max - pMarg / 4 * 0.95
m25_2Dwn = max - pMarg  / 4 * 1.05

//the coordinates of the lines for the labels.
l100 = (m100_1Up + m100_2Up) / 2
l101 = (m100_1Dwn + m100_2Dwn) / 2
l50 = (m50_1Up + m50_2Up) / 2
l51 = (m50_1Dwn + m50_2Dwn) / 2
l25 = (m25_1Up + m25_2Up) / 2
l251 = (m25_1Dwn + m25_2Dwn) / 2
linelabel = l100 and l101 and l50 and l51 and l25 and l251, color = #00000000, linewidth=1

                         //display of margin zones
//zones up
//+100
line100Up1 = plot(ShowAgo and ShwU and Show_100?m100_1Up:na, color = #FF0000, title="+100_1up")
line100Up2 = plot(ShowAgo and ShwU and Show_100?m100_2Up:na, color = #FF0000, title="+100_2up")
fill(line100Up1, line100Up2, color = #FF0000, transp=90, title="+100")
var label100Up = label.new(x=0,y=l100[0],
   text="                 +100",color = #00000000, style=label.style_label_center, size=size.normal)
label.set_xloc(Show_100 and ShwU?label100Up:na, time, xloc.bar_time)
label.set_textcolor(id=label100Up, textcolor = #FF0000)

//+50
line50Up1 = plot(ShowAgo and ShwU and Show_50?m50_1Up:na, color = #FF0000, title="+50_1up")
line50Up2 = plot(ShowAgo and ShwU and Show_50?m50_2Up:na, color = #FF0000, title="+50_2up")
fill(line50Up1, line50Up2, color = #FF0000, transp=90, title="+50")
var label50Up = label.new(x=0,y=l50[0],
   text="                 +50",color = #00000000, style=label.style_label_center, size=size.normal)
label.set_xloc(Show_50 and ShwU?label50Up:na, time, xloc.bar_time)
label.set_textcolor(id=label50Up, textcolor = #FF0000)

//+25
line25Up1 = plot(ShowAgo and ShwU and Show_25?m25_1Up:na, color = #FF0000, title="+25_1up")
line25Up2 = plot(ShowAgo and ShwU and Show_25?m25_2Up:na, color = #FF0000, title="+25_2up")
fill(line25Up1, line25Up2, color = #FF0000, transp=90, title="+25")
var label25Up = label.new(x=0,y=l25[0],
   text="                 +25",color = #00000000, style=label.style_label_center, size=size.normal)
label.set_xloc(Show_25 and ShwU?label25Up:na, time, xloc.bar_time)
label.set_textcolor(id=label25Up, textcolor = #FF0000)

//zones dwn
//-100
line100Dwn1 = plot(ShowAgo and ShwD and Show100?m100_1Dwn:na, color = #00FF00, title="-100_1Dwn")
line100Dwn2 = plot(ShowAgo and ShwD and Show100?m100_2Dwn:na, color = #00FF00, title="-100_2Dwn")
fill(line100Dwn1, line100Dwn2, color = #00FF00, transp=90, title="-100")
var label100Dwn = label.new(x=0,y=l101[0],
   text="                 -100",color = #00000000, style=label.style_label_center, size=size.normal)
label.set_xloc(Show100 and ShwD?label100Dwn:na, time, xloc.bar_time)
label.set_textcolor(id=label100Dwn, textcolor = #00FF00)

//-50
line50Dwn1 = plot(ShowAgo and ShwD and Show50?m50_1Dwn:na, color = #00FF00, title="-50_1Dwn")
line50Dwn2 = plot(ShowAgo and ShwD and Show50?m50_2Dwn:na, color = #00FF00, title="-50_2Dwn")
fill(line50Dwn1, line50Dwn2, color = #00FF00, transp=90, title="-50")
var label50Dwn = label.new(x=0,y=l51[0],
   text="                 -50",color = #00000000, style=label.style_label_center, size=size.normal)
label.set_xloc(Show50 and ShwD?label50Dwn:na, time, xloc.bar_time)
label.set_textcolor(id=label50Dwn, textcolor = #00FF00)

//-25
line25Dwn1 = plot(ShowAgo and ShwD and Show25?m25_1Dwn:na, color = #00FF00, title="-25_1Dwn")
line25Dwn2 = plot(ShowAgo and ShwD and Show25?m25_2Dwn:na, color = #00FF00, title="-25_2Dwn")
fill(line25Dwn1, line25Dwn2, color = #00FF00, transp=90, title="-25")
var label25Dwn = label.new(x=0,y=l251[0],
   text="                 -25",color = #00000000, style=label.style_label_center, size=size.normal)
label.set_xloc(Show25 and ShwD?label25Dwn:na, time, xloc.bar_time)
label.set_textcolor(id=label25Dwn, textcolor = #00FF00)



