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

 

下午好!!!。祝大家新年快乐!!!。

以下是显示网格中订单平均价格的截图

以下是创建平均价格和铭文的水平线的代码

//+----------------------------------------------------------------------------+
//| Расчет среденй цены (0)-buy (1)-sell ()-all                                |
//+----------------------------------------------------------------------------+
double GetAveragePrice(int ot=-1)
  {
   double order_lots = 0, order_price = 0, avg_price = 0;
     {
      for(int i = OrdersTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
           {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
              {
               if(OrderType()==ot||ot<0)
                 {
                  order_lots += OrderLots();
                  order_price += OrderOpenPrice() * OrderLots();
                 }
              }
           }
        }
     }
   avg_price = NormalizeDouble(order_price / order_lots, Digits);

   if(ObjectFind(0,"AveragePriceLine"+IntegerToString(ot))!=0)
      ObjectCreate(0,"AveragePriceLine"+IntegerToString(ot),OBJ_HLINE, 0, 0, avg_price);
   else
      ObjectSetDouble(0,"AveragePriceLine"+IntegerToString(ot),OBJPROP_PRICE,avg_price);
   if(ot==0)
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrLime);
   ObjectCreate("signal4",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("signal4",OBJPROP_XDISTANCE,100);
   ObjectSet("signal4",OBJPROP_YDISTANCE,260);
   ObjectSetText("signal4","- Средняя цена сетки ордеров на покупку",14,"Times New Roman", clrLime);
   if(ot==1)
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrRed);
   ObjectCreate("signal3",OBJ_LABEL,0, 0, 0, 0, 0);
   ObjectSet("signal3",OBJPROP_XDISTANCE, 100);
   ObjectSet("signal3",OBJPROP_YDISTANCE, 280);
   ObjectSetText("signal3", "- Средняя цена сетки ордеров на продажу", 14, "Times New Roman", clrRed);
   return(avg_price);
  }

以下是删除横线的代码

//-------------------------------------------------------------------+  Команда на удаление линий отображающую среднюю цену
   if(CountTrade() == 0)
     {
      if(ObjectFind(0,"AveragePriceLine" + IntegerToString(0))==0&&CountTrade(0)<1)//для бай
        {
         ObjectDelete(0,"AveragePriceLine"+ IntegerToString(0));
        }
      if(ObjectFind(0,"AveragePriceLine" + IntegerToString(1))==0&&CountTrade(1)<1)//для селл
        {
         ObjectDelete(0,"AveragePriceLine" + IntegerToString(1));
        }
     }

请帮助重做代码,使题词出现在行的上方,并在行被移除时被移除。

谢谢你的帮助。

 
EVGENII SHELIPOV #:

请帮助我重写代码,以便

如果你能帮忙,到底是什么事你不能做?

 
Andrey Sokolov #:

如果你能帮忙,到底是什么事你不能做?

我们不要太粗鲁,如果我知道怎么做,我就不会来这里了。

这个问题很简单,你需要知道铭文与水平线的坐标,因为我不知道如何计算。


 
EVGENII SHELIPOV #:

我们不要太粗鲁,如果我知道怎么做,我就不会来这里了。

这个问题很简单,我需要知道铭文与水平线的坐标,因为我不知道如何计算它。


你的意思是 "让我们不要粗鲁"?我是否写了 "帮助 "而不是 "做我"。

 
EVGENII SHELIPOV #:

下午好!!!。大家新年快乐!!!。

水代码删除水平线

谢谢你的帮助。

这已经绰绰有余了。

//-------------------------------------------------------------------+  Команда на удаление линий отображающую среднюю цену
   if(CountTrade() == 0)
     {
      ObjectsDeleteAll(0,"AveragePriceLine");
     }
evgenii shelipov#:

这个问题很简单,你需要知道铭文与水平线的坐标,因为我不知道如何计算。

在这里你可以帮助

计时价格到XY

ChartXYToTimePrice

 
Tretyakov Rostyslav #:

这已经绰绰有余了。

这里是你可以得到帮助的地方。

计时价格到XY

ChartXYToTimePrice

谢谢你的提示,但我做错了。

我只需要改变0Y轴,但铭文不愿意与水平线联姻。

我附上了代码和截图,请告知错误在哪里?

//+----------------------------------------------------------------------------+
//| Расчет среденй цены (0)-buy (1)-sell ()-all                                |
//+----------------------------------------------------------------------------+
double GetAveragePrice(int ot=-1)
  {
   double order_lots = 0, order_price = 0, avg_price = 0;
   int x = 0, y = 0;
     {
      for(int i = OrdersTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
           {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
              {
               if(OrderType()==ot||ot<0)
                 {
                  order_lots += OrderLots();
                  order_price += OrderOpenPrice() * OrderLots();
                 }
              }
           }
        }
     }
   avg_price = NormalizeDouble(order_price / order_lots, Digits);

   if(ObjectFind(0,"AveragePriceLine"+IntegerToString(ot))!=0)
      ObjectCreate(0,"AveragePriceLine"+IntegerToString(ot),OBJ_HLINE, 0, 0, avg_price);
   else
      ObjectSetDouble(0,"AveragePriceLine"+IntegerToString(ot),OBJPROP_PRICE,avg_price);
   if(ot==0)
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrLime);
   ObjectCreate("signal4",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("signal4",OBJPROP_XDISTANCE,500);
   ChartTimePriceToXY(0, 0, 0,avg_price, x, y);
   ObjectSet("signal4",OBJPROP_YDISTANCE, y + 10);
   ObjectSetText("signal4","- Средняя цена сетки ордеров на покупку",14,"Times New Roman", clrLime);
   if(ot==1)
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrRed);
   ObjectCreate("signal3",OBJ_LABEL,0, 0, 0, 0, 0);
   ObjectSet("signal3",OBJPROP_XDISTANCE, 500);
   ChartTimePriceToXY(0, 0, 0, avg_price, x, y);
   ObjectSet("signal3",OBJPROP_YDISTANCE, y + 10);
   ObjectSetText("signal3","- Средняя цена сетки ордеров на продажу", 14, "Times New Roman", clrRed);
   return(avg_price);
  }


 
EVGENII SHELIPOV #:

Rostislav,谢谢你的提示,但我做错了。

我只需要改变0Y轴,但铭文不愿意与水平线联姻。

我附上了代码和截图,你能告诉我错误在哪里吗?

不要忘了支架的作用。

//+----------------------------------------------------------------------------+
//| Расчет среденй цены (0)-buy (1)-sell ()-all                                |
//+----------------------------------------------------------------------------+
double GetAveragePrice(int ot=-1)
  {
   double order_lots = 0, order_price = 0, avg_price = 0;
   int x = 0, y = 0;
     {
      for(int i = OrdersTotal()-1; i>=0; i--)
        {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
           {
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
              {
               if(OrderType()==ot||ot<0)
                 {
                  order_lots += OrderLots();
                  order_price += OrderOpenPrice() * OrderLots();
                 }
              }
           }
        }
     }
   avg_price = NormalizeDouble(order_price / order_lots, Digits);

   if(ObjectFind(0,"AveragePriceLine"+IntegerToString(ot))!=0)
      ObjectCreate(0,"AveragePriceLine"+IntegerToString(ot),OBJ_HLINE, 0, 0, avg_price);
   else
      ObjectSetDouble(0,"AveragePriceLine"+IntegerToString(ot),OBJPROP_PRICE,avg_price);
   if(ot==0)
     {
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrLime);
      ObjectCreate("signal4",OBJ_LABEL,0,0,0,0,0);
      ObjectSet("signal4",OBJPROP_XDISTANCE,500);
      ChartTimePriceToXY(0, 0, 0,avg_price, x, y);
      ObjectSet("signal4",OBJPROP_YDISTANCE, y + 10);
      ObjectSetText("signal4","- Средняя цена сетки ордеров на покупку",14,"Times New Roman", clrLime);
     }
   if(ot==1)
     {
      ObjectSet("AveragePriceLine"+IntegerToString(ot),OBJPROP_COLOR, clrRed);
      ObjectCreate("signal3",OBJ_LABEL,0, 0, 0, 0, 0);
      ObjectSet("signal3",OBJPROP_XDISTANCE, 500);
      ChartTimePriceToXY(0, 0, 0, avg_price, x, y);
      ObjectSet("signal3",OBJPROP_YDISTANCE, y + 10);
      ObjectSetText("signal3","- Средняя цена сетки ордеров на продажу", 14, "Times New Roman", clrRed);
     }
   return(avg_price);
  }
 
Tretyakov Rostyslav #:

不要忘了支架的作用。

不,还缺少其他东西。

 
EVGENII SHELIPOV #:

不,还缺少其他东西

记录本中一定有错误
 

复制到一个数组

MqlRates CopySymb[];  
if(CopyRates(mSymbol,PERIOD_CURRENT,0,6,CopySymb)<0) return;
Print( ArrayMaximum(???) );

如何获得一个数组中的最大高度?