title: how do i declare variables, compare them and then use them inside a function
body: <p>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.</p>
  
  <p>same for opposite side trades, i need to compare previous 2 lows and use the lower one as stop loss value.</p>
  
  <p>what i am doing is this:- </p>
  
  <pre><code>void onTick()
  {
    static int ticket=0;
  
    double ab=(//calculation for ab);
    double de=(//calculation for de); 
     if(Low[1]&lt;Low[2])
        double sll=Low[1];
     if(Low[1]&gt;Low[2])
        double sll=Low[2];
    if(buy logic comes here) 
    {
     double entryPrice=////////;
     double stoploss=sll-xyz;
     double takeprofit=entryPrice+((entryPrice-stoploss)*3);
     ticket = OrderSend(Symbol(),...entryPrice,stoploss,takeprofit,.....);
    }
      if(ticket == false)
           {
             Alert("Order Sending Failed");
           }
  }
  </code></pre>
  
  <p>the problem is i am not able to reference the values of sll and get an error message saying "sll undeclared identifier" </p>
  
  <p>i am fairly new to programming and would appreciate if someone can help me out with this.
  I have added most of the code for you to understand the logic.</p>