Download MetaTrader 5
To add comments, please log in or register
Have you developed a profitable strategy? Share it with millions of traders via Signals!
Donald Gibson
483
Donald Gibson 2014.08.23 10:44 

i have created a multiple time frame indicator for the MACD Indicator, but i have a problem i can not seem to work through.

first let me say i have done all the searching and reading necessary to figure this out, for me this is my last resort. i have been self learning MQL for years and some of the problems i have are probably simple and easy to explain,sometimes i overlook the obvious.

problem- the colored graph is limited to values -100 to 100.

              i need to auto adjust the value above 100 and below -100. i am guessing this is a array problem that i am missing or simply do not know how to do.

if there is a better way to create a graph i would love to see an example.

the code has 531 lines so in the interest of space i thought it would be better to post the code as a file instead of SRC.

any help will be appreciated

Files:
Keith Watford
Moderator
7906
Keith Watford 2014.08.23 12:30  

I haven't looked at your code, but have you researched

   IndicatorSetDouble(INDICATOR_MINIMUM,?);
   IndicatorSetDouble(INDICATOR_MAXIMUM,?);
Donald Gibson
483
Donald Gibson 2014.08.23 12:36  

no i haven't but i will.

thanks

Donald Gibson
483
Donald Gibson 2014.08.27 22:07  
really? not even an attempt to help? am i posting wrong?
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.08.28 00:42  
Your solving clue have been done by GumRai. We want you to figure out the rest.
Keith Watford
Moderator
7906
Keith Watford 2014.08.28 00:57  
4x_Gypsy:
really? not even an attempt to help? am i posting wrong?


You have to realise that not many can glance at a 30KB mq4 file with 531 lines and quickly work out the logic behind what you are trying to do.

In fact we have no idea what you are trying to achieve and so have to work it out from the code.

I may be slow, but it could possibly take me at least 2 hours just to work out your algorithms.

Maybe you could extract a small section of code that is giving you the problem, explain what you are trying to achieve and how you have tried to achieve it.

Donald Gibson
483
Donald Gibson 2014.08.28 07:42  

OK, so i am posting wrong.

the problem i am stuck with is how to make each time frame of the graph show and adjust to the real value of the indicator. right now it is showing values of -100 to 100 in the colored boxes, where 1 box equals 10. this works fine on the smaller time frames but once the value gets past 100 or below -100 it doesn't adjust for the higher/lower values.

i hope i am explaining the problem clearly, if not let me know.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int MACD_Panel()
  {
//-------------------------------------------------------------------------------------------------
/////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\--MACD
//-------------------------------------------------------------------------------------------------
   double MACD_mainArray=iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0);
   double MACD_signalArray=iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0);

   double levelminus10,levelminus9,levelminus8,levelminus7,levelminus6,levelminus5,levelminus4,levelminus3,levelminus2,levelminus1,
   level0,levelplus1,levelplus2,levelplus3,levelplus4,levelplus5,levelplus6,levelplus7,levelplus8,levelplus9,levelplus10;
//-------------------------------------------------------------------------------------------------
   string TrendPeriod             = "Choose your Trend Period";
   string trendPeriods            = "1,5,15,30,60,240,1440,43200";
   int    macd_TrendPeriod=1440;                        //-user defined
   string EntryPeriod             = "Choose your Entry Period";
   string entryPeriods            = "1,5,15,30,60,240,1440,43200";
   int    macd_EntryPeriod=15;                          //-user defined
//-------------------------------------------------------------------------------------------------
   string textColor="Choose your text color";
   color  macd_MainColor=White;                       //-user defined
   string panelColor="Background Color of Graph";
   color  macd_PanelColor=Black;                       //-user defined
   string text="Default font";
   string macd_font="Arial";                     //-user defined

                                                 //-macd calculations for the trend--user defined trendperiod
   double macd_TrendMainC     = iMACD(NULL,macd_TrendPeriod,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0);
   double macd_TrendSignalC   = iMACD(NULL,macd_TrendPeriod,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0);
   double macd_TrendMainP     = iMACD(NULL,macd_TrendPeriod,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,1);
   double macd_TrendSignalP   = iMACD(NULL,macd_TrendPeriod,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,1);

//-current macd calculations
   double macd_CurrentMainC   = iMACD(NULL,0,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0);
   double macd_CurrentSignalC = iMACD(NULL,0,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0);
   double macd_CurrentMainP   = iMACD(NULL,0,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0);
   double macd_CurrentSignalP = iMACD(NULL,0,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0);

//-macd calculations for the entry--user defined entryperiod
   double macd_EntryMainC     = iMACD(NULL,macd_EntryPeriod,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0);
   double macd_EntrySignalC   = iMACD(NULL,macd_EntryPeriod,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0);
   double macd_EntryMainP     = iMACD(NULL,macd_EntryPeriod,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,1);
   double macd_EntrySignalP   = iMACD(NULL,macd_EntryPeriod,macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,1);


//+------------------------------------------------------------------+
//|                              Graph                               |                                
//+------------------------------------------------------------------+
//-calculations for the levels
//-yen pairs
   if(Digits==2 || Digits==3)
     {
      levelminus10=-0.0100;
      levelminus9=-0.0090;
      levelminus8=-0.0080;
      levelminus7=-0.0070;
      levelminus6=-0.0060;
      levelminus5=-0.0050;
      levelminus4=-0.0040;
      levelminus3=-0.0030;
      levelminus2=-0.0020;
      levelminus1=-0.0010;
      level0=0.0;
      levelplus1=0.0010;
      levelplus2=0.0020;
      levelplus3=0.0030;
      levelplus4=0.0040;
      levelplus5=0.0050;
      levelplus6=0.0060;
      levelplus7=0.0070;
      levelplus8=0.0080;
      levelplus9=0.0090;
      levelplus10=0.0100;
     }
//-usd pairs     
   if(Digits==4 || Digits==5)
     {
      levelminus10=-0.000100;
      levelminus9=-0.000090;
      levelminus8=-0.000080;
      levelminus7=-0.000070;
      levelminus6=-0.000060;
      levelminus5=-0.000050;
      levelminus4=-0.000040;
      levelminus3=-0.000030;
      levelminus2=-0.000020;
      levelminus1=-0.000010;
      level0=0.0;
      levelplus1=0.000010;
      levelplus2=0.000020;
      levelplus3=0.000030;
      levelplus4=0.000040;
      levelplus5=0.000050;
      levelplus6=0.000060;
      levelplus7=0.000070;
      levelplus8=0.000080;
      levelplus9=0.000090;
      levelplus10=0.000100;
     }
//-creates panel - 9 across and 21 down     
   for(x=0;x<9;x++)
      for(y=0;y<21;y++)
        {
         ObjectCreate("macdbox"+IntegerToString(x,0)+IntegerToString(y,0),OBJ_LABEL,0,0,0);
         ObjectSet("macdbox"+IntegerToString(x,0)+IntegerToString(y,0),OBJPROP_CORNER,3);
         ObjectSet("macdbox"+IntegerToString(x,0)+IntegerToString(y,0),OBJPROP_XDISTANCE,x*24+10);
         ObjectSet("macdbox"+IntegerToString(x,0)+IntegerToString(y,0),OBJPROP_YDISTANCE,y*4+25);
         ObjectSetText("macdbox"+IntegerToString(x,0)+IntegerToString(y,0),"_",30,macd_font,macd_PanelColor);
        }
//-creates period string on panel        
   for(x=0;x<9;x++)
     {
      ObjectCreate("macdperiod"+IntegerToString(x,0),OBJ_LABEL,0,0,0);
      ObjectSet("macdperiod"+IntegerToString(x,0),OBJPROP_CORNER,3);
      ObjectSet("macdperiod"+IntegerToString(x,0),OBJPROP_XDISTANCE,x*25+6);
      ObjectSet("macdperiod"+IntegerToString(x,0),OBJPROP_YDISTANCE,10);
      ObjectSetText("macdperiod"+IntegerToString(x,0),periodString[x],8,macd_font,macd_MainColor);
      //--creates directional arrows on panel
      ObjectCreate("macdarrow"+IntegerToString(x,0),OBJ_LABEL,0,0,0);
      ObjectSet("macdarrow"+IntegerToString(x,0),OBJPROP_CORNER,3);
      ObjectSet("macdarrow"+IntegerToString(x,0),OBJPROP_XDISTANCE,x*25+10);
      ObjectSet("macdarrow"+IntegerToString(x,0),OBJPROP_YDISTANCE,113);
      ObjectSetText("macdarrow"+IntegerToString(x,0),CharToStr(233),10,"Wingdings",macd_MainColor);
     }
//-name label     
   ObjectCreate("macd"+IntegerToString(y,0),OBJ_LABEL,0,0,0);
   ObjectSet("macd"+IntegerToString(y,0),OBJPROP_CORNER,3);
   ObjectSet("macd"+IntegerToString(y,0),OBJPROP_XDISTANCE,35);
   ObjectSet("macd"+IntegerToString(y,0),OBJPROP_YDISTANCE,133);
   ObjectSetText("macd"+IntegerToString(y,0),"MACD MTF Panel",15,"Ariel",macd_MainColor);

   ObjectCreate("macdline1",OBJ_LABEL,0,0,0);
   ObjectSetText("macdline1","____________________________________",8,macd_font,macd_MainColor);
   ObjectSet("macdline1",OBJPROP_CORNER,3);
   ObjectSet("macdline1",OBJPROP_XDISTANCE,x);
   ObjectSet("macdline1",OBJPROP_YDISTANCE,130);

   ObjectCreate("macdline2",OBJ_LABEL,0,0,0);
   ObjectSetText("macdline2","____________________________________",8,macd_font,macd_MainColor);
   ObjectSet("macdline2",OBJPROP_CORNER,3);
   ObjectSet("macdline2",OBJPROP_XDISTANCE,x);
   ObjectSet("macdline2",OBJPROP_YDISTANCE,112);

   ObjectCreate("macdline3",OBJ_LABEL,0,0,0);
   ObjectSetText("macdline3","____________________________________",8,macd_font,macd_MainColor);
   ObjectSet("macdline3",OBJPROP_CORNER,3);
   ObjectSet("macdline3",OBJPROP_XDISTANCE,x);
   ObjectSet("macdline3",OBJPROP_YDISTANCE,22);
//------------------------------------------------------------------------------------------------- 

//------------------------------------------------------------------------------------------------- 
//-determines direction--red arrow shows macd is going up--green arrow shows macd is going down   
   for(x=0;x<9;x++)
     {
      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0)>
         iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0))
         ObjectSetText("macdarrow"+IntegerToString(x,0),CharToStr(228),12,"Wingdings",clrRed);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0)>
         iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0) && 
         iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,1)<
         iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,1))
         ObjectSetText("macdarrow"+IntegerToString(x,0),CharToStr(251),12,"Wingdings",clrRed);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0)<
         iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0))
         ObjectSetText("macdarrow"+IntegerToString(x,0),CharToStr(230),12,"Wingdings",clrGreen);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,0)<
         iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0) && 
         iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_MAIN,1)>
         iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,1))
         ObjectSetText("macdarrow"+IntegerToString(x,0),CharToStr(251),12,"Wingdings",clrGreen);
     }
//-changes colors of the graph according to macd calculations     
   for(x=0;x<9;x++)
     {
      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus10)
         ObjectSetText("macdbox"+IntegerToString(x,0)+"0","_",30,macd_font,clrDarkGreen);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus9)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"1","_",30,macd_font,clrGreen);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus8)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"2","_",30,macd_font,clrForestGreen);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus7)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"3","_",30,macd_font,clrLime);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus6)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"4","_",30,macd_font,clrLawnGreen);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus5)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"5","_",30,macd_font,clrGreenYellow);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus4)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"6","_",30,macd_font,clrYellow);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus3)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"7","_",30,macd_font,clrGold);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus2)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"8","_",30,macd_font,clrOrange);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=levelminus1)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"9","_",30,macd_font,clrDarkOrange);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)<=0)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"10","_",30,macd_font,clrRed);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=0)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"10","_",30,macd_font,clrRed);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus1)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"11","_",30,macd_font,clrDarkOrange);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus2)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"12","_",30,macd_font,clrOrange);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus3)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"13","_",30,macd_font,clrGold);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus4)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"14","_",30,macd_font,clrYellow);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus5)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"15","_",30,macd_font,clrGreenYellow);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus6)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"16","_",30,macd_font,clrLawnGreen);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus7)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"17","_",30,macd_font,clrLime);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus8)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"18","_",30,macd_font,clrForestGreen);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus9)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"19","_",30,macd_font,clrGreen);

      if(iMACD(NULL,period[x],macdFastEMA,macdSlowEMA,macdSignal,PRICE_CLOSE,MODE_SIGNAL,0)>=levelplus10)
         ObjectSetText("macdbox"+DoubleToString(x,0)+"20","_",30,macd_font,clrDarkGreen);
     }
   ChartRedraw();
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
/
To add comments, please log in or register