Ontick and OnTimer not working for an indicator

 

Hello all,

I have tried searching for this answer, but could not find the answer I am looking for.

I would like my OBJ_HLINE to update every tick to be at the current bid price.


To test if OnTick or OnTimer were working I used these:


void OnTick() {

Print("onTickworking");

}


void OnTimer() {

Print("onTimer working");

}

Both don't seem to work for an indicator. Is there any other way?


Thanks.


Simon

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
  1. 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 2019.05.06
              Messages Editor

  2. Perhaps you should read the manual.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    OnTick is only called on EAs.
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 2016.05.11

  3. Did you enable the timer? The call can fail — retry in OnCalculate if necessary.

 
Simon Liu:

Hello all,

I have tried searching for this answer, but could not find the answer I am looking for.

I would like my OBJ_HLINE to update every tick to be at the current bid price.


To test if OnTick or OnTimer were working I used these:



Both don't seem to work for an indicator. Is there any other way?


Thanks.


Simon

int OnInit()
  {
 
 EventSetTimer(60);
   
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }
void OnTimer()
  {
//---
OnSMSKontrol();
  
  }

 void OnSMSKontrol()
  {
Print(" xx");
}
 
Simon Liu:

Hello all,

I have tried searching for this answer, but could not find the answer I am looking for.

I would like my OBJ_HLINE to update every tick to be at the current bid price.


To test if OnTick or OnTimer were working I used these:



Both don't seem to work for an indicator. Is there any other way?


Thanks.


Simon

"I would like my OBJ_HLINE to update every tick to be at the current bid price."


It is unnecessary to use Timer for this.


You do the desired action at each tick. Using a timer is to process without waiting for a tick.

void OnTick() {

ObjeCiz();

}

void ObjeCiz() {
    // example 
   ObjectCreate(0,"SMSClose",OBJ_BUTTON,0,0,0);
   ObjectSetInteger(0,"SMSClose",OBJPROP_XDISTANCE,150);
   ObjectSetInteger(0,"SMSClose",OBJPROP_YDISTANCE,25);
   ObjectSetInteger(0,"SMSClose",OBJPROP_XSIZE,100);
   ObjectSetInteger(0,"SMSClose",OBJPROP_YSIZE,50);

}
The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
Mehmet Bastem:

You do the desired action at each tick. Using a timer is to process without waiting for a tick.

As William has already pointed out, indicators do not use OnTick(), EAs do.

 
Simon Liu:


I would like my OBJ_HLINE to update every tick to be at the current bid price.


Why don't you just enable "Show bid price line" in chart properties !

 
Simon Liu:

Hello all,

I have tried searching for this answer, but could not find the answer I am looking for.

I would like my OBJ_HLINE to update every tick to be at the current bid price.


To test if OnTick or OnTimer were working I used these:



Both don't seem to work for an indicator. Is there any other way?


Thanks.


Simon

I think indicator use onCalculate() instead of onTick(). Then if there is no data from server eg. during weekend, it won't triggered because there is basically no data received. Try onChartEvent() instead. For a timer, you need to activated it first.

 

Hello all,


Thank you for your comments.

As mentioned before: OnTick() and OnTimer() seem to be inactive. As for OnCalculate(), this one seems to only trigger once.

As to why i dont just use show bid price line. That's because its part of something bigger. I just wanted to know how to trigger methods each tick or second.

 
Simon Liu:

Thank you for your comments.

As mentioned before: OnTick() and OnTimer() seem to be inactive. As for OnCalculate(), this one seems to only trigger once.

As to why i dont just use show bid price line. That's because its part of something bigger. I just wanted to know how to trigger methods each tick or second.

All of these have already been addressed

OnTick() is for EAs, not indicators

Have you actually enabled OnTimer()?

OnCalculate() will only be called after the indicator is initialized and when there is a new incoming tick. At the weekend there are no new ticks for most symbols.

Reason: