Questions from Beginners MQL5 MT5 MetaTrader 5 - page 544

 
Vitalii Ananev:
You have to set the level yourself in the indicator settings manually. By default there is no level 50. I showed in the picture above.

I did so, but it's not reflected. I must have misunderstood again(

extern double RSI          = 10;
extern double RSI_uroven_1 = 70;
extern double RSI_uroven_2 = 30;
extern double RSI_uroven_3 = 50;
extern double Lots         = 0.01;
extern int    Slip         = 30;
extern int    Magic        = 125;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int kolpos=0;
   double rsi=0,uroven70=70,uroven30=30,uroven50=50;
   rsi=iRSI(Symbol(),0,10,PRICE_CLOSE,1);
   for(int pos=0; pos<OrdersTotal(); pos++) 
     {
      OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
         kolpos++;
     }
   if(kolpos==0)
     {
      if (rsi>uroven70) 
         OrderSend(Symbol(),OP_BUY,Lots,Ask,30,0,0,"",Magic,0,clrGreen);
      if (rsi<uroven30) 
         OrderSend(Symbol(),OP_SELL,Lots,Bid,30,0,0,"",Magic,0,clrRed);
     }
 }
 
Vitalii Ananev:

RSI is an oscillator, it does not show a trend.

Add another trend indicator e.g. MA

I understand what you're saying, but I'm getting confused without a muwing.

The main thing for me is to have a logically and technically correct algorithm.

I will just open: below 30 - Sell, above 70 - Buy.

 
edutak:

I understand what you're saying, but I'm still without a muving - I get confused.

The main thing for me is to make a logically and technically correct algorithm

I will just open: below 30 - Sell, above 70 - Buy.

Then do it better if rsi crosses 50 from bottom to top - Buy, from top to bottom - Sell.

void OnTick()
  {
   int kolpos=0;
   double rsi=0,uroven70=70,uroven30=30,uroven50=50;
   rsi=iRSI(Symbol(),0,10,PRICE_CLOSE,1);
   rsi2=iRSI(Symbol(),0,10,PRICE_CLOSE,2);
   for(int pos=0; pos<OrdersTotal(); pos++) 
     {
      OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
         kolpos++;
     }
   if(kolpos==0)
     {
      if (rsi>=uroven50 && rsi2<uroven50) 
         OrderSend(Symbol(),OP_BUY,Lots,Ask,30,0,0,"",Magic,0,clrGreen);
      if (rsi<=uroven50 && rsi2>uroven50) 
         OrderSend(Symbol(),OP_SELL,Lots,Bid,30,0,0,"",Magic,0,clrRed);
     }
 }
 

I did that. Right?

extern double RSI          = 10;
extern double RSI_uroven_1 = 70;
extern double RSI_uroven_2 = 30;
extern double RSI_uroven_3 = 50;
extern double Lots         = 0.01;
extern int    Slip         = 30;
extern int    Magic        = 125;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int kolpos=0;
   double rsi=0,uroven70=RSI_uroven_1,uroven30=RSI_uroven_2,uroven50=RSI_uroven_3;
   rsi=iRSI(Symbol(),0,10,PRICE_CLOSE,1);
   for(int pos=0; pos<OrdersTotal(); pos++) 
     {
      OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
         kolpos++;
     }
   if(kolpos==0)
     {
      if (rsi>RSI_uroven_1) 
         OrderSend(Symbol(),OP_BUY,Lots,Ask,30,0,0,"",Magic,0,clrGreen);
      if (rsi<RSI_uroven_2) 
         OrderSend(Symbol(),OP_SELL,Lots,Bid,30,0,0,"",Magic,0,clrRed);
     }
 }
 
Vitalii Ananev:

Then do it better if the rsi crosses 50 from bottom to top buy, top to bottom sell.

No, I have a different idea.
 
edutak:

I did that. Right?

No logical errors.

...

uroven70=RSI_uroven_1,uroven30=RSI_uroven_2,uroven50=RSI_uroven_3;

This entry would then be superfluous.

 
Vitalii Ananev:

No logical errors.

...

This entry would then be redundant.

Thank you, I'll redo it then and move on.
 
edutak:
Thank you, I'll redo it then and move on.
You're welcome. Good luck with that.
 
Wait, how do you take it to external settings then?
 
edutak:
Wait, then how do you put it in the external settings?

What to put in the external settings?

If you are referring to the settings for the levels to be optimised and changed by the user, you already have them in place.

extern double RSI_uroven_1 = 70;
extern double RSI_uroven_2 = 30;
extern double RSI_uroven_3 = 50;
Reason: