RISK MANAGEMENT
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © shakibsharifian

//@version=5
indicator("RISK MANAGEMENT",overlay=true)

roundDec(val,dec)=>
    ret=math.pow(10,-dec)*(int(val*math.pow(10,dec)))

vlinePrc(BarIndex, Color, LineStyle, LineWidth,prc1,prc2) => // Verticle Line, 54 lines maximum allowable per indicator
    barindx=bar_index+BarIndex
    _return = line.new(barindx, prc1, barindx, prc2, xloc.bar_index, extend.none, Color, LineStyle, LineWidth)

//
deci=input.int(5,title='ROUND to DECIMAL:',group='⌘ GENERAL',inline='a')
feebuyPer=input.float(0.07,title='Buying Fee (%):',group='⌘ GENERAL',inline='a')
feesellPer=input.float(0.07,title='Selling Fee (%):',group='⌘ GENERAL',inline='a')

Colblnc1=input.color(color.new(color.maroon,0),title='0% Line ',group='😐 0% LINE',inline='a')
Colblnc2=input.color(color.new(color.white,0),title='0% Line ',group='😐 0% LINE',inline='a')

bnft=input.float(2,title='BENEFIT (%):',group='💲💲💲 GOAL',inline='a')
Colbnft1=input.color(color.new(color.lime,0),title='GOAL Line' ,group='💲💲💲 GOAL',inline='b')
Colbnft2=input.color(color.new(color.yellow,0),title='GOAL Line',group='💲💲💲 GOAL',inline='b')

en1=input.bool(false,group='BUY ORDERS',inline='a')
en2=input.bool(false,group='BUY ORDERS',inline='b')
en3=input.bool(false,group='BUY ORDERS',inline='c')
en4=input.bool(false,group='BUY ORDERS',inline='d')
en5=input.bool(false,group='BUY ORDERS',inline='e')
en6=input.bool(false,group='BUY ORDERS',inline='f')
en7=input.bool(false,group='BUY ORDERS',inline='g')
en8=input.bool(false,group='BUY ORDERS',inline='h')
en9=input.bool(false,group='BUY ORDERS',inline='i')
en10=input.bool(false,group='BUY ORDERS',inline='j')
en11=input.bool(false,group='BUY ORDERS',inline='k')
en12=input.bool(false,group='BUY ORDERS',inline='l')

order1=input.float(0,title='Order 1:',group='BUY ORDERS',inline='a')
order2=input.float(0,title='Order 2:',group='BUY ORDERS',inline='b')
order3=input.float(0,title='Order 3:',group='BUY ORDERS',inline='c')
order4=input.float(0,title='Order 4:',group='BUY ORDERS',inline='d')
order5=input.float(0,title='Order 5:',group='BUY ORDERS',inline='e')
order6=input.float(0,title='Order 6:',group='BUY ORDERS',inline='f')
order7=input.float(0,title='Order 7:',group='BUY ORDERS',inline='g')
order8=input.float(0,title='Order 8:',group='BUY ORDERS',inline='h')
order9=input.float(0,title='Order 9:',group='BUY ORDERS',inline='i')
order10=input.float(0,title='Order 10:',group='BUY ORDERS',inline='j')
order11=input.float(0,title='Order 11:',group='BUY ORDERS',inline='k')
order12=input.float(0,title='Order 12:',group='BUY ORDERS',inline='l')

vol1=input.float(0,minval=0,title='VOLUME 1:',group='BUY ORDERS',inline='a')
vol2=input.float(0,minval=0,title='VOLUME 2:',group='BUY ORDERS',inline='b')
vol3=input.float(0,minval=0,title='VOLUME 3:',group='BUY ORDERS',inline='c')
vol4=input.float(0,minval=0,title='VOLUME 4:',group='BUY ORDERS',inline='d')
vol5=input.float(0,minval=0,title='VOLUME 5:',group='BUY ORDERS',inline='e')
vol6=input.float(0,minval=0,title='VOLUME 6:',group='BUY ORDERS',inline='f')
vol7=input.float(0,minval=0,title='VOLUME 7:',group='BUY ORDERS',inline='g')
vol8=input.float(0,minval=0,title='VOLUME 8:',group='BUY ORDERS',inline='h')
vol9=input.float(0,minval=0,title='VOLUME 9:',group='BUY ORDERS',inline='i')
vol10=input.float(0,minval=0,title='VOLUME 10:',group='BUY ORDERS',inline='j')
vol11=input.float(0,minval=0,title='VOLUME 11:',group='BUY ORDERS',inline='k')
vol12=input.float(0,minval=0,title='VOLUME 12:',group='BUY ORDERS',inline='l')


float ttlVol=0
ttlVol:=(en1 and order1>0?ttlVol+vol1:ttlVol)
ttlVol:=(en2 and order2>0?ttlVol+vol2:ttlVol)
ttlVol:=(en3 and order3>0?ttlVol+vol3:ttlVol)
ttlVol:=(en4 and order4>0?ttlVol+vol4:ttlVol)
ttlVol:=(en5 and order5>0?ttlVol+vol5:ttlVol)
ttlVol:=(en6 and order6>0?ttlVol+vol6:ttlVol)
ttlVol:=(en7 and order7>0?ttlVol+vol7:ttlVol)
ttlVol:=(en8 and order8>0?ttlVol+vol8:ttlVol)
ttlVol:=(en9 and order9>0?ttlVol+vol9:ttlVol)
ttlVol:=(en10 and order10>0?ttlVol+vol10:ttlVol)
ttlVol:=(en11 and order11>0?ttlVol+vol11:ttlVol)
ttlVol:=(en12 and order12>0?ttlVol+vol12:ttlVol)


plot(en1 and order1>0?  order1  :na,  color=bar_index%2==0 ? color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 1')
plot(en2 and order2>0?  order2  :na,  color=bar_index%3==0 ? color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 2')
plot(en3 and order3>0?  order3  :na,  color=bar_index%5==0 ? color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 3')
plot(en4 and order4>0?  order4  :na,  color=bar_index%7==0 ? color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 4')
plot(en5 and order5>0?  order5  :na,  color=bar_index%11==0 ?color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 5')
plot(en6 and order6>0?  order6  :na,  color=bar_index%13==0 ?color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 6')
plot(en7 and order7>0?  order7  :na,  color=bar_index%17==0 ?color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 7')
plot(en8 and order8>0?  order8  :na,  color=bar_index%19==0 ?color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 8')
plot(en9 and order9>0?  order9  :na,  color=bar_index%23==0 ?color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 9')
plot(en10 and order10>0?order10:na,color=bar_index%29==0 ?color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 10')
plot(en11 and order11>0?order11:na,color=bar_index%31==0 ?color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 11')
plot(en12 and order12>0?order12:na,color=bar_index%33==0 ?color.new(color.yellow,0):color.new(color.yellow,70),linewidth=1,title='ORDER 12')

buyPort=(1+(feebuyPer/100))
sellPort=(1+(feesellPer/100))
meanOrder=((vol1*buyPort*order1)+(vol2*buyPort*order2)+(vol3*buyPort*order3)+(vol4*buyPort*order4)+(vol5*buyPort*order5)+(vol6*buyPort*order6)+(vol7*buyPort*order7)+(vol8*buyPort*order8)+(vol9*buyPort*order9)+(vol10*buyPort*order10)+(vol11*buyPort*order11)+(vol12*buyPort*order12))/ttlVol
meanOrder:=meanOrder*(sellPort)
GoalOrder=meanOrder*(1+(bnft/100))

l1=plot(meanOrder,color=bar_index%2==1?Colblnc1:Colblnc2,linewidth=4,title='0% Line')
l2=plot(close,color=color.new(color.olive,100),linewidth=4,title='close Line')
l3=plot(GoalOrder,color=bar_index%2==0?Colbnft1:Colbnft2,linewidth=4,title='Goal Line')

fill(l1,l2,meanOrder<close?color.new(color.lime,90):color.new(color.maroon,90))

label0 = label.new(bar_index,meanOrder , text='😐 '+str.tostring(roundDec(meanOrder,deci)) ,size=size.normal,style=label.style_label_left,color=color.new(color.white,0))
label.delete(label0[1])
labelW = label.new(bar_index,GoalOrder , text='💲💲💲 '+str.tostring(roundDec(GoalOrder,deci)),size=size.normal,style=label.style_label_left,color=color.new(color.white,0))
label.delete(labelW[1])

diffPrc=vlinePrc(1, color.new(color.yellow,50) , line.style_dotted, 2,close,meanOrder)
line.delete(diffPrc[1])
labelS = label.new(bar_index+2,close+((meanOrder-close)/2) , text=(meanOrder<close?'🔺':'🔻')+str.tostring(roundDec(100*((-meanOrder+close)/meanOrder),1))+'%',size=size.normal,style=label.style_label_center,color=color.new(color.white,0))
label.delete(labelS[1])