编码帮助 - 页 263

 
mladen:
MrWigglesworth 这是一个加入了Dema作为4型的版本:ma__dema_crossover_with_arrow_and_email.mq4

很好!非常感谢你的帮助,MLaden

节日快乐!!

 

现在有谁能从代码中自动找出经纪人的格林尼治时间(而不是我自己的格林尼治时间)?

 
techmac:
现在有谁能从代码中自动找出经纪商的GMT(不是我自己的GMT)?

没有自动查找经纪人的方法(在所有的数据中没有这样的信息--甚至在新的metatrader 4中也没有--至少我没有发现)。

 

嗨,mladen。

我曾经问过一个关于脚本的问题,这个脚本在实际的图表中切割了几个小时的时间。现在我想在每个条形图上放一个延迟,这样我的图表中就有一个时间偏移。

我试着这样做了,但是没有成功(就像我想的那样)。

input int TimeDelay_Minutes = 60;

input int StartHour = 8;

input int StartMinute = 0;

input int CloseHour = 16;

input int CloseMinute = 30;

int InpPeriodMultiplier=1; // Period multiplier factor

int ExtHandle=-1;

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

void OnStart()

{

datetime time0;

ulong last_fpos=0;

long last_volume=0;

int i, start_pos, periodseconds;

int hwnd=0, cnt=0;

//---- History header

int version=401;

string c_copyright;

string c_symbol=Symbol();

int i_period=Period()*InpPeriodMultiplier;

int i_digits=Digits;

int i_unused[13];

MqlRates rate;

//---

ExtHandle=FileOpenHistory(c_symbol+(string)3+".hst", FILE_BIN|FILE_WRITE|FILE_SHARE_READ|FILE_ANSI);

if(ExtHandle<0)

return;

ArrayInitialize(i_unused,0);

//--- write history file header

FileWriteInteger(ExtHandle, version, LONG_VALUE);

FileWriteString(ExtHandle, c_copyright, 64);

FileWriteString(ExtHandle, c_symbol, 12);

FileWriteInteger(ExtHandle, 3, LONG_VALUE);

FileWriteInteger(ExtHandle, i_digits, LONG_VALUE);

FileWriteInteger(ExtHandle, 0, LONG_VALUE); //timesign

FileWriteInteger(ExtHandle, 0, LONG_VALUE); //last_sync

FileWriteArray(ExtHandle, i_unused, 0, 13);

//--- write history file

periodseconds=i_period*60;

start_pos=Bars-1;

rate.open=Open[start_pos];

rate.low=Low[start_pos];

rate.high=High[start_pos];

rate.tick_volume=(long)Volume[start_pos];

rate.spread=0;

rate.real_volume=0;

//--- normalize open time

rate.time=Time[start_pos]/periodseconds;

rate.time*=periodseconds;

for(i=start_pos-1; i>=0; i--)

{

if(IsStopped())

break;

time0=Time- 1 * 60 *TimeDelay_Minutes;

//--- history may be updated

if(i==0)

{

//--- modify index if history was updated

if(RefreshRates())

i=iBarShift(NULL,0,time0);

}

//---

if((time0>=rate.time+periodseconds || i==0)&& MainTime(time0)==true)

{

if(i==0)

{

rate.time=time0/periodseconds; //NEU

rate.tick_volume+=(long)Volume[0];

if(rate.low>Low[0])

rate.low=Low[0];

if(rate.high<High[0])

rate.high=High[0];

rate.close=Close[0];

}

last_fpos=FileTell(ExtHandle);

last_volume=(long)Volume;

FileWriteStruct(ExtHandle,rate);

cnt++;

if(time0>=rate.time+periodseconds)

{

rate.time=time0/periodseconds;

rate.time*=periodseconds;

rate.open=Open;

rate.low=Low;

rate.high=High;

rate.close=Close;

rate.tick_volume=last_volume;

}

}

else if(MainTime(time0)==true)

{

rate.time=time0/periodseconds; //NEU

rate.tick_volume+=(long)Volume;

if(rate.low>Low)

rate.low=Low;

if(rate.high<High)

rate.high=High;

rate.close=Close;

}

}

FileFlush(ExtHandle);

//Print(cnt," record(s) written");

//--- collect incoming ticks

datetime last_time=LocalTime()-5;

while(!IsStopped())

{

datetime cur_time=LocalTime();

//--- check for new rates

if(RefreshRates())

{

time0=Time[0]- 1 * 60 *TimeDelay_Minutes;

FileSeek(ExtHandle,last_fpos,SEEK_SET);

//--- is there current bar?

if(time0<rate.time+periodseconds && MainTime(time0)==true)

{

rate.tick_volume+=(long)Volume[0]-last_volume;

last_volume=(long)Volume[0];

if(rate.low>Low[0])

rate.low=Low[0];

if(rate.high<High[0])

rate.high=High[0];

rate.close=Close[0];

}

else if(MainTime(time0)==true)

{

//--- no, there is new bar

rate.tick_volume+=(long)Volume[1]-last_volume;

if(rate.low>Low[1])

rate.low=Low[1];

if(rate.high<High[1])

rate.high=High[1];

//--- write previous bar remains

FileWriteStruct(ExtHandle,rate);

last_fpos=FileTell(ExtHandle);

//----

rate.time=time0/periodseconds;

rate.time*=periodseconds;

rate.open=Open[0];

rate.low=Low[0];

rate.high=High[0];

rate.close=Close[0];

rate.tick_volume=(long)Volume[0];

last_volume=rate.tick_volume;

}

//----

FileWriteStruct(ExtHandle,rate);

FileFlush(ExtHandle);

//---

if(hwnd==0)

{

hwnd=WindowHandle(Symbol(),i_period);

if(hwnd!=0)

Print(" "); //Chart window detected

}

//--- refresh window not frequently than 1 time in 2 seconds

if(hwnd!=0 && cur_time-last_time>=2)

{

PostMessageA(hwnd,WM_COMMAND,33324,0);

last_time=cur_time;

}

}

Sleep(50);

}

//---

}

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---

if(ExtHandle>=0)

{

FileClose(ExtHandle);

ExtHandle=-1;

}

//---

}

 
sunshineh:
你好,mladen。

我曾经问过一个关于脚本的问题,这个脚本在实际的图表中切割了几个小时的时间。现在我想在每个条形图上放一个延迟,这样我的图表中就有一个时间偏移。

我试着这样做了,但并不奏效(就像我想的那样)。

input int TimeDelay_Minutes = 60;

input int StartHour = 8;

input int StartMinute = 0;

input int CloseHour = 16;

input int CloseMinute = 30;

int InpPeriodMultiplier=1; // Period multiplier factor

int ExtHandle=-1;

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

void OnStart()

{

datetime time0;

ulong last_fpos=0;

long last_volume=0;

int i, start_pos, periodseconds;

int hwnd=0, cnt=0;

//---- History header

int version=401;

string c_copyright;

string c_symbol=Symbol();

int i_period=Period()*InpPeriodMultiplier;

int i_digits=Digits;

int i_unused[13];

MqlRates rate;

//---

ExtHandle=FileOpenHistory(c_symbol+(string)3+".hst", FILE_BIN|FILE_WRITE|FILE_SHARE_READ|FILE_ANSI);

if(ExtHandle<0)

return;

ArrayInitialize(i_unused,0);

//--- write history file header

FileWriteInteger(ExtHandle, version, LONG_VALUE);

FileWriteString(ExtHandle, c_copyright, 64);

FileWriteString(ExtHandle, c_symbol, 12);

FileWriteInteger(ExtHandle, 3, LONG_VALUE);

FileWriteInteger(ExtHandle, i_digits, LONG_VALUE);

FileWriteInteger(ExtHandle, 0, LONG_VALUE); //timesign

FileWriteInteger(ExtHandle, 0, LONG_VALUE); //last_sync

FileWriteArray(ExtHandle, i_unused, 0, 13);

//--- write history file

periodseconds=i_period*60;

start_pos=Bars-1;

rate.open=Open[start_pos];

rate.low=Low[start_pos];

rate.high=High[start_pos];

rate.tick_volume=(long)Volume[start_pos];

rate.spread=0;

rate.real_volume=0;

//--- normalize open time

rate.time=Time[start_pos]/periodseconds;

rate.time*=periodseconds;

for(i=start_pos-1; i>=0; i--)

{

if(IsStopped())

break;

time0=Time- 1 * 60 *TimeDelay_Minutes;

//--- history may be updated

if(i==0)

{

//--- modify index if history was updated

if(RefreshRates())

i=iBarShift(NULL,0,time0);

}

//---

if((time0>=rate.time+periodseconds || i==0)&& MainTime(time0)==true)

{

if(i==0)

{

rate.time=time0/periodseconds; //NEU

rate.tick_volume+=(long)Volume[0];

if(rate.low>Low[0])

rate.low=Low[0];

if(rate.high<High[0])

rate.high=High[0];

rate.close=Close[0];

}

last_fpos=FileTell(ExtHandle);

last_volume=(long)Volume;

FileWriteStruct(ExtHandle,rate);

cnt++;

if(time0>=rate.time+periodseconds)

{

rate.time=time0/periodseconds;

rate.time*=periodseconds;

rate.open=Open;

rate.low=Low;

rate.high=High;

rate.close=Close;

rate.tick_volume=last_volume;

}

}

else if(MainTime(time0)==true)

{

rate.time=time0/periodseconds; //NEU

rate.tick_volume+=(long)Volume;

if(rate.low>Low)

rate.low=Low;

if(rate.high<High)

rate.high=High;

rate.close=Close;

}

}

FileFlush(ExtHandle);

//Print(cnt," record(s) written");

//--- collect incoming ticks

datetime last_time=LocalTime()-5;

while(!IsStopped())

{

datetime cur_time=LocalTime();

//--- check for new rates

if(RefreshRates())

{

time0=Time[0]- 1 * 60 *TimeDelay_Minutes;

FileSeek(ExtHandle,last_fpos,SEEK_SET);

//--- is there current bar?

if(time0<rate.time+periodseconds && MainTime(time0)==true)

{

rate.tick_volume+=(long)Volume[0]-last_volume;

last_volume=(long)Volume[0];

if(rate.low>Low[0])

rate.low=Low[0];

if(rate.high<High[0])

rate.high=High[0];

rate.close=Close[0];

}

else if(MainTime(time0)==true)

{

//--- no, there is new bar

rate.tick_volume+=(long)Volume[1]-last_volume;

if(rate.low>Low[1])

rate.low=Low[1];

if(rate.high<High[1])

rate.high=High[1];

//--- write previous bar remains

FileWriteStruct(ExtHandle,rate);

last_fpos=FileTell(ExtHandle);

//----

rate.time=time0/periodseconds;

rate.time*=periodseconds;

rate.open=Open[0];

rate.low=Low[0];

rate.high=High[0];

rate.close=Close[0];

rate.tick_volume=(long)Volume[0];

last_volume=rate.tick_volume;

}

//----

FileWriteStruct(ExtHandle,rate);

FileFlush(ExtHandle);

//---

if(hwnd==0)

{

hwnd=WindowHandle(Symbol(),i_period);

if(hwnd!=0)

Print(" "); //Chart window detected

}

//--- refresh window not frequently than 1 time in 2 seconds

if(hwnd!=0 && cur_time-last_time>=2)

{

PostMessageA(hwnd,WM_COMMAND,33324,0);

last_time=cur_time;

}

}

Sleep(50);

}

//---

}

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---

if(ExtHandle>=0)

{

FileClose(ExtHandle);

ExtHandle=-1;

}

//---

}

你为什么不在写入文件 之前简单地在rate.time 中加入一些时间偏移(加法可以是正的或负的),然后,当你把文件写入时,再恢复它的原始值呢?

 
mladen:
MrWigglesworth 这里有一个将DEMA添加为类型4的版本:ma__dema_crossover_with_arrow_and_email.mq4

你好,MLaden先生。

你今天好吗?附上一张带有5和12DEMA指标的图表。图表上还有你修改的ma+DEMA指标。它被设置为5-ma1和12-ma2,并为两个MA选择了类型4(DEMA)......正如你可以从箭头看到的,它们似乎与线不匹配......有什么想法吗?非常感谢!

 
MrWigglesworth:
你好,MLaden先生。

你今天好吗?附上一张带有5和12DEMA指标的图表。图表上还有你修改的ma+DEMA指标。它被设置为5-ma1和12-ma2,并为两个MA选择了类型4(DEMA)......正如你从箭头中看到的,它们似乎与线条不匹配......对什么问题有什么想法?谢谢

哦,顺便说一下,这是我使用的DEMA指标,如果它有帮助的话

附加的文件:
dema_1.mq4  4 kb
 
MrWigglesworth:
你好,MLaden先生。

你今天好吗?附上一张带有5和12DEMA指标的图表。图表上还有你修改的ma+DEMA指标。它被设置为5-ma1和12-ma2,并为两个MA选择了类型4(DEMA)......正如你从箭头中看到的,它们似乎与线条不匹配......对什么问题有什么想法?非常感谢

你用什么DEMA进行比较?

提醒一下:Dema不是ema的ema,而是2 x ema和ema的ema之差。

这方面的公式甚至可以在这里找到。双指数移动平均线 - MetaTrader 5 帮助

问候

 
mladen:
你用什么DEMA做比较?

请看上面的2631号帖子和所附的DEMA.mq4...这有帮助吗?

 
mladen:
你用什么DEMA做比较?

提醒一下:Dema不是ema的ema,而是2 x ema和ema的ema之差。

这方面的公式甚至可以在这里找到。双指数移动平均线 - MetaTrader 5 帮助

问候

是的,我对DEMA很熟悉,尽管没有记住公式......这里是5-SMA(红色)和5-DEMA(绿色)之间的实际区别。

附加的文件: