change time frame

 

hi, 

I'm new for ea coding, and trying to learn from internet, but I cannot find out how to solve my problem.

I want to change time frame on my ea 2 times but it's like keep looping when I run it,


Could someone help please? thank you in advance.


int OnInit()
  {
//---

   ChartSetSymbolPeriod(0,NULL,PERIOD_D1); // Change TF to D1;
   
   double ClosePrice=Close[1];

   Comment(
      "D1 Closed Price =  " + ClosePrice
   );
   
   
   ChartSetSymbolPeriod(0,NULL,PERIOD_H4); // Change TF to H4;

   ;

//---
   return(INIT_SUCCEEDED);
  }
 
  1. Why are you changing the TF twice?
  2. After the call, you must return. Then a de-init occurs, the TF changes, and a new init occurs. You must arrange that you do not change the TF again until the new init.
  3. Why are you changing the TF? The EA can see all timeframes via code.
 
William Roeder:
  1. Why are you changing the TF twice?
  2. After the call, you must return. Then a de-init occurs, the TF changes, and a new init occurs. You must arrange that you do not change the TF again until the new init.
  3. Why are you changing the TF? The EA can see all timeframes via code.

Thank you " William Roeder:"

I just want some value from anther TF, but you've just giving me for solution in your No.3 , I'll try it. thanks again. :)