Yu631365331 发表于 2020-11-4 22:14:54

跪求,自动止损止盈,添加注释代码

大师们,这个是自动止盈止损的代码,想在上面加上可以自动注释的代码,我小白一个跪求帮忙。谢谢了~~

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓



//+------------------------------------------------------------------+
//|                     自动止损、止盈、盈利后移动止损、分批出场.mq4 |
//|                                    Copyright ?2009, 龙德而隐者 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009 by 龙德而隐者"
#property link      "http://www.metaquotes.net/"
extern string 自动止损参数="默认打开";
extern bool AutoStoploss=True;
extern double stoploss= 22;
extern string 自动止盈参数="默认打开";
extern bool AutoTakeProfit=True;
extern double takeprofit=30;
extern string 盈利后移动止损="默认打开";
extern bool AutoTrailingStop=true;
extern double TrailingStop = 15;
extern string 分次离场参数="按比例分步撤退";
extern bool Gradually = False;               
extern int GraduallyNum = 3;               
double OriginalLot;
//+------------------------------------------------------------------+
//| expert start function                                          |
//+------------------------------------------------------------------+
int start()
{
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{

if(OrderSymbol()==Symbol())
{
   double stp=OrderStopLoss();   
   double tpt=OrderTakeProfit();
   double OpenPrice = OrderOpenPrice();

       if (OriginalLot == 0)
         {
         OriginalLot=OrderLots();
         }         


   if(OrderType()==OP_BUY)         
   {
      CraduallyBuy ();
          if (AutoStoploss && AutoTakeProfit && stp==0 && tpt==0&&OrderMagicNumber()<=0)   
          OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,Ask+Point*takeprofit,0,Green);
      else
      {
          if (AutoStoploss && stp==0)                  
          {
            OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,OrderTakeProfit(),0,Green);
              }

              if (AutoTakeProfit && tpt==0)               
          {
            OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask+Point*takeprofit,0,Green);
          }   


          if (AutoTrailingStop&& ((Bid - OpenPrice) > Point*TrailingStop)&&OrderMagicNumber()<=0)      
          {
            if((Bid-stp)>TrailingStop*Point )
            OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
          }
          }   
   }

if(OrderType()==OP_SELL)                  
{
   CraduallySell ();
   if (AutoStoploss && AutoTakeProfit && stp==0 && tpt==0)
       OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*stoploss,Bid-Point*takeprofit,0,Green);
   else
   {
      if (AutoStoploss && stp==0)         
      {
            OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*stoploss,OrderTakeProfit(),0,Green);
      }
      if (AutoTakeProfit && tpt==0)      
      {
            OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-Point*takeprofit,0,Green);
      }

      if(AutoTrailingStop&& ((OpenPrice-Ask) > Point*TrailingStop ))      
      {
                   if((stp-Ask)>TrailingStop*Point)
            OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Green);
      }
   }
}

}
}
else
{
    OriginalLot=0;
}
       
}
}





void CraduallyBuy ()               
{
double OpenPrice = OrderOpenPrice();
double lot=OrderLots();            

for (int yi=1;yi<=GraduallyNum;yi++)
   {
          if (NormalizeDouble((Bid - OpenPrice)/Point,0) == NormalizeDouble(TrailingStop/GraduallyNum*yi,0))
          {

      if(lot != NormalizeDouble(OriginalLot*(1-yi/GraduallyNum),2))
         {
         OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Bid,3,CLR_NONE);
         }
                   
          }
        }
}



void CraduallySell ()               
{
double OpenPrice = OrderOpenPrice();
double lot=OrderLots();            

for (int yi=1;yi<=GraduallyNum;yi++)
   {
          if (NormalizeDouble((OpenPrice - Ask)/Point,0) == NormalizeDouble(TrailingStop/GraduallyNum*yi,0))
          {          

      if(lot != NormalizeDouble(OriginalLot*(1-yi/GraduallyNum),2))
         {
         OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Ask,3,CLR_NONE);
         }
                   
          }
        }

}

小明明 发表于 2020-11-4 22:40:47

你可以看下这个文档:https://docs.mql4.com/cn/trading/ordersend

yzrcpmlq 发表于 2020-11-12 13:00:32

谢谢

smihwhox 发表于 2020-12-5 14:32:40

{:1_181:}

cpymypte 发表于 2020-12-24 12:50:09

支持下

昕昕 发表于 2020-12-27 10:00:49

谢谢

晓彬 发表于 2021-1-5 10:00:20

顶下

科飞 发表于 2021-1-8 18:54:03

{:1_186:}

陈科林 发表于 2021-1-13 10:36:38

支持下

simon_lm01 发表于 2021-1-20 10:00:57

顶下
页: [1] 2 3 4 5 6 7 8
查看完整版本: 跪求,自动止损止盈,添加注释代码