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

 
Fast235 #:

只有这句话提出了一个问题

-50个额外的和一个阵列

这是为了在 "0 "的上方/下方画出。

但你可以不这样做,我需要的是它的要点,如何使用手柄。

 
Vladimir Simakov #:

我强烈推荐它。

否则,你会得到一个 "哎呀"。)

另外,在除法后马上把它弄成一个整体。否则二进制计数可以做很多事情)。

 
MakarFX #:

这是为了在 "0 "的上方/下方作画。

但你可以不这样做,我需要知道如何使用手柄。

Handle是一个指向指标文件的指针,通常在OnInit()中创建。

   Handle=iCustom(Symbol(),PERIOD_H1,"_iTrend",10);
//--- Если не удалось получить хендл индикатора
   if(Handle==INVALID_HANDLE)
     {
      PrintFormat("Failed to create handle of the iAO indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //---
      return(INIT_FAILED);
     }

在代码中更进一步

    if(CopyBuffer(Handle,0,1,1,Buffer1) <=0 проверка на ошибку
---
в Buffer1[1111] получаем значение
 
Fast235 #:

Handle是一个指向指标文件的指针,通常在OnInit()中创建。

在代码中更进一步

谢谢,但它看起来像帮助,不幸的是,它对我来说并不清楚(

这就是为什么我要求把我的代码翻译成mql5,以便理解工作逻辑的原因

我是这样做的

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
   prd = _Period > TimeFrame ? _Period : TimeFrame;
   atrHandle = iATR(_Symbol, prd, Per_Count);
   if(atrHandle == INVALID_HANDLE)
     {
      Print("Can't load indicator."); return INIT_FAILED;
     }
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,Label2Buffer,INDICATOR_DATA);
   
   ArraySetAsSeries(Label1Buffer, true);
   ArraySetAsSeries(Label2Buffer, true);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int limit,i;
   int barPlus=iBarShift(_Symbol,_Period,iTime(_Symbol,PERIOD_W1,WeekCount),false);
   limit=rates_total-prev_calculated-3;
   if(WeekCount!=0)limit=barPlus-1;
   if(limit<1) return(0);
   for(i=limit;i>=0;i--)
     {
      TimeToStruct(time[i],inTime);
      index01=iBarShift(_Symbol,PERIOD_D1,time[i],false);
      if(inTime.hour==0&&inTime.min==0)
        {
         Label1Buffer[i]=GetIndicator(atrHandle, index01+1);
        }
     }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
double GetIndicator(const int handle, const int i)
  {
   double res[1];
   if(CopyBuffer(handle, 0, i, 1, res) <= 0) return 0;
   return res[0];
  }
//+------------------------------------------------------------------+

但我感觉有些不对劲,帮助中没有提到iMAOnArray。

 

下午好。

我无法解决马汀循环的问题。

我无法解决马丁的循环问题。它在执行后被断开:(n>=OrdersClose)-然后马丁不会被触发,直到发生盈利的交易

我需要在(n>=OrdersClose)之后返回(dLots),如果下一次交易再次失败,马丁将重新开始

你能告诉我如何做到这一点吗?

double LOT()
{
   int n=0;
   double OL=dLots;
   for (int j = OrdersHistoryTotal()-1; j >= 0; j--)
   {
      if (OrderSelect(j, SELECT_BY_POS,MODE_HISTORY))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == iMagic)
         {
            if (OrderProfit()<0) 
            {
               if (n==0) OL=NormalizeDouble(OrderLots()*K_Martin,DigitsLot);
               n++;
               if (n>=OrdersClose) {return(dLots);}
            }
            else
            {
               if (n==0) {return(dLots);}
               else {return(OL);}
            }
         }
      }
   }
   return(OL);
}
 

大家好!!!。

请告诉我在网格顾问代码中规定了图表上平均价格的显示。我本来是可以的,但关闭网格后没有正确删除这一行,也就是说,平均价格没有。 请告诉我我做错了什么。下面是代码和图片。

//+----------------------------------------------------------------------------+
//| 修改组内订单 |
//+----------------------------------------------------------------------------+
void ModifyOrders(int otype)
{
double avg_price, AveragePriceBuy, AveragePriceSell, order_lots = 0;
price = 0;

for(int i = OrdersTotal()-1; i>)=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
{
price += OrderOpenPrice() * OrderLots();
order_lots += OrderLots() ;
}
}
}
avg_price = NormalizeDouble(price / order_lots, Digits);
AveragePriceBuy = NormalizeDouble(avg_price + Spread, Digits);
AveragePriceSell = NormalizeDouble(avg_price - Spread, Digits) 。
{
ObjectDelete(0, "AveragePriceLine");
ObjectCreate("AveragePriceLine" ,OBJ_HLINE, 0, 0 , AveragePriceBuy);
ObjectCreate("AveragePriceLine" ,OBJ_HLINE, 0, 0 ,AveragePriceSell);
ObjectSet("AveragePriceLine" ,OBJPROP_COLOR,Blue);
}
如果((otype == OP_BUY) && (Drawdown <= DrawdownClosingTakeprofitZero))
tp = NormalizeDouble (AveragePriceBuy + TakeProfitGroupOrder*Point, Digits);
如果((otype == OP_SELL) && (Drawdown <= DrawdownClosingTakeeprofitZero))
tp = NormalizeDouble (AveragePriceSell - TakeProfitGroupOrder*Point, Digits);
如果((otype == OP_BUY) && (Drawdown > DrawdownClosingTakeeprofitZero))
tp = NormalizeDouble (AveragePriceBuy, Digits);
如果((otype == OP_SELL) &/or& (Drawdown > DrawdownClosingTakeeprofitZero))
tp = NormalizeDouble (AveragePriceSell, Digits);

for(int i = OrdersTotal()-1;i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
{
如果(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0))
Print("Orders successfully modified!";
else Print("修改订单错误!");
}
}
}
} }


 
EVGENII SHELIPOV #:

大家好!!!。

请告诉我在网格顾问代码中规定了图表上平均价格的显示。这就可以了,但不能正确地删除关闭网格后的线,也就是说,平均价格没有了。 请告诉我我做错了什么。下面是代码和图片。

试试这样的方式

//+----------------------------------------------------------------------------+
//| Модификация групповых ордеров                                              |
//+----------------------------------------------------------------------------+
void ModifyOrders(int otype)
{
    double avg_price, AveragePriceBuy, AveragePriceSell, order_lots = 0;
    price = 0;
   
    for(int i = OrdersTotal()-1; i>=0; i--)
    {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
       {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
         {
            price += OrderOpenPrice() * OrderLots();
            order_lots += OrderLots() ;
         }
       }
    }
    avg_price = NormalizeDouble(price / order_lots, Digits);
    AveragePriceBuy = NormalizeDouble(avg_price + Spread, Digits);
    AveragePriceSell = NormalizeDouble(avg_price - Spread, Digits);
    if(ObjectFind(0,"AveragePriceLineBuy")==0)
     {
     ObjectDelete(0,"AveragePriceLineBuy");
     ObjectCreate(0,"AveragePriceLineBuy" ,OBJ_HLINE, 0, 0 ,AveragePriceBuy);
     ObjectSetInteger(0,"AveragePriceLine",OBJPROP_COLOR,Blue);
     }
    else
     {
     ObjectCreate(0,"AveragePriceLineBuy" ,OBJ_HLINE, 0, 0 ,AveragePriceBuy);
     ObjectSetInteger(0,"AveragePriceLine",OBJPROP_COLOR,Blue);
     }
    if(ObjectFind(0,"AveragePriceLineSell")==0)
     {
     ObjectDelete(0,"AveragePriceLineSell");
     ObjectCreate(0,"AveragePriceLineSell" ,OBJ_HLINE, 0, 0 ,AveragePriceSell);
     ObjectSetInteger(0,"AveragePriceLine",OBJPROP_COLOR,Blue);
     }
    else
     {
     ObjectCreate(0,"AveragePriceLineSell" ,OBJ_HLINE, 0, 0 ,AveragePriceSell);
     ObjectSetInteger(0,"AveragePriceLine",OBJPROP_COLOR,Blue);
     }
    if ((otype == OP_BUY) && (Drawdown <= DrawdownClosingTakeprofitZero)) 
    tp = NormalizeDouble (AveragePriceBuy + TakeProfitGroupOrder*Point, Digits);
    if ((otype == OP_SELL) && (Drawdown <= DrawdownClosingTakeprofitZero))
    tp = NormalizeDouble (AveragePriceSell - TakeProfitGroupOrder*Point, Digits);
    if ((otype == OP_BUY) && (Drawdown > DrawdownClosingTakeprofitZero)) 
    tp = NormalizeDouble (AveragePriceBuy, Digits);
    if ((otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero))
    tp = NormalizeDouble (AveragePriceSell, Digits);
    
    for(int i = OrdersTotal()-1; i>=0; i--) 
    {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
       {
           if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
           {
               if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0))
                  Print("Ордера успешно модифицированы!");
                else Print("Ошибка модификации ордеров!");
           }
       }
    }
}   

或更好地开出处方。

如果没有未平仓的卖出订单,请删除卖出行。

白事也是如此

 
晚上好,如何在点击时重置图形按钮的状态,使其在再次点击前不会一直被按下?
 
Nerd Trader #:
晚上好,如何在点击时重置图形按钮的状态,使其在再次点击前不会一直被按下?
ObjectSetInteger(0,name,OBJPROP_STATE,false);
 
MakarFX #:
不,你搞错了。我需要像普通按钮一样,在点击释放后重置状态。如果mql4没有鼠标按钮的状态事件,如何实现这个:点击/释放。
原因: