how do i declare variables and then use them inside a function

 

hi guys,

i am developing an ea that requires me to compare the high of previous 2 bars and whichever one is higher, use that as a stop loss value.

same for opposite side trades, i need to compare previous 2 lows and use the lower one as stop loss value.

what i am doing is this:- 

if(Low[1]<Low[2])

      double sll=Low[1];

   if(Low[1]>Low[2])

      double sll=Low[2];

if(buy logic comes here) 

{

 OrderSend = ..........

the problem is i am not able to reference the values of sll and get an error message saying "sll undeclared identifier" 

 

i am fairly new to programming and would appreciate if someone can help me out with this

 

double sll;

if(Low[1]<Low[2])

      sll=Low[1];

   if(Low[1]>Low[2])

      sll=Low[2];

if(buy logic comes here) 

{

 OrderSend = ..........

}