Experts: Examples from the book "Neural networks for algorithmic trading with MQL5" - page 4

 
no " our_model.net ", what are we going?
 
اللعبه :

MQL5 :

Author: MetaQuotes

I am a new technology expert, software developer, and application creator.
 
Thank you so much to the author for the book! The only minus)))) - my Alice Pro lost the magic of "consciousness" for me) With respect, Igor.
 
//+------------------------------------------------------------------+
//|                                          Advanced FVG EA.mq5     |
//+------------------------------------------------------------------+
#property strict

input double Lots = 0.1;
input int TakeProfit = 200;
input int StopLoss = 200;
input int MaxLookback = 50;
input int Slippage = 5;
input int MagicNumber = 123456;
input double MaxSpreadPoints = 20.0; // Maksimum izin verilen spread
input int MA_Period = 50; // Trend filtresi
input int StartHour = 8;  // İşlem saat aralığı başlangıç
input int EndHour = 20;   // İşlem saat aralığı bitiş

//+------------------------------------------------------------------+
int OnInit()
  {
   Print("Advanced FVG EA başlatıldı.");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   // Yeni bar kontrolü
   static datetime lastBarTime = 0;
   MqlRates candles[3];
   if(CopyRates(_Symbol, PERIOD_M5, 0, 3, candles) < 3) return;
   if(candles[0].time == lastBarTime) return;
   lastBarTime = candles[0].time;

   // Zaman filtresi
   int currentHour = TimeHour(TimeCurrent());
   if(currentHour < StartHour || currentHour >= EndHour) return;

   // Spread kontrolü
   double spread = (SymbolInfoDouble(_Symbol, SYMBOL_ASK) - SymbolInfoDouble(_Symbol, SYMBOL_BID)) / _Point;
   if(spread > MaxSpreadPoints) return;

   // Pozisyon kontrolü
   if(PositionSelect(_Symbol)) return;

   // Trend filtresi (MA)
   double ma = iMA(_Symbol, PERIOD_M5, MA_Period, 0, MODE_SMA, PRICE_CLOSE, 0);
   double price = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   // FVG tespiti
   double fvgHigh = 0;
   double fvgLow = 0;
   bool isBullishFVG = false;
   bool isBearishFVG = false;

   MqlRates rates[];
   if(CopyRates(_Symbol, PERIOD_M5, 2, MaxLookback, rates) < 3) return;

   for(int i = 0; i < ArraySize(rates)-2; i++)
     {
      double high0 = rates[i].high;
      double low2 = rates[i+2].low;
      double low0 = rates[i].low;
      double high2 = rates[i+2].high;

      // Bullish FVG (sadece yükselen trendde aç)
      if(high0 < low2 && price > ma)
        {
         isBullishFVG = true;
         fvgHigh = low2;
         fvgLow = high0;
         break;
        }
      // Bearish FVG (sadece düşen trendde aç)
      else if(low0 > high2 && price < ma)
        {
         isBearishFVG = true;
         fvgHigh = low0;
         fvgLow = high2;
         break;
        }
     }

   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

   // İşlem açma
   if(isBullishFVG && bid <= fvgHigh && bid >= fvgLow)
     {
      trade_buy(ask);
     }
   else if(isBearishFVG && ask >= fvgLow && ask <= fvgHigh)
     {
      trade_sell(bid);
     }
  }
//+------------------------------------------------------------------+
void trade_buy(double price)
  {
   double sl = price - StopLoss * _Point;
   double tp = price + TakeProfit * _Point;

   MqlTradeRequest req = {};
   MqlTradeResult res  = {};

   req.action = TRADE_ACTION_DEAL;
   req.symbol = _Symbol;
   req.volume = Lots;
   req.type = ORDER_TYPE_BUY;
   req.price = price;
   req.sl = NormalizeDouble(sl, _Digits);
   req.tp = NormalizeDouble(tp, _Digits);
   req.deviation = Slippage;
   req.magic = MagicNumber;
   req.comment = "FVG Buy";

   if(OrderSend(req, res))
      Print("Buy order gönderildi: ", res.retcode);
   else
      Print("Buy order hatası: ", res.retcode);
  }
//+------------------------------------------------------------------+
void trade_sell(double price)
  {
   double sl = price + StopLoss * _Point;
   double tp = price - TakeProfit * _Point;

   MqlTradeRequest req = {};
   MqlTradeResult res  = {};

   req.action = TRADE_ACTION_DEAL;
   req.symbol = _Symbol;
   req.volume = Lots;
   req.type = ORDER_TYPE_SELL;
   req.price = price;
   req.sl = NormalizeDouble(sl, _Digits);
   req.tp = NormalizeDouble(tp, _Digits);
   req.deviation = Slippage;
   req.magic = MagicNumber;
   req.comment = "FVG Sell";

   if(OrderSend(req, res))
      Print("Sell order gönderildi: ", res.retcode);
   else
      Print("Sell order hatası: ", res.retcode);
  }
//+------------------------------------------------------------------+
 
When I use the gpt_not_norm.net after running the "gpt_test_not_norm" script I get the following error

" Error of Feed Forward: 0" in the strategy tester

I made sure to set the "BarsToLine" input variable to 40, which i used for collecting and for training the model.

if I used the "attention" script it works fine


 
It is a great and very useful work, but there is a problem.(Error of load mode gpt_not_norm.net: 5008)Is there a solution for it?
 
The power of traders most the Best
 

Hi everyone. I believe many of us have hit into errors and it's very frustrating. To be honest with you, I too was very excited in the beginning to get the expert advisor to work and as expected found myself in a pile of errors. 

If you have patience and go through the book while looking at the code step by step I guarantee you will find yourself doing the right thing and getting the results you want. What you need the most is to understand the mql5 language as best you can.


I am luckily able to get the whole code to work and the expert advisor is also working but I need a strategy.


One more thing. Whenever the code is running and I stop it, I am getting two buffer objects leaking in memory. I need help finding this bug.

 
607967 #:

One more thing. Whenever the code is running and I stop it, I am getting two buffer objects leaking in memory. I need help finding this bug.

That usually happens when indicator handles are not released from the terminal's memory upon EA removal.

Try changing:

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(!!net)
      delete net;
   if(!!trade)
      delete trade;
   IndicatorRelease(h_RSI);
   IndicatorRelease(h_MACD);
  }

to:

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(!!net)
      delete net;
   if(!!trade)
     delete trade;
   if(h_RSI != INVALID_HANDLE || h_MACD != INVALID_HANDLE)
    {
     IndicatorRelease(h_RSI);
     IndicatorRelease(h_MACD);
    }
  } // This code is untested.