Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 318

 

Good afternoon. Help me deal with a strange problem.

The point is: I am writing a multitime indicator, i.e. an indicator, which, being open at any time, will calculate and give signals for all other times as well.

The basis of the indicator is RSI.

In init() when switching the timeframe, a separate array is put in correspondence of the indicator line. For each of them the line is displayed, when you are at this or that time, but the calculations for other times are not going on (function iRSI is stupidly chasing zeros in the calculation). I.e. the current time is calculated, but other times are not.

I am pasting the code:

#property indicator_separate_window
#property indicator_minimum 20
#property indicator_maximum 80

#property indicator_level1 20          // уровень RSI
#property indicator_level2 42          // уровень RSI
#property indicator_level3 50          // уровень RSI
#property indicator_level4 58          // уровень RSI
#property indicator_level5 80          // уровень RSI

#property indicator_levelcolor White   // цвет уровней 

#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2           // толщина RSI

//--- buffers
double   RSI_M1[];               // буферы под RSI
double   RSI_M5[];
double   RSI_M15[];
double   RSI_M30[];
double   RSI_H1[];
double   RSI_H4[];
double   RSI_D1[];
double   RSI_W1[];
double   RSI_MN[];

int         RSI_per           = 12;                // период RSI
int         RSIPriceType      =  PRICE_CLOSE;      // покакой цене считать RSI
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
//---- indicators
   IndicatorShortName("test");
   
   switch(Period()) {
      case PERIOD_M1:
          SetIndexBuffer(0, RSI_M1);
          break;
      case PERIOD_M5:
          SetIndexBuffer(0, RSI_M5);
          break;
      case PERIOD_M15:
          SetIndexBuffer(0, RSI_M15);
          break;
      case PERIOD_M30:
          SetIndexBuffer(0, RSI_M30);
          break;
      case PERIOD_H1:
          SetIndexBuffer(0, RSI_H1);
          break;
      case PERIOD_H4:
          SetIndexBuffer(0, RSI_H4);
          break;
      case PERIOD_D1:
          SetIndexBuffer(0, RSI_D1);
          break;
      case PERIOD_W1:
          SetIndexBuffer(0, RSI_W1);
          break;
      case PERIOD_MN1:
          SetIndexBuffer(0, RSI_MN);
          break;
   }   
   
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexLabel(0,"RSI(" + RSI_per + ")");
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int   shift, _Bars;
   static int  _counted_bars_W1 = 0,
               _counted_bars_D1 = 0;
   //--------------------------------------------------------------------
   _Bars = iBars(NULL, PERIOD_W1);
   shift = _Bars - _counted_bars_W1 - 1;   // Индекс первого непосчитанного
   _counted_bars_W1 = _Bars - 1;
   
   while(shift >= 0) {                // Цикл по непосчитанным барам
      RSI_W1[shift]       = iRSI(NULL, PERIOD_W1, RSI_per, RSIPriceType, shift);
      Print(RSI_W1[shift]);
      shift--;
   }
   //------------------------------------------
   _Bars = iBars(NULL, PERIOD_D1);
   shift = _Bars - _counted_bars_D1 - 1;   // Индекс первого непосчитанного
   _counted_bars_D1 = _Bars - 1;
   
   while(shift >= 0) {                // Цикл по непосчитанным барам
      RSI_D1[shift]       = iRSI(NULL, PERIOD_D1, RSI_per, RSIPriceType, shift);
      shift--;
   }
   //------------------------------------------   
   return(0);
  }
//+------------------------------------------------------------------+

What is interesting, if we leave only one array for the indicator line and calculate only W1 at any time, everything is calculated and drawn correctly at any(!) time.
What's the trick? It is impossible to take different arrays for the indicator line during initialization, depending on the time?

 
satorifx:

Good afternoon. Help me to deal with a strange problem.

The point is: I am writing a multitime indicator, i.e. an indicator, which, being open at any time, will perform calculations and give signals for all other times as well.

The basis of the indicator is RSI.

In init() when switching the timeframe, a separate array is put in correspondence of the indicator line. For each of them the line is displayed, when you are at this or that time, but the calculations for other times are not going on (function iRSI is stupidly chasing zeros in the calculation). I.e. the current time is calculated, but other times are not.

I am pasting the code:

What is interesting, if we leave only one array for the indicator line and calculate only W1 at any time, everything is calculated and drawn correctly at any(!) time.
What's the trick? It is impossible to take different arrays for the indicator line during initialization, depending on the time?

Only W1 and D1 are read! What do you want? Finish it for the others!
 
borilunad:
Only W1 and D1 are read! What do you want? Finish it for the others!

That's not the point. I have given calculations only for D1 and W1, so that the code is not too long. Note: on every tick on every timeframe, calculated values of W1 are printed. So, if any time is opened except W1, zeros are printed. If it works for W1, it will work for others.
 
satorifx:

That's not the point. I have given calculations only for D1 and W1, so as not to make the code too long. Please note: on every tick on any timeframe the calculated values of W1 are printed. So, if any time is opened except W1, zeros are printed. If it works for W1, it will work for all others.
Right! We have to open the weekly chart to show it on other charts!
 
borilunad:
Correct! To show on other charts, you have to open the weekly chart as well!


To be honest, I did not understand this statement.
And there is no need to show anything else. If you run the code, you will see that it already shows what I want: on D1 it shows chart RSI D1 and on W1 - chart RSI W1, but at the same time, if D1 is open, then RSI for W1 are all zero, and if W1 is open, then the calculations for D1 are zero. The question is why this is the case and how to fix it.

 

The problem is that the index array initializes and resizes itself to the right size.
So when I open D1 - RSI_D1[] becomes indexed, and everything is OK with it, but other arrays remain in embryonic state.
I tried it this way: I declared all arrays this way:

double   RSI_W1[]    =  {0};
I changed the switch in init() like this:
      case PERIOD_D1:
          SetIndexBuffer(0, RSI_D1);
          ArrayResize(RSI_W1, iBars(NULL, PERIOD_W1));
          break;

However, on ArrayResize GetLastError gives an error:

EURUSD,Daily: cannot resize the array

EURUSD,Daily: some array error

Anyway, who can tell me how to solve this problem?

 
satorifx:

The problem is that the index array initializes and resizes itself to the right size.
So when I open D1 - RSI_D1[] becomes indexed, and everything is OK with it, but other arrays remain in embryonic state.
I tried it this way: I declared all arrays this way:

I changed the switch in init() like this:

However, on ArrayResize GetLastError gives an error:

EURUSD,Daily: cannot resize the array

EURUSD,Daily: some array error

Anyway, who can tell me how to solve this problem?

If the array is dynamic, make sure that when you write values into it, you increase the size of the array to accommodate the new data. ArrayResize()
 
artmedia70:
If the array is dynamic, be sure to increase the size of the array to accommodate the new data when you write values to it. ArrayResize()

I wrote about it above:
But ArrayResize GetLastError gives an error:

EURUSD,Daily: cannot resize the array

EURUSD,Daily: some array error
 
satorifx:
This is what I wrote about above:
However on ArrayResize GetLastError gives an error:

EURUSD,Daily: cannot resize the array

EURUSD,Daily: some array error
satorifx:


To be honest, I didn't understand that statement.
And there is no need to show anything else. If you run my code, you will see that it already shows everything that is needed: RSI D1 shows chart on D1 and RSI W1 on W1, but at the same time, if D1 is open, then RSI for W1 are all zero, and if W1 is open, then RSI for D1 are all zero. The question is why this is the case and how to fix it.

Because the buffer is alone and shows one by one on your call!

#property indicator_buffers 1
Do you really think I have nothing better to do than to download your "codes" and test them? I'm helping you with advice. And if something's wrong, it's all up there for you! Or was laziness born before you?!
 

Hi all. Help me to limit placing pending stop orders with the same price. I need a function which when a new pending order price is detected tries out the existing ones, and if they are not set, puts them, if they are - exit. In case the program is functional, the fee is MUST be paid.