请帮忙给增加个止盈谢谢

 
//+------------------------------------------------------------------+
//|                                                                  3!!  .mq4 |
//|                                                                                 |
//+------------------------------------------------------------------+
#property copyright " "
#property link      "https:// "
#property show_inputs
#include <stdlib.mqh>

extern double Risk = 0.02;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   double MinLot = MarketInfo(Symbol(), MODE_MINLOT);
   double MaxLot = MarketInfo(Symbol(), MODE_MAXLOT);
   double Step = MarketInfo(Symbol(), MODE_LOTSTEP);

   double StopLoss = WindowPriceOnDropped();
   double MoneyRisk = AccountFreeMargin() * Risk;
   double TickValue = MarketInfo(Symbol(), MODE_TICKVALUE);

   double PointLoss;
   int cmd;
   double price;
   if(Ask>StopLoss)
   {
      //Open Long
      PointLoss = (Ask - StopLoss) / Point;
      cmd = OP_BUY;
      price = Ask;
   }
   else
   {
      //Open Short
      PointLoss = (StopLoss - Bid) / Point;
      cmd = OP_SELL;
      price = Bid;
   }

   double LotsRough = MoneyRisk / (TickValue * PointLoss);
   if(LotsRough<MinLot)
   {
      Print("Error. You don\'t have enough money!");
      return(0);
   }
   
   double Lots = MaxLot;
   for(double CheckedLot=MinLot; CheckedLot<=MaxLot; CheckedLot+=Step)
   {
      if(CheckedLot>LotsRough)
      {
         Lots = CheckedLot - Step;
         break;
      }
   }
   
   Print("Lots=",Lots);
   
   int ticket = OrderSend(Symbol(), cmd, Lots, price, 3, StopLoss, 0);
   if (ticket<0)
   {
      Print("Error: ", ErrorDescription(GetLastError()));
   }
//----
   return(0);
  }

//+------------------------------------------------------------------+


修改内容:增加自动设置止盈,默认止盈是止损的2倍

 
//+------------------------------------------------------------------+
//|                                                                  3!!  .mq4 |
//|                                                                                 |
//+------------------------------------------------------------------+
#property copyright " "
#property link      "htTakeProfits:// "
#property show_inputs
#include <stdlib.mqh>

extern double Risk = 0.02;
input double RR = 2;//盈亏比
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//----
   RefreshRates();

   double MinLot = MarketInfo(Symbol(), MODE_MINLOT);
   double MaxLot = MarketInfo(Symbol(), MODE_MAXLOT);
   double Step = MarketInfo(Symbol(), MODE_LOTSTEP);

   double StopLoss = WindowPriceOnDropped();
   double MoneyRisk = AccountFreeMargin() * Risk;
   double TickValue = MarketInfo(Symbol(), MODE_TICKVALUE);

   double PointLoss;
   int cmd;
   double price;
   double TakeProfit=0.0;//takeprofit price
   if(Ask>StopLoss)
   {
      //Open Long
      PointLoss = (Ask - StopLoss) / Point;
      cmd = OP_BUY;
      price = Ask;
      if(RR>0)
      {
         TakeProfit = Ask + RR*PointLoss*Point;
      }
   }
   else
   {
      //Open Short
      PointLoss = (StopLoss - Bid) / Point;
      cmd = OP_SELL;
      price = Bid;
      if(RR>0)
      {
         TakeProfit =Bid- RR*PointLoss*Point;
      }
   }
   printf("PointLoss = %.f, StopLoss = %.f, TakeProfit = %.f",PointLoss,StopLoss,TakeProfit);
   double LotsRough = MoneyRisk / (TickValue * PointLoss);
   if(LotsRough<MinLot)
   {
      printf("Error. You don\'t have enough money! PointLoss = %.f, LotsRough = %.f, MoneyRisk = %.f",PointLoss,LotsRough,MoneyRisk);
      return;
   }

   double Lots = MaxLot;
   for(double CheckedLot=MinLot; CheckedLot<=MaxLot; CheckedLot+=Step)
   {
      if(CheckedLot>LotsRough)
      {
         Lots = CheckedLot - Step;
         break;
      }
   }

   Print("Lots=",Lots);

   int ticket = OrderSend(Symbol(), cmd, Lots, nd(price), 30, nd(StopLoss), nd(TakeProfit));
   if (ticket<0)
   {
      printf("Error: ", ErrorDescription(GetLastError()));
   }
//----
   return;
}
//+------------------------------------------------------------------+
double nd(double x)
{
   return NormalizeDouble(x,_Digits);
}
//+------------------------------------------------------------------+
 
Ziheng Zhuang #:
万分感谢,非常好用
 
上面的是大佬