Acutally this post is related to this one /forum/cbot-support/1121, but it doesnt work for me, so I look for some help here. The thing is, my code works fine in OnStart or OnTick. But the best scenario is to use "OnTimer", which cAlgo doesnt directly support. Nevertheless, using OnTimedEvent can be an alternative solution.
Following is my code (but it doesnt work)
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.Timers;
////////////
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MyStrategy : Robot
{
public readonly Timer _timer = new Timer();
[Parameter("xxx", DefaultValue = 1)]
public int xxx { get; set; }
[Parameter("yyy", DefaultValue = 2)]
public double yyy { get; set; }
protected override void OnStart()
{
_timer.Elapsed += OnTimedEvent;
_timer.AutoReset = true;
_timer.Interval = 100; // 100 ms
_timer.Enabled = true;
Print(" check point 1");
_timer.Start();
Print("check point 2");
}
private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
==> my main logic <===
Print("Check point 3");
}
}
}
It can be compiled and built, but when it is run in the live mode, only the check point 1& 2 are printed, and the check point 3 doesnt occur, which means the OnTimedEvent is not triggered. And I am not sure why.
btw, I am more familiar with C++ rather than C#, and mostly coding in MT4/5. So I might be silly.
Jus that I have done my works and some research online, but haven't found a solution.
Not sure if that is a c# issue or a cAlgo issue.
Wjack07
20 May 2014, 02:10
Hi:
Acutally this post is related to this one /forum/cbot-support/1121, but it doesnt work for me, so I look for some help here. The thing is, my code works fine in OnStart or OnTick. But the best scenario is to use "OnTimer", which cAlgo doesnt directly support. Nevertheless, using OnTimedEvent can be an alternative solution.
Following is my code (but it doesnt work)
It can be compiled and built, but when it is run in the live mode, only the check point 1& 2 are printed, and the check point 3 doesnt occur, which means the OnTimedEvent is not triggered. And I am not sure why.
btw, I am more familiar with C++ rather than C#, and mostly coding in MT4/5. So I might be silly.
Jus that I have done my works and some research online, but haven't found a solution.
Not sure if that is a c# issue or a cAlgo issue.
Many thanks
Wjack07.
@Wjack07