But not getting with success because i'm thinking that when rsi is out of condition of string, the string will have a new value.
Strange way to do it, why not use a bool instead of a string?
Any way, you are declaring the variable locally so it will be lost every tick.
string r="pos0";
Declare it as a static variable and remember to reset it if/when necessary
static string r="pos0";
RSI is unlikely to ever equal 69
if(r=="pos1" && rsi==69)
Maybe
if(r=="pos1" && rsi<=69)
I will move this to the MQL4/MT4 section
if(r=="pos1" && rsi==69){
- r equals "pos1" only if rsi >= 72. Therefor your test will never be true. If r was static
(or global) then you would be testing if it went above 72 and then back down below 69.
- Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum - Don't use strings when you mean a bool or an enum.
Strange way to do it, why not use a bool instead of a string?
Any way, you are declaring the variable locally so it will be lost every tick.
Declare it as a static variable and remember to reset it if/when necessary
RSI is unlikely to ever equal 69
Maybe
I will move this to the MQL4/MT4 section
Thanks for the Reply Keith. I think that i can't use bool because will have more 2 positions, will have pos0 (between 30 and 70), pos1 (above 70), pos2(above 75), pos3(above 80), pos 4(when rsi below 69 and pos is diferent from pos1 or pos0).
I runned this code and worked Keith!!!!!
Really thank you for your tip!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm developing a code(on MQL4) that when RSI is on vaue 72, he store on a string like "position 1". And i want to open a order when rsi has an different value but also string has position 1.
For eg. IF RSI is 72, x = "position 1".
if rsi is 69 and x = "position 1", open order.
But not getting with success because i'm thinking that when rsi is out of condition of string, the string will have a new value.
Here is the code: