Multicolor Fibonacci indicator: Associate the different color to the level of percentage.

 

I cannot associate the color to the level of percentage, in either direction retracement.

Someone can correct the command string?

Thank you.

 

//+------------------------------------------------------------------+
//|                                          AG Multi Color Fib.mq4  |
//|                                              Alan.81@live.it     |
//+------------------------------------------------------------------+
#property copyright "Alan Gasperi"
#property indicator_chart_window

extern int   mLineExtend = 400;  
extern bool  mSendAlerts = true;                     
extern color mCol0   = SteelBlue;
extern color mCol1   = SteelBlue;
extern color mCol2   = DimGray;
extern color mCol3   = Red;
extern color mCol4   = Yellow;
extern color mCol5   = Yellow;
extern color mCol6   = Red;
extern color mCol7   = SteelBlue;
extern color mCol8   = SteelBlue;
extern color mCol    = DimGray;
extern color mTxtCol = White;  
             
extern double mFib0  = 0.0;
extern double mFib1  = 100.0;
extern double mFib2  = 23.6;
extern double mFib3  = 38.2;
extern double mFib4  = 50.0;   
extern double mFib5  = 61.8;
extern double mFib6  = 76.6;
extern double mFib7  = 123.6;
extern double mFib8  = 138.2;              

double mPipFact = 1, mP1, mP2, mFibPcnts[9], mFibs[9];
int    mT1, mT2, mLabT, mArrSize;
color  mFibCols[9];

//------------------------------------------------------------------|
int init()
  {
   if(Digits == 3 || Digits == 5)
     mPipFact = 10;
    
   mFibPcnts[0] = mFib0;
   mFibPcnts[1] = mFib1;
   mFibPcnts[2] = mFib2;
   mFibPcnts[3] = mFib3;
   mFibPcnts[4] = mFib4;
   mFibPcnts[5] = mFib5;
   mFibPcnts[6] = mFib6;
   mFibPcnts[7] = mFib7;
   mFibPcnts[8] = mFib8;
    
   mFibCols[0] = mCol0;
   mFibCols[1] = mCol1;
   mFibCols[2] = mCol2;
   mFibCols[3] = mCol3;
   mFibCols[4] = mCol4;
   mFibCols[5] = mCol5;
   mFibCols[6] = mCol6;
   mFibCols[7] = mCol7;
   mFibCols[8] = mCol8;
   
   mArrSize = ArraySize(mFibPcnts) +1 ;
   
   return(0);
  }

//+------------------------------------------------------------------+
int deinit()
  {
   for(int i = ObjectsTotal(); i >= 0; i--)
     if(StringSubstr(ObjectName(i), 0, 2) == "m.")
       ObjectDelete(ObjectName(i));

   return(0);
  }

//+------------------------------------------------------------------+
int start()
  {
    CreateObj();

    mT1 = iBarShift(NULL, 0, ObjectGet("m.Fib", 0));
    mT2 = iBarShift(NULL, 0, ObjectGet("m.Fib", 2));
    if(mT1 < mT2)
      {  
        mT1 = mT2;
        mT2 = iBarShift(NULL, 0, ObjectGet("m.Fib", 0));
      }
    mT2 = MathMax(0, mT2 - mLineExtend);
    
    SetFibs();
    
    
    return(0);
  }
  
//+------------------------------------------------------------------+
void CreateObj()
 {
   if(ObjectFind("m.Fib") == -1)
     {
       double mDepth = (WindowPriceMax(0) - WindowPriceMin(0)) / 4;
       ObjectCreate("m.Fib", OBJ_TREND, 0, Time[30], High[30], Time[10], High[30] + mDepth);
       ObjectSet("m.Fib", OBJPROP_RAY, false);
       ObjectSet("m.Fib", OBJPROP_WIDTH, 1); ObjectSet("m.Fib", OBJPROP_STYLE,STYLE_DOT);
       ObjectSet("m.Fib", OBJPROP_COLOR, mCol);
     }
   
   for(int c = 0; c < mArrSize; c++)
     {
         if(ObjectFind("m.Fib"+c) == -1)
           {
             ObjectCreate("m.Fib"+c, OBJ_TREND, 0, 0, 0, 0, 0);
             ObjectSet("m.Fib"+c, OBJPROP_RAY, false);
             ObjectSet("m.Fib"+c, OBJPROP_WIDTH, 2);

             ObjectCreate("m.Lab"+c, OBJ_TEXT, 0, 0, 0, 0, 0);
           }
     }
     
   return(0);
  }
  
//+------------------------------------------------------------------+
void SetFibs()
 {
   double mRange;

    mP1 = ObjectGet("m.Fib", 1);
    mP2 = ObjectGet("m.Fib", 3);
    mRange = MathAbs(mP1 - mP2);
    
    if(mP2 < mP1)
      {
        ArraySort(mFibPcnts, WHOLE_ARRAY, 0, MODE_ASCEND);
        for(int y = 0; y < mArrSize; y++)
          mFibs[y] = mP1 - mRange * mFibPcnts[y] /  100;
      }
    else 
      {
        ArraySort(mFibPcnts, WHOLE_ARRAY, 0, MODE_DESCEND);
        for(y = 0; y < mArrSize; y++)
          mFibs[y] = mP1 + mRange * mFibPcnts[y] /  100;
      }

   for(y = 0; y < mArrSize; y++)
     {
         ObjectSet("m.Fib"+y, OBJPROP_TIME1, Time[mT1]);
         ObjectSet("m.Fib"+y, OBJPROP_TIME2, Time[mT2]);
         ObjectSet("m.Fib"+y, OBJPROP_PRICE1, mFibs[y]);
         ObjectSet("m.Fib"+y, OBJPROP_PRICE2, mFibs[y]);
         ObjectSet("m.Fib"+y, OBJPROP_COLOR, mFibCols[y]);
         ObjectSetText("m.Lab"+y, DoubleToStr(mFibPcnts[y], 0) + "%  " + DoubleToStr(mFibs[y], Digits), 9, "Arial", mTxtCol);
         mLabT = MathMin(mT1, mT2) + 4;
         ObjectSet("m.Lab"+y, OBJPROP_TIME1, Time[mLabT]);
         ObjectSet("m.Lab"+y, OBJPROP_PRICE1, mFibs[y]);
     }

   return(0);
 }
  
//+------------------------------------------------------------------+
Files:
 
         ObjectSetText("m.Lab"+y, DoubleToStr(mFibPcnts[y], 0) + "%  " + DoubleToStr(mFibs[y], Digits), 9, "Arial", mTxtCol);
         mLabT = MathMin(mT1, mT2) + 4;
         ObjectSet("m.Lab"+y, OBJPROP_TIME1, Time[mLabT]);
         ObjectSet("m.Lab"+y, OBJPROP_PRICE1, mFibs[y]);
         ObjectSet("m.Lab"+y, OBJPROP_COLOR, mFibCols[y]);
 
Ernst Van Der Merwe:
Thanks for Your help, but I do not want to change the text color, but the color of the line remains the same color of the retracement percentage, in tracking both upwards and downwards!
Forgive my poor english.
 
Alan Gasperi:
Thanks for Your help, but I do not want to change the text color, but the color of the line remains the same color of the retracement percentage, in tracking both upwards and downwards!
Forgive my poor english.

Ok I see now. Just remove ArraySort().

    if(mP2 < mP1)
      {
        //ArraySort(mFibPcnts, WHOLE_ARRAY, 0, MODE_DESCEND);
        for(int y = 0; y < mArrSize; y++)
          mFibs[y] = mP1 - mRange * mFibPcnts[y] /  100;
      }
    else 
      {
        //ArraySort(mFibPcnts, WHOLE_ARRAY, 0, MODE_ASCEND);
        for(y = 0; y < mArrSize; y++)
          mFibs[y] = mP1 + mRange * mFibPcnts[y] /  100;
      }
 
Ernst Van Der Merwe:

Ok I see now. Just remove ArraySort().

Many thanks, one last help, I would only see the percentage value as text, and not the price ...
 
Alan Gasperi:
Many thanks, one last help, I would only see the percentage value as text, and not the price ...
         ObjectSetText("m.Lab"+y, DoubleToStr(mFibPcnts[y], 0) + "%  " + DoubleToStr(mFibs[y], Digits), 9, "Arial", mTxtCol);
         mLabT = MathMin(mT1, mT2) + 20;
 
Need to add more levels is it possible sir
 
venkatsait1977: Need to add more levels is it possible sir
You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help 2017.04.21

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum 2018.05.12

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
          No free help 2017.04.21