Trade with RVI at zero line

 

Hi,

does anyone have any idea how I can better write the condition for OrderSend()?

If the main line from RVI indicator falls down of zero line. Go short.

If the line goes up thrue the zero line. Go long.


i have this:

extern string
  RVIsettings="------------Relative Vigor I. Settings";
extern int        RVIperiod=6;            // Period Open Order
extern double     RVIopenbuy=0.03;        // buy over ...
extern double     RVIopensell=-0.03;      // sell under ...

extern string
  MAsettings="------------MA Settings";
extern int        SMAperiod=12;
extern int        LWMAperiod=1;


   double sig_rvi_0, sig_rvi_1, sig_sma, sig_lwma;


   sig_rvi_0=iRVI(NULL,0,RVIperiod,MODE_MAIN,0);
   sig_rvi_1=iRVI(NULL,0,RVIperiod,MODE_SIGNAL,1);
   sig_sma=iMA(NULL,0,SMAperiod,0,MODE_EMA,PRICE_OPEN,0);
   sig_lwma=iMA(NULL,0,LWMAperiod,0,MODE_LWMA,PRICE_LOW,0);

//---- sell conditions
   if((sig_rvi_0<sig_rvi_1)<=RVIopensell && sig_lwma<sig_sma)  
     {
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Point*StopLoss,Bid-TakeProfit*Point,Comentsell,MagicNumber,0,Red);
      TimeBar=Time[0];
      return;
     }
//---- buy conditions
   if((sig_rvi_0>RVIopenbuy)>=RVIopenbuy && sig_sma>sig_lwma)  
     {
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Point*StopLoss,Ask+TakeProfit*Point,Comentbuy,MagicNumber,0,Blue);
      TimeBar=Time[0];
      return;
     }


picture from RVI: red=short, green=long

i can't write:

if((sig_rvi_0>RVIopenbuy)==RVIopenbuy && sig_sma>sig_lwma) 

and i have profit, but the signal is not at zero line!

pls help

 

In some programming languages (most of the ones I've come across, which is only a few), ints can be treated as booleans. For example, the number 1 could either indicate the integer '1', or the boolean value true. 0 could be '0' or false. In the majority of those that allow this awesome feature, any integer other than 0 can be treated as true. Obviously, this works the other way around. In other word, these languages could treat the boolean variable x = true as the integer 1. I'm not quite sure if this is how it works with MQL4 specifically, but I have a strong feeling it is. Knowing that, you should be able to figure out your problem.

 

I learn these functions. I am a newcomer. It makes me crazy if I do not knows.

Do you have a code sample?

 

I don't want to give you the answer directly, 'cause that's not fun. ;) I'll supply you with some sample statements and the corresponding output to help with my other post.

Alert(5<10); //outputs 1
Alert(5>10); //outputs 0
Alert((5<10)>=1); //outputs 1
Alert((5<10)==1); //outputs 1
Alert((5>10)==0); //outputs 1

Specifically, note the format similarities between the above last 3 statements, and the first half of your OrderSend conditions. Good luck and happy coding.

 

my advice is to make the statements clear, even if the code gets a few lines longer. thats the first thing beginners should lern. do not try to start coding with chained if() statements.

start with building a very clear program, statement after statement. if after if. so the code gets better readable.

btw: don't like the behavior of mql in this case. bool-int comparison, could be a very hard to find bug. compiler should at least give a warning...

 
Goldron: did you solve your problem yet?
 
zzuegg:

my advice is to make the statements clear, even if the code gets a few lines longer. thats the first thing beginners should lern. do not try to start coding with chained if() statements.

start with building a very clear program, statement after statement. if after if. so the code gets better readable.

btw: don't like the behavior of mql in this case. bool-int comparison, could be a very hard to find bug. compiler should at least give a warning...

Totally agree with you, zzuegg. As written, the code tries to compare a bool with a double. I think it should be...

if((sig_rvi_0-sig_rvi_1)<=RVIopensell && sig_lwma<sig_sma) 
Reason: