I use the following code to Change, for instance, the background Color of the Chart via mql5 Code:
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?
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.
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.
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).
// Set the chart settings.
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_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.
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
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.
Anyone knows how to open the strategy tester in Fullscreen?