colin.hong 发表于 2024-12-31 04:52:12

图表显示均价代码和位置代码





//+------------------------------------------------------------------+
void 均价线()
{
   double longVolume = 0;
   double shortVolume = 0;
   double longCost = 0;
   double shortCost = 0;
   double longProfit = 0;
   double shortProfit = 0;
   for(int i=0; i<OrdersTotal(); i++)
   {
      if(OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic3)
      {
         if(OrderType()==OP_BUY)
         {
            longVolume += OrderLots();
            longCost += OrderOpenPrice() * OrderLots();
            longProfit += OrderProfit();
         }
         else
            if(OrderType()==OP_SELL)
            {
               shortVolume += OrderLots();
               shortCost += OrderOpenPrice() * OrderLots();
               shortProfit += OrderProfit();
            }
      }
   }
   double avgLongPrice = (longVolume>0) ? longCost/longVolume : 0;
   double avgShortPrice = (shortVolume>0) ? shortCost/shortVolume : 0;
   均价显示("Arrow1_YCEA",0,6,1,Time+2*Period()*60,avgLongPrice,ANCHOR_BOTTOM,clrRed);
   均价显示("Arrow2_YCEA",0,6,1,Time+2*Period()*60,avgShortPrice,ANCHOR_BOTTOM,clrAqua);
}
//+------------------------------------------------------------------+
void 均价显示(string Name,int Sub_window,int ArrowCode,int Width,datetime Time1, double Price1,int Anchor,int ArrowColor)
{
   if(ObjectFind(0,Name)==-1)
   {
      ObjectCreate(0,Name,OBJ_ARROW,Sub_window,0,0);
      ObjectSetInteger(0,Name,OBJPROP_ARROWCODE,ArrowCode);
      ObjectSetInteger(0,Name,OBJPROP_WIDTH,Width);
      ObjectSetInteger(0,Name,OBJPROP_COLOR,ArrowColor);
      ObjectSetInteger(0,Name,OBJPROP_ANCHOR,Anchor);
   }
   ObjectSetInteger(0,Name,OBJPROP_TIME,Time1);
   ObjectSetDouble(0,Name,OBJPROP_PRICE,Price1);
}
//+------------------------------------------------------------------+


页: [1]
查看完整版本: 图表显示均价代码和位置代码