Download MetaTrader 5

calculate indicator value in expert

To add comments, please log in or register
Shay Matityahu
235
Shay Matityahu  
Hi

I'm trying to manipulate an indicator value,
For example:

if (a=(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)) {
   int b=a-3

}

 

The problem is that a returns true and not the value of the indicator (75).
how to get the value of the indicator ?

I know I can try:  if (a=(iRSI(NULL,0,14,PRICE_CLOSE,0)>75-3)) but it is not good to me because it is returns true when indicator reaches 72 and I need the indicator value.

Please help

Thanks in advance

 Shay 



honest_knave
Moderator
2326
honest_knave  
if (a=(iRSI(NULL,0,14,PRICE_CLOSE,0)>75))

iRSI will either be above 75, or below.

True or false.

1 or 0

Shay Matityahu:
 
The problem is that a returns true and not the value of the indicator (75).
how to get the value of the indicator ?

 In MQL4 (are you using MQL4?):

   double a = iRSI(NULL,0,14,PRICE_CLOSE,0);


 

whroeder1
15925
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. Don't write code like that.
    It could be interpreted as assign to a the RSI value, then test the value.
    if (a=(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)) {
       int b=a-3
    }

    What it actually does (per the parentheses) is compare the RSI to 75 and then assign the result (0 or 1) to a and then test a.

    Since a is 0 or 1, b makes no sense.

    if (a=(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)) {
       int b=a-3
    }

    Make it obvious.

    Code becomes self-documenting when you use meaningful variable names, A and b say nothing. You should be able to read the code out loud and have it make sense. "Aye is greater than 75" doesn't, "current RSI is over bought," does.

    #define OVER_BOUGHT 75
    double currentRSI = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
    if(currentRSI > OVER_BOUGHT){
       int b=a-3
    }

  3. Why did you post MT4 code in the MT5 forum (Automated Trading and Strategy Testing Forum / Expert Advisors and Automated Trading - MQL5 programming forum) instead of the MT4 forum (Automated Trading and Strategy Testing Forum / MQL4 and MetaTrader 4 - MQL4 programming forum)?
Shay Matityahu
235
Shay Matityahu  

Hi 

Thanks for the quick response
Yes, I am using MQL4, and I am sorry I posted in MT5 I did not pay attention.

Thanks to you now I did get the numeric value of the indicator.
What I'm trying to do is to close order when the RSI crosses the 75 but drops back to 72
So I tried the following:

 

 

#define OVER_BOUGHT 75
double currentRSI = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
if(currentRSI > OVER_BOUGHT){
   if(CloseBuyOrder=75-3){
      OrderClose(order_id,1,Ask,3,Red);
   }
}


The problem is that the order is closed immediately when the indicator reaches 72 and before it reaches 75.

Any idea?

Thanks in advance

Shay


stanislass
89
stanislass  
You must go back in time iRSI with shift in a While loop until you find> 75 before <72.
Roberto Jacobs
48495
Roberto Jacobs  
Shay Matityahu:

Hi 

Thanks for the quick response
Yes, I am using MQL4, and I am sorry I posted in MT5 I did not pay attention.

Thanks to you now I did get the numeric value of the indicator.
What I'm trying to do is to close order when the RSI crosses the 75 but drops back to 72
So I tried the following:

 

 

#define OVER_BOUGHT 75
double currentRSI = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
if(currentRSI > OVER_BOUGHT){
   if(CloseSellOrder=75-3){
      OrderClose(order_id,1,Ask,3,Red);
   }
}


The problem is that the order is closed immediately when the indicator reaches 72 and before it reaches 75.

Any idea?

Thanks in advance

Shay


If you define the over_bought = 75, why do you subtract the value of 75 with 3, what do you mean with a value of 3.
it should be if the RS! > over_bought CloseSellOrder
honest_knave
Moderator
2326
honest_knave  
#define OVER_BOUGHT 75
static bool was_OB = false;
double currentRSI = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
if(currentRSI > OVER_BOUGHT) was_OB = true;
else if(was_OB && currentRSI < OVER_BOUGHT-3) OrderClose(order_id,1,Ask,3,Red);

Just remember to reset the value of was_OB to false when you open an order

Shay Matityahu
235
Shay Matityahu  

Hi All

Thank you very much for your help

 Regards

 Shay 


To add comments, please log in or register