求大佬给修改下这个下单脚本

 

这个下单脚本获取的资金比例是按照净值来计算下单手数,不太合理

想要按照余额减去了预付款,得到的资金再计算下单量

感谢,感谢,感谢!!!


//+------------------------------------------------------------------+
//|                                       3!!_Super挂单脚本.mq4 |
//|                                                          一|
//|                                    |
//+------------------------------------------------------------------+
#property copyright "一"
#property link      ""
#property show_inputs
#include <stdlib.mqh>

extern double Risk = 0.02;//风险资金比例
input double RR = 50;//盈亏比
//+------------------------------------------------------------------+
//| 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);
}
//+------------------------------------------------------------------+
 
double MoneyRisk = AccountFreeMargin() * Risk;

修改成

double MoneyRisk = AccountBalance()* Risk;

如果是多持倉單交易 他的設計是對的 

如果只交易一筆 使用餘額計算也可以

原因: