Experts: "MQL5를 이용한 알고리즘 트레이딩을 위한 신경망" 책의 예시 - 페이지 4

 
아니 " our_model.net", 어디로 가나요?
 
اللعبه :

MQL5 :

언어 : 메타쿼트

메타쿼터에 대한 자세한 내용은 다음을 참조하십시오.
 
책을 주신 저자에게 정말 감사합니다! 유일한 마이너스)))) - 나의 앨리스 프로는 나를 위해 "의식"의 마법을 잃었습니다) 존경심을 담아, 이고르.
 
//+------------------------------------------------------------------+
//|고급 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; // 스프레드 최대화
input int MA_Period = 50; // 트렌드 필터링
input int StartHour = 8;  // 이글루시큐리티에 가입하기
input int EndHour = 20;   // 이 게시물에 댓글 달기

//+------------------------------------------------------------------+
int OnInit()
  {
   Print("고급 FVG EA 구매.");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   // 바 제어
   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;

   // 자만 필터링
   int currentHour = TimeHour(TimeCurrent());
   if(currentHour < StartHour || currentHour >= EndHour) return;

   // 컨트롤 확산
   double spread = (SymbolInfoDouble(_Symbol, SYMBOL_ASK) - SymbolInfoDouble(_Symbol, SYMBOL_BID)) / _Point;
   if(spread > MaxSpreadPoints) return;

   // 제어 센터
   if(PositionSelect(_Symbol)) return;

   // 트렌드 필터링 (MA)
   double ma = iMA(_Symbol, PERIOD_M5, MA_Period, 0, MODE_SMA, PRICE_CLOSE, 0);
   double price = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   // FVG 테스피티
   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;

      // 강세 FVG (상승 추세)
      if(high0 < low2 && price > ma)
        {
         isBullishFVG = true;
         fvgHigh = low2;
         fvgLow = high0;
         break;
        }
      // 약세 FVG (하락 추세)
      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);

   // 이슬렘 아스마
   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("구매 주문 기준: ", res.retcode);
   else
      Print("주문 하타시 구매: ", 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("판매 주문 기준: ", res.retcode);
   else
      Print("주문 하타시 판매: ", res.retcode);
  }
//+------------------------------------------------------------------+
 
"gpt_test_not_norm" 스크립트를 실행한 후 gpt_not_norm.net을 사용할 때 다음 오류가 발생합니다.

" 전략 테스터에서 "피드 포워드 오류: 0" 발생

수집 및 모델 훈련에 사용한 "BarsToLine" 입력 변수를 40으로 설정했습니다.

"주의" 스크립트를 사용하면 정상적으로 작동합니다.


 
훌륭하고 매우 유용한 작업이지만 문제가 있습니다. (로드 모드 오류 gpt_not_norm.net : 5008)이에 대한 해결책이 있습니까?
 

안녕하세요, 여러분. 많은 분들이 오류에 부딪혀 매우 실망하셨을 거라고 생각합니다. 솔직히 말씀드리자면 저도 처음에는 전문 어드바이저의 도움을 받게 되어 매우 기뻤고 예상대로 오류 더미를 발견했습니다.

인내심을 가지고 코드를 차근차근 살펴보면서 책을 읽다 보면 어느새 올바른 작업을 수행하고 원하는 결과를 얻을 수 있을 것입니다. 가장 필요한 것은 mql5 언어를 최대한 이해하는 것입니다.


운 좋게도 전체 코드가 작동하고 전문 고문도 일하고 있지만 전략이 필요합니다.


한 가지 더 있습니다. 코드가 실행 중일 때 중지할 때마다 메모리에서 두 개의 버퍼 객체가 누수되고 있습니다. 이 버그를 찾는 데 도움이 필요합니다.

 
607967 #:

한 가지 더 있습니다. 코드가 실행 중일 때 중지할 때마다 메모리에서 두 개의 버퍼 객체가 누수됩니다. 이 버그를 찾는 데 도움이 필요합니다.

일반적으로 EA 제거 시 표시기 핸들이 터미널의 메모리에서 해제되지 않을 때 발생합니다.

변경해 보세요:

//+------------------------------------------------------------------+
//| 전문가 초기화 기능|
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(!!net)
      delete net;
   if(!!trade)
      delete trade;
   IndicatorRelease(h_RSI);
   IndicatorRelease(h_MACD);
  }

로 변경해 보세요:

//+------------------------------------------------------------------+
//| 전문가 초기화 기능|
//+------------------------------------------------------------------+
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);
    }
  } // 이 코드는 테스트되지 않았습니다.