Export & Import Data for Single-Layer Perceptron

 

Hi guys, I'm very new in MQL5 programming., I came across the "Artificial Intelligence EA by Yury Reshetov". I converted the code from MQL4 to MQL5 the best I could, but one thing I can't seem accomplish is to export the data and use it for the EA to train itself. I've been reading articles like this one "https://www.mql5.com/en/articles/252"., but still having issues on grasping the way to do it. Not sure if its much to ask, but can anyone give me a hand? Here is the code I have so far:

#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>

CTrade trade;
CPositionInfo position;

input int    x1 = 135;
input int    x2 = 127;
input int    x3 = 16;
input int    x4 = 93;
input int SL = 100;
input int TP = 100;
input int tlsl = 100;
input int tltp = 100;
input int inprofit = 100;
input int buySL = 100;
input int buyTP = 100;
input int buytlsl = 100;
input int buytltp = 100;
input int buyinprofit = 100;


void OnTick()
{
   double bid = NormalizeDouble(SymbolInfoDouble(NULL,SYMBOL_BID),_Digits);
   double ask = NormalizeDouble(SymbolInfoDouble(NULL,SYMBOL_ASK),_Digits);

   if(PositionsTotal()==0)
   if(perceptron() < 0) // SELL ORDER
      {
      trade.Sell(0.10,NULL,bid,(bid+SL*_Point)),(bid-TP*_Point),NULL);
      }
   else 
   if(perceptron() > 0) // BUY ORDER
      {
      trade.Buy(0.10,NULL,ask,(ask-buySL*_Point)),(ask+buyTP*_Point),NULL);
      }
   CheckTrailingStop(bid, ask);  
}
void CheckTrailingStop(double bid, double ask)
{  
   for(int i=PositionsTotal()-1; i>=0; i--)
      {
         string symbol=PositionGetSymbol(i);
         if(_Symbol==symbol)
         {
         ulong PT=PositionGetInteger(POSITION_TICKET);
         double csl=PositionGetDouble(POSITION_SL);
         double ctp=PositionGetDouble(POSITION_TP);
         double price=PositionGetDouble(POSITION_PRICE_OPEN);
         if(bid==price-inprofit*_Point)
            {
            trade.PositionModify(PT,(bid-csl-tlsl*_Point),(bid-ctp-tltp);               
            }
         }   
      	 else 
         {
         ulong PT=PositionGetInteger(POSITION_TICKET);
         double csl=PositionGetDouble(POSITION_SL);
         double ctp=PositionGetDouble(POSITION_TP);
         double price=PositionGetDouble(POSITION_PRICE_OPEN);
         if(ask==price+buyinprofit*_Point)
            {
            trade.PositionModify(PT,(ask+csl+buytlsl*_Point),(ask+ctp+buytltp*_Point)); 
            }
         }
      }
} 
   double perceptron()
  {
      // iAC Indicator
   double iprice[];
   int iACDef=iAC(_Symbol,_Period);
   ArraySetAsSeries(iprice,true);
   CopyBuffer(iACDef,0,0,22,iprice);
   double iACVal0=NormalizeDouble(iprice[0],4);
   double iACVal7=NormalizeDouble(iprice[7],4);
   double iACVal14=NormalizeDouble(iprice[14],4);
   double iACVal21=NormalizeDouble(iprice[21],4);
 
   double w1 = x1 - 100;
   double w2 = x2 - 100;
   double w3 = x3 - 100;
   double w4 = x4 - 100;
   double a1 = iACVal0;
   double a2 = iACVal7;
   double a3 = iACVal14;
   double a4 = iACVal21;
   return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
  }
Using MetaTrader 5 Indicators with ENCOG Machine Learning Framework for Timeseries Prediction
Using MetaTrader 5 Indicators with ENCOG Machine Learning Framework for Timeseries Prediction
  • www.mql5.com
This article presents connecting MetaTrader 5 to ENCOG - Advanced Neural Network and Machine Learning Framework. It contains description and implementation of a simple neural network indicator based on a standard technical indicators and an Expert Advisor based on a neural indicator. All source code, compiled binaries, DLLs and an exemplary trained network are attached to the article.
 
In MQL5, the indicator handle MUST be received ONCE! And you MUST do it in OnInit !!!