MetaTrader 5용 ExpertClor_v01: 포지션 닫기 전용 EA 소개

Mike 2017.08.10 21:55 66 0 0
첨부파일

아이디어 저자John Smith, MQL5 코드 저자barabashkakvn.

ExpertClor_v01은 포지션을 닫기 위한 보조 Expert Advisor입니다:

ExpertClor_v01

이 EA는 포지션을 Breakeven으로 이동시키고, Stop Loss는 StopATR_auto 지표를 기반으로 계산됩니다. 포지션은 두 개의 이동 평균(MA)이 교차할 때 닫힙니다.

EA가 제대로 작동하려면, 컴파일된 StopATR_auto 지표 파일을 다음 폴더에 추가해야 합니다: MQL5\Indicators\Downloads:

//+------------------------------------------------------------------+
//| Expert initialization function                                     |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
...
//--- create handle of the indicator iCustom
   handle_iCustom=iCustom(m_symbol.Name(),TimeFrame,"Downloads\\StopATR_auto",
                          CountBarsForAverage,
                          Target
                          );

이 Expert Advisor는 포지션을 닫기만 하지만, 포지션을 여는 작은 코드도 추가했습니다:

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(MQLInfoInteger(MQL_DEBUG) || MQLInfoInteger(MQL_PROFILER) || 
      MQLInfoInteger(MQL_TESTER) || MQLInfoInteger(MQL_OPTIMIZATION))
     {
      static long counter=-50;
      static bool trade_buy=true;

      if(counter==0)
         m_trade.Buy(m_symbol.LotsMin());
      else if(counter%1500==0)
        {
         if(RefreshRates())
           {
            if(trade_buy)
              {
               OpenBuy(m_symbol.LotsMin());
               trade_buy=false;
              }
            else
              {
               OpenSell(m_symbol.LotsMin());
               trade_buy=true;
              }
           }
         else
            counter=counter-9;
    }

      counter++;
  }
//---

이 기능은 이 Expert Advisor를 테스트하거나 최적화할 때만 작동하며, 매 1,500틱마다 Buy 또는 Sell이 열립니다.

목록
댓글 0