1

我的问题是我想在特定货币图表的所有历史中分别在看涨蜡烛和看跌蜡烛中绘制一个向上箭头(绿色)和向下箭头(红色)这是我的代码到目前为止

    //+------------------------------------------------------------------+
//|                                                  PriceAction.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

DrawArrowUp("up"+Bars,Close[1]+10*Point,Lime);

//---
   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[])
  {
//---


//--- return value of prev_calculated for next call
   return(rates_total);
 }
//+------------------------------------------------------------------+
void DrawArrowUp(string ArrowName,double LinePrice,color LineColor)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[0], LinePrice); //draw an up arrow
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
}

void DrawArrowDown(string ArrowName,double LinePrice,color LineColor)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[0], LinePrice); //draw an up arrow
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
}

但它只在最后一个柱上绘制箭头,我希望它在所有图表蜡烛中谢谢,

4

1 回答 1

1

在您的函数中DrawArrowUp(),您调用需要名称、对象类型、时间和价格的DrawArrowDn()mt4 函数。ObjectCreate()因为你把所有的物体都放在上面Time[0]——也许你可以在同一个(最后一个)蜡烛上有很多箭头。

const string PREFIX = "ALL_BARS_ARROWS";//to easily delete all objects in OnDeinit()
 void DrawArrow(double linePrice,datetime time,bool bullish){
    string name = PREFIX+"arrow"+(bullish?"up":"down")+IntegerToString(time);
    ObjectCreate(name,OBJ_ARROW,0,time,linePrice);
    ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
    ObjectSet(name, OBJPROP_ARROWCODE, bullish?SYMBOL_ARROWUP:SYMBOL_ARROWDOWN);
    ObjectSet(name, OBJPROP_COLOR, bullish? clrLime : clrRed);
}

可以在此处找到创建和编辑箭头属性的更多选项

现在在OnCalculate()函数中:

int limit, i;
if(prev_calculated==0){
   limit = rates_total-1;
}else{
   limit = rates_total - prev_calculated;
}
bool isCandleBullish;
for(i=limit; i>0; i--){
   isCandleBullish = close[i]>open[i];//think of doji candles also
   DrawArrow(Close[i]+10*Point*(isCandleBullish?1:-1),time[i],isCandleBullish);
}
于 2017-06-24T06:38:48.283 回答