Using an Expert Advisor to Change Chart Parameters on Init

 

Greetings, I ran a search and did not see a mention of how to fix my problem. Maybe I am searching for the wrong thing. This seems extremely basic. I have used #include <Charts/Chart.mqh>, after using redraw, the chart does not seem to update. 

This is my first time really looking for help with code, the documentation has always served me in the past. When I call this function from OnInit(), nothing happens. 

void SetChart()
{
   CharID=Char.ChartId();
   Char.Attach(CharID);  
   Char.Mode(2);
   Char.ShowGrid(false);
   Char.ShowOHLC(true);
   Char.ShowLastLine(true);
   Char.ShowLineAsk(true);
   Char.ShowLineBid(true);
   Char.ShowPeriodSep(true);
   Char.ColorBackground(clrBlack);
   Char.ColorCandleBear(clrDarkRed);
   Char.ColorCandleBull(clrDarkGreen);
   Char.ColorForeground(clrOlive);
   Char.ColorLineAsk(clrDarkOliveGreen);
   Char.ColorLineBid(clrMaroon);
   Char.ColorLineLast(clrSienna);
   Char.ColorStopLevels(clrMidnightBlue);
   Char.ColorVolumes(clrDarkSeaGreen);
   Char.Redraw();

 }


What am I doing wrong?

 
DStupar:

Greetings, I ran a search and did not see a mention of how to fix my problem. Maybe I am searching for the wrong thing. This seems extremely basic. I have used #include <Charts/Chart.mqh>, after using redraw, the chart does not seem to update. 

This is my first time really looking for help with code, the documentation has always served me in the past. When I call this function from OnInit(), nothing happens. 


What am I doing wrong?

hi, 


Use my working function as a reference, and modify it for your needs

void SetupWindowChar(int deInitReason) {
   
   int chart_ID = 0;
   
   //ChartSetInteger(chart_ID,CHART_IS_DOCKED,true);
    
   ChartSetInteger(chart_ID,CHART_SHOW,true);
   ChartSetInteger(chart_ID,CHART_CROSSHAIR_TOOL,false);    
    
   // Altura da sub-window informativa: 100px
   ChartHeightInPixelsSet(125,0,1);

   ChartSetInteger(chart_ID,CHART_SHOW_OHLC,0);
   ChartSetInteger(chart_ID,CHART_SHOW_ASK_LINE,1);
   ChartSetInteger(chart_ID,CHART_SHOW_BID_LINE,1);
   ChartSetInteger(chart_ID,CHART_SHOW_TRADE_LEVELS,1);
   ChartSetInteger(chart_ID,CHART_SHOW_GRID,0);
   ChartSetInteger(chart_ID,CHART_SHOW_DATE_SCALE,1);
   //ChartSetInteger(chart_ID,CHART_SHOW_ONE_CLICK,1);
   ChartSetInteger(chart_ID,CHART_SHOW_PERIOD_SEP,0);
   ChartSetInteger(chart_ID,CHART_SHOW_PRICE_SCALE,1);
   ChartSetInteger(chart_ID,CHART_SHOW_OBJECT_DESCR,1);
   ChartSetInteger(chart_ID,CHART_SHOW_VOLUMES,0);
  // ChartSetInteger(chart_ID,CHART_SHOW_VOLUMES,CHART_VOLUME_TICK); 
   ChartSetInteger(chart_ID,CHART_SHOW_LAST_LINE,1);
   
   ChartSetInteger(chart_ID,CHART_COLOR_ASK,clrTangerina);
   ChartSetInteger(chart_ID,CHART_COLOR_BID,C'200,250,245');
   ChartSetInteger(chart_ID,CHART_COLOR_BACKGROUND,C'5,5,27');
   ChartSetInteger(chart_ID,CHART_COLOR_FOREGROUND,clrDourado);
   ChartSetInteger(chart_ID,CHART_COLOR_GRID,8213269);
   ChartSetInteger(chart_ID,CHART_COLOR_CANDLE_BEAR,clrVermelhoNivel4);
   ChartSetInteger(chart_ID,CHART_COLOR_CANDLE_BULL,clrVerdeNivel5);
   ChartSetInteger(chart_ID,CHART_COLOR_VOLUME,clrLime);
   ChartSetInteger(chart_ID,CHART_COLOR_STOP_LEVEL,4408318);
   ChartSetInteger(chart_ID,CHART_COLOR_LAST,C'1,176,190');
   ChartSetInteger(chart_ID,CHART_COLOR_CHART_LINE,4294967295);
   ChartSetInteger(chart_ID,CHART_COLOR_CHART_DOWN,clrRos);
   ChartSetInteger(chart_ID,CHART_COLOR_CHART_UP,clrAzul);
   
   ChartSetInteger(chart_ID,CHART_SHIFT,1);
   ChartSetInteger(chart_ID,CHART_SCALEFIX_11,0);
   ChartSetInteger(chart_ID,CHART_SCALEFIX,0);
   
   ChartSetInteger(chart_ID,CHART_FOREGROUND,1);
   ChartSetInteger(chart_ID,CHART_MODE,0,CHART_CANDLES);
   ChartSetInteger(chart_ID,CHART_MODE,0,CHART_SHOW_TRADE_LEVELS);
   ChartSetInteger(chart_ID,CHART_DRAG_TRADE_LEVELS,1);


   if (deInitReason != 3 && deInitReason !=1) {   // Alteracao de Timeframa, mantenho a escala
      ChartSetInteger(chart_ID,CHART_SCALE,3);
   }      
   
   ChartRedraw();

}


You can call it inside OnInit()

int OnInit() {

   SetupWindowChar(0);

// ... other OnInit code here

}


PS: I have some custom color names on it (clrTangerina, clrRos, clrAzul, etc..) change them to default metatrader color names to avoid compilation errors.

 

Good looking out, I will review your code and modify to my needs. 


Thank you. 




rrocchi:

hi, 


Use my working function as a reference, and modify it for your needs


You can call it inside OnInit()


PS: I have some custom color names on it (clrTangerina, clrRos, clrAzul, etc..) change them to default metatrader color names to avoid compilation errors.

 
void SetChart()
{
   //CharID=Char.ChartId();
   Char.Attach();  
   Char.Mode(2);