Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
public class Lalgo : Strategy
{
        #region Variables
		private string filename;
		private bool init = true;
		private int outputsize = 1;
		private int inputsize = 50;
		private BasicNetwork network;
		private BasicNeuralData present;
		private BasicNeuralData predict; 
		private double[] input;
        #endregion

        /// <summary>
        /// 
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			if (init == true)
			{
				Ignite();
			}
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
			input = new double[network.InputLayer.NeuronCount];
            for (int i = 1; i < InputSize + 1; i++)
            {
                input[i] = Close[i+1] - Close[i];
                i++;
                input[i] = RSI(14, 3)[i];
                i++;
                input[i] = Stochastics(7, 14, 3).K[i];
                i++;
                input[i] = Stochastics(7, 14, 3).D[i];
                i++;
                input[i] = ADX(14)[i];
                i++;
                input[i] = OBV()[i];
                //i++;
                //input[i] = ToTime(Time[i]);
            }
			Print("Before predict");
			predict = network.Compute(present) as BasicNeuralData;
			Print("After predict");
			
			Print(predict[0].ToString());
        }
		
		/// <summary>
		/// Does the initial network loading and other dirty work that we only need to 
		/// happen once.
		/// </summary>
		private void Ignite()
		{
			Logging.StopConsoleLogging();
//			try 
//			{
				string filename = "es0909.NET";
				Load(filename);
				this.present = new BasicNeuralData(new double[InputSize * 2]);
				this.predict = new BasicNeuralData(new double[OutputSize]);
				this.init = false;
//			} 
//			catch (Exception error)
//			{
//				Print(error.ToString());
//				Print("------------------------------------------");
//				Print(error.StackTrace.ToString());
//			}
		}
		
        private void Load(string filename)
        {            
            Stream s = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryFormatter b = new BinaryFormatter();
            object obj = b.Deserialize(s);
            s.Close();
	    network = obj as BasicNetwork;
        }
}