Indicators cannot work together - page 2

 
Samuel Manoel De Souza #:
What about the indicator short name? if you are gonna add the same indicator twice on the chart you need make sure the shortname is different for different parâmeters.

Hi, Samuel. Sorry but I don't know what is a shortname. I named them differently but in a similar way. These are the names:

Trend-channel-1-xau-adaptive.mq5

Trend-channel-5-xau-adaptive.mq5

Trend-channel-15-xau-adaptive.mq5

Trend-channel-60-xau-adaptive.mq5

Trend-channel-240-xau-adaptive.mq5

Trend-channel-1440-xau-adaptive.mq5


Are they too similar?

 
Alain Verleyen #:

No. The issue comes from your code.

Hi, Alain. The weird thing is that the indicators work well alone but after a while one or two or them stop working if used together while in the tester everything is fine.
 
danerstizz #:
Hi, Alain. The weird thing is that the indicators work well alone but after a while one or two or them stop working if used together while in the tester everything is fine.

Sorry but 5 persons tried to help you and still you don't seem to understand you didn't provide enough details.

"Stop working" what that means exactly ? Provide screenshots or logs to show it.

It's a coding issue, provide the relevant source code, remove some logic from it if you don't want to share all.

Provide all details to understand your issue otherwise it's just a waste of time.

 

it's not a state secret. This is the code for the 15 minutes period. The others are the same, the only difference are the lines names, the time and iMA parameters and the internal variable names. There are many useless variables in it because I made a second version without cleaning.

//------------------------------------------------------------------
#property copyright "Daniele-Nerstini"
//------------------------------------------------------------------
#property indicator_chart_window
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
CPositionInfo Position;
CTrade Trade;
//
//
//
//
//

extern bool   SaveVolume = false; 
int fileHandle;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//

double middle_high;
double middle_low;
double pointb_middle;

double pointsb[100000];
double points_tried[100000];
double tried;
double nearest;
double nearest2;


string arr_up_above = "\x21A5"; 
string arr_down_below = "\x21A7";
string arr_up ="\x2191";
string arr_down ="\x2193";
string arr_hor = "\x21FF";

string arr_up_incr = "\x21C8";
string arr_down_incr = "\x21CA";
string arr_up_limit = "\x21C5";
string arr_down_limit = "\x21C5";



int minute_direction;

double new_pointa;
double new_pointb;
double new_pointc;

int counter3=0;

double middle_point;
int proj_middle;

double shift_value=5;
double old_pointb_M15;


int counter1;
int counter2;


datetime Time_new;
int direction=3;
int old_direction=3;
int rotation=3;
int exit=3;

int max_length=5;
int distance=15;


int range=5;


double bollM15a;
double bollM15c;
string str1;
string str3;
string str2;

int counter;

double middles;

double old_proj_pointb;

int points_counter;
int points_tried_counter;
int proj_point1=range + 2;
int trigger=range+2;
int proj_point2=proj_point1-range;
int proj_point4;
int proj_point5;

double old_start_pointb;
double old_end_pointb;

datetime Starts[100000];

double start_point_high;
double end_point_high;
double start_point_low;
double end_point_low;
double start_pointb1;

int point_found;

double start_pointa;
double start_pointb;
double start_pointc;

double boll15bshift;

int counter5;
int counter6;
double shift_sum;
int divisor;


double end_pointb;

double b1_M15;
double b3_M15;

int state_start;
int state_end;

double shifting;
double shifting2;
int timediff;
double proj_pointb;


double shift_high;
double shift_low;

double shift_high1;
double shift_low1;

double shift_high_middle;
double shift_low_middle;

double step_by5;
double step_by1;


datetime TimeStart;
datetime TimeEnd;

string handle1M15;
string handle2M15;

string handle2shift;
string str2shift;

string handle1shift;
string handle2M15shift;

string str1a;
string previous_str1a;

double lower_band[];
double upper_band[];
double middle_band[];





double boll15b1;

double boll15b;

string arrow_icon1="=";
string arrow_icon2="=";
string arrow_icon3="=";





int loops_M15=0;

 double spread;    
   double step;
   double proj;
   
   double pointb_M15;
   
   double start;


int preload;

void OnInit()
  {
  handle2M15=iMA(NULL,PERIOD_M1,15,0,MODE_SMMA,PRICE_MEDIAN);

handle1M15=iBands(NULL,PERIOD_M1,15,5,1.4,PRICE_OPEN);


  }

int OnCalculate(const int rates_total, const int prev_calculated, const datetime &Time[],
                const double &Open[], const double &High[], const double &Low[], const double &Close[],
                const long &TickVolume[], const long &Volume[], const int &Spread[])
{        




                  if(preload < 2)
                  {
                              loops_M15=0;
                             preload=preload+1;

                                       
                                       
                             counter=range+distance+5+15;
                              counter2=1;
                              for(counter; counter > 3; counter=counter-1)
                              {
                                         
           
                           Starts[counter2] = iTime(Symbol(), PERIOD_M1, counter);
                           counter2=counter2+1;
                           }
 
                                       
                                       
                                       counter=range+distance+15;
                                       points_counter=0;
                                       
                                       
                                       for(counter; counter > 1; counter=counter-1)
                                       {
                                       
                                       
                                handle2M15=iMA(NULL,PERIOD_M1,15,counter,MODE_SMA,PRICE_MEDIAN);
       
                                     
                                       
                                       ArraySetAsSeries(middle_band,true);
                                       CopyBuffer(handle2M15,0,0,LOWER_BAND,middle_band);
                                       str2=(middle_band[0]);
                                       
                                       
                                       
                                       boll15b = NormalizeDouble(str2,2);
                                       

                                       
                                       pointsb[points_counter]=boll15b;
                                       
                                       points_counter=(points_counter+1);
                                       
                      
                        
                              }
                              
                              
                              points_counter=points_counter-1;
                              
                                     
                              
          
   
                     points_counter=points_counter-1;

                           proj_point1=points_counter;
                           proj_point2=proj_point1-range;
                           
                          
               
            
              
                                  
            
         }



             //   Print(Starts[points_counter]+","+pointsb[points_counter]+","+points_counter);





//calculate bollinger 15 values



ArraySetAsSeries(middle_band,true);
CopyBuffer(handle2M15,0,0,LOWER_BAND,middle_band);
string str2=(middle_band[0]);



boll15b = NormalizeDouble(str2,2);



/// calculate shift from middle point for the channel






ArraySetAsSeries(lower_band,true);
CopyBuffer(handle1M15,2,0,2,lower_band);
str1=(lower_band[0]);

ArraySetAsSeries(upper_band,true);
CopyBuffer(handle1M15,1,0,2,upper_band);
str3=(upper_band[0]);



bollM15a = NormalizeDouble(str1,2);
bollM15c = NormalizeDouble(str3,2);


shift_value=(bollM15c - bollM15a)/2;
shift_value=NormalizeDouble(shift_value,2);



shifting=NormalizeDouble(shift_value,2);



if(boll15b1 != boll15b)
      {
         
           
         
         
    boll15b1=boll15b;     

   loops_M15=(loops_M15 +1);
         
   
   

pointb_M15 = NormalizeDouble(boll15b,2);




         
      Time_new = iTime(Symbol(), PERIOD_M1, 5);
     
      
         
               // check if the date is the same and overwrite
                  
                  if(Time_new == Starts[points_counter])
                  {
                    pointsb[points_counter]=pointb_M15;              
                  }   
                  else
                  { 
                     points_counter=points_counter+1;
                     pointsb[points_counter]=pointb_M15;  
                     Starts[points_counter]=Time_new;
                     }            
                    
         
     
     
proj_point1=points_counter;
proj_point2=proj_point1-range;
end_pointb=pointsb[proj_point1];
start_pointb=pointsb[proj_point2];





spread=MathAbs(start_pointb - end_pointb);    
 step_by1=(spread / range);
step_by1=NormalizeDouble(step_by1,2);
 step_by1=NormalizeDouble(((step_by1)*1),_Digits);          
 step_by5=(step_by1 * 5);
 step_by5=NormalizeDouble(step_by5,2); 


         
         /// determines the length of the channel
         
           
shift_high=end_pointb + shifting;
shift_high=NormalizeDouble(shift_high,2);

shift_low=end_pointb - shifting;
shift_low=NormalizeDouble(shift_low,2);  


shift_high1=shift_high;
shift_low1=shift_low;



      
      counter=proj_point1;
      
         
            if(end_pointb > start_pointb)
            {
         
         
               for(counter; counter > 2; counter=counter-1)
               { 
                 
                  
                  if(pointsb[counter] < shift_low1 || pointsb[counter] > shift_high1)
                  {max_length=(points_counter-counter-1); 
                  counter=1;
                  shift_high1=shift_high1+step_by1;
                  shift_low1=shift_low1+step_by1;}
                  
                  
                  shift_high1=shift_high1-step_by1;
                  shift_low1=shift_low1-step_by1;
                  
            
                  
                  
                  }
                  
   
              }    
                  
            
            if(pointsb[proj_point1] < pointsb[proj_point2])
            {
         
         
               for(counter; counter > 2; counter=counter-1)
               { 
                 
                  
                  if(pointsb[counter] < shift_low1 || pointsb[counter] > shift_high1)
                  {max_length=(points_counter-counter-1);
                   counter=1;
                   shift_high1=shift_high1-step_by1;
                   shift_low1=shift_low1-step_by1;}
                  
                  
                  shift_high1=shift_high1+step_by1;
                  shift_low1=shift_low1+step_by1;
                  }
                  
      
              }    
      
      
      



               
               
                 
    /////////////////////////              
         
           
           
           
       
         

       
        if(pointsb[proj_point1] < pointsb[proj_point2])
        {
            end_point_high=shift_high-(step_by1*7);
            end_point_low=shift_low-(step_by1*7);
            start_point_high=shift_high+(step_by1*max_length);
             start_point_low=shift_low+(step_by1*max_length);
          }
             
             if(pointsb[proj_point1] > pointsb[proj_point2])
        {
            end_point_high=shift_high+(step_by1*7);
            end_point_low=shift_low+(step_by1*7);
            start_point_high=shift_high-(step_by1*max_length);
             start_point_low=shift_low-(step_by1*max_length);
          }        
             
             
             
             
             start_point_high=NormalizeDouble(start_point_high,2);
              start_point_low=NormalizeDouble(start_point_low,2);
            
             
             end_point_high=NormalizeDouble(end_point_high,2);
              end_point_low=NormalizeDouble(end_point_low,2);
            
            TimeStart = iTime(Symbol(), PERIOD_M1,(max_length));
            TimeEnd = iTime(Symbol(), PERIOD_M1,0);

             
             
             
             
            

         
   
         
                      
                      ObjectDelete(0,"TrendChanM15A");
               ObjectSetInteger(0,"TrendChanM15A",OBJPROP_BACK,false);              
               ObjectCreate(0, "TrendChanM15A", OBJ_TREND, 0, TimeStart, start_point_high, TimeEnd, end_point_high);  
                        ObjectSetInteger(0,"TrendChanM15A",OBJPROP_STYLE, STYLE_SOLID);
              ObjectSetInteger(0,"TrendChanM15A",OBJPROP_COLOR, clrBlack);
              ObjectSetInteger(0,"TrendChanM15A",OBJPROP_WIDTH, 6);
              
                                 ObjectDelete(0,"TrendChanM15B");
               ObjectSetInteger(0,"TrendChanM15B",OBJPROP_BACK,false);              
               ObjectCreate(0, "TrendChanM15B", OBJ_TREND, 0, TimeStart, start_point_high, TimeEnd, end_point_high);  
                        ObjectSetInteger(0,"TrendChanM15BC",OBJPROP_STYLE, STYLE_DOT);
              ObjectSetInteger(0,"TrendChanM15B",OBJPROP_COLOR, clrYellow);
              ObjectSetInteger(0,"TrendChanM15B",OBJPROP_WIDTH, 2);
            
            
            
                              ObjectDelete(0,"TrendChanM15C");
               ObjectSetInteger(0,"TrendChanM15C",OBJPROP_BACK,false);              
               ObjectCreate(0, "TrendChanM15C", OBJ_TREND, 0, TimeStart, start_point_low, TimeEnd, end_point_low);  
                        ObjectSetInteger(0,"TrendChanM15C",OBJPROP_STYLE, STYLE_SOLID);
              ObjectSetInteger(0,"TrendChanM15C",OBJPROP_COLOR, clrBlack);
              ObjectSetInteger(0,"TrendChanM15C",OBJPROP_WIDTH, 6);
              
                                 ObjectDelete(0,"TrendChanM15D");
               ObjectSetInteger(0,"TrendChanM15D",OBJPROP_BACK,false);              
               ObjectCreate(0, "TrendChanM15D", OBJ_TREND, 0, TimeStart, start_point_low, TimeEnd, end_point_low);  
                        ObjectSetInteger(0,"TrendChanM15DC",OBJPROP_STYLE, STYLE_DOT);
              ObjectSetInteger(0,"TrendChanM15D",OBJPROP_COLOR, clrYellow);
              ObjectSetInteger(0,"TrendChanM15D",OBJPROP_WIDTH, 2);
                
            
            
            
    
            
            
            
         
                 
              
                 
                 
    }  
        
        
        
        
        
        
        
        
   return(0);
}

 

I've just discovered that changing profile and apply the indicators to a new chart everything start working again. Some kind of metatrader bug?

Indicators cannot work together
Indicators cannot work together
  • 2023.03.28
  • www.mql5.com
Hi everybody and a good day...
 
danerstizz #:
Hi, Carl. It means the lines on the screen stop moving because the iMA is not calculated anymore inside the code. I'm sure of that because I used  a Print line to watch the iMA progress.

It's because of your code! It could be that you have to many handles...

Expect that you have to learn how to do it before you can do it.

 
Carl Schreiber #:

It's because of your code! It could be that you have to many handles...

Expect that you have to learn how to do it before you can do it.

You're right Carl, I'm not an expert, only trying to learn. As an update I can say changing profile and chart didn't work.

But I've just tried to calculate the most long lines in a different way.

Instead of calculating every iMA and Bands handle on the 1 minute time frame I'm using the 5 minute for the four hours line and the 15 minute for the daily line.

It seems everything working fine for the moment.

 
danerstizz #:

Hi, Samuel. Sorry but I don't know what is a shortname. I named them differently but in a similar way. These are the names:

Trend-channel-1-xau-adaptive.mq5

Trend-channel-5-xau-adaptive.mq5

Trend-channel-15-xau-adaptive.mq5

Trend-channel-60-xau-adaptive.mq5

Trend-channel-240-xau-adaptive.mq5

Trend-channel-1440-xau-adaptive.mq5


Are they too similar?

Oh, you were able to reply before i delete that. i deleted because doesn't seem to be the case.

Anyway you can learn about that reading the documentation.

https://www.mql5.com/en/docs/standardlibrary/cchart/cchartindicatorname

https://www.mql5.com/en/docs/constants/indicatorconstants/customindicatorproperties#enum_customind_property_string

Documentation on MQL5: Standard Library / Price Charts / IndicatorName
Documentation on MQL5: Standard Library / Price Charts / IndicatorName
  • www.mql5.com
IndicatorName(int,int) - Price Charts - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Samuel Manoel De Souza #:

Oh, you were able to reply before i delete that. i deleted because doesn't seem to be the case.

Anyway you can learn about that reading the documentation.

https://www.mql5.com/en/docs/standardlibrary/cchart/cchartindicatorname

https://www.mql5.com/en/docs/constants/indicatorconstants/customindicatorproperties#enum_customind_property_string

thanks
 

Thanks very much for all your answers. I would like to add that I was able to solve the problem using less handles on the 1 minute timeframe and instead, for the long cycles, using the 5 minute timeframe.

From my limited experience I would say I had too much handles using the iMA and iBands functions on the 1 minute timeframe. Apparently there is a limit  when using handles on the same timeframe. what do you think?

Reason: