Download MetaTrader 5

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

To add comments, please log in or register
MQL5 Reference is available in 8 languages. Learn MQL5 in the language that suits you best!
Mohit Marwaha
600
Mohit Marwaha 2015.04.05 09:38 

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

Aleksei Beliakov
23960
Aleksei Beliakov 2015.04.05 12:54  

double sll;

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

      sll=Low[1];

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

      sll=Low[2];

if(buy logic comes here) 

{

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

}

To add comments, please log in or register