Change Time frame - page 2

 

Hello all,

This works.

input int a= PERIOD_M15,PERIOD_M30 ,PERIOD_H1 ,PERIOD_M5;
long chart_id=0; 
string charts ="GOLD";

int OnInit() {
  bool TimeFunction=ChartSetSymbolPeriod(chart_id,charts,a);


Thank you all for your help.
 

Why doesn't this code change the timeframe please:

int a= PERIOD_M5;
long chart_id=0;
string charts ="EURUSD";

int init ()
{

bool TimeFunction=ChartSetSymbolPeriod(chart_id,charts,a);
return (0);
}
 
Jimparker:

Please do not keep posting the same question!

I have deleted your other 3 topics.

You have been warned before about multiple posts with the same subject.

Do it again and you will be banned.

 
Jimparker: Why doesn't this code change the timeframe
  1. Don't double post!
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  3. Check your return codes for errors, and report them including GLE/LE. Don't look at it unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  4. Perhaps you do it in OnTick after there is a chart.
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  5. Perhaps you should check that you are already on the required symbol/TF before making the call.
 
Jimparker:
Keith Watford:

Please do not keep posting the same question!

I have deleted your other 3 topics.

You have been warned before about multiple posts with the same subject.

Do it again and you will be banned.

And yet you post a new topic with exactly the same question!!!!

The topic has been deleted and you are banned for 1 week.

 
GrumpyDuckMan:

Still not working :(

This is how I got it work.  The DrawEvents there is also for another feature: I don't redraw this panel of News Events unless the chart is resized or changed in some way.  There is no way AFAIK to further address what change is actually happening using the lparam, dparam, sparam's.  I've checked documentation.  If you are okay with calling OnInit again each resize, then this will work for you.  OnInit gets called anyway each time the user refreshes or clicks a timeframe button, so I don't see the problem unless you absolutely cannot call your OnInit more than once.  

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if (id == CHARTEVENT_CHART_CHANGE)
   {
      ChartSetSymbolPeriod(0, NULL, PERIOD_M1);
      DrawEvents();      
   }
}
 
enjoys_math #:

This is how I got it work.  The DrawEvents there is also for another feature: I don't redraw this panel of News Events unless the chart is resized or changed in some way.  There is no way AFAIK to further address what change is actually happening using the lparam, dparam, sparam's.  I've checked documentation.  If you are okay with calling OnInit again each resize, then this will work for you.  OnInit gets called anyway each time the user refreshes or clicks a timeframe button, so I don't see the problem unless you absolutely cannot call your OnInit more than once.  

Hello. Thank you for your code. i now find best answer for this question.

very simple 

Thank you 

Reason: