[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 279

 

Something is wrong with my function returning the value of elements of the same array. I will describe everything in order regarding this issue.

The global variables are:

extern int i_TF = 0;
int g_maPeriod[3] = {6, 25, 150, 250},             // Периоды обрабатываемых МА
    g_singMa[3] = {1,2,3,4};                     // признаки машек, добавляемые к основному мэйджику

// Идентификаторы сигналов
#define SIGNAL_BUY           0                                 // Сигнал на покупку
#define SIGNAL_SELL          1                                 // Сигнал на продажу
#define SIGNAL_NO           -1                                 // Сигнала нет

#define CROSS_UP             0                                 // Признак нахождения быстрой средней
                                                               // ..над медленной
#define CROSS_DN             1                                // Признак нахождения медленной..
                                                               // ..средней над быстрой
#define CROSS_NO            -1                                 // Признак равенства двух средних
int crossDir[3];

Functions used in this calculation:

//+-------------------------------------------------------------------------------------+
//| Получение значений МА на двух соседних барах                                        |
//+-------------------------------------------------------------------------------------+
double GetCurAndPrevMA(int maPeriod, double& prevMA)
{
   prevMA = iMA(NULL, i_TF, maPeriod, 0, MODE_EMA, MODE_CLOSE, 1);
   return (iMA(NULL, i_TF, maPeriod, 0, MODE_EMA, MODE_CLOSE, 0));
}
//+-------------------------------------------------------------------------------------+
//| Получение положения машек между собой                                               |
//+-------------------------------------------------------------------------------------+
void GetStateMa(int& crossDir[])
{
   double ema365_1;
   double ema365_0 = GetCurAndPrevMA(365, ema365_1);

   Print("g_maPeriod[0] = ", g_maPeriod[0]);
   Print("g_maPeriod[1] = ", g_maPeriod[1]);
   Print("g_maPeriod[2] = ", g_maPeriod[2]);
   Print("g_maPeriod[3] = ", g_maPeriod[3]);
   
   for (int i=0; i<4; i++)
   {
      double ema1;
      double ema0 = GetCurAndPrevMA(g_maPeriod[i], ema1);

      crossDir[i] = CROSS_NO;

      Print("ema1 < 365_1 ", ema1 ," < ", ema365_1);
      if (ema1 < ema365_1 && ema0 > ema365_0)
      {
         Print("ema1 < 365_1 ", ema1 ," < ", ema365_1);
         crossDir[i] = CROSS_UP;
      }
      if (ema1 > ema365_1 && ema0 < ema365_0)
      {
         Print("ema1 > 365_1 ", ema1 ," > ", ema365_1);
         crossDir[i] = CROSS_DN;
      }
   }
}

I additionally print the value of array items returned by theGetStateMa(int& crossDir[]) function:

   Print("crossDir[0] = ", crossDir[0]);
   Print("crossDir[1] = ", crossDir[1]);
   Print("crossDir[2] = ", crossDir[2]);
   Print("crossDir[3] = ", crossDir[3]);

This is what is returned:

2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: crossDir[3] = 0
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: crossDir[2] = -1
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: crossDir[1] = -1
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: crossDir[0] = -1
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: open #1 buy 0.10 EURUSD at 1.29654 ok
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: ema1 < 365_1 1.3129 < 1.3225
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: ema1 < 365_1 1.3017 < 1.3225
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: ema1 < 365_1 1.2886 < 1.3225
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: ema1 < 365_1 1.2916 < 1.3225
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: g_maPeriod[3] = 250
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: g_maPeriod[2] = 150
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: g_maPeriod[1] = 25
2013.04.11 15:08:48     2009.01.25 23:46  Base150_New EURUSD,H1: g_maPeriod[0] = 6

The values of the array elementscrossDir[] are returned are different, although they should all be with value 1.

This can be seen from the unsetting of expressions comparing Mach 4 periods and 365 periods. Can you tell me why the values are returned incorrectly?

 
Ekburg:


Thanks for being specific, because the link I was sent didn't have these arrays in it, and I didn't pay attention to the column on the left because I was at work.

but no one will swallow everything you spit up but you ;)


How did you learn, if at all, from hints? Only active and inquisitive self-study will bear fruit! I've chewed you up and you're "spitting back" on sound advice! Get a babysitter to clean up your mess!
 
Good evening all, I have indicator B built from indicator A (via iCustom) .Both indicators are on the chart.When I change the parameters of indicator A , indicator B does not automatically rebuild, it needs to be recompiled forcibly! Why won't indicator B automatically rebuild? Please advise what my mistake is?
 
MK07:
Good evening all, I have indicator B built from indicator A (through iCustom) . Both indicators are on the chart. When I change indicator A' s parameters, indicator B doesn't automatically rebuild, I need to recompile it forcibly. Why isn't indicator B rebuilt automatically? Please tell me my mistake?
You call indicator A (via iCustom) with some specific settings that are INDEPENDENT from the settings of indicator A. It means that the terminal simultaneously calculates two independent copies of indicator A. The indicator that is called from the outside (from another code) is calculated virtually by the terminal.
 
TarasBY:
You call indicator A (via iCustom) with certain settings, which do NOT depend on the settings of indicator A. It means that the terminal simultaneously calculates two independent copies of indicator A.

And what should be done to make the terminal calculate the second variant of the indicator A?
 
MK07:
What should be done to make the terminal calculate the second version of indicator A?
Be more specific about the task.
 
borilunad:

How did you learn, if you learned, from the prompts? Only active and inquisitive self-study will bear fruit! I've chewed you up and you're spitting out sound advice! Get a babysitter to clean up your mess!

moderate your ego! I do not bounce back from that advice, I took it and thanked you, but I do not take it that way! I asked and answered in a civilized manner!
 

Hello!

The value of the Point variable needs to be used in the EA.

But it is equal to 0.

As far as I understand, this is because of the 5 digits after the decimal point in the quote.

Is there any way to determine this value?

Thank you.

 
TarasBY:
Please make your task clearer.

Indicator A - normal AO (My_AO) - top one in the picture.

Indicator B-histogram(+1/-1) of AO indicator (My_AO) - middle one in the figure.

When you change the parameters of indicator A (the bottom one in the picture), indicator B does not change even if you recompile.

I showed two AO indicators (My_AO) at the same time just to illustrate what happens with the indicators, but in real conditions there should be one AO (My_AO).



The first code is indicator A.

Second code- indicator B.

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Black
#property  indicator_color2  Green
#property  indicator_color3  Red
#property  indicator_width2  2
#property  indicator_width3  2
#property  indicator_level1 0.0

//---- input parameters
extern int FastPeriod =5;
extern int LowPeriod  =34;
//---- indicator buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,34);
   SetIndexDrawBegin(1,34);
   SetIndexDrawBegin(2,34);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("My_AO");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
      
  
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current;
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd
   for(int i=0; i<limit; i++)
      ExtBuffer0[i]=iMA(NULL,0,FastPeriod,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,LowPeriod,0,MODE_SMA,PRICE_MEDIAN,i);
//---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=ExtBuffer0[i];
      prev=ExtBuffer0[i+1];
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         ExtBuffer2[i]=current;
         ExtBuffer1[i]=0.0;
        }
      else
        {
         ExtBuffer1[i]=current;
         ExtBuffer2[i]=0.0;
        }
        
       
     }
//---- done
   return(0);
  }
#property indicator_separate_window
#property indicator_minimum -1.5
#property indicator_maximum 1.5
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
#property  indicator_width1  2
#property  indicator_width2  2
#property indicator_level1 0.0

//--- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {  
      
       
    double UP,DN;     
  
  
    int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;
//----
   for(int i=0;i<limit;i++)
       
      { 
        UP=iCustom(NULL,0,"My_AO",1,i+1);               
        DN=iCustom(NULL,0,"My_AO",2,i+1);    
             
        
       if(UP>0)       
         {ExtMapBuffer1[i+1]=1;
          ExtMapBuffer2[i+1]=0;
         }
         
       if(UP<0)       
         {ExtMapBuffer1[i+1]=-1;
          ExtMapBuffer2[i+1]=0;
         }  
         
                              
       if(DN>0)            
         {
          ExtMapBuffer1[i+1]=0;
          ExtMapBuffer2[i+1]=1;
         }
              
       if(DN<0)            
         {
          ExtMapBuffer1[i+1]=0;
          ExtMapBuffer2[i+1]=-1;
         }
               
                       
    
    }
//----
   return(0);
 
   }
   
//+------------------------------------------------------------------+    
   
        
        
 
MK07:

Indicator A - normal AO indicator (My_AO) - top one in the figure.

Indicator B - histogram(+1/-1) of AO indicator (My_AO) - middle in the figure.

If you change the parameters of indicator A (bottom in the figure), indicator B does not change even if you recompile.

The two AO indicators (My_AO) at the same time I have shown just to illustrate what happens with the indicators, but in real life there should be one AO (My_AO).

The first code is indicator A.

The second code is indicator B.

And this order of things is normal (these are the principles of the terminal).

If you want to change the parameters of indicator A, make the exchange of information between indicators (may be a file, global variables of the terminal, RAM): indicator A passes the initializable parameters during initialization and indicator B periodically checks the changes of indicator A. When it detects changes, indicator B also should be initialized with the new parameters (forced init()).

Reason: