Download MetaTrader 5

Change timeframe of the current chart with a script doesn't work - page 2

To add comments, please log in or register
mar
1148
mar  

Please have a look at this picture. I coloured the space where the chart is hidden and on the very right you see a bar. If you see this example and you wanted to analyze that chart and predict where it may go, then you know exactly that price will rise. So your bias will be long because you see that bar. That is the problem. There are 2-3 pixel columns that can't be coloured.

 

If there is no chance to colour the last bar then it is so. I have to live with it and I will use that fixed scale relating to the not-hidden part of the chart. 

mar
1148
mar  
I use smaller boxes now and it works. There are no non-hidden pixels left on the very right border. So this is done. Now I finish the expert advisor that will adjust the fixed scale to the visible part of the chart.
Alain Verleyen
Moderator
33234
Alain Verleyen  
mar:
I use smaller boxes now and it works. There are no non-hidden pixels left on the very right border. So this is done. Now I finish the expert advisor that will adjust the fixed scale to the visible part of the chart.
Good, but I suggest you to use a RECTANGLE_LABEL object, instead of label for this.
honest_knave
Moderator
2325
honest_knave  

You can easily match the color of your rectangle label to the chart background

color BG=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND)
mar
1148
mar  

Done! :)

There is just one general thing I would like to improve but I haven't done that before. I only made expert advisors which run on tick. But this is a backtesting/learning expert advisor and so I don't need ticks (I also would like to test at the weekends when no ticks arrive). I saw that there is a possibility to run the expert advisor on a chart event. Because I scroll the chart by pressing F12 I want to use CHARTEVENT_KEYDOWN.

So I wanted to do a test with the keystroke-event but I don't know what's wrong here:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if (id == CHARTEVENT_KEYDOWN && lparam == 123) Alert("F12 pressed"); // F12 pressed?
  }
//+------------------------------------------------------------------+

Can't I just ignore OnTick() ? I only want to run the expert advisor on a keystroke and therefore I need no tick but I guess that's not possible, is it?

Alain Verleyen
Moderator
33234
Alain Verleyen  
mar:

Done! :)

There is just one general thing I would like to improve but I haven't done that before. I only made expert advisors which run on tick. But this is a backtesting/learning expert advisor and so I don't need ticks (I also would like to test at the weekends when no ticks arrive). I saw that there is a possibility to run the expert advisor on a chart event. Because I scroll the chart by pressing F12 I want to use CHARTEVENT_KEYDOWN.

So I wanted to do a test with the keystroke-event but I don't know what's wrong here:

Can't I just ignore OnTick() ? I only want to run the expert advisor on a keystroke and therefore I need no tick but I guess that's not possible, is it?

Yes it's possible. But F12 is an MT4 predefined shortcut key, you can't use it with CHARTEVENT_KEYDOWN.
mar
1148
mar  

Completed! 

Thank you very much for your help! 

12
To add comments, please log in or register