How to get the value of multiple time frame of an indicator calculating with iMAOnArray

 

Hello ;

you know when we use the function iMA( string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift), there is way to know the value of all time frame, but in applied price, we must use they are constants .

but I would like to show the trend of this indicator . I simplify the code . for example :

             for(int i=0; i<limit; i++)
    {
             ExtMapBuffer1[i] = (Open[i]-Low[i]);
             ExtMapBuffer4[i] = (High[i]-Open[i]);

    }

   

       for( i=0; i<limit; i++)
    {
        
         
         ExtMapBuffer5[i] = iMAOnArray(ExtMapBuffer1,0,period1,0,MODE_EMA,i);
         
          ExtMapBuffer6[i] = iMAOnArray(ExtMapBuffer4,0,period1,0,MODE_EMA,i);
          
         
         
                  
    }

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

             ExtMapBuffer2[i] =   ExtMapBuffer5[i]-  ExtMapBuffer6[i] ;
    }

here I want just to get and show in the same chart the value of ExtMapBuffer2[i] for all multiple Time frame (M1-M5-M15....)

thanks

 
Write another indicator that gets ExtMapBuffer2 for all time frames using iCustom.
 

Hello WHRoeder ;

thank you so much, it makes easy my work, I search info about iCustom and it s very helpful .

I Would like to create objects basing on this indicator and I suppose that I can proces like this jus a simple code to exmplain

// for example in my indicator personnal I write that where there is ExtMapBuffer2
    SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);

// in the new code indicator we can do 

// for example for M5 

double M5 = iCustom(NULL,5, "My_indicator",1,0);// here line index 1 review  SetIndexBuffer

if it is like this, my question is how to attach that (M5) to an object for example a Text via createObject because we need only Price and data Time on the parameters for ??

thanks

 
ludo31:

Hello WHRoeder ;

thank you so much, it makes easy my work, I search info about iCustom and it s very helpful .

I Would like to create objects basing on this indicator and I suppose that I can proces like this jus a simple code to exmplain

if it is like this, my question is how to attach that (M5) to an object for example a Text via createObject because we need only Price and data Time on the parameters for ??

thanks

After creating the object, try . .

ObjectSetText("name", DoubleToStr(M5,Digits), 12 );
 

Hello ;

my real problem is the way to create a Text without know the value of parameters . I mean for example when we create a Horizontal line for example we know the coordinate

 for(int i = 0; i < obj_total; i++)
     {
     
       name = ObjectName(i);
       
       if(ObjectType(name) == OBJ_RECTANGLE)
         {
         
               
         
            valeur1 = ObjectGet(name,OBJPROP_PRICE1);
             temps1 = ObjectGet(name,OBJPROP_TIME1);

    // line 1 
             
           if(!ObjectCreate("ligne1",OBJ_HLINE,0,temps1,valeur1))
           {
             Print("error: can't create text_object! code #",GetLastError());
            return(0);

           }
           else
           
           {
              ObjectCreate("ligne1label", OBJ_TEXT, 0, Time[0], ObjectGet("ligne1", OBJPROP_PRICE1) );
               ObjectSetText("ligne1label", " L1 ", 8, "Arial", Red);
           
           
           }
           

}              


here we know the value of valeur1, and temps1 because we draw the rectangle and so this code verify if there 's a rectangle . So we can create a Text as an object . So we procede like this but before we must create the object Text

ObjectSetText("MM5",DoubleToStr(M5,Digits), 10, "Times New Roman", Green);

but how we can create the text

 if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],???))

thanks

 
ludo31:

but how we can create the text

thanks

I can't tell you where you want to place the text . . . where do you want to place the text ?

Maybe . .

if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0], M5 ))
 

hello ;

I would like to place the text here (the blue rectangle)

I change the correct because I make mistake ; according the custom indicator We need 2 buffers for on time

here is the code

//+------------------------------------------------------------------+
//|                                          MultiTimeframeTrend.mq4 |
//|                                           rami                   |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright " Rami"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    
    // we get the value of custom indicator 
    double MM5 , MM5bis ;
     string name ;
     color Textcolor ;
     double valueM5 ;
 
   int    counted_bars=IndicatorCounted();
    //
   
   int  obj_total = ObjectsTotal();  
//----


    // we try to get the value of custom indicator 
    // setindexbuffer 0 and 1
       MM5 = iCustom(NULL,5,"histogramtrend",0,0); // the value         ExtMapBuffer2 of histogramtrend
       MM5bis = iCustom(NULL,15,"histogramtrend",1,0); // the moving average    ExtMapBuffer1 of histogramtrend

    // we create an object Text
    // we make the difference and we show this value
    
        valueM5 = MM5-MM5bis;
    
                
            
             // here we create the Text for the M5
             if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],valueM5))
                  {
                     Print("error: can't create label_object! code #",GetLastError());
                        return(0);
                   }
                   
               else
                 // we change the value and the position 
                 
                                
               {
                   
           
                    ObjectSetText("TextM5", DoubleToStr(valueM5,Digits), 12 );
                    
                    // we change the position 
                   
                    
                    ObjectSet("TextM5", OBJPROP_XDISTANCE,100);
                    ObjectSet("TextM5", OBJPROP_YDISTANCE,200);
                    
                    
                    
                    // we change the color
                    
                  if(valueM5<0)
                  Textcolor=Red;
                  else if (valueM5>0)
                   Textcolor=Green;
                   else
                    Textcolor=White;
                    ObjectSet("TextM5", OBJPROP_COLOR, Textcolor  );
                    
               
               }
               
               
            
   
   
   
 
    
   


   
//----
   return(0);
  }
//+------------------------------------------------------------------+

but the result is : nothing in main window but the object (Text ) is there with the value

I just do for the M5

 
ludo31:

hello ;

I would like to place the text here (the blue rectangle)

Use https://docs.mql4.com/windows/WindowPriceMin + 0.05 * ( https://docs.mql4.com/windows/WindowPriceMax - https://docs.mql4.com/windows/WindowPriceMin ) for the price1 value
 

you mean like that :

 if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],WindowPriceMin()+0.05*(WindowPriceMax()-WindowPriceMin())))

the code

int start()
  {
    
    // we get the value of custom indicator 
    double MM5 , MM5bis ;
     string name ;
     color Textcolor ;
     double valueM5 ;
 
   int    counted_bars=IndicatorCounted();
    //
   
   int  obj_total = ObjectsTotal();  
//----


    // we try to get the value of custom indicator 
    // setindexbuffer 0 and 1
       MM5 = iCustom(NULL,5,"histogramtrend",0,0); // the value         ExtMapBuffer1 of histogramtrend
       MM5bis = iCustom(NULL,15,"histogramtrend",1,0); // the moving average    ExtMapBuffer2 of histogramtrend

    // we create an object Text
    // we make the difference and we show this value
    
        valueM5 = MM5-MM5bis;
    
                
            
             // here we create the Text for the M5
             if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],WindowPriceMin()+0.05*(WindowPriceMax()-WindowPriceMin())))
                  {
                     Print("error: can't create label_object! code #",GetLastError());
                        return(0);
                   }
                   
               else
                 // we change the value and the position 
                 
                                
               {
                   
           
                    ObjectSetText("TextM5", DoubleToStr(valueM5,Digits), 12 );
                    
                    // we change the position 
                   
                    
                    ObjectSetText("TextM5", OBJPROP_XDISTANCE,200);
                    ObjectSetText("TextM5", OBJPROP_YDISTANCE,100);
                    
                    
                    
                    // we change the color
                    
                  if(valueM5<0)
                  Textcolor=Red;
                  else if (valueM5>0)
                   Textcolor=Green;
                   else
                    Textcolor=White;
                    ObjectSet("TextM5", OBJPROP_COLOR, Textcolor  );
                    
               
               }
               
               
            
   
   
   
 
    
   


   
//----
   return(0);
  }
//+------------------------------------------------------------------+

I try but nothing change

and I remark nothing strange : I calculate the difference between of the indicator and his MM7 so if they are crossed it make the value NULL .

in histogramtrend.mq4

        for(i=0;i<limit;i++)
                                {
                                    // histogram 
                                        ExtMapBuffer2[i] = ExtMapBuffer4[i] - ExtMapBuffer5[i];
                                   
                                }
                                
                                
                   // the MM of ExtMapBuffer2
                                for(i=0;i<limit;i++)
                                {
                                
                                   // ligne 
                                    ExtMapBuffer1[i] = iMAOnArray(ExtMapBuffer2,0,period2,0,MODE_LWMA,i);  // 0 ; 
                                   
                                
                                }

so after we would compare ExtMapBuffer2 (the indicator) and his ExtMapBuffer1 (his MM7)

in the new custom indicator using object

// we try to get the value of custom indicator 
    // setindexbuffer 0 and 1
       MM5 = iCustom(NULL,5,"histogramtrend",0,0); // the value         ExtMapBuffer2 of histogramtrend
       MM5bis = iCustom(NULL,15,"histogramtrend",1,0); // the moving average    ExtMapBuffer1 of histogramtrend


  valueM5 = MM5bis-MM5;

the result is different when the 2 lines of histogramtrend are crossed valueM5 is different of 0 .

so I create an indicator in order to verify the difference between those 2 buffer :

for(i=0;i<limit;i++)
                                {
                                    // histogram 
                                        ExtMapBuffer2[i] = ExtMapBuffer4[i] - ExtMapBuffer5[i];
                                   
                                }
                                
                                
                                for(i=0;i<limit;i++)
                                {
                                
                                   // ligne 
                                    ExtMapBuffer1[i] = iMAOnArray(ExtMapBuffer2,0,period2,0,MODE_LWMA,i);  // 0 ; 
                                   
                                
                                }
                                
                                        for(i=0;i<limit;i++)
                                {
                                    ExtMapBuffer6[i] = ExtMapBuffer2[i]-ExtMapBuffer1[i];
                                
                                }

here I show just ExtMapBuffer6[i]

as you can see : the histogramtrend (top) and the other indicator (to verify) in down and when the ExtMapBuffer2[i] (Black line) cross ExtMapBuffer1[i]

the indicator ExtMapBuffer6[i] is different of 0 (down indicator )

I don't know what's wrong with this and also with the object

 

excuse me for the message there is something wrong and I think the real problem

the real problem is here

// we try to get the value of custom indicator 
    // setindexbuffer 0 and 1
       MM5 = iCustom(NULL,5,"histogramtrend",0,0); // the value         ExtMapBuffer2 of histogramtrend
       MM5bis = iCustom(NULL,15,"histogramtrend",1,0); // the moving average    ExtMapBuffer1 of histogramtrend


  valueM5 = MM5bis-MM5;

and in MM15bis remark that I write 15 instead of 5

so the right code is

 MM5bis = iCustom(NULL,5,"histogramtrend",1,0); 

so when I compile the code it works as you can see

it works and We want just to make it at the appropriate position and put the label M5

I try to put the all time

when I take the function like this

    if(!ObjectCreate("TextM5", OBJ_TEXT, 0, Time[0],WindowPriceMin()+0.05*(WindowPriceMax()-WindowPriceMin())))

it shows this value 0.00002 but if you try to calculate the real differnence of the 2 trends the estimate value is probably wrong

 

finally I would like to use comment() as a function but I don't know how to change the color of the value

 Comment("value5 - ",valueM5,"\n",
                  "value15 -",valueM15);

Reason: