新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 1371

 
MakarFX:

到了EA的最底部。

不幸的是,它并没有成倍增长!()()()。

 
Сергей Дыбленко:

不幸的是,它并没有成倍增长!()()()。

这个函数计算出与自由保证金和指定风险有关的手数!

你说的是什么乘法?

 
MakarFX:

这个函数计算出与自由保证金和指定风险有关的手数!

你说的是什么乘法?

每次获利后的手数增加!

 
Сергей Дыбленко:

关于每次盈利后增加手数的问题!

该函数将在盈利后增加手数,但如果盈利允许增加最小手数的增量

 
Сергей Дыбленко:

关于每次盈利后增加手数!

下面是一个例子,在10 000以下,你的余额将以0.1手为单位,从10 000到20 000以0.5手为单位。

从20000到40000,批次1.0,超过40000,批次2.0。

//+------------------------------------------------------------------+
//|                                               Moving Average.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Average sample expert advisor"

#define  MAGICMA  20131111
//--- Inputs
input double InpLots       =0.1;
input int    MovingPeriod  =12;
input int    MovingShift   =6;
//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)
            buys++;
         if(OrderType()==OP_SELL)
            sells++;
        }
     }
//--- return orders volume
   if(buys>0)
      return(buys);
   else
      return(-sells);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double Lots=InpLots;
   double ab=AccountBalance();
   if(ab>=10000 && ab<20000)
      Lots=0.5;
   if(ab>=20000 && ab<40000)
      Lots=1.0;
   if(ab>=40000)
      Lots=2.0;
   return(Lots);
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double ma;
   int    res;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1)
      return;
//--- get Moving Average
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//--- sell conditions
   if(Open[1]>ma && Close[1]<ma)
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"",MAGICMA,0,Red);
      return;
     }
//--- buy conditions
   if(Open[1]<ma && Close[1]>ma)
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Blue);
      return;
     }
//---
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1)
      return;
//--- get Moving Average
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol())
         continue;
      //--- check order type
      if(OrderType()==OP_BUY)
        {
         if(Open[1]>ma && Close[1]<ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]<ma && Close[1]>ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0)
      CheckForOpen();
   else
      CheckForClose();
//---
  }
//+------------------------------------------------------------------+
 
SanAlex:

下面是一个例子,在10 000以下,你的余额将以0.1手为单位,从10 000到20 000以0.5手为单位。

从20000到40000,1.0手,超过40000,2.0手

这是一个固定的地段增量。

对我来说,如果利润大于或等于

 MarketInfo(Symbol(), MODE_MARGINREQUIRED)*MarketInfo(Symbol(), MODE_LOTSTEP)

它将增加该地段。

但如果没有其他使用保证金的未结订单。

 
MakarFX:

它是一个固定的增加地段。

在我的案例中,如果利润大于或等于

那么,该地段就会有增加。

但如果没有其他使用保证金的未结订单。

我在作弊--如果头寸处于亏损状态,就会增加地段。

//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedBuy(void)
  {
   double PROFIT_BUY=0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
           {
            PROFIT_BUY=PROFIT_BUY+NormalizeDouble(OrderProfit(),2);
           }
        }
     }
   double Lots=InpLots;
   double ab=PROFIT_BUY;
   if(ab<-1 && ab>=-InpLots_01)
      Lots=InpLots1;
   if(ab<-InpLots_01 && ab>=-InpLots_02)
      Lots=InpLots2;
   if(ab<-InpLots_02 && ab>=-InpLots_03)
      Lots=InpLots3;
   if(ab<-InpLots_03)
      Lots=InpLots4;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell(void)
  {
   double PROFIT_SELL=0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol())
        {
         if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
           {
            PROFIT_SELL=PROFIT_SELL+NormalizeDouble(OrderProfit(),2);
           }
        }
     }
   double Lots=InpLots;
   double ab=PROFIT_SELL;
   if(ab<-1 && ab>=-InpLots_01)
      Lots=InpLots1;
   if(ab<-InpLots_01 && ab>=-InpLots_02)
      Lots=InpLots2;
   if(ab<-InpLots_02 && ab>=-InpLots_03)
      Lots=InpLots3;
   if(ab<-InpLots_03)
      Lots=InpLots4;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+
 
谢谢大家的帮助,但我的大脑没有足够的能力去做我需要的事情。
 
Сергей Дыбленко:
谢谢大家的帮助,但我的大脑不足以完成我需要做的事情。

你逐点解释需要什么。

工作中的订单有多少,你同时交易多少个货币对,每笔交易的风险是什么(如果有)?

还有你的其他东西)

 
SanAlex:

我一直在作弊--如果头寸处于亏损状态,那么这批货会增加。

萨沙对其进行了一些调整,以增加该地段的赔率

input double factor=1.05;        // коофициент умножения
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double OptimizedSell(void)
  {
   double Lots       =0.00;
   double PROFIT_BUY =0.00;
   double LOT_BUY    =0.00;
   double PROFIT_SELL=0.00;
   double LOT_SELL   =0.00;
   for(int i=OrdersTotal()-1; i>=0; i--) // returns the number of open positions
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY)
              {
               PROFIT_BUY=PROFIT_BUY+NormalizeDouble(OrderProfit(),2);
               LOT_BUY   =LOT_BUY+NormalizeDouble(OrderLots(),2);
              }
            if(OrderType()==OP_SELL)
              {
               PROFIT_SELL=PROFIT_SELL+NormalizeDouble(OrderProfit(),2);
               LOT_SELL   =LOT_SELL+NormalizeDouble(OrderLots(),2);
              }
           }
        }
     }
   if(PROFIT_BUY<0)
      Lots=LOT_BUY*factor;
      else Lots=LOT_BUY;
   if(PROFIT_SELL<0)
      Lots=LOT_SELL*factor;
      else Lots=LOT_SELL;
//--- return trading volume
   return(Lots);
  }
//+------------------------------------------------------------------+ 
原因: