コーディングのヘルプ - ページ 262

 

mladenさん、こんにちは。

PeriodConverterを変更したコードです。

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

//| PeriodConverter.mq4 |

//| Copyright 2006-2014, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

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

#property copyright "2006-2014, MetaQuotes Software Corp."

#property link "http://www.mql4.com"

#property description "Period Converter to updated format of history base"

#property strict

#property show_inputs

#include

input int StartHour = 9;

input int StartMinute = 0;

input int CloseHour = 17;

input int CloseMinute = 30;

int ExtHandle=-1;

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

//| script program start function |

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

void OnStart()

{

datetime time0;

ulong last_fpos=0;

long last_volume=0;

int i,start_pos;

int hwnd=0,cnt=0;

//---- History header

int file_version=401;

string c_copyright;

string c_symbol=Symbol();

int i_period=Period();

int i_digits=Digits;

int i_unused[13];

MqlRates rate;

//---

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

if(ExtHandle<0)

return;

c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";

ArrayInitialize(i_unused,0);

//--- write history file header

FileWriteInteger(ExtHandle,file_version,LONG_VALUE);

FileWriteString(ExtHandle,c_copyright,64);

FileWriteString(ExtHandle,c_symbol,12);

FileWriteInteger(ExtHandle,i_period,LONG_VALUE);

FileWriteInteger(ExtHandle,i_digits,LONG_VALUE);

FileWriteInteger(ExtHandle,0,LONG_VALUE);

FileWriteInteger(ExtHandle,0,LONG_VALUE);

FileWriteArray(ExtHandle,i_unused,0,13);

//--- write history file

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];

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

{

if(IsStopped())

break;

time0=Time;

//--- history may be updated

if(i==0)

{

//--- modify index if history was updated

if(RefreshRates())

i=iBarShift(NULL,0,time0);

}

//---

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

{

if(i==0)

{

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)

{

rate.time=time0;

rate.open=Open;

rate.low=Low;

rate.high=High;

rate.close=Close;

rate.tick_volume=last_volume;

}

}

else if(MainTime(time0)==true)

{

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];

FileSeek(ExtHandle,last_fpos,SEEK_SET);

//--- is there current bar?

if(time0<rate.time && 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;

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;

}

//---

}

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

bool MainTime(datetime time0)

{

datetime temp = time0 - 1 * 60 *60;

if(((TimeHour(temp) == StartHour && TimeMinute(temp) >= StartMinute) ||

TimeHour(temp) > StartHour) &&

(TimeHour(temp)< CloseHour ||

(TimeHour(temp) == CloseHour && TimeMinute(temp) < CloseMinute)))

{

Print(".......return (true) - Time0 = "+TimeToString(time0) + " tempTime = "+TimeToString(temp));

return(true);

}

else

{

Print("+++++++false - Time0 = "+TimeToString(time0) + " tempTime = "+TimeToString(temp));

return(false);

}

}

新しいオフラインのチャートに表示したいバーを選択するために、MainTimeという関数を 追加しました。

(また、時間を1時間移動させましたが、それは重要ではありません)。

0:00 (Starttime) - 12:00 (Closetime) の15046本のバー (M5) があるチャートでテストしてみました。

正しい印刷メッセージが表示され、最終的に7596本のバーが書き込まれたという情報が得られます。

つまり、元のチャートの約半分であり、すべてがうまくいったと思います。

しかし、対応するオフラインのチャートを開くと、元のチャートと全く同じように全てのバーが表示されています。

この動作は本当に理解できないのですが?

 
sunshineh:
こんにちは、mladen。

これはPeriodConverterから変更したコードです。

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

//| PeriodConverter.mq4 |

//| Copyright 2006-2014, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

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

#property copyright "2006-2014, MetaQuotes Software Corp."

#property link "http://www.mql4.com"

#property description "Period Converter to updated format of history base"

#property strict

#property show_inputs

#include

input int StartHour = 9;

input int StartMinute = 0;

input int CloseHour = 17;

input int CloseMinute = 30;

int ExtHandle=-1;

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

//| script program start function |

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

void OnStart()

{

datetime time0;

ulong last_fpos=0;

long last_volume=0;

int i,start_pos;

int hwnd=0,cnt=0;

//---- History header

int file_version=401;

string c_copyright;

string c_symbol=Symbol();

int i_period=Period();

int i_digits=Digits;

int i_unused[13];

MqlRates rate;

//---

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

if(ExtHandle<0)

return;

c_copyright="(C)opyright 2003, MetaQuotes Software Corp.";

ArrayInitialize(i_unused,0);

//--- write history file header

FileWriteInteger(ExtHandle,file_version,LONG_VALUE);

FileWriteString(ExtHandle,c_copyright,64);

FileWriteString(ExtHandle,c_symbol,12);

FileWriteInteger(ExtHandle,i_period,LONG_VALUE);

FileWriteInteger(ExtHandle,i_digits,LONG_VALUE);

FileWriteInteger(ExtHandle,0,LONG_VALUE);

FileWriteInteger(ExtHandle,0,LONG_VALUE);

FileWriteArray(ExtHandle,i_unused,0,13);

//--- write history file

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];

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

{

if(IsStopped())

break;

time0=Time;

//--- history may be updated

if(i==0)

{

//--- modify index if history was updated

if(RefreshRates())

i=iBarShift(NULL,0,time0);

}

//---

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

{

if(i==0)

{

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)

{

rate.time=time0;

rate.open=Open;

rate.low=Low;

rate.high=High;

rate.close=Close;

rate.tick_volume=last_volume;

}

}

else if(MainTime(time0)==true)

{

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];

FileSeek(ExtHandle,last_fpos,SEEK_SET);

//--- is there current bar?

if(time0<rate.time && 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;

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;

}

//---

}

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

bool MainTime(datetime time0)

{

datetime temp = time0 - 1 * 60 *60;

if(((TimeHour(temp) == StartHour && TimeMinute(temp) >= StartMinute) ||

TimeHour(temp) > StartHour) &&

(TimeHour(temp)< CloseHour ||

(TimeHour(temp) == CloseHour && TimeMinute(temp) < CloseMinute)))

{

Print(".......return (true) - Time0 = "+TimeToString(time0) + " tempTime = "+TimeToString(temp));

return(true);

}

else

{

Print("+++++++false - Time0 = "+TimeToString(time0) + " tempTime = "+TimeToString(temp));

return(false);

}

}

新しいオフライン・チャートに表示したいバーを選択するために、MainTimeという関数を追加しました。

(また、時間を1時間移動させましたが、それは重要ではありません)。

0:00 (Starttime) - 12:00 (Closetime) の15046本のバー (M5) があるチャートでテストしてみました。

正しい印刷メッセージが表示され、最終的に7596本のバーが書き込まれたという情報が得られます。

つまり、元のチャートの約半分であり、すべてがうまくいったと思います。

しかし、対応するオフラインのチャートを開くと、オリジナルのチャートと全く同じように全てのバーが表示されています。

その行動が本当に理解できない!!!!

それは、シンボルのオリジナルの名前と時間枠を使用しているためです。シンボル名か時間枠のどちらかを変更する必要があります(時間枠を変更する方がよいでしょう、そうすればすべてのコードが正しいシンボル名を認識するはずです)。

タイムフレームを変更する場合は、「合法的な」タイムフレーム(1,5,15,30,60,...)を使用しないように注意してください。

 

こんにちは。

このEAは、他のEAと組み合わせて株式保護に使用します。このEAは他のEAと組み合わせて使うもので、損益の制限を入力し、制限に達すると全ての注文をクローズし、他のEAもクローズします。

ea equity guardの問題点は、mt4が最大化されている時のみ動作することです。最小化されているか、VPSで mt4が動作している場合、リミットヒット時にEAはEAを最大化するか、VPSにログインするまで注文をクローズし始めないのです。ログインするか最大化した瞬間にEAが決済を開始します。

Thnx.

ファイル:
 
DarkForex33:
こんにちは

このEAは、他のEAと組み合わせて株式保護に使用します。エクイティのリミット(利益・損失)を入力することができ、リミットに達するとすべての注文をクローズし、他のEAをクローズします。

ea equity guardの問題点は、mt4が最大化されているときのみ動作することです。最小化されていたり、VPSでmt4が動作している場合、EAを最大化するかVPSにログインするまで、指値がヒットしてもEAは注文をクローズし始めません。ログインするか最大化した瞬間にEAが決済を開始します。

Thnx.

VPSでなくPCでも同じように動作しますか?

もしPCで同じ条件で問題なく動作するのであれば、VPSに 問題があると思われます。

 
mladen:
これは、シンボルのオリジナルの名前と時間枠を使用しているためです。シンボル名か時間枠のどちらかを変更する必要があります(時間枠を変更する方が良いでしょう、そうすれば全てのコードが正しいシンボル名を認識するはずです)時間枠を変更する場合、いくつかの「合法的」時間枠(1、5、15、30、60、...)を使用しないことを確認してください。

ありがとうございます、変更しました。

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

and

FileWriteInteger(ExtHandle,3,LONG_VALUE);

しかし、オフラインのチャートを開くと...,M3は "Waiting for Updates "と表示されるだけで、何も起こりません。

 
sunshineh:
ありがとうございます、変更しました

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

and

FileWriteInteger(ExtHandle,3,LONG_VALUE);

しかし、オフラインのチャートを開くと...,M3は "更新を待っています "と表示されるだけで、何も起こりません。

面白い

こちらをベースにインジケーターを作成してください。こちらは動作します(ベースにしたバージョンにエラーがあるようです)。

ファイル:
 

ヘルプミー!この電子メールのために

ごあいさつ

専門家の方々へ

EAでストップロスやテイクプロフィットを設定する

ギャップ.ex4

ギャップ.mq4

ファイル:
gaps.ex4  6 kb
gaps.mq4  4 kb
 

こんにちは。

添付のインジケーターにDEMA オプションを追加するのを手伝っていただけませんか?

現在、オプションは

0=sma

1=ema

2=smma

3=lwma

を追加したいと思います。

4=DEMA これは可能でしょうか?ありがとうございまし

 
MrWigglesworth:
こんにちは。

添付のインジケータにDEMAオプションを追加するのを手伝ってもらえますか?

現在、オプションは

0=sma

1=ema

2=smma

3=lwma

を追加したいと思います。

4= DEMA これは可能なのでしょうか?ありがとうございました。

MrWigglesworth

タイプ4としてdemaを追加したバージョンはこちら :ma__dema_crossover_with_arrow_and_email.mq4

 
amirreza132:
ご挨拶

専門家の方へ

EAでストップロスやテイクプロフィットを設定する

ギャップ.ex4

ギャップ.mq4

amirreza132

そのEAはギャップを捕らえるように設計されており、ギャップが発生した場合の利食いを既に設定しています。