I created an indicator from something that was on a forum. It is a SecondsTimer that uses a Custom Event and automatically stops timer after a certain amount. The MyCustomTimerEvent(...) method is the thing I have a question about.
The way it works is when StartTimer() is executed, it will start counting based on the Clock on your computer event intervals. So, it is not based on OnBarUpdate.
The whole purpose of this is because I was writing a Strategy that enters on EntryStopLimit using IOrders.
When the order is Accepted, it starts the Timer.
When the state of the entryOrder is "Working" but not "Filled", and the number of seconds is lets say 20, it Cancels Order.
If I was going to write a Strategy that uses this SecondsTimer, is it possible to Override the MyCustomTimerEvent(...) from a strategy?
I want to not have all my methods in one file. I want to abstract things out, so I figured I could do it in the form of an Indicator. The only problem is the MyCustomTimerEvent(....) is inside of the Indicator, and therefore I don't know how to say from the strategy that seconds == 20 as soon as it happens.
In-fact, I think I have to make up another custom event for the Strategy and somehow synch it to the Indicator one.
I am showing 2 files, one SecondsTimer.cs which is an Indicator, and sd.cs which is a Strategy. I was hoping to execute code in the Strategy based on the Seconds in the Indicator. Right now if you run sd.cs, it simply starts the clock, counts to 10, then stops. But this is inside of the Custom Event.
What if I have a strategy and I am using EntryStopLimit order and if the state gets "Accepted", but not "Filled" after 10 seconds, I want to Cancel the Order. I was hoping to have one Indicator that just counts when I say start and when I say this event happens, it stops.
This is the Indicator
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using System.Windows.Forms;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/*
Spencer Davis [email protected]
A Seconds Timer that has its own Event Processor and does not rely on OnBarUpdate() so it is smooth as it should be :-)
*/
[Description("A Seconds Timer based on the windows Clock with its own multi-threaded event separate from OnBarUpdate, so smooth accurate Seconds count. ")]
public class SecondsTimer : Indicator
{
#region Variables
#region Custom Timer Functions
// Public so it can be turned OFF
// You probably won't need to turn it off since it gets
// turned off automatically. But if you need to, here it is :-)
public void StopTimer()
{
myTimer.Stop();
timerStopped = true;
timerStarted = false;
Print("Timer "+ TimerName+ " stopped!");
}
// Public so it can be turned ON
public void StartTimer()
{
myTimer.Tick += new EventHandler(TimerEventProcessor);
myTimer.Interval = 1000;
myTimer.Start();
timerStarted = true;
timerStopped = false;
Print("Timer "+ TimerName+ " started!");
}
private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
{
this.TriggerCustomEvent(MyCustomTimerEvent, 0, myTimer.Interval);
}
private void MyCustomTimerEvent(object state)
{
ExecuteEvent(); // I want to be able to override this method from a Strategy ??
}
public …