我如何通过试验和错误组装我的顾问 - 页 34

 

想出了如何正确开出风险

#define  Magic_Number 0
//+------------------------------------------------------------------+
//| Enum Lor or Risk                                                 |
//+------------------------------------------------------------------+
enum ENUM_LOT_OR_RISK
  {
   lots=0,     // Constant lot
   risk=1,     // Risk in percent
  };
//+------------------------------------------------------------------+


input double   MaximumRisk             = 0.01;          // Maximum Risk in percentage
input double   DecreaseFactor          = 3;             // Descrease factor
input ENUM_LOT_OR_RISK InpLotOrRisk    = lots;          // Money management: Lot OR Risk
   //+------------------------------------------------------------------+
   //| Calculate optimal lot size                                       |
   //+------------------------------------------------------------------+
   double            TradeSizeOptimized(void)
     {
      double price=0.0;
      double margin=0.0;
      //--- select lot size
      if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,price))
         return(0.0);
      if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1.0,price,margin))
         return(0.0);
      if(margin<=0.0)
         return(0.0);
      double lot=0;
      //---
      switch(InpLotOrRisk)
        {
         case lots:
            lot=MaximumRisk;
            break;
         case risk:
            lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_MARGIN_FREE)*MaximumRisk/margin,2);
         default:
            break;
        }
      //--- calculate number of losses orders without a break
      if(DecreaseFactor>0)
        {
         //--- select history for access
         HistorySelect(0,TimeCurrent());
         //---
         int    orders=HistoryDealsTotal();  // total history deals
         int    losses=0;                    // number of losses orders without a break

         for(int i=orders-1; i>=0; i--)
           {
            ulong ticket=HistoryDealGetTicket(i);
            if(ticket==0)
              {
               Print("HistoryDealGetTicket failed, no trade history");
               break;
              }
            //--- check symbol
            if(HistoryDealGetString(ticket,DEAL_SYMBOL)!=_Symbol)
               continue;
            //--- check Expert Magic number
            if(HistoryDealGetInteger(ticket,DEAL_MAGIC)!=Magic_Number)
               continue;
            //--- check profit
            double profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
            if(profit>0.0)
               break;
            if(profit<0.0)
               losses++;
           }
         //---
         if(losses>1)
            lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
        }
      //--- normalize and check limits
      double stepvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
      lot=stepvol*NormalizeDouble(lot/stepvol,0);

      double minvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
      if(lot<minvol)
         lot=minvol;

      double maxvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
      if(lot>maxvol)
         lot=maxvol;
      //--- return trading volume
      return(lot);

     }
   //+------------------------------------------------------------------+

其中手数 - 插入TradeSizeOptimized()

我需要在专家顾问中纠正它 - 否则它在那里是不正确的。

 

重新命名 - 专家完成。所有错误都已纠正。标题<马步><马步

马的动作

附加的文件:
Horse_move.mq5  190 kb
 


亚历山大-克拉帕秋克

在前一个专家的基础上,增加了水平线 的两个方法。

1种可能性:线1将在给定距离打开线4,线2在给定距离 打开线3。

第二种可能:第7行将在给定的距离上 打开一条10号线 它在价格后面移动,当价格触及它时,将触发一个命令。第8行将在给定的距离上 打开一条9号线,-- 与7和10的动作相同。

#财产版本 "1.01"

还有一个选择--1号线将打开4和9。2号线 将打开3和10

第7行将打开10和3。第8行将打开9和4

input string   t3="------ Obj:Name 1-2-3-4 ------";     // Имя Объекта
input string   InpObjUpNameZ           = "TOP 1";       // Obj: TOP (Name Obj) ВВЕРХУ 1
input string   InpObjDownNameZ         = "LOWER 2";     // Obj: LOWER (Name Obj) ВНИЗУ 2
input int      Step                    = 5;             // Obj: Шаг сетки, пунктов(0 = false)
input string   InpObjDownName0         = "TOP 3";       // Obj: TOP (Name Obj) ВВЕРХУ 3
input ENUM_TRADE_COMMAND InpTradeCommand=open_sell;     // Obj:  command:
input string   InpObjUpName0           = "LOWER 4";     // Obj: LOWER (Name Obj) ВНИЗУ 4
input ENUM_TRADE_COMMAND InpTradeCommand0=open_buy;     // Obj:  command:
input string   t5="- 2_Obj:Trailing Line 7-8-9-10 --- ";// Trailing Obj:Line
input string   InpObjUpNameZx          = "TOP 7";       // Obj: TOP (Name Obj) ВВЕРХУ 7
input string   InpObjDownNameZx        = "LOWER 8";     // Obj: LOWER (Name Obj) ВНИЗУ 8
input int      StepZx                  = 5;             // Obj: Шаг сетки, пунктов(0 = false)
input string   InpObjUpNameX           = "TOP 9";       // Obj: TOP (Horizontal Line) ВВЕРХУ 9
input ENUM_TRADE_COMMAND InpTradeCommandX=open_buy;     // Obj:  command:
input string   InpObjDownNameX         = "LOWER 10";    // Obj: LOWER (Horizontal Line) ВНИЗУ 10
input ENUM_TRADE_COMMAND InpTradeCommand0X=open_sell;   // Obj:  command:
input ushort   InpObjTrailingStopX     = 5;             // Obj: Trailing Stop (distance from price to object, in pips)
input ushort   InpObjTrailingStepX     = 5;             // Obj: Trailing Step, in pips (1.00045-1.00055=1 pips)

来打开反面的位置,不要碰设置Obj:命令。

有一个反转 -

input string   t6="------ Obj: Revers Buy and Sell --"; // Obj: Revers Buy and Sell
input bool     ObjRevers               = false;         // Obj: Revers
附加的文件:
Horse_move.mq5  190 kb
2.mq5  17 kb
 
Aleksandr Klapatyuk:

#财产版本 "1.01"

结果是另一种可能--1号线将开出4和9。2号线 将开出3和10。

第7行将打开10和3。第8行将打开9和4

以反向方式打开位置,不要碰设置Obj: 命令。

有一个反转 -

我现在已经开始测试了--我在月底之前不会做任何事情,我想知道会发生什么。- 阄,我把它设定为风险 - 它将以某种方式计算出

测试

 

不错!很慢--但正在变得更好

测试1

 

是的!它将直接进入顶部。

Alpari MT5

 
Aleksandr Klapatyuk:

重新命名 - 专家完成。所有错误都已纠正。标题<马步><马步

有趣的专家顾问。

 

设置输入 double TargetProfit = 30000.00;// 目标利润

现在我们需要再次等待,进入点和设置 TargetProfit = 35000.00;// 目标利润

//+------------------------------------------------------------------+
input string   t0="------ Parameters --------";         // Настройка Эксперта
input string   Template                = "ADX";         // Имя шаблона(without '.tpl')
input datetime HoursFrom               = D'1970.01.01'; // Время старта Эксперта
input datetime HoursTo                 = D'2030.12.31'; // Время закрытия всех позиций
input double   TargetProfit            = 900000.00;     // Целевая прибыль
input uint     maxLimits               = 1;             // Кол-во Позиции Открыть в одну сторону
input double   MaximumRisk             = 0.01;          // Maximum Risk in percentage
input double   DecreaseFactor          = 3;             // Descrease factor
input ENUM_LOT_OR_RISK InpLotOrRisk    = lots;          // Money management: Lot OR Risk

从指标枢轴线timezone.mq5中打开仓位,从线R2--向下S2--向上。

快照1

该指标不能被删除 - 它的线条在第二天被更新。

Alpari MT5

该指标如下 - 我将在网站上寻找该指标的链接https://www.mql5.com/ru/code/1114

附加的文件:
 
Aleksandr Klapatyuk:

设置输入 double TargetProfit = 30000.00; // 目标利润

现在我们需要再次等待,进入点和设置 TargetProfit = 35000.00; // 目标利润

从指标枢轴线timezone.mq5中打开仓位,从线R2--向下S2--向上。

该指标不能被删除 - 它的线条在第二天被更新。

下面的指标 - 现在在网站上搜索该指标的链接https://www.mql5.com/ru/code/1114

这是其中一个选择,但有一百万个选择。

我忘了说关于手数--设置为风险输入 ENUM_LOT_OR_RISK InpLotOrRisk = lots;// 资金管理:手数或风险

(.log中的专家信息)发出哪些警告https://www.mql5.com/ru/docs/event_handlers/ondeinit
Документация по MQL5: Обработка событий / OnDeinit
Документация по MQL5: Обработка событий / OnDeinit
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Возвращает текстовое описания причины деинициализации            |
附加的文件:
20191107.log  272 kb
 

#财产版本 "1.02"

为按钮找到了另一种方式

//+------------------------------------------------------------------+
//| Enum ENUM_BUTTON                                                 |
//+------------------------------------------------------------------+
enum ENUM_BUTTON
  {
   Button0=0,  // ВЫКЛ
   Button1=1,  // ВКЛ
   Button2=2,  // ВКЛ: AVGiS
  };
//+------------------------------------------------------------------+

这里我们选择

input string   t9="------ Button: AVGiS -----";         // AVGiS (Или обычный режим Buy/Sell)
input ENUM_BUTTON Buttons              = Button0;       // Вкл: Копки Buy/Sell
input bool     ObjectLineX             = false;         // Button: Horizontal Line(true) || Buy/Sell(false)
input bool     TickRevers              = false;         // Button: Revers
input int      TrailingStop_STOP_LEVEL = 350;           // Trailing Stop LEVEL
input ENUM_TIMEFRAMES _period          = PERIOD_CURRENT;// period
input int      limit_total_symbol      = 190;           // limit_total_symbol
input int      limit_total             = 190;           // limit_total
//---

开仓时 - 立即设置止损(黄色水平线)。

在此调整 -输入 double InpStopLoss = 55;// Obj:止损,单位为点(1.00045-1.00055=1个点)

停用设置0

input string   t2="------ Obj:Trailing Line     --- ";  // Trailing Obj:Line
input double   InpStopLoss             = 55;            // Obj: Stop Loss, in pips (1.00045-1.00055=1 pips)
input ushort   InpObjTrailingStop      = 27;            // Obj: Trailing Stop (distance from price to object, in pips)
input ushort   InpObjTrailingStep      = 9;             // Obj: Trailing Step, in pips (1.00045-1.00055=1 pips)
附加的文件:
Horse_move.mq5  198 kb
2.mq5  17 kb