我的问题是我想在特定货币图表的所有历史中分别用看涨蜡烛和看跌蜡烛画一个向上箭头(绿色)和向下箭头(红色) 这是我到目前为止的代码
//+------------------------------------------------------------------+
//| 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);
}
但它只在最后一个条上画出箭头, 我想要它在所有的蜡烛图表中 谢谢,
答案 0 :(得分:0)
在您的函数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);
}
可以找到更多用于创建和编辑箭头属性的选项here
现在在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+10*Point*(isBullish?1:-1),time[i],isCandleBullish);
}