Chart Properties only in OnTick() function?

 

Hi!


I use the following code to Change, for instance, the background Color of the Chart via mql5 Code:

ChartSetInteger(0,CHART_COLOR_BACKGROUND,clrAqua);

However, this only takes effect, when it is put in the void OnTick() function.

If I put this Code into the OnStart() or OnInit() function the Background Color does not Change? Why is this?


Best!

 

Cause OnTick() changes the chart. You have to add a ChartRedraw().

Dont use the functions, be clever and use the classes. You see the hassle all this guys have when migrating from MT4 to MT5, this is just because almost nobody uses the classes stuff.

#include <Charts/Chart.mqh>
CChart chart;

// ...

chart.Attach();
chart.ColorBackground(clrAqua);
chart.Redraw();
 
Doerk Hilger:

Cause OnTick() changes the chart. You have to add a ChartRedraw().

Dont use the functions, be clever and use the classes. You see the hassle all this guys have when migrating from MT4 to MT5, this is just because almost nobody uses the classes stuff.


Cool thank you for your comment.

I have just tested it and this now also works in the OnInit() function which is great. Such Code should only be executed once at the beginning and not at every tick as it uses a lot of Memory etc.

Do you also know why this Code is now wokring in the OnInit() function. It is not working in the OnStart() function though.

 
wokl:

Hi!


I use the following code to Change, for instance, the background Color of the Chart via mql5 Code:

ChartSetInteger(0,CHART_COLOR_BACKGROUND,clrAqua);

However, this only takes effect, when it is put in the void OnTick() function.

If I put this Code into the OnStart() or OnInit() function the Background Color does not Change? Why is this?


Best!

Hello Wolk.

For what I understand you are trying to set the chart properties when you load the EA right? Well in that case you have to do it on the OnInit() function. I am not sure why your error but here is a sample code i use to set the chart properties OnInit() that works for me.

long chart_id; // OnInit() the EA will retrieve the current chart number(id).

int OnInit()
{
  Colours();
  return(INIT_SUCCEEDED);
}

// Set the chart settings.

void Colours()
{
  ChartSetInteger(chart_id,CHART_COLOR_FOREGROUND,clrBlack); // Set the foreground colour(X and Y axis). 
  ChartSetInteger(chart_id,CHART_COLOR_BACKGROUND,clrOldLace); // Set the backgroud colour.
  ChartSetInteger(chart_id,CHART_SHOW_OHLC,false); // Will hide the OHLC.
  ChartSetInteger(chart_id,CHART_MODE,CHART_CANDLES); // Will set the chart mode to Japanese candles.
  ChartSetInteger(chart_id,CHART_COLOR_CANDLE_BULL,clrBlack); // Color of bull candle.
  ChartSetInteger(chart_id,CHART_COLOR_CANDLE_BEAR,clrWhite); // Color of bear candle.
  ChartSetInteger(chart_id,CHART_COLOR_CHART_UP,clrBlack);
  ChartSetInteger(chart_id,CHART_COLOR_CHART_DOWN,clrBlack);
  ChartSetInteger(chart_id,CHART_SHOW_BID_LINE,true); // Show the bid line OnInit() - By default MT does show it.
  ChartSetInteger(chart_id,CHART_COLOR_BID,clrOrangeRed);  // Set the bid line colour.
  ChartSetInteger(chart_id,CHART_SHOW_ASK_LINE,true); // Show the ask line OnInit() - By default MT does not show it.
  ChartSetInteger(chart_id,CHART_COLOR_ASK,clrRed); // Set the ask line colour.
  //
  ChartSetInteger(chart_id,CHART_SHOW_GRID,false); // Hide the Grid.
  ChartSetInteger(chart_id,CHART_SHOW_ONE_CLICK,false); // Hide the Quick Trading Buttons.
  //
  ChartSetInteger(chart_id,CHART_SHOW_TRADE_LEVELS,true); // Shows the open positions, pending orders, and TakeProfit or StopLoss if any.
}

Please fell free to copy it into your EA and tell me if you were able to solve the issue.

 
AWer1001:

Hello Wolk.

For what I understand you are trying to set the chart properties when you load the EA right? Well in that case you have to do it on the OnInit() function. I am not sure why your error but here is a sample code i use to set the chart properties OnInit() that works for me.

Please fell free to copy it into your EA and tell me if you were able to solve the issue.


Hi AWer!

thanks for your Input too.

I want to Change the Chart Colors in the Strategy Backtester. Maybe there it is different and you cannot put the Code into the OnInit() function. No clue.

However, I prefer to use the object oriented Approach from Doerk Hilger. It is more like a common OO language such as Java and it also works in the OnInit() function

 
wokl:


Hi AWer!

thanks for your Input too.

I want to Change the Chart Colors in the Strategy Backtester. Maybe there it is different and you cannot put the Code into the OnInit() function. No clue.

However, I prefer to use the object oriented Approach from Doerk Hilger. It is more like a common OO language such as Java and it also works in the OnInit() function

Glad to help. BTW you can add code in OnInit() and test it on the strategy tester.
 
Doerk Hilger:

Cause OnTick() changes the chart. You have to add a ChartRedraw().

Dont use the functions, be clever and use the classes. You see the hassle all this guys have when migrating from MT4 to MT5, this is just because almost nobody uses the classes stuff.

Doerk I have a question if you coud answer it I would be thanksful.

With the CChart Class how do I set this properties:

  ChartSetInteger(chart_id,CHART_SHOW_ONE_CLICK,false);
 
  ChartSetInteger(chart_id,CHART_SHOW_TRADE_LEVELS,true);

I have been trying to find them in the MQL5 Reference but no sign of them.

Thanks a lot.

 
AWer1001:

Doerk I have a question if you coud answer it I would be thanksful.

With the CChart Class how do I set this properties:

I have been trying to find them in the MQL5 Reference but no sign of them.

Thanks a lot.


Trade Levels would be great to know as I would like to Switch those off too!
 

Anyone knows how to open the strategy tester in Fullscreen?

Reason: