Discussion of article "Using MetaTrader 5 Indicators with ENCOG Machine Learning Framework for Timeseries Prediction" - page 3

 

Have anyone made money using this Neural net Expert Advisor?

 

Would like to see this translated into Encog 3.1; since I am having issues with the original version on Norwegian platform.

On 3.1 I am not sure how to do the time boxing, and when skipping this step, the network does not seem to produce the final


            // Step 2: Normalize
            Console.WriteLine("Step 2: Create Future Indicators");

            var analyst = new EncogAnalyst();
            var wizard = new AnalystWizard(analyst);
            wizard.Wizard(new System.IO.FileInfo(STEP2_FILENAME), true, AnalystFileFormat.DecpntComma);
            analyst.Script.Normalize.NormalizedFields[0].MakePassThrough();      //Is this needed?
            analyst.Script.Normalize.NormalizedFields[1].MakePassThrough();
            var norm = new AnalystNormalizeCSV();
            norm.Analyze(new System.IO.FileInfo(STEP2_FILENAME), true, CSVFormat.English, analyst);
            norm.ProduceOutputHeaders = true;

            norm.Normalize(new System.IO.FileInfo(STEP4_FILENAME));

// STEP 3 omitted since I dont know how to time box in 3.1. It says Optional in the original sample.

            Console.WriteLine("Step 4: Train");
            Console.ReadKey();
            INeuralDataSet training = (BasicNeuralDataSet)EncogUtility.LoadCSV2Memory(STEP4_FILENAME, 3 + externalIndicatorCount,   // I cannot find well documented what the input count and ideal count should be. Identical?
                                                                                      3 + externalIndicatorCount, true, CSVFormat.English, true);
            BasicNetwork network = new BasicNetwork();
            network.AddLayer(new BasicLayer(new ActivationTANH(), true, inputNeurons));
            network.AddLayer(new BasicLayer(new ActivationTANH(), true, HIDDEN1_NEURONS));
            network.AddLayer(new BasicLayer(new ActivationLinear(), true, outputNeurons));
            network.Structure.FinalizeStructure();
            network.Reset();
            // train the neural network
            EncogUtility.TrainConsole(network, training, 3);
            Console.WriteLine(@"Training complete, saving network.");  // It never gets here, so obviously somethingis wrong
            EncogDirectoryPersistence.SaveObject(new System.IO.FileInfo(STEP5_FILENAME), network);
      

As it stands (in the original sample/version) I have my first problem in the ind.Process line, where the produced file has 3 columns only. The Analyze step seem to be picking up the file correctly with all 6 columns, but the produced file should have 7 columns. When setting Country settings to US(English) the produced file is OK, but this is not my normal config and gives me some other issues I would like to avoid.


            ProcessIndicators ind = new ProcessIndicators();
            ind.Analyze(STEP1_FILENAME, true, CSVFormat.DECIMAL_POINT);
            int externalIndicatorCount = ind.Columns.Count - 3;
            ind.AddColumn(new BestReturn(RESULT_WINDOW,true)); 
            ind.Process(STEP2_FILENAME);    
 

Hi,

I have eventually worked our where to put the dlls, got the script and indicator to work but not the ea.

My Intel  i7 core 1st generation wants to access OpenCL for multicore computing which I don't seem to have therefore the ea doesn't want to know.

I transferred all this to my Intel i7 core 2nd generation laptop and now it wants my EncogNNTrainDLL.dll in the 64 bit version! 

I have scoured the internet for this but don't seem to be able to put my hands on it - anybody have any ideas?

Brilliant article by the way, I have always been interested in neural nets - right from the days when computer memory was measured in kilobytes.

Love Jeff Heaton's videos - well worth watching. 

Thank you for that - Rewop 

 

Hi Ivesteo, 

Good article, thanks!

May I know what type of training you're using? Are you using SOM, or FeedForward Network. I'm not really clear what is the Ideal data you're using.

Thanks,

HyperPro. 

 

Great article.  I'm a very appreciative C# developer. 

I followed your previous article on getting Unmanaged DLL to talk to .NET application. I then used managed pipes to allow my C# wrapped code to talk to a .NET web-application with WCF. 

I plan to back it onto a SQL Database with reporting and remote order management of the EA. The next step is to plugin some Neural Network code and start testing. 

Thanks again, these are some of the best articles I have read recently. 

 

Hi guys,

I try to port this article to encog v.3.2 but I have problem with step3 time-boxes. Is someone able to do step 3?


 // Step 1: Create future indicators
            Console.WriteLine("Step 1: Analyze MT5 Export & Create Future Indicators");
            ProcessIndicators ind = new ProcessIndicators();
            ind.Analyze(new FileInfo(STEP1_FILENAME), true, CSVFormat.DecimalPoint);
            int externalIndicatorCount = ind.Columns.Count - 3;
            ind.AddColumn(new BestReturn(RESULT_WINDOW, true));
            ind.Process(new FileInfo(STEP2_FILENAME));
            Console.WriteLine("External indicators found: " + externalIndicatorCount);

            // Step 2: Normalize
            Console.WriteLine("Step 2: Create Future Indicators");
            var analyst = new EncogAnalyst();
            var wizard = new AnalystWizard(analyst);
            wizard.Goal = AnalystGoal.Classification;
            wizard.Wizard(new System.IO.FileInfo(STEP2_FILENAME), true, AnalystFileFormat.DecpntComma);
            analyst.Script.Normalize.NormalizedFields[0].MakePassThrough();      //Is this needed?
            analyst.Script.Normalize.NormalizedFields[1].MakePassThrough();

            var norm = new AnalystNormalizeCSV();
            norm.ExpectInputHeaders = true;
            norm.Format = CSVFormat.English;
            norm.Analyze(new FileInfo(STEP2_FILENAME), true, CSVFormat.English, analyst);
            norm.ProduceOutputHeaders = true;

            norm.Normalize(new FileInfo(STEP3_FILENAME));


            Console.WriteLine("Step 3: Time-boxses");
            // neuron counts
            int inputNeurons = INPUT_WINDOW * externalIndicatorCount;
            int outputNeurons = PREDICT_WINDOW;

            FileInfo rawFile = new FileInfo(STEP3_FILENAME);


               //Step 3 

                HOW???
            
            Console.WriteLine("Step 4: Train");
            IMLDataSet training = (IMLDataSet)EncogUtility.LoadCSV2Memory(STEP4_FILENAME, inputNeurons,
                                                                                     outputNeurons, true, CSVFormat.English,false);
            

            BasicNetwork network = new BasicNetwork();
            network.AddLayer(new BasicLayer(new ActivationTANH(), true, inputNeurons));
            network.AddLayer(new BasicLayer(new ActivationTANH(), true, HIDDEN1_NEURONS));
            network.AddLayer(new BasicLayer(new ActivationLinear(), true, outputNeurons));
            network.Structure.FinalizeStructure();
            network.Reset();

            //EncogUtility.TrainToError(network, training, TARGET_ERROR);
            EncogUtility.TrainConsole(network, training, 3);
            Console.WriteLine(@"Training complete, saving network.");  // It never gets here, so obviously somethingis wrong
            EncogDirectoryPersistence.SaveObject(new System.IO.FileInfo(STEP5_FILENAME), network);
 

Hi,

I am also trying to port all the necessary stuff up to version 3.2. I see no other way because the version 2.6 is not available on the net. But it seems to be a ride through the jungle. I am yet working for about 4 weeks. But I cannot see the end.

Did anybody succeed in porting? Can anybody help.

Thank you very much.

refltr 

 
i have succeded porting this thread with encog 3.3 and using mt4. but i havent done yet with expert advisor. just pm me if you need help at porting
 
Valentin Petkov:

Hi guys,

I try to port this article to encog v.3.2 but I have problem with step3 time-boxes. Is someone able to do step 3?


Use Mine @Valentin petkov. i am using encog 3.3 . i hope can help you ..

 

using System;

using Encog.Util.CSV;

using Encog.App.Quant.Indicators;

using Encog.App.Quant.Indicators.Predictive;

using Encog.Util.Simple;

using Encog.Neural.Networks;

using Encog.Neural.Networks.Layers;

using Encog.Engine.Network.Activation;

using Encog.Persist;

using Encog.App.Analyst;

using System.IO;

using Encog.App.Analyst.CSV.Normalize;

using Encog.App.Analyst.Wizard;

using Encog.Util.Arrayutil;

using Encog.Util.ArrayUtil;

using Encog.ML.Data;


namespace Encog

{

    public class Program

    {

        /// <summary>

        /// The directory that all of the files will be stored in.

        /// </summary>

        public const String DIRECTORY = "your directory files";


        /// <summary>

        /// The input file that starts the whole process.  This file should be downloaded from NinjaTrader using the EncogStreamWriter object.

        /// </summary>

        public const String STEP1_FILENAME = DIRECTORY + "mt4export.csv";


        /// <summary>

        /// We apply a predictive future indicator and generate a second file, with the additional predictive field added.

        /// </summary>

        public const String STEP2_FILENAME = DIRECTORY + "step2_future.csv";


        /// <summary>

        /// Next the entire file is normalized and stored into this file.

        /// </summary>

        public const String STEP3_FILENAME = DIRECTORY + "step3_norm.csv";


        /// <summary>

        /// The file is time-boxed to create training data.

        /// </summary>

        public const String STEP4_FILENAME = DIRECTORY + "step4_train.csv";


        /// <summary>

        /// Finally, the trained neural network is written to this file.

        /// </summary>

        public const String STEP5_FILENAME = DIRECTORY + "step5_network.eg";


        /// <summary>

        /// The size of the input window.  This is the number of bars used to predict the next bar.

        /// </summary>

        public const int INPUT_WINDOW = 6;


        /// <summary>

        /// The number of bars forward we are trying to predict.  This is usually just 1 bar.  The future indicator used in step 1 may

        /// well look more forward into the future. 

        /// </summary>

        public const int PREDICT_WINDOW = 1;


        /// <summary>

        /// The number of bars forward to look for the best result.

        /// </summary>

        public const int RESULT_WINDOW = 5;


        /// <summary>

        /// The number of neurons in the first hidden layer.

        /// </summary>

        public const int HIDDEN1_NEURONS = 12;


        /// <summary>

        /// The target error to train to.

        /// </summary>

        public const double TARGET_ERROR = 0.01;


        static void Main(string[] args)

        {

            

            // Step 1: Create future indicators

            Console.WriteLine("Step 1: Analyze NinjaTrader Export & Create Future Indicators");

            ProcessIndicators ind = new ProcessIndicators();

            ind.Analyze(new FileInfo(STEP1_FILENAME), true, CSVFormat.English);  //.Analyze(STEP1_FILENAME, true, AnalystFileFormat.DecpntComma);

            int externalIndicatorCount = ind.Columns.Count - 3;

            ind.AddColumn(new BestReturn(RESULT_WINDOW, true)); // najlepszy zwrot w nastepnym RESULT_WINDOW

            ind.Process(new FileInfo(STEP2_FILENAME));// Process(STEP2_FILENAME);

            Console.WriteLine("External indicators found: " + externalIndicatorCount);

            Console.ReadKey();

            

            // Step 2: Normalize

            Console.WriteLine("Step 2: Create Future Indicators");

            var analyst = new EncogAnalyst();

            var wizard = new AnalystWizard(analyst);

            wizard.Wizard(new FileInfo(STEP2_FILENAME), true, AnalystFileFormat.DecpntComma);

            analyst.Script.Normalize.NormalizedFields[0].Action=NormalizationAction.PassThrough;

            analyst.Script.Normalize.NormalizedFields[1].Action = NormalizationAction.PassThrough;


            analyst.Script.Normalize.NormalizedFields[2].Action = NormalizationAction.Normalize;

            analyst.Script.Normalize.NormalizedFields[3].Action = NormalizationAction.Normalize;

            analyst.Script.Normalize.NormalizedFields[4].Action = NormalizationAction.Normalize;

            analyst.Script.Normalize.NormalizedFields[5].Action = NormalizationAction.Normalize;

            analyst.Script.Normalize.NormalizedFields[6].Action = NormalizationAction.Normalize;


            var norm = new AnalystNormalizeCSV();

            norm.Analyze(new FileInfo(STEP2_FILENAME), true, CSVFormat.English, analyst);

            norm.ProduceOutputHeaders = true;

            norm.Normalize(new FileInfo(STEP3_FILENAME));

            

            // neuron counts

            int inputNeurons = INPUT_WINDOW * externalIndicatorCount;

            int outputNeurons = PREDICT_WINDOW;

            Console.WriteLine("inputneurons : {0}",inputNeurons);

            Console.WriteLine("outputNeurons : {0}", outputNeurons);

            Console.ReadKey();

            

            // Step 3: Time-box (optional)

            Console.WriteLine("Step 3: Timebox");

            var twcsv = new TemporalWindowCSV();

            twcsv.Analyze(new FileInfo(STEP3_FILENAME), true, CSVFormat.English);

            twcsv.InputWindow = INPUT_WINDOW;

            twcsv.PredictWindow = PREDICT_WINDOW;

            int index = 0;

            twcsv.Fields[index++].Action = TemporalType.Ignore;

            twcsv.Fields[index++].Action = TemporalType.Ignore;

            twcsv.Fields[index++].Action = TemporalType.Ignore;

            for (int i = 0; i < externalIndicatorCount; i++)

                twcsv.Fields[index++].Action = TemporalType.Input; // external indicators

            twcsv.Fields[index++].Action = TemporalType.Predict; // PredictBestReturn


            twcsv.Process(STEP4_FILENAME);

            Console.ReadKey();

            

            // Step 4: Train neural network

            Console.WriteLine("Step 4: Train");

            Console.ReadKey();

            IMLDataSet training = EncogUtility.LoadCSV2Memory(STEP4_FILENAME, inputNeurons, outputNeurons, true, CSVFormat.English,false);

            BasicNetwork network = new BasicNetwork();

            network.AddLayer(new BasicLayer(new ActivationTANH(), true, inputNeurons));

            network.AddLayer(new BasicLayer(new ActivationTANH(), true, HIDDEN1_NEURONS));

            network.AddLayer(new BasicLayer(new ActivationLinear(), true, outputNeurons));

            network.Structure.FinalizeStructure();

            network.Reset();


            //EncogUtility.TrainToError(network, training, TARGET_ERROR);

            EncogUtility.TrainConsole(network, training,1);

            Console.ReadKey();

            // Step 5: Save neural network and stats

            Console.WriteLine("Step 5: Save Neural network and normalized fields");

            Console.WriteLine("or here ?");

            EncogDirectoryPersistence.SaveObject(new FileInfo(STEP5_FILENAME), network);

            Console.WriteLine("error here ?");

            //EncogDirectoryPersistence.SaveObject(new FileInfo(STEP5_FILENAME), analyst);

            Console.ReadKey();

        }

    }

}

 
Had anyone success porting to Encog 3.3? It seems there is no interests in make MQL compatible with ENCOG 3.3 ou later versions. I don't understanding why MQL does not create an own neural network for metatrader, avoiding a lot of work for commom mortals.
Reason: