私が試行錯誤しているアドバイザーの組み立て方 - ページ 46

削除済み  
Alexsandr San:

4本の水平線があり、そのうち2本はHeiken_Ashiからきている。

2つのレベルが売買可能で、赤と交差すると1つのシグナル、青と交差するともう1つのシグナルが 表示されます。

-------------

真ん中に位置する場合(線(赤と青)の間の)信号は動作しません - どちらかの方向に行くように、動作します。

このIndicatorにExpert Advisorを添付しました。

チャート上にインジケータをインストールし、同じチャート上にExpert Advisorをインストールする必要があります。

---------------------

ポジションを持った後、インジケータが削除され、しばらくして再度インジケータを設定した。

---------------

シグナルが発生したら、ポジションをオープンし、ラインと一緒にインジケータを削除します。


ファイル:
Exp_LN_2.mq5  20 kb
削除済み  

2人のエキスパートを組み合わせたマニュアル取引

これhttps://www.mql5.com/ru/code/24803

そしてこれhttps://www.mql5.com/ru/code/26353

AutoClose Line
AutoClose Line
  • www.mql5.com
Помощник закрытия позиции, если цена пересекла линию: Правило закрытия: цена Open и цена Close текущего бара должны оказаться по разные стороны от линии. Имя линии задаётся в параметре "Line name" - эту линию пользователь проводит сам. Тип линии может быть...
ファイル:
削除済み  
Alexsandr San:

2人のエキスパートを組み合わせたマニュアル取引

これhttps://www.mql5.com/ru/code/24803

そしてこれhttps://www.mql5.com/ru/code/26353

別の行を追加

//+------------------------------------------------------------------+
//| Enum Lor or Risk                                                 |
//+------------------------------------------------------------------+
enum ENUM_TRADE_COMMAND
  {
   close_buys=0,     // Close All Buy's
   close_sells=1,    // Close All Sell's
   close_all=2,      // Close All Buy's and Sell's
   open_buy=3,       // Open Buy
   open_sell=4,      // Open Sell
   open_buy_sell=5,  // Open Buy and Sell
  };
//--- input parameters
input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots
input ushort   InpSignalsFrequency          = 10;                // Search signals, in seconds (min value "10")
input string   InpNameR                     = "LineR";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandR   = close_all;         // Trade command:
input bool     ObjRevers                    = false;             // Obj: Revers
input string   InpNameS                     = "LineS";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandS   = close_all;         // Trade command:
input ulong    InpMagic                     = 78712995;          // Magic number
//---
ファイル:
削除済み  
Alexsandr San:

もう一行追加しました。

本格的なExpertの場合、ミッシング-。

1 - ストップロス、テイクプロフィット(ピップ単位)(表示なし

2 - 水平線からのトレーリングストップ

3 - インジケーターからの信号

さらにExpert Advisor2_LineOpenClose.mq5を 修正します。

//--- input parameters
input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots
input ushort   InpSignalsFrequency          = 10;                // Search signals, in seconds (min value "10")
input string   InpNameR                     = "LineR";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandR   = close_all;         // Trade command:
input bool     ObjRevers                    = false;             // Obj: Revers
input string   InpNameS                     = "LineS";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandS   = close_all;         // Trade command:
input ulong    InpMagic                     = 78712995;          // Magic number
//---
削除済み  
Alexsandr San:

本格的なExpertの場合、ミッシング-。

1 - ストップロス、テイクプロフィット(ピップ単位)(表示なし

2 - 水平線からのトレーリングストップ

3 - インジケーターからの信号

さらにExpert Advisor2_LineOpenClose.mq5を 修正します。

インジケーターからのシグナルを 追加

此の方

//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
double iGetArray(const int handle,const int buffer,const int start_pos,const int count,double &arr_buffer[])
  {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer))
     {
      Print("This a no dynamic array!");
      return(false);
     }
   ArrayFree(arr_buffer);
//--- reset error code
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
   if(copied!=count)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      return(false);
     }
   return(result);
  }
//+------------------------------------------------------------------+
//| Search trading signals                                           |
//+------------------------------------------------------------------+
bool SearchTradingSignals(void)
  {
//--- we work only at the time of the birth of new bar
   datetime time_0=iTime(m_symbol.Name(),Period(),0);
   if(time_0==ExtPrevBarsY)
      return(true);
   ExtPrevBarsY=time_0;
   if(!m_symbol.RefreshRates())
     {
      ExtPrevBarsY=0;
      return(false);
     }
//---
   double BuyBuffer[];
   double SellBuffer[];
   ArraySetAsSeries(BuyBuffer,true);
   ArraySetAsSeries(SellBuffer,true);
   if(!iGetArray(handle_iCustom,1,0,2,BuyBuffer) || !iGetArray(handle_iCustom,0,0,2,SellBuffer))
     {
      ExtPrevBarsY=0;
      return(false);
     }
//---
   if(BuyBuffer[1]!=0.0)
     {
      switch(InpTradeCommandY)
        {
         case  close_buys:
            ExtNeedCloseBuy=true;
            if(LongObjClosed())
               break;
         case  close_sells:
            ExtNeedCloseSell=true;
            if(ShortObjClosed())
               break;
         case close_all:
            ExtNeedCloseAll=true;
            if(LongShortObjClosed())
               break;
         case open_buy:
            ExtNeedOpenBuy=true;
            if(LongObjOpened())
               break;
         case open_sell:
            ExtNeedOpenSell=true;
            if(ShortObjOpened())
               break;
         default:
            ExtNeedOpenBuySell=true;
            if(LongShortObjOpened())
               break;
        }
     }
   if(SellBuffer[1]!=0.0)
     {
      switch(InpTradeCommandU)
        {
         case  close_buys:
            ExtNeedCloseBuy=true;
            if(LongObjClosed())
               break;
         case  close_sells:
            ExtNeedCloseSell=true;
            if(ShortObjClosed())
               break;
         case close_all:
            ExtNeedCloseAll=true;
            if(LongShortObjClosed())
               break;
         case open_buy:
            ExtNeedOpenBuy=true;
            if(LongObjOpened())
               break;
         case open_sell:
            ExtNeedOpenSell=true;
            if(ShortObjOpened())
               break;
         default:
            ExtNeedOpenBuySell=true;
            if(LongShortObjOpened())
               break;
        }
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+

これで設定

//--- input parameters
input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots
input ushort   InpSignalsFrequency          = 10;                // Search signals, in seconds (min value "10")
input string   InpNameR                     = "LineR";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandR   = open_buy;          // Trade command:
input string   InpNameS                     = "LineS";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandS   = open_sell;         // Trade command:
input string   short_name             = "Examples\\ZigzagColor"; // Name Indicators
input ENUM_TRADE_COMMAND InpTradeCommandY   = open_buy;          // Trade command: (BuyBuffer Indicators)
input ENUM_TRADE_COMMAND InpTradeCommandU   = open_sell;         // Trade command: (SellBuffer Indicators)
input bool     ObjRevers                    = false;             // Obj: Revers
//---

インジケーター信号の確認

パー

麩

ファイル:
XXX_Ind.mq5  52 kb
削除済み  
Alexsandr San:

本格的なExpertの場合、ミッシング-。

1 - ストップロス、テイクプロフィット(ピップ単位)(表示なし

2 - 水平線からのトレーリングストップ

3 - インジケーターからの信号

Expert Advisor2_LineOpenClose.mq5 を微調整する。

また、水平線からトレーリングストップを追加しました。なんとなく全部入れて、今、作業性を確認しています。

以下はその設定です。

//+------------------------------------------------------------------+
input string   t="-----  Parameters         -----";              //
input string   Template                     = "ADX";             // Имя шаблона(without '.tpl')
input double   TargetProfit                 = 999999.99;         // Цель Баланса(Ваш Баланс + сумма)
input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots
input int      InpTakeProfit                = 50;                // Take Profit ("0"-No. 5<100)
input string   t0="----- Trailing Line      -----";              //
input string   InpObjUpName                 = "TOP";             // Obj: TOP (Horizontal Line)
input ENUM_TRADE_COMMAND InpTradeCommand    = close_sells;       // Obj:  command:
input string   InpObjDownName               = "LOWER";           // Obj: LOWER (Horizontal Line)
input ENUM_TRADE_COMMAND InTradeCommand     = close_buys;        // Obj:  command:
input ushort   InpObjTrailingStop           = 30;                // Obj: Trailing Stop (distance from price to object, in pips)
input ushort   InpObjTrailingStep           = 5;                 // Obj: Trailing Step, in pips (1.00045-1.00055=1 pips)
input string   t1="----- Line name: 1       -----";              //
input string   InpNameR                     = "LineR";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandR   = open_buy;          // Trade command:
input string   t2="----- Line name: 2       -----";              //
input string   InpNameS                     = "LineS";           // Line name (Horizontal Line or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommandS   = open_sell;         // Trade command:
input string   t3="----- Indicators:        -----";              //
input string   short_name                   = "Examples\\ZigzagColor"; // Name Indicators
input bool     InpIndicators                = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY   = open_buy;          // Trade command: (BuyBuffer Indicators)
input ENUM_TRADE_COMMAND InpTradeCommandU   = open_sell;         // Trade command: (SellBuffer Indicators)
input string   t4="----- Revers Buy><Sell   -----";              //
input bool     ObjRevers                    = false;             //  Revers
//---


ファイル:
削除済み  
Alexsandr San:

水平線からのトレーリングストップも 追加しました。すべて追加したと思うので、あとは動くかどうか確認するだけです。

以下はその設定 です。

仕事の原理は、ここではこれらのパラメータです。

資金が目標額に達すると、すべてのポジションがすべてのペアで決済され、すべてのチャートが 「ADX」パターンに 変更されます。

(Expert Advisor はすべてのポジションを決済し、テンプレートのチャートを変更します。

//+------------------------------------------------------------------+
input string   t="-----  Parameters         -----";              //
input string   Template                     = "ADX";             // Имя шаблона(without '.tpl')
input double   TargetProfit                 = 999999.99;         // Цель Баланса(Ваш Баланс + сумма)

-------------------------------------------------------------

ロットパラメータ。

0.06を1ポジション、0.01を6ポジションに設定 することは可能か

input uint     maxLimits                    = 1;                 // Кол-во Позиции Открыть в одну сторону
input double   InpLots                      = 0.01;              // Lots

---------------------------------------------------------------

パラメータにテイクプロフィットTを設定します。

pipsの数でトリガーされ(0ならポジションを閉じる)、距離を指定する必要があります。

input int      InpTakeProfit                = 50;                // Take Profit ("0"-No. 5<100)

XXX_Trailing Line.mq5

削除済み  
Alexsandr San:

インジケーターからのシグナルを 追加

このように

設定では、次のようになります。

インジケーターからの信号の確認

インジケータはクローズするポジションを開くだけなので、ターミナルのExpert Advisorから取りました(Moving Average)

ちょっとだけ逆転の罰金

//+------------------------------------------------------------------+
//| Check for close position conditions                              |
//+------------------------------------------------------------------+
void CheckForClose(void)
  {
//---
   double BuyBuffer[];
   double SellBuffer[];
   ArraySetAsSeries(BuyBuffer,true);
   ArraySetAsSeries(SellBuffer,true);
   if(!iGetArray(handle_iCustom,1,0,2,BuyBuffer) || !iGetArray(handle_iCustom,0,0,2,SellBuffer))
     {
      return;
     }
//--- positions already selected before
   bool signal=false;
   long type=PositionGetInteger(POSITION_TYPE);
   if(ObjRevers)
     {
      if(type==(long)POSITION_TYPE_BUY && BuyBuffer[1]!=0.0)
         signal=true;
      if(type==(long)POSITION_TYPE_SELL && SellBuffer[1]!=0.0)
         signal=true;
     }
   if(!ObjRevers)
     {
      if(type==(long)POSITION_TYPE_BUY && SellBuffer[1]!=0.0)
         signal=true;
      if(type==(long)POSITION_TYPE_SELL && BuyBuffer[1]!=0.0)
         signal=true;
     }
//--- additional checking
   if(signal)
     {
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && Bars(_Symbol,_Period)>100)
         m_trade.PositionClose(_Symbol,3);
     }
//---
  }
//+------------------------------------------------------------------+

撮影者

セマフォ・インジケータを使った最もシンプルなトレーディングシステム

2012年1月13日 13:27



代表的なセマフォ、シグナルインジケータのサンプル

現在、Code Baseには 似たようなインジケータがたくさんあります。 この記事の目的上、ソース・リソースへのリンクをいくつか紹介するにとどめます。


ファイル:
削除済み  
Alexsandr San:

インジケータから、ポジションを開くだけで、閉じるには、私は端末(移動平均)のExpert Advisorから方法を取った

リバースに少し細工をした

ポジションを閉じるときが嫌なんです。インジケータからポジションを 閉じる機能を修正する方法を探しています。

-------------------------------------------------------------------

修正しました。 移動平均の インジケーターから追加しました。

//+------------------------------------------------------------------+
//| Position select depending on netting or hedging                  |
//+------------------------------------------------------------------+
bool SelectPosition()
  {
   bool res=false;
//--- check position in Hedging mode
   if(ExtHedging)
     {
      uint total=PositionsTotal();
      for(uint i=0; i<total; i++)
        {
         string position_symbol=PositionGetSymbol(i);
         if(_Symbol==position_symbol && InpMagic==PositionGetInteger(POSITION_MAGIC))
           {
            res=true;
            break;
           }
        }
     }
//--- check position in Netting mode
   else
     {
      if(!PositionSelect(_Symbol))
         return(false);
      else
         return(PositionGetInteger(POSITION_MAGIC)==InpMagic); //---check Magic number
     }
//--- result for Hedging mode
   return(res);
  }
//+------------------------------------------------------------------+

で、OnTick()で

      if(InpCloseOpposite && InpIndicators)
        {
         //---
         if(SelectPosition())
            CheckForClose();
         else
            SearchTradingSignals();
        }
      if(!InpCloseOpposite && InpIndicators)
        {
         SearchTradingSignals();
        }

SelectPosition() がそれを通過する必要があることが判明しました。

ファイル:
削除済み  

それでも、コードに違いがあり、Indicatorからの信号が異なる

その場合、より少ない指標が適している

//---
   double BuyBuffer[];
   double SellBuffer[];
   ArraySetAsSeries(BuyBuffer,true);
   ArraySetAsSeries(SellBuffer,true);
   if(!iGetArray(handle_iCustom,1,0,2,BuyBuffer) || !iGetArray(handle_iCustom,0,0,2,SellBuffer))
     {
      ExtPrevBarsY=0;
      return(false);
     }
//---
   if(BuyBuffer[1]!=0.0)
     {

この方がいい。

//---
   double main[],signal[];
   ArraySetAsSeries(main,true);
   ArraySetAsSeries(signal,true);
   int start_pos=0,count=3;
   if(!iGetArray(handle_iCustom,MAIN_LINE,start_pos,count,main) ||
      !iGetArray(handle_iCustom,SIGNAL_LINE,start_pos,count,signal))
     {
      ExtPrevBarsY=0;
      return(false);
     }

   if(main[1]>signal[1])
     {

こちらに変更しました!やはりExpert Advisorの稼働状況を確認すると、すべてうまくいっているようです。

このタイプのインジケータ(下のファイル)でうまく動作します。

ファイル:
2.mq5  17 kb