WAMASAMA/Intraday SL
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © avsr90

//@version=5


indicator(title="WAMASAMA",shorttitle="WASA",precision=2,overlay=false,max_bars_back=5000)


//Moving averages 

Moving_Average1=ta.ema(close,9)
Moving_Average2=ta.ema(close,21)
Moving_Average3=ta.ema(close,50)


//Wama and Sama 

wama1=Moving_Average1-Moving_Average2
sama1=Moving_Average2-Moving_Average1
wama11=wama1-sama1
wama2=Moving_Average2-Moving_Average3
sama2=Moving_Average3-Moving_Average2
wama22=wama2-sama2
WA_MA=(wama11+wama22)
SA_MA=(wama11-wama22)

//Upentry and Dnentry
Up_entry=ta.crossover(WA_MA,SA_MA)
Dn_entry=ta.crossunder(WA_MA,SA_MA)


plot(WA_MA,color=(WA_MA>WA_MA[1] ?color.green:color.red),style=plot.style_columns,title="WAMA")
plotshape(Up_entry,title="Upentry",color=color.green,text="U",textcolor=color.green,style=shape.arrowup,location=
  location.bottom, size=size.normal)
plotshape(Dn_entry,title="Dnentry",color=color.red,text="D",textcolor=color.red,style=shape.arrowdown,location=
 location.top, size=size.normal)




//intraday Stop Loss Calxulations

Res=input.timeframe(defval="D",title="resolution")
[Open_Price,Last_Price,OPCL_Dif]= request.security(syminfo.tickerid ,Res,[close[1],close,close-close[1]],barmerge.gaps_off, barmerge.lookahead_on) 


Ch_Open= ta.change(Open_Price)
Length=int(math.max(1, nz(ta.barssince(Ch_Open)) + 1))

Op=math.round_to_mintick(Open_Price)
Cl=math.round_to_mintick(Last_Price)
Dif=math.round_to_mintick(Last_Price-Open_Price)

//Table

BT = 0
TW = 0
TH=0


TL = input.string("bottom_center", title='Select Table Position',options=["top_left","top_center","top_right",
   "middle_left","middle_center","middle_right","bottom_left","bottom_center","bottom_right"] , 
  tooltip="Default location is at bottom_center")
  
TS = input.string("Auto", title='Select Table Text Size',options=["Auto","Huge","Large","Normal","Small",
  "Tiny"] , tooltip="Default Text Size is Auto")


assignedposition = switch TL
    "top_left" => position.top_left
    "top_center" => position.top_center
    "top_right" => position.top_right
    "middle_left" => position.middle_left
    "middle_center" => position.middle_center
    "middle_right" => position.middle_right
    "bottom_left" => position.bottom_left
    "bottom_center" => position.bottom_center
    "bottom_right" => position.bottom_right

celltextsize = switch TS
    "Auto" => size.auto
    "Huge" => size.huge
    "Large" => size.large
    "Normal" => size.normal
    "Small" => size.small
    "Tiny" => size.tiny
    
    
var table i = table.new (TL,6, 6, color.yellow,border_width=BT)

if barstate.islast

    table.cell(i, 1, 1, "Open ",text_size=celltextsize,width=TW,height=TH,bgcolor=color.green)
    table.cell(i, 2, 1, "Close ",text_size=celltextsize,width=TW,height=TH,bgcolor=color.green)
    table.cell(i, 3, 1, "Op-Cl ",text_size=celltextsize,width=TW,height=TH,bgcolor=color.green)
        
    table.cell(i, 1, 2, str.tostring(Op) ,text_size=celltextsize, width=TW,height=TH)
    table.cell(i, 2, 2, str.tostring(Cl) ,text_size=celltextsize, width=TW,height=TH,text_color=Last_Price>Last_Price[1] ?
     color.green:color.red)
    table.cell(i, 3, 2, str.tostring(Dif) ,text_size=celltextsize, width=TW,height=TH,text_color=OPCL_Dif>0?color.green:color.red)




