Download MetaTrader 5

Evaluate int at specific bars

To add comments, please log in or register
Move from theory to practice. Code Base will help you!
nicolasphilipp
7
nicolasphilipp 2015.09.03 13:47 

Hi,

Im new to metatrader and have a question about syntax. I have created a variable int uRSI_b, that will assume the values 0 or 1 depending on the RSI value on my chart. I want this variable to work like a switch, where it turns to 1 if the RSI-value goes above a certain value. However, I want it to stay at 1 even if the RSI-value goes back below this value, and only set back to 0 once I've entered a trade. I was therefore thinking I'd wanted to make uRSI_b dependant on the barcount, so that I can write something along the lines of

if(iRSI>75) uRSI_b(current bar) = 1; else uRSI_b(current bar)=uRSI_b(previous bar)

is this possible?


otherwise, if I don't initiate the integer when I declare it, if iRSI goes above 75 and I have only written:

if(iRSI>75) uRSI_b = 1;

what will be the value of uRSI_b at the next bar if iRSI goes below 75? will it stay at 1?


Thank you!

Alain Verleyen
Moderator
30721
Alain Verleyen 2015.09.03 21:56  
nicolasphilipp:

Hi,

Im new to metatrader and have a question about syntax. I have created a variable int uRSI_b, that will assume the values 0 or 1 depending on the RSI value on my chart. I want this variable to work like a switch, where it turns to 1 if the RSI-value goes above a certain value. However, I want it to stay at 1 even if the RSI-value goes back below this value, and only set back to 0 once I've entered a trade. I was therefore thinking I'd wanted to make uRSI_b dependant on the barcount, so that I can write something along the lines of

if(iRSI>75) uRSI_b(current bar) = 1; else uRSI_b(current bar)=uRSI_b(previous bar)

is this possible?


otherwise, if I don't initiate the integer when I declare it, if iRSI goes above 75 and I have only written:

if(iRSI>75) uRSI_b = 1;

what will be the value of uRSI_b at the next bar if iRSI goes below 75? will it stay at 1?


Thank you!

It depends how your variable is declared (globally or locally) and initialized.
To add comments, please log in or register