#property indicator_separate_window #property indicator_buffers1 #property indicator_plots1 //---- plot MA #property indicator_label1 "MA" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters bool AsSeries=true; int period=15; inputENUM_TIMEFRAMES TimeFrame=PERIOD_CURRENT;//Период графика ENUM_MA_METHOD smootMode=MODE_EMA; ENUM_APPLIED_PRICE price=PRICE_CLOSE; int shift=0; //--- indicator buffers double MABuffer[]; int ma_handle; int to_copy; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ intOnInit() { //--- indicator buffers mapping SetIndexBuffer(0,MABuffer,INDICATOR_DATA); Print("Параметр AsSeries = ",AsSeries); Print("Индикаторный буфер после SetIndexBuffer() является таймсерией = ", ArrayGetAsSeries(MABuffer)); //--- set short indicator name IndicatorSetString(INDICATOR_SHORTNAME,"MA("+period+")"+AsSeries); //--- set AsSeries (depends on input parameter) ArraySetAsSeries(MABuffer,AsSeries); Print("Индикаторный буфер после ArraySetAsSeries(MABuffer,true); является таймсерией = ", ArrayGetAsSeries(MABuffer)); //--- ma_handle=iMA(Symbol(),TimeFrame,period,shift,smootMode,price); EventSetTimer(1); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ intOnCalculate(constint rates_total, constint prev_calculated, constdatetime &time[], constdouble &open[], constdouble &high[], constdouble &low[], constdouble &close[], constlong &tick_volume[], constlong &volume[], constint &spread[]) { //--- check if all data calculated if(BarsCalculated(ma_handle)<rates_total) return(0); //--- we can copy not all data //int to_copy; if(prev_calculated>rates_total || prev_calculated<=0) to_copy=rates_total; else { to_copy=rates_total-prev_calculated; //--- last value is always copied to_copy++; } //--- try to copy
//--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ voidOnTimer() { //--- CopyBuffer(ma_handle,0,0,to_copy,MABuffer); Print("Таймер"); } //+------------------------------------------------------------------+
我用OnTimer()实现了它,但没有任何结果。不幸的是,onTimer()事件没有计算指标,延迟被保存,也许是一个响亮的声明,我做错了什么,请纠正。谢谢!
你所做的不是通过OnTimer()实现的。你只在那里得到价值(所有的历史,以及每一秒,没有任何检查)。一般来说,你不太可能自己实施。等待支部作者的答复:)
我用OnTimer()实现了它,但没有任何结果。不幸的是,onTimer()事件没有计算指标,延迟被保存,也许是一个响亮的声明,我做错了什么,请纠正。谢谢!
//| TestCopyBuffer3.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
//---- plot MA
#property indicator_label1 "MA"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
bool AsSeries=true;
int period=15;
input ENUM_TIMEFRAMES TimeFrame=PERIOD_CURRENT; //Период графика
ENUM_MA_METHOD smootMode=MODE_EMA;
ENUM_APPLIED_PRICE price=PRICE_CLOSE;
int shift=0;
//--- indicator buffers
double MABuffer[];
int ma_handle;
int to_copy;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
Print("Параметр AsSeries = ",AsSeries);
Print("Индикаторный буфер после SetIndexBuffer() является таймсерией = ",
ArrayGetAsSeries(MABuffer));
//--- set short indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"MA("+period+")"+AsSeries);
//--- set AsSeries (depends on input parameter)
ArraySetAsSeries(MABuffer,AsSeries);
Print("Индикаторный буфер после ArraySetAsSeries(MABuffer,true); является таймсерией = ",
ArrayGetAsSeries(MABuffer));
//---
ma_handle=iMA(Symbol(),TimeFrame,period,shift,smootMode,price);
EventSetTimer(1);
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[])
{
//--- check if all data calculated
if(BarsCalculated(ma_handle)<rates_total) return(0);
//--- we can copy not all data
//int to_copy;
if(prev_calculated>rates_total || prev_calculated<=0) to_copy=rates_total;
else
{
to_copy=rates_total-prev_calculated;
//--- last value is always copied
to_copy++;
}
//--- try to copy
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
CopyBuffer(ma_handle,0,0,to_copy,MABuffer);
Print("Таймер");
}
//+------------------------------------------------------------------+
我想这意味着把OnCalculate 中的所有内容都移到OnTimer 中去。
为了重写它,所有要包括的指标也必须在mql5之下
下午。我在Delta_RSI指标上,我让它不断地绘制(见截图)histo两边同时进行(寻找错误)。而且可以对高于/低于零的无信号颜色进行着色。你能看到(正确)吗?谢谢你。
描述你做什么来打破它 ))))
图表、TF、序列等。
描述你做什么来打破它 ))))
图表、TF、序列等。