[MQL5] OBJPROP_LEVELCOLOR not working

 

This is problem on MQL5

I set ObjectSetInteger(0,".....",OBJPROP_LEVELCOLOR,.....); to fibonacci retracment object.

But color not change. Check and fix it please. Thank you so much.

 
momocoong:

This is problem on MQL5

I set ObjectSetInteger(0,".....",OBJPROP_LEVELCOLOR,.....); to fibonacci retracment object.

But color not change. Check and fix it please. Thank you so much.

Hello

You have to specify the level index followed by the color 

consult this code :

//FIBONACCI DISCO
#property version   "1.00"
input color C1=clrYellow;//Color 1
input color C2=clrOrangeRed;//Color 2
input color C3=clrYellowGreen;//Color 3
input color C4=clrViolet;//Color 4

color spectrum[]={C1,C2,C3,C4};
string fibs[];
int fibc[];
int signal=1;
bool fibexists(string name){
     for(int i=0;i<ArraySize(fibs);i++){
        if(fibs[i]==name){return(true);}
        }
     return(false);
     }
void add_fibs(string name,int &colorSignal){
    int ns=ArraySize(fibs)+1;
    ArrayResize(fibs,ns,0);
    ArrayResize(fibc,ns,0);
    fibs[ns-1]=name;
    int levels=(int)ObjectGetInteger(ChartID(),name,OBJPROP_LEVELS);
    for(int i=0;i<levels;i++){
       colorSignal++;
       if(colorSignal>ArraySize(spectrum)){colorSignal=1;}
       fibc[ns-1]=colorSignal;
       //ObjectSetInteger(ChartID(),name,OBJPROP_LEVELCOLOR,level_index,color);
       ObjectSetInteger(ChartID(),name,OBJPROP_LEVELCOLOR,i,spectrum[colorSignal-1]);
       }
    ChartRedraw();
    }
int OnInit()
  {
  ChartSetInteger(ChartID(),CHART_EVENT_OBJECT_CREATE,true);
  EventSetMillisecondTimer(144);
  return(INIT_SUCCEEDED);
  }

void OnTimer(){
for(int j=0;j<ArraySize(fibs);j++){
    int levels=(int)ObjectGetInteger(ChartID(),fibs[j],OBJPROP_LEVELS);
    for(int i=0;i<levels;i++){
       fibc[j]++;
       if(fibc[j]>ArraySize(spectrum)){fibc[j]=1;}
       ObjectSetInteger(ChartID(),fibs[j],OBJPROP_LEVELCOLOR,i,spectrum[fibc[j]-1]);
       }   
   }
ChartRedraw();
}

void OnDeinit(const int reason)
  {
  EventKillTimer();
  }

void OnTick()
  {

   
  }

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
  if(id==CHARTEVENT_OBJECT_DRAG){
    if(ObjectGetInteger(ChartID(),sparam,OBJPROP_TYPE)==OBJ_FIBO){
    if(!fibexists(sparam)){
      add_fibs(sparam,signal);
      }
    }
    }
  }

 
We need to see your code to be able to help you effectively. It can literally be one word off but we can't guess the issue.
 
Lorentzos Roussos #:

Hello

You have to specify the level index followed by the color 

consult this code :

Thank you. It's correct! Fibo levels in mql5 must be set colour all of levels.

This is my code after solved.

ObjectSetInteger(0,"FiboUp",OBJPROP_LEVELCOLOR,0,clrPink);

ObjectSetInteger(0,"FiboUp",OBJPROP_LEVELCOLOR,1, clrPink );

ObjectSetInteger(0,"FiboUp",OBJPROP_LEVELCOLOR,2, clrPink );

ObjectSetInteger(0,"FiboUp",OBJPROP_LEVELCOLOR,3, clrPink );

ObjectSetInteger(0,"FiboUp",OBJPROP_LEVELCOLOR,4, clrPink );

ObjectSetInteger(0,"FiboUp",OBJPROP_LEVELCOLOR,5, clrPink );

ObjectSetInteger(0,"FiboUp",OBJPROP_LEVELCOLOR,6, clrPink );
 
momocoong #:

Thank you. It's correct! Fibo levels in mql5 must be set colour all of levels.

This is my code after solved.

excellent , don't forget ChartRedraw()