跪求mt5亏损加倍下单怎么写

 
上一单亏损,这单加倍下单,直到盈利恢复原来的下单手数
 
//+------------------------------------------------------------------+
//|                                                   亏损加倍追单.mq5 |
//+------------------------------------------------------------------+
#property copyright "亏损加倍追单"
#property link      "https://www.mql5.com/zh/users/sohoguhu"
#property description "Copyright 2022, by vx:qq626915022 即兴代编"
#property version   "1.00"

#include <Trade\Trade.mqh>
CTrade EAtrade;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  { 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int i,Ticket;
   long type=0;
   double lots=0,profit=0;
   ulong ticket; 
   string symbol;
   
   if(PositionsTotal()>0)
   return;
   
 //检测新鬼  
   HistorySelect(0,TimeCurrent()); 
   if(HistoryDealsTotal()>0)
   {
     i=HistoryDealsTotal()-1;
     ticket=HistoryDealGetTicket(i); 
      if(HistoryDealGetInteger(ticket,DEAL_ENTRY)==1)
       {
       profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
       lots=HistoryDealGetDouble(ticket,DEAL_VOLUME);
       type=HistoryDealGetInteger(ticket,DEAL_TYPE);
       symbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
       }
   }
   
 //翻倍补刀  
   if(profit<0 && PositionsTotal()<1)
    {
    lots=lots*2;
    if(type==0)
    Ticket=EAtrade.Buy(lots,symbol,0,0,0,"B+");
    if(type==1)
    Ticket=EAtrade.Sell(lots,symbol,0,0,0,"S+");
    }
    
//盈利方休  
   if(profit>0)
   MessageBox("My god,玩的就是心跳! 恭喜你赢啦!再来一局?!");
  }
//+------------------------------------------------------------------+
Nianfu Li
Nianfu Li
  • 2021.04.05
  • www.mql5.com
交易者的个人资料
 
Nianfu Li #:

檢測新鬼!! 翻被捕刀!!! 盈利方休!!!!

這詞....用的好

 
1432117983:
上一单亏损,这单加倍下单,直到盈利恢复原来的下单手数
   double 历史盈亏=交易.历史尾单盈亏(Symbol(),magic号码,1);
   long  历史时间=交易.历史尾单时间(Symbol(),magic号码,1);
    Comment(尾单时间 ,"   ",历史盈亏);
   if(历史时间>尾单时间&&历史盈亏>0)
     {
      系数=1;
      尾单时间=历史时间;
     }
   if(历史时间>尾单时间&&历史盈亏<0)
     {
      系数=2*系数;
      尾单时间=历史时间;
     }
   double 手数=初始手数*系数;
 
Nianfu Li #:
谢谢
原因: