Draw a line every X minutes
Draw a line every X minutes
21 Jun 2019, 18:58
Hi guys - do you know if its possible to write an indicator that draws a line X amount of time set by the user?
Replies
igorjrmedeiros
12 Jul 2019, 13:20
RE:
alex_mihail said:
Hi guys - do you know if its possible to write an indicator that draws a line X amount of time set by the user?
Hi Alex,
In the indicator class I have been trying to use the Timer (from Algo.API) but without sucess.
So, I used the System.Timers class and it work...
Try this:
Put the namespace as the example bellow: (NOTE: put it in this order... because if you reference the System.Timers afterthe cAlgo.API a ambiguos error is showed.)
using System; using System.Timers; // This is the Timer class from System namespace using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators;
After this you need create the Class for it...
Declare this class inside your Public Class Indicator
private static System.Timers.Timer aTimer;
So now... you need to initialize the timer and set the interval.
In the Initialize function do it:
protected override void Initialize() { aTimer = new System.Timers.Timer(1000); // 1000 is the time in milliseconds aTimer.Elapsed += OnTimedEvent; // ---------->> Attention here!! aTimer.AutoReset = true; aTimer.Enabled = true; }
look into the code a line aTimer.Elapsed += OnTimedEvent. This is the function that will be called when the Timer elapsed happen.
So you need to created this function.... so try it:
private void OnTimedEvent(Object source, ElapsedEventArgs e) { // Put here your code that will be executed in timer elapsed. Print("something"); }
So... I hope this helps
:)
@igorjrmedeiros
PanagiotisCharalampous
24 Jun 2019, 09:59
Hi Alex,
You can consider using OnTimer for this.
Best Regards,
Panagiotis
@PanagiotisCharalampous