I am using a timer , copied directly from your script , only difference is that initialisation is done in Initialise ().
Here is the code.
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using System.Collections;
using System.Collections.Generic;
[B]using System.Windows.Forms;[/B]
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// TestLinkedList
/// </summary>
[Description("TestLinkedList")]
public class TestLinkedList : Strategy
{
#region Variables
// Wizard generated variables
private LinkedList<double> printlist;
private double lastprint;
private double someprint;
private LinkedListNode<double> currentnode;
[B]private System.Windows.Forms.Timer secondtimer ; [/B]
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = false;
currentnode = new LinkedListNode<double>(0.00);
printlist = new LinkedList<double>();
[B]secondtimer = new System.Windows.Forms.Timer();[/B]
//LinkedList<double> printlist = new LinkedList<double>();
}
protected override void OnStartUp()
{
[B]secondtimer.Interval = 10000;
secondtimer.Tick+= new EventHandler((sender,e)=>ProcessPerSecond(currentnode));
secondtimer.Enabled = true; [/B]
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
}
protected override void OnTermination()
{
[B]secondtimer.Dispose();[/B]
// Cleans up our Timer object
}
[B]protected void ProcessPerSecond(LinkedListNode<double> somenode)
{
var instance = new Empty();
if(Math.Round(somenode.Value,1)!= 0&&somenode!=null)
{
if(Math.Round(somenode.Value,1) != Math.Round(printlist.Last.Value,1))
{
while(somenode!=null)
{
instance.Print("From LList");
instance.Print("Last="+somenode.Value);
somenode = somenode.Next;
}
}
}
instance.Print("here");
instance.Print("Current Time= "+ DateTime.Now);
currentnode= printlist.Last;
}[/B]
protected override void OnMarketData(MarketDataEventArgs e)
{
if(e.MarketDataType==MarketDataType.Last)
{
double nowprint = e.Price;
if(Math.Round(nowprint,2)!=Math.Round(lastprint,2))
{
Print("Last Print is"+ nowprint );
printlist.AddLast(nowprint);
lastprint = nowprint;
}
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
[XmlIgnore()]
public LinkedList<double> Printlist
{
get{return printlist;} set{ printlist=value;}
}
public double Lastprint
{
get{return lastprint;} set{lastprint =value ;}
}
public double Someprint
{
get{return someprint;} set{someprint=value;}
}
[XmlIgnore()]
public LinkedListNode<double> Currentnode
{
get{return currentnode;} set{currentnode=value;}
}
[XmlIgnore()]
public Timer Secondtimer
{
get{return secondtimer;} set{secondtimer=value;}
}
#endregion
}
}
1) why is that System.Timer does not work , but System.Windows.Forms timer works
2) why is the timer getting fired twice, i tried changing
var instance = new TestLinkedList(), to another instance of some empty strategy, but i cant understand why the timer is getting fired twice.
Everything works under visual studio.. I have checked individual logic.
The Print("here") along with the time is getting printed twice.
Please help

Comment