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

 
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.
 
tiagobr:
I don't understanding why MQL does not create an own neural network for metatrader, avoiding a lot of work for commom mortals.
If you search mql5.com for neural networks you'll get a lot of articles and codes - all the stuff is available for you on the "plug and play" basis. Don't they suit your needs?
 

Hi,

 

Thanks you for the article because it is very helpful to start knowing how to develop programs. Howeverm I am a newbie and I would like to know how I can run all the steps. I could download the data using the script but then I do not know how I perform the normalization and timeboxing in Metatrader. Is there a step by step information about running the codes? Thanks you in advance and sorry for a so basic question.

 

Best regards 

 

Hi,

 I'm stuck at

7. Neural Network Training

 I downloaded .Net Core, Visual Basic Code for Mac, Encog 3.3

What should I do next with Encog?

 Thanks in advance. 

 

There are also broken links in the article.

Would there be any update?

i.e. 

error calculation and training algorithms 

Full ENCOG documentation is available online.

 

HI ,nvesteo

I downloaded the sample code, with MT5 loading neuralencogindicator display exception, ask for help.


 

Hi Guys,

Really excellent article, but i didn't reproduce the same result.

When called the indicator it is not normalized to 1 and -1 like example of article and plot just a straight line.

Somebody did have this problem and solve it?

 
Automated-Trading:

Try to change Decimal symbol to "." instead of "," in Control Panel->Region and Language->Additional settings...


This was my problem. Change this and solve it. 

THANK YOU!! 

 
Indicator makes no drawing. Copied dll files to different locations, still no result. Any idea?
 
Can this work with MT4?