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;
}
}