编写免费的EA - 页 12

 
SanAlex:

我不知道--这是我做的!我是自学成才的,都是靠科学探究。

\\\\\\\\\\\\\ 我自己也很惊讶--这似乎也是一个好的结果--我的专家很重--需要很长时间来测试

你的信号是不同的
原本是一个交叉的正负线
你的信号中也有主线

 
Iurii Tokman:

你有一个不同的信号
,在原来的交叉线加减
,你也有信号中的主线

是的!我用了三条线--负的(粉红色)线就像零--与它交叉的两条线给出了信号。

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

3月正处于下行期----------,我可能会在新年前完成这项测试。

到目前为止进展顺利 4

 
SanAlex:

是的!我使用了三条线--减去(粉红色)的线是零--而与之相交的两条线给出了一个信号

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

3月下去----------,我可能会在新年前完成这个测试(只完成了一半)。


如果猫头鹰使用自定义指标
,那么应该简单地将信号转移到专家顾问
,不要使用该指标。

 
对不起,你能根据我的要求制作一个adx-buy-sell指标的EA吗?
 
SAJSRAh:
对不起,你能根据我对adx-buy-sell指标的要求创建一个专家顾问吗?

如果它是一个信号指标 - 你可以使用这个专家顾问(mt4)https://www.mql5.com/ru/forum/310846/page63#comment_17088893

input string   t="------------- Balans Parameters -----"; //
input double   TargetProfit     = 999999.99;     // Баланс + Прибыль(прибавить к балансу)
input double   TargetLoss       = 0;             // Баланс - Убыток(отнять от баланса)
input string   t2="------------ Exchange TP SL --------"; //
input double   InpTProfit       = 1000;          // Exchange TP
input double   InpStopLoss      = 1000000;       // Exchange SL
input string   t0="------------ Lots Parameters -------"; //
input double   InpLots          = 0.01;          // Lots
input double   InpLots1         = 0.02;          // : Lots 1
input int      InpLots_01       = 200;           // Exchange Lots
input double   InpLots2         = 0.04;          // : Lots 2
input int      InpLots_02       = 400;           // Exchange Lots
input double   InpLots3         = 0.08;          // : Lots 3
input int      InpLots_03       = 800;           // Exchange Lots
input double   InpLots4         = 0.16;          // : Lots 4
input string   _Orders_="------ Parameters Order ------"; //
input double   TakeProfit       = 500;           // Take Profit
input double   TrailingStop     = 300;           // Фиксированный размер трала
input double   TrailingStep     = 50;            // Шаг трала
input string   short_name       = "FilterSignal";// Name Indicators
input bool     InpOnlyOne       = false;         // Close opposite
input bool     ObjRevers        = false;         // Revers

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

黄色标记的地方--写上你的指标名称

Как я собираю себе советника методом тыка
Как я собираю себе советника методом тыка
  • 2020.06.19
  • www.mql5.com
Из этих Советников весь материал Автор MQL5-кода: Vladimir Karputov. Stop loss Take profit.mq5TrendMeLeaveMe(barabashkakvn's edition...
 
SanAlex:

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

如果你用一个十字架,没有未来,那就没有利润了


 
Iurii Tokman:

如果猫头鹰使用自定义指标
,那么你只需要将信号转移到EA
,而不是使用指标。

我有一个沉重的专家顾问,从事实来看,它有很多的功能,从水平线和趋势线。

这里是https://www.mql5.com/ru/code/34046

函数本身--从这里开始工作的指标

sinput group "----------------- Indicators: UP -----------------------"
sinput bool               InpIndicators_1            = false;            // Indicators: Start (true)
sinput ENUM_MODE          FilterLine_3               = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput string             short_name_1               = "Имя Индикатора"; // Name Indicators "UP"
sinput int                InpBars_1                  = 1;                // Bars
sinput ENUM_TIMEFRAMES    Period_1                   = PERIOD_CURRENT;   // Period Indicators
sinput ENUM_TRADE_COMMAND InpLongOpened_1Command     = close_open_b;     // Buy command:
sinput ENUM_TRADE_COMMAND InpShortOpened_1Command    = close_open_s;     // Sell command:
//+------------------------------------------------------------------+
//| Initialization of the indicators                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::InitIndicators_1(void)
  {
//--- create MACD indicator
   if(m_handle_macd_1==INVALID_HANDLE)
      if((m_handle_macd_1=iCustom(m_symbol.Name(),Period_1,short_name_1))==INVALID_HANDLE)
        {
         printf("Error creating indicator_1");
         return(false);
        }
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Check for long position opening                                  |
//+------------------------------------------------------------------+
bool CSampleExpert::LongOpened_1(void)
  {
   bool res=false;
//--- check for long position (BUY) possibility
   if(m_macd_current_1<m_signal_current_1)
     {
      InpTradeCommand(InpLongOpened_1Command);
      //--- in any case we must exit from expert
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//| Check for short position opening                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::ShortOpened_1(void)
  {
   bool res=false;
//--- check for short position (SELL) possibility
   if(m_macd_current_1>m_signal_current_1)
     {
      InpTradeCommand(InpShortOpened_1Command);
      //--- in any case we must exit from expert
      res=true;
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| main function returns true if any position processed             |
//+------------------------------------------------------------------+
bool CSampleExpert::Processing_1(void)
  {
//--- we work only at the time of the birth of new bar
   datetime time_0=iTime(m_symbol.Name(),Period_1,0);
   if(time_0==ExtPrevBars_1)
      return(false);
   ExtPrevBars_1=time_0;
   if(!m_symbol.RefreshRates())
     {
      ExtPrevBars_1=0;
      return(false);
     }
//--- refresh indicators
   if(BarsCalculated(m_handle_macd_1)<2)
      return(false);
   if(CopyBuffer(m_handle_macd_1,0,InpBars_1,2,m_buff_MACD_main_1)  !=2 ||
      CopyBuffer(m_handle_macd_1,1,InpBars_1,2,m_buff_MACD_signal_1)!=2)
     {
      ExtPrevBars_1=0;
      return(false);
     }
//   m_indicators.Refresh();
//--- to simplify the coding and speed up access
//--- data are put into internal variables
   m_macd_current_1   =m_buff_MACD_main_1[0];
   m_signal_current_1 =m_buff_MACD_signal_1[0];
//--- check for long position (BUY) possibility
   if(LongOpened_1())
      return(true);
//--- check for short position (SELL) possibility
   if(ShortOpened_1())
      return(true);
//--- exit without position processing
   return(false);
  }
//+------------------------------------------------------------------+

到目前为止进展顺利 5

Algorithm manually automate
Algorithm manually automate
  • www.mql5.com
Эксперт для Автоматизации Ручной торговли.
 
Iurii Tokman:

如果你用一个十字架,没有未来,就没有利润。


不过,我有一个不同的结果--在测试结束前还有一段路要走

到目前为止进展顺利 6

 

TOTAL:"来回ADX "3月和4月指标--由于某种原因没有成功。

到目前为止进展顺利 7

到目前为止进展顺利 8

到目前为止进展顺利 9

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

以下是指标本身

附加的文件:
 
SanAlex :

结果:指标“来回 ADX”3 月 4 月 - 由于某种原因不成功

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

这是指标

在这里,专家在测试仪中巧妙地工作 - 检查信号指标

//+------------------------------------------------------------------+
//|                                           Back and forth ADX.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link        " http://www.mql5.com "
#property version    "1.00"

#define   MACD_MAGIC 9294501
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---
input double InpLots          = 0.01 ;                 // Lots
input int     InpTakeProfit    = 500 ;                   // Take Profit (in pips)
input int     InpTrailingStop  = 300 ;                   // Trailing Stop Level (in pips)
sinput group "----------------- Indicators: -----------------------"
input string Inp_name_1       = "Back and forth ADX" ; // Name Indicators
input int     InpBars_1        = 1 ;                     // Bars
//---
int ExtTimeOut= 10 ; // time out in seconds between trade operations
//+------------------------------------------------------------------+
//| MACD Sample expert class                                         |
//+------------------------------------------------------------------+
class CSampleExpert
  {
protected :
   double             m_adjusted_point;             // point value adjusted for 3 or 5 points
   CTrade            m_trade;                       // trading object
   CSymbolInfo       m_symbol;                     // symbol info object
   CPositionInfo     m_position;                   // trade position object
   CAccountInfo      m_account;                     // account info wrapper
   //--- indicators
   int                m_handle_macd;                 // MACD indicator handle
   //--- indicator buffers
   double             m_buff_MACD_main[];           // MACD indicator main buffer
   double             m_buff_MACD_signal[];         // MACD indicator signal buffer
   //--- indicator data for processing
   double             m_macd_current;
   double             m_signal_current;
   //---
   double             m_traling_stop;
   double             m_take_profit;

public :
                     CSampleExpert( void );
                    ~CSampleExpert( void );
   bool               Init( void );
   void               Deinit( void );
   bool               Processing( void );

protected :
   bool               InitCheckParameters( const int digits_adjust);
   bool               InitIndicators( void );
   bool               LongClosed( void );
   bool               ShortClosed( void );
   bool               LongModified( void );
   bool               ShortModified( void );
   bool               LongOpened( void );
   bool               ShortOpened( void );
  };
//--- global expert
CSampleExpert ExtExpert;
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CSampleExpert::CSampleExpert( void ) : m_adjusted_point( 0 ),
   m_handle_macd( INVALID_HANDLE ),
   m_macd_current( 0 ),
   m_signal_current( 0 ),
   m_traling_stop( 0 ),
   m_take_profit( 0 )
  {
   ArraySetAsSeries (m_buff_MACD_main, true );
   ArraySetAsSeries (m_buff_MACD_signal, true );
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CSampleExpert::~CSampleExpert( void )
  {
  }
//+------------------------------------------------------------------+
//| Initialization and checking for input parameters                 |
//+------------------------------------------------------------------+
bool CSampleExpert::Init( void )
  {
//--- initialize common information
   m_symbol.Name( Symbol ());                   // symbol
   m_trade.SetExpertMagicNumber(MACD_MAGIC); // magic
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol( Symbol ());
//--- tuning for 3 or 5 digits
   int digits_adjust= 1 ;
   if (m_symbol. Digits ()== 3 || m_symbol. Digits ()== 5 )
      digits_adjust= 10 ;
   m_adjusted_point=m_symbol. Point ()*digits_adjust;
//--- set default deviation for trading in adjusted points
   m_traling_stop    =InpTrailingStop*m_adjusted_point;
   m_take_profit     =InpTakeProfit*m_adjusted_point;
//--- set default deviation for trading in adjusted points
   m_trade.SetDeviationInPoints( 3 *digits_adjust);
//---
   if (!InitCheckParameters(digits_adjust))
       return ( false );
   if (!InitIndicators())
       return ( false );
//--- succeed
   return ( true );
  }
//+------------------------------------------------------------------+
//| Checking for input parameters                                    |
//+------------------------------------------------------------------+
bool CSampleExpert::InitCheckParameters( const int digits_adjust)
  {
//--- initial data checks
   if (InpTakeProfit*digits_adjust<m_symbol.StopsLevel())
     {
       printf ( "Take Profit must be greater than %d" ,m_symbol.StopsLevel());
       return ( false );
     }
   if (InpTrailingStop*digits_adjust<m_symbol.StopsLevel())
     {
       printf ( "Trailing Stop must be greater than %d" ,m_symbol.StopsLevel());
       return ( false );
     }
//--- check for right lots amount
   if (InpLots<m_symbol.LotsMin() || InpLots>m_symbol.LotsMax())
     {
       printf ( "Lots amount must be in the range from %f to %f" ,m_symbol.LotsMin(),m_symbol.LotsMax());
       return ( false );
     }
   if ( MathAbs (InpLots/m_symbol.LotsStep()- MathRound (InpLots/m_symbol.LotsStep()))> 1.0 E- 10 )
     {
       printf ( "Lots amount is not corresponding with lot step %f" ,m_symbol.LotsStep());
       return ( false );
     }
//--- warning
   if (InpTakeProfit<=InpTrailingStop)
       printf ( "Warning: Trailing Stop must be less than Take Profit" );
//--- succeed
   return ( true );
  }
//+------------------------------------------------------------------+
//| Initialization of the indicators                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::InitIndicators( void )
  {
//--- create MACD indicator
   if (m_handle_macd== INVALID_HANDLE )
       if ((m_handle_macd= iCustom ( _Symbol , _Period ,Inp_name_1))== INVALID_HANDLE )
        {
         printf ( "Error creating MACD indicator" );
         return ( false );
        }
//--- succeed
   return ( true );
  }
//+------------------------------------------------------------------+
//| Check for long position closing                                  |
//+------------------------------------------------------------------+
bool CSampleExpert::LongClosed( void )
  {
   bool res= false ;
//--- should it be closed?
   if (m_macd_current>m_signal_current)
     {
       //--- close position
       if (m_trade.PositionClose( Symbol ()))
         printf ( "Long position by %s to be closed" , Symbol ());
       else
         printf ( "Error closing position by %s : '%s'" , Symbol (),m_trade.ResultComment());
       //--- processed and cannot be modified
      res= true ;
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Check for short position closing                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::ShortClosed( void )
  {
   bool res= false ;
//--- should it be closed?
   if (m_macd_current<m_signal_current)
     {
       //--- close position
       if (m_trade.PositionClose( Symbol ()))
         printf ( "Short position by %s to be closed" , Symbol ());
       else
         printf ( "Error closing position by %s : '%s'" , Symbol (),m_trade.ResultComment());
       //--- processed and cannot be modified
      res= true ;
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Check for long position modifying                                |
//+------------------------------------------------------------------+
bool CSampleExpert::LongModified( void )
  {
   bool res= false ;
//--- check for trailing stop
   if (InpTrailingStop> 0 )
     {
       if (m_symbol.Bid()-m_position.PriceOpen()>m_adjusted_point*InpTrailingStop)
        {
         double sl= NormalizeDouble (m_symbol.Bid()-m_traling_stop,m_symbol. Digits ());
         double tp=m_position.TakeProfit();
         if (m_position.StopLoss()<sl || m_position.StopLoss()== 0.0 )
           {
             //--- modify position
             if (m_trade.PositionModify( Symbol (),sl,tp))
               printf ( "Long position by %s to be modified" , Symbol ());
             else
              {
               printf ( "Error modifying position by %s : '%s'" , Symbol (),m_trade.ResultComment());
               printf ( "Modify parameters : SL=%f,TP=%f" ,sl,tp);
              }
             //--- modified and must exit from expert
            res= true ;
           }
        }
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Check for short position modifying                               |
//+------------------------------------------------------------------+
bool CSampleExpert::ShortModified( void )
  {
   bool    res= false ;
//--- check for trailing stop
   if (InpTrailingStop> 0 )
     {
       if ((m_position.PriceOpen()-m_symbol.Ask())>(m_adjusted_point*InpTrailingStop))
        {
         double sl= NormalizeDouble (m_symbol.Ask()+m_traling_stop,m_symbol. Digits ());
         double tp=m_position.TakeProfit();
         if (m_position.StopLoss()>sl || m_position.StopLoss()== 0.0 )
           {
             //--- modify position
             if (m_trade.PositionModify( Symbol (),sl,tp))
               printf ( "Short position by %s to be modified" , Symbol ());
             else
              {
               printf ( "Error modifying position by %s : '%s'" , Symbol (),m_trade.ResultComment());
               printf ( "Modify parameters : SL=%f,TP=%f" ,sl,tp);
              }
             //--- modified and must exit from expert
            res= true ;
           }
        }
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Check for long position opening                                  |
//+------------------------------------------------------------------+
bool CSampleExpert::LongOpened( void )
  {
   bool res= false ;
//--- check for long position (BUY) possibility
   if (m_macd_current<m_signal_current)
     {
       double price=m_symbol.Ask();
       double tp   =m_symbol.Bid()+m_take_profit;
       //--- check for free money
       if (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_BUY ,InpLots,price)< 0.0 )
         printf ( "We have no money. Free Margin = %f" ,m_account.FreeMargin());
       else
        {
         //--- open position
         if (m_trade.PositionOpen( Symbol (), ORDER_TYPE_BUY ,InpLots,price, 0.0 ,tp))
             printf ( "Position by %s to be opened" , Symbol ());
         else
           {
             printf ( "Error opening BUY position by %s : '%s'" , Symbol (),m_trade.ResultComment());
             printf ( "Open parameters : price=%f,TP=%f" ,price,tp);
           }
        }
       //--- in any case we must exit from expert
      res= true ;
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| Check for short position opening                                 |
//+------------------------------------------------------------------+
bool CSampleExpert::ShortOpened( void )
  {
   bool res= false ;
//--- check for short position (SELL) possibility
   if (m_macd_current>m_signal_current)
     {
       double price=m_symbol.Bid();
       double tp   =m_symbol.Ask()-m_take_profit;
       //--- check for free money
       if (m_account.FreeMarginCheck( Symbol (), ORDER_TYPE_SELL ,InpLots,price)< 0.0 )
         printf ( "We have no money. Free Margin = %f" ,m_account.FreeMargin());
       else
        {
         //--- open position
         if (m_trade.PositionOpen( Symbol (), ORDER_TYPE_SELL ,InpLots,price, 0.0 ,tp))
             printf ( "Position by %s to be opened" , Symbol ());
         else
           {
             printf ( "Error opening SELL position by %s : '%s'" , Symbol (),m_trade.ResultComment());
             printf ( "Open parameters : price=%f,TP=%f" ,price,tp);
           }
        }
       //--- in any case we must exit from expert
      res= true ;
     }
//--- result
   return (res);
  }
//+------------------------------------------------------------------+
//| main function returns true if any position processed             |
//+------------------------------------------------------------------+
bool CSampleExpert::Processing( void )
  {
//--- refresh rates
   if (!m_symbol.RefreshRates())
       return ( false );
//--- refresh indicators
   if ( BarsCalculated (m_handle_macd)< 2 )
       return ( false );
   if ( CopyBuffer (m_handle_macd, 0 ,InpBars_1, 2 ,m_buff_MACD_main)  != 2 ||
       CopyBuffer (m_handle_macd, 1 ,InpBars_1, 2 ,m_buff_MACD_signal)!= 2 )
       return ( false );
//   m_indicators.Refresh();
//--- to simplify the coding and speed up access
//--- data are put into internal variables
   m_macd_current   =m_buff_MACD_main[ 0 ];
   m_signal_current =m_buff_MACD_signal[ 0 ];
//--- it is important to enter the market correctly,
//--- but it is more important to exit it correctly...
//--- first check if position exists - try to select it
   if (m_position.Select( Symbol ()))
     {
       if (m_position.PositionType()== POSITION_TYPE_BUY )
        {
         //--- try to close or modify long position
         if (LongClosed())
             return ( true );
         if (LongModified())
             return ( true );
        }
       else
        {
         //--- try to close or modify short position
         if (ShortClosed())
             return ( true );
         if (ShortModified())
             return ( true );
        }
     }
//--- no opened position identified
   else
     {
       //--- check for long position (BUY) possibility
       if (LongOpened())
         return ( true );
       //--- check for short position (SELL) possibility
       if (ShortOpened())
         return ( true );
     }
//--- exit without position processing
   return ( false );
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ( void )
  {
//--- create all necessary objects
   if (!ExtExpert.Init())
       return ( INIT_FAILED );
//--- secceed
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Expert new tick handling function                                |
//+------------------------------------------------------------------+
void OnTick ( void )
  {
   static datetime limit_time= 0 ; // last trade processing time + timeout
//--- don't process if timeout
   if ( TimeCurrent ()>=limit_time)
     {
       //--- check for data
       if ( Bars ( Symbol (), Period ())> 2 )
        {
         //--- change limit time by timeout in seconds if processed
         if (ExtExpert.Processing())
            limit_time= TimeCurrent ()+ExtTimeOut;
        }
     }
  }
//+------------------------------------------------------------------+

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

更正 - 没有写在这里

       if ((m_handle_macd= iCustom ( _Symbol , _Period , Inp_name_1 ))== INVALID_HANDLE )
附加的文件: