[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 326

 

I'm not a fan of indicators, but I decided to check one thing. The Expert Advisor should buy at the price of the upper RSI indicator and sell at the price of the lower one, respectively. Only if the price is already above the upper boundary of the RSI indicator, then buy should be above this boundary and below the value of this boundary + some value of indent from the boundary upwards (in the code I specified just a number 0.1), for sales, on the contrary.

I did it like this:

External parameters:

extern string ___H1 = " __________ Параметры RSI _________ ";
extern int     i_RSITF = 5,
               i_RSIPeriod = 21,
               i_RSIApplied = PRICE_CLOSE;
extern double  i_RSIToUpLimit = 55,                                     // Верхняя граница RSI
               i_RSIToDnLimit = 45;                                     // Нижняя граница RSI

Code of the function receiving the signal and the RSI value itself:(0.1 here is the margin tolerance for the range of buying or selling)

//+-------------------------------------------------------------------------------------+
//| Получаем RSI с заданными параметрами                                                |
//+-------------------------------------------------------------------------------------+
double GetRSI(int RSIIndex)
{
   return (iRSI(NULL, i_RSITF, i_RSIPeriod, i_RSIApplied, RSIIndex));
}
//+-------------------------------------------------------------------------------------+
//| Получаем общий торговый сигнал                                                      |
//+-------------------------------------------------------------------------------------+
int GetGeneralSignal()
{
   if (FindOrders() > 0)
       return (SIGNAL_NO);

 //  if (GetRSI(PRICE_CLOSE, 0) > GetRSI(PRICE_CLOSE, 1))
   if (GetRSI(0) > i_RSIToUpLimit)
      if (GetRSI(0) < (i_RSIToUpLimit + 0.1))
         return (SIGNAL_BUY);                  // Запускаем функцию открытия покупки
           
   if (GetRSI(0) < i_RSIToDnLimit)
      if (GetRSI(0) > (i_RSIToDnLimit - 0.1))
         return (SIGNAL_SELL);                // Запускаем функцию открытия продаж
   
   return (SIGNAL_NO);
}

Sometimes the EA opens orders from the very level, sometimes much higher (for buying) and sometimes much lower (for selling). Why? The algorithm is elementary.

 
Hi all. I have a question. I got myself a copier /**/, good and handy thing when working with several accounts. But the problem is that when you run any other program (video, game, just maps) in parallel, there is a constant crackling noise coming out of the speakers. Is it possible to eliminate the problem (rattle)? Thanks in advance.
 

I am trying to write a simple indicator based on RSI (the analogue is RandomIndicatorSignals mq4).

I am trying to write a simple indicator based on RSI (for the analogue of this indicator RandomIndicatorSignals.mq4 from the article MQL4 Language for Dummies. Custom Indicators (Part 1)(https://www.mql5.com/ru/articles/1500).

The idea is simple, if RSI draws a top or a trough, it draws an arrow on the chart.

It seems to be ok, but in my opinion RSI value buffer for each candle is not filled, because of this it doesn't work. Here is the code.

//+------------------------------------------------------------------+
//|                                                    RSI+Arrow.mq4 |
//|                                                         _______ |
//|                                                    |
//+------------------------------------------------------------------+
#property copyright "_______"
#property link      "_________"


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Crimson
#property indicator_color2 RoyalBlue
//---- input parameters
extern int       barsToProcess=500;
//---- buffers
double ExtMapBuffer1[],
       ExtMapBuffer2[],
       RSIBuffer3[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(3);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,236);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,238);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer (2,RSIBuffer3);
   // для информации о значениях буфера
   SetIndexLabel  (2,"RSIBuffer3");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {    
   //расчет индикатора на последних барах 
   int limit,i;
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   if(limit>barsToProcess)
   limit=barsToProcess;
   
   //заполняем буфер RSI значениями 
   for(i=0; i<limit; i++)
   if(i>=1)
     {
       RSIBuffer3[i]=iRSI(0,0,8,PRICE_CLOSE,0);
     }       
  //проводим сравнения                        
   for(i=0; i<limit; i++)
   if(i>=1)
        
        {
        if(RSIBuffer3[i+2]-RSIBuffer3[i+1]>0 && RSIBuffer3[i+1]-RSIBuffer3[i]>0) // условия выставления стрелки 

        /* так тоже не работает
        if(RSIBuffer3[i+2]>=RSIBuffer3[i+1] && RSIBuffer3[i+1]<=RSIBuffer3[i])
        */
        
        ExtMapBuffer2[i]=Low[i]-5*Point;
                    
        else
           
        ExtMapBuffer2[i]=0.0;
               
        if(RSIBuffer3[i+2]-RSIBuffer3[i+1]<0 && RSIBuffer3[i+1]-RSIBuffer3[i]<0) // условия выставления стрелки
        
        /* так тоже не работает
        if(RSIBuffer3[i+2]<=RSIBuffer3[i+1] && RSIBuffer3[i+1]>=RSIBuffer3[i])
        */
              
        ExtMapBuffer1[i]=High[i]+5*Point;
           
        else      
           
        ExtMapBuffer1[i]=0.0;           
        }
                   
   return(0);
   }
        
//+------------------------------------------------------------------+      
 
Merincool:

I am trying to write a simple indicator based on RSI (the analogue is RandomIndicatorSignals mq4).

I am trying to write a simple indicator based on RSI (for the analogue of this indicator RandomIndicatorSignals.mq4 from the article MQL4 Language for Dummies. Custom Indicators (Part 1)(https://www.mql5.com/ru/articles/1500).

The idea is simple, if RSI draws a top or a trough, it draws an arrow on the chart.

It seems to be ok, but in my opinion RSI value buffer for each candle is not filled, because of this it doesn't work. Here is the code.

You are accessing uncalculated indicator values in loop.

Change

for(i=0; i<limit; i++)

to

for(i=limit-1; i>=0; i--)
 
PapaYozh:

You are cycling back to the uncalculated indicator values.

Change

to


Thank you, it gave me an idea! However, I would like to understand the "physical meaning":) as our physicist used to say

I have a problem myself: 2 "slightly" different, but essentially the same action codes: Delete ALL pending orders

1) Does not work properly - only one order is deleted

void start()

  {

   bool   result;     int    cmd,total,OT;

   total=OrdersTotal();

   for(int i=0; i<total; i++)

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         cmd=OrderType();    OT=OrderTicket();

         if(cmd>1)   // !=OP_BUY && cmd!=OP_SELL)

           {

            result=OrderDelete(OT);

           }

        }

     } //end FOR

  }

2) It works fine - deletes all of them

void start()
{
    string msg="Удалить все отложенные ордера?    ";
//   if (MessageBox(msg,title,MB_YESNO|MB_ICONQUESTION)!=IDYES) return;

   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if (OrderType()>1) OrderDelete(OrderTicket());
   }
}

Please explain: the meaning of "in this loop, you access the uncalculated values of the indicator".

 
PapaYozh:

You are cycling back to the uncalculated indicator values.

Change

to


Can you spell it out? Why is that? So I don't make any more mistakes in the future.
 
PapaYozh:

You are cycling back to the uncalculated indicator values.

Change

to


still not working, RSIBuffer3 only shows the RSI value on the last bar when hovering over a bar
 
Merincool:

And it still doesn't work, RSIBuffer3 only shows the RSI value on the last bar when hovering over the bar

Your 5th parameter is 0 - i.e. the last bar!

make it like this:

       RSIBuffer3[i]=iRSI(0,0,8,PRICE_CLOSE,i);  

Excerpt from doc:

double iRSI( string symbol, int timeframe, int period, int applied_price, int shift)
Calculates the Relative strength index and returns its value.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
period - Number of periods for calculation.
applied_price - Applied price. It can be any of Applied price enumeration values.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
 
PapaYozh:

You are cycling back to the uncalculated indicator values.

Change

to


And what I also thought, according to your logic the tool should calculate RSI from limit and to 0 bar, but does it make a difference which side should calculate RSI from the end or from the beginning? It should calculate RSI for each bar in a given range and put the value into a buffer (I mean in an array), and then just compare three consecutive values in an array with each other. Or is it not?

 
amurik61:

Your 5th parameter is 0 - i.e. the last bar!

make it like this:

Excerpt from doc:

double iRSI( string symbol, int timeframe, int period, int applied_price, int shift)
Calculates the Relative strength index and returns its value.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
period - Number of periods for calculation.
applied_price - Applied price. It can be any of Applied price enumeration values.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of time ago).

I'll give it a try, thanks