忍者ブログ

forex tester2のインディケーターを自作

fx(外国為替証拠金取引)のトレードの練習やルールの検証をForex Tester 2というソフトでしてみます。 Meta Trader4(MT4)のインディケーター(indicator)をForex Tester2用に移植できたらしてみます。

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。


VQ2

VQ2.mq4 みたいなのを ForexTester2用に移植しました。


dllのみの販売です。
VQ2.mq4 [ForexTester2用indicator]


c++ ソースコードの販売です。
VQ2 c++ ソース [ForexTester2用indicator]


MT4の表示です。



FT2の表示です。ついでに普通のVQも表示しています。


PR

コメント

kuchart (日付区切りver)を是非ともforextester で動かせるようにしていただけないでしょうか
作成者 fai
http://d.hatena.ne.jp/fai_fx/20110711/1310340511
コードはこちら

//+------------------------------------------------------------------+
//| Ku-chart-Maker.mq4 |
//| Copyright ゥ 2010, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ゥ 2010, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#include <WinUser32.mqh>
#define CHART_CMD_UPDATE_DATA 33324
#define HEADER_BYTE 148
#define DATA_BYTE 44

#property indicator_separate_window
#property indicator_buffers 8

extern int MaxBars = 2000;//計算するバーの本数
extern int TimeOffset=0;
extern int LongTermMode=0;

// 平滑化したい場合は下記2つを調整. デフォルトでは rawdataとなる。
extern int MAPeriod = 1;//3;
extern int MAPrice = PRICE_CLOSE;//PRICE_TYPICAL;
extern int MAMethod = MODE_LWMA;

extern color Color_USD = White;
extern color Color_EUR = Lime;
extern color Color_GBP = Yellow;
extern color Color_CHF = Snow;
extern color Color_JPY = Red;
extern color Color_AUD = Orange;
extern color Color_CAD = BlueViolet;
extern color Color_NZD = DeepPink;


extern int SelectedLineWidth = 3;//チャートの通貨のラインの太さ

extern int OriginTime = 1000;//1000なら1000本前基準

extern int ZeroLevelShift = 100;//原点のレベル
extern bool UseZeroCheck = true;


extern bool UseUSD = true;//計算に使うかどうか。
extern bool UseEUR = true;
extern bool UseGBP = true;
extern bool UseCHF = false;
extern bool UseJPY = true;
extern bool UseAUD = true;
extern bool UseCAD = false;
extern bool UseNZD = false;



extern bool DoNotOverwrite = true;




// 基本の6ペア
string sEURUSD = "EURUSD";
string sUSDJPY = "USDJPY";
string sUSDCHF = "USDCHF";
string sGBPUSD = "GBPUSD";
string sAUDUSD = "AUDUSD";
string sUSDCAD = "USDCAD";
string sNZDUSD = "NZDUSD";


//---- buffers
double EURAV[];
double USDAV[];
double JPYAV[];
double CHFAV[];
double GBPAV[];
double AUDAV[];
double CADAV[];
double NZDAV[];

string Indicator_Name = " EUR USD JPY CHF GBP AUD CAD NZD";
int Objs = 0;
int Pairs = 7;
string objname = "Ku-chart-OriginTime";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,EMPTY,2,Color_EUR);
SetIndexBuffer(0,EURAV);
SetIndexLabel(0,"EUR");
SetIndexStyle(1,DRAW_LINE,EMPTY,2,Color_USD);
SetIndexBuffer(1,USDAV);
SetIndexLabel(1,"USD");
SetIndexStyle(2,DRAW_LINE,EMPTY,2,Color_JPY);
SetIndexBuffer(2,JPYAV);
SetIndexLabel(2,"JPY");
SetIndexStyle(3,DRAW_LINE,EMPTY,GetWidth("CHF"),Color_CHF);
SetIndexBuffer(3,CHFAV);
SetIndexLabel(3,"CHF");
SetIndexStyle(4,DRAW_LINE,EMPTY,2,Color_GBP);
SetIndexBuffer(4,GBPAV);
SetIndexLabel(4,"GBP");

SetIndexStyle(5,DRAW_LINE,EMPTY,2,Color_AUD);
SetIndexBuffer(5,AUDAV);
SetIndexLabel(5,"AUD");
SetIndexStyle(6,DRAW_LINE,EMPTY,GetWidth("CAD"),Color_CAD);
SetIndexBuffer(6,CADAV);
SetIndexLabel(6,"CAD");
SetIndexStyle(7,DRAW_LINE,EMPTY,GetWidth("NZD"),Color_NZD);
SetIndexBuffer(7,NZDAV);
SetIndexLabel(7,"NZD");

if(!UseEUR) SetIndexStyle(0,DRAW_NONE);
if(!UseUSD) SetIndexStyle(1,DRAW_NONE);
if(!UseJPY) SetIndexStyle(2,DRAW_NONE);
if(!UseCHF) SetIndexStyle(3,DRAW_NONE);
if(!UseGBP) SetIndexStyle(4,DRAW_NONE);
if(!UseAUD) SetIndexStyle(5,DRAW_NONE);
if(!UseCAD) SetIndexStyle(6,DRAW_NONE);
if(!UseNZD) SetIndexStyle(7,DRAW_NONE);

if(!UseEUR) Color_EUR = DimGray;
if(!UseUSD) Color_USD = DimGray;
if(!UseJPY) Color_JPY = DimGray;
if(!UseCHF) Color_CHF = DimGray;
if(!UseGBP) Color_GBP = DimGray;
if(!UseAUD) Color_AUD = DimGray;
if(!UseCAD) Color_CAD = DimGray;
if(!UseNZD) Color_NZD = DimGray;

Pairs = 7;
if(!UseEUR) Pairs--;
if(!UseUSD) Pairs--;
if(!UseJPY) Pairs--;
if(!UseCHF) Pairs--;
if(!UseGBP) Pairs--;
if(!UseAUD) Pairs--;
if(!UseCAD) Pairs--;
if(!UseNZD) Pairs--;
if(Pairs<1) Alert("Pairs is ",Pairs);

SetLevelValue(0, ZeroLevelShift);

IndicatorShortName(Indicator_Name);

IndicatorDigits(2);

Objs = 0;
int cur = 0;
int st = 23;// ~の長さが23
sl("~", cur, Color_EUR);
cur += st;
sl("~", cur, Color_USD);
cur += st;
sl("~", cur, Color_JPY);
cur += st;
sl("~", cur, Color_CHF);
cur += st;
sl("~", cur, Color_GBP);
cur += st;
sl("~", cur, Color_AUD);
cur += st;
sl("~", cur, Color_CAD);
cur += st;
sl("~", cur, Color_NZD);
cur += st;
//----

return(0);
}
void sl(string sym, int y, color col)
{ // ~記号を描く
int window = WindowFind(Indicator_Name);
string ID = Indicator_Name+Objs;
Objs++;
if(col<0) col=EMPTY_VALUE;//CLR_NONE;
if(window == -1 ) return;
ObjectCreate(ID, OBJ_LABEL, window, 0, 0);
ObjectSet(ID, OBJPROP_XDISTANCE, y +6);
ObjectSet(ID, OBJPROP_YDISTANCE, 0);
ObjectSetText(ID, sym, 18, "Arial Black", col);
//Print("ID=",ID," ",col);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
switch(UninitializeReason())
{
case REASON_CHARTCLOSE: Print("KU-deinit REASON_CHARTCLOSE");break;
case REASON_REMOVE: Print("KU-deinit REASON_REMOVE");break;
case REASON_RECOMPILE: Print("KU-deinit REASON_RECOMPILE");break;
case REASON_CHARTCHANGE: Print("KU-deinit REASON_CHARTCHANGE");break;
case REASON_PARAMETERS: Print("KU-deinit REASON_PARAMETERS");break;
case REASON_ACCOUNT: Print("KU-deinit REASON_ACCOUNT");break;
}

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int GetWidth(string sym1){
int index = StringFind(Symbol(),sym1);
if(index == -1) return(1);
return(SelectedLineWidth);// 選択通貨を含む場合のみラインを太くしている。
}

double GetVal(string sym1,datetime t1,datetime t2){
double v1,v2;

v1 = iMA(sym1,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym1,0,t1));
v2 = iMA(sym1,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym1,0,t2));

if(v2==0) return(0);
return(MathLog(v1/v2)*1000);
}

double GetValM(string sym1,string sym2,datetime t1,datetime t2){
double v1,v2;

v1 = iMA(sym1,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym1,0,t1));
v2 = iMA(sym1,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym1,0,t2));

v1 = v1*iMA(sym2,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym2,0,t1));
v2 = v2*iMA(sym2,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym2,0,t2));

if(v2==0) return(0);
return(MathLog(v1/v2)*1000);
}

double GetValD(string sym1,string sym2,datetime t1,datetime t2){
double v1,v2,v3,v4;

v1 = iMA(sym1,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym1,0,t1));
v2 = iMA(sym1,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym1,0,t2));

v3 = iMA(sym2,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym2,0,t1));
v4 = iMA(sym2,NULL,MAPeriod,0,MAMethod,MAPrice,iBarShift(sym2,0,t2));
if(v3==0) return(0);
if(v4==0) return(0);

v1 = v1/v3;
v2 = v2/v4;

if(v2==0) return(0);
return(MathLog(v1/v2)*1000);
}

datetime GetOriginTime(){
// 過去に Ku-chart で起点となる時刻を決めていたら、それを再度利用する。
datetime ret;


if(DoNotOverwrite && ObjectFind(objname) != -1){
ret = ObjectGet(objname, OBJPROP_TIME1);
if(ret >= Time[Bars-1] && ret <=Time[0]) return(ret);
}

ret = Time[OriginTime];
ObjectCreate(objname, OBJ_TEXT, 0, ret, 0);
return(ret);
}


int start()
{
// ~を描くのに、WindowsFind を呼んでいるが、本当は init では呼んではいけないので、startから呼びなおす。
static bool startInit= false;
if(!startInit) init();
startInit= true;

int i;
//----
double EURUSD,EURJPY,EURCHF,EURGBP,USDJPY,USDCHF,GBPUSD,CHFJPY,GBPCHF,GBPJPY,AUDUSD,AUDCHF,AUDJPY,GBPAUD,EURAUD,AUDCAD,USDCAD,GBPCAD,EURCAD,CADCHF,CADJPY;
double AUDNZD,EURNZD,GBPNZD,NZDCAD,NZDCHF,NZDJPY,NZDUSD;
datetime t1;
static datetime t2 = 0;
static datetime HstWriteTime = 0;

int indicator_counted = IndicatorCounted();
int limit = MathMin(MaxBars,Bars);
if(HstWriteTime !=0) limit = MathMin(limit,Bars-indicator_counted+1);
if(limit <1) return;

//if(checkDownloadBars()<0) return;
int ret = checkDownloadBars();
if(ret <-1) return;//bar が不足。
if(ret ==2) { limit = MathMin(MaxBars,Bars);HstWriteTime = 0;Print("reload");}//全リロード

//Print("limit=",limit);
if(t2 == 0) t2 = GetOriginTime();//Time[OriginTime];
ObjectCreate(objname, OBJ_TEXT, 0, t2, 0);

for(i=limit;i>=0;i--){
t1 = Time[i];
//追加
t2 = MathFloor((Time[i]+TimeOffset*60*60)/86400)*86400-(TimeOffset*60*60);
if(TimeDayOfWeek(t2)==0) t2 =t2-2*24*60*60;
if(LongTermMode>0)t2=Time[LongTermMode];
if(t1==t2)
{
EURAV[i]= EMPTY_VALUE;
USDAV[i]= EMPTY_VALUE;
JPYAV[i]= EMPTY_VALUE;
CHFAV[i]= EMPTY_VALUE;
GBPAV[i]= EMPTY_VALUE;
AUDAV[i]= EMPTY_VALUE;
CADAV[i]= EMPTY_VALUE;
NZDAV[i]= EMPTY_VALUE;
continue;
}

//追加終わり
EURUSD = GetVal(sEURUSD,t1,t2);
USDJPY = GetVal(sUSDJPY,t1,t2);
USDCHF = GetVal(sUSDCHF,t1,t2);
GBPUSD = GetVal(sGBPUSD,t1,t2);
AUDUSD = GetVal(sAUDUSD,t1,t2);
USDCAD = GetVal(sUSDCAD,t1,t2);

NZDUSD = GetVal(sNZDUSD,t1,t2);

EURJPY = GetValM(sEURUSD,sUSDJPY,t1,t2);
EURCHF = GetValM(sEURUSD,sUSDCHF,t1,t2);
EURGBP = GetValD(sEURUSD,sGBPUSD,t1,t2);
CHFJPY = GetValD(sUSDJPY,sUSDCHF,t1,t2);
GBPCHF = GetValM(sGBPUSD,sUSDCHF,t1,t2);
GBPJPY = GetValM(sGBPUSD,sUSDJPY,t1,t2);
AUDCHF = GetValM(sAUDUSD,sUSDCHF,t1,t2);
AUDJPY = GetValM(sAUDUSD,sUSDJPY,t1,t2);
AUDCAD = GetValM(sAUDUSD,sUSDCAD,t1,t2);
EURCAD = GetValM(sEURUSD,sUSDCAD,t1,t2);
GBPCAD = GetValM(sGBPUSD,sUSDCAD,t1,t2);
GBPAUD = GetValD(sGBPUSD,sAUDUSD,t1,t2);
EURAUD = GetValD(sEURUSD,sAUDUSD,t1,t2);
CADCHF = GetValD(sUSDCHF,sUSDCAD,t1,t2);
CADJPY = GetValD(sUSDJPY,sUSDCAD,t1,t2);

AUDNZD = GetValD(sAUDUSD,sNZDUSD,t1,t2);
EURNZD = GetValD(sEURUSD,sNZDUSD,t1,t2);
GBPNZD = GetValD(sGBPUSD,sNZDUSD,t1,t2);
NZDCAD = GetValM(sNZDUSD,sUSDCAD,t1,t2);
NZDCHF = GetValM(sNZDUSD,sUSDCHF,t1,t2);
NZDJPY = GetValM(sNZDUSD,sUSDJPY,t1,t2);


if(!UseNZD){
AUDNZD = 0;EURNZD = 0;GBPNZD = 0;NZDCAD = 0;NZDCHF = 0;NZDJPY = 0;NZDUSD = 0;
}
if(!UseCAD){
EURCAD = 0;USDCAD = 0;CADJPY = 0;CADCHF = 0;GBPCAD = 0;AUDCAD = 0;NZDCAD = 0;
}
if(!UseCHF){
EURCHF = 0;USDCHF = 0;CHFJPY = 0;GBPCHF = 0;AUDCHF = 0;CADCHF = 0;NZDCHF = 0;
}
if(!UseAUD){
EURAUD = 0;AUDUSD = 0;AUDJPY = 0;AUDCHF = 0;GBPAUD = 0;AUDCAD = 0;AUDNZD = 0;
}
if(!UseEUR){
EURUSD = 0;EURJPY = 0;EURCHF = 0;EURGBP = 0;EURAUD = 0;EURCAD = 0;EURNZD = 0;
}
if(!UseUSD){
EURUSD = 0;USDJPY = 0;USDCHF = 0;GBPUSD = 0;AUDUSD = 0;USDCAD = 0;NZDUSD = 0;
}
if(!UseJPY){
EURJPY = 0;USDJPY = 0;CHFJPY = 0;GBPJPY = 0;AUDJPY = 0;CADJPY = 0;NZDJPY = 0;
}
if(!UseGBP){
EURGBP = 0;GBPUSD = 0;GBPCHF = 0;GBPJPY = 0;GBPAUD = 0;GBPCAD = 0;GBPNZD = 0;
}

// マイナスの値はチャート化できないので ZeroLevelShift(100)を足す
EURAV[i]=( EURUSD+EURJPY+EURCHF+EURGBP+EURAUD+EURCAD+EURNZD)/Pairs + ZeroLevelShift;
USDAV[i]=(-EURUSD+USDJPY+USDCHF-GBPUSD-AUDUSD+USDCAD-NZDUSD)/Pairs + ZeroLevelShift;
JPYAV[i]=(-EURJPY-USDJPY-CHFJPY-GBPJPY-AUDJPY-CADJPY-NZDJPY)/Pairs + ZeroLevelShift;
CHFAV[i]=(-EURCHF-USDCHF+CHFJPY-GBPCHF-AUDCHF-CADCHF-NZDCHF)/Pairs + ZeroLevelShift;
GBPAV[i]=(-EURGBP+GBPUSD+GBPCHF+GBPJPY+GBPAUD+GBPCAD+GBPNZD)/Pairs + ZeroLevelShift;

AUDAV[i]=(-EURAUD+AUDUSD+AUDJPY+AUDCHF-GBPAUD+AUDCAD+AUDNZD)/Pairs + ZeroLevelShift;
CADAV[i]=(-EURCAD-USDCAD+CADJPY+CADCHF-GBPCAD-AUDCAD-NZDCAD)/Pairs + ZeroLevelShift;
NZDAV[i]=(-EURNZD+NZDUSD+NZDJPY+NZDCHF-GBPNZD+NZDCAD-AUDNZD)/Pairs + ZeroLevelShift;


if(UseZeroCheck){
// ゼロより小さくなっていたら警告する。
if(EURAV[i] < 0){ Alert("ERROR: EURAV is less than ZeroLevel. ",EURAV[i]);return;}
if(USDAV[i] < 0){ Alert("ERROR: USDAV is less than ZeroLevel. ",USDAV[i]);return;}
if(JPYAV[i] < 0){ Alert("ERROR: JPYAV is less than ZeroLevel. ",JPYAV[i]);return;}
if(CHFAV[i] < 0){ Alert("ERROR: CHFAV is less than ZeroLevel. ",CHFAV[i]);return;}
if(GBPAV[i] < 0){ Alert("ERROR: GBPAV is less than ZeroLevel. ",GBPAV[i]);return;}
if(AUDAV[i] < 0){ Alert("ERROR: AUDAV is less than ZeroLevel. ",AUDAV[i]);return;}
if(CADAV[i] < 0){ Alert("ERROR: CADAV is less than ZeroLevel. ",CADAV[i]);return;}
if(NZDAV[i] < 0){ Alert("ERROR: NZDAV is less than ZeroLevel. ",NZDAV[i]);return;}
}

}


if(HstWriteTime==0){
// 初回
WriteHistoryHeader("KU_EUR2");
WriteHistoryAll("KU_EUR2",EURAV);
WriteHistoryHeader("KU_USD2");
WriteHistoryAll("KU_USD2",USDAV);
WriteHistoryHeader("KU_JPY2");
WriteHistoryAll("KU_JPY2",JPYAV);
WriteHistoryHeader("KU_CHF2");
WriteHistoryAll("KU_CHF2",CHFAV);

WriteHistoryHeader("KU_GBP2");
WriteHistoryAll("KU_GBP2",GBPAV);
WriteHistoryHeader("KU_AUD2");
WriteHistoryAll("KU_AUD2",AUDAV);
WriteHistoryHeader("KU_CAD2");
WriteHistoryAll("KU_CAD2",CADAV);
WriteHistoryHeader("KU_NZD2");
WriteHistoryAll("KU_NZD2",NZDAV);

HstWriteTime = Time[0];

}else if(HstWriteTime == Time[0]){
// バーが増えないときの更新
WriteHistory("KU_EUR2",EURAV,2);
WriteHistory("KU_USD2",USDAV,2);
WriteHistory("KU_JPY2",JPYAV,2);
WriteHistory("KU_CHF2",CHFAV,2);

WriteHistory("KU_GBP2",GBPAV,2);
WriteHistory("KU_AUD2",AUDAV,2);
WriteHistory("KU_CAD2",CADAV,2);
WriteHistory("KU_NZD2",NZDAV,2);

}else{
// 新規バー追加の更新
WriteHistory("KU_EUR2",EURAV,1);
WriteHistory("KU_USD2",USDAV,1);
WriteHistory("KU_JPY2",JPYAV,1);
WriteHistory("KU_CHF2",CHFAV,1);

WriteHistory("KU_GBP2",GBPAV,1);
WriteHistory("KU_AUD2",AUDAV,1);
WriteHistory("KU_CAD2",CADAV,1);
WriteHistory("KU_NZD2",NZDAV,1);

HstWriteTime = Time[0];
//PlaySound("tick");
}


//チャートの更新
UpdateChartWindow("KU_EUR2");
UpdateChartWindow("KU_USD2");
UpdateChartWindow("KU_JPY2");
UpdateChartWindow("KU_CHF2");
UpdateChartWindow("KU_GBP2");
UpdateChartWindow("KU_AUD2");
UpdateChartWindow("KU_CAD2");
UpdateChartWindow("KU_NZD2");

//----
return(0);
}
//+------------------------------------------------------------------+
int checkDownloadBars()
{
// ここはもう少し丁寧にチェックしたほうが良いだろう・・・
if(iBars(sEURUSD,0)<MaxBars){ Comment("ERROR: "+sEURUSD+" is "+iBars(sEURUSD,0)); return(-1);}
if(iBars(sUSDJPY,0)<MaxBars){ Comment("ERROR: "+sUSDJPY+" is "+iBars(sUSDJPY,0)); return(-1);}
if(iBars(sUSDCHF,0)<MaxBars){ Comment("ERROR: "+sUSDCHF+" is "+iBars(sUSDCHF,0)); return(-1);}
if(iBars(sGBPUSD,0)<MaxBars){ Comment("ERROR: "+sGBPUSD+" is "+iBars(sGBPUSD,0)); return(-1);}
if(iBars(sAUDUSD,0)<MaxBars){ Comment("ERROR: "+sAUDUSD+" is "+iBars(sAUDUSD,0)); return(-1);}
if(iBars(sUSDCAD,0)<MaxBars){ Comment("ERROR: "+sUSDCAD+" is "+iBars(sUSDCAD,0)); return(-1);}
if(iBars(sNZDUSD,0)<MaxBars){ Comment("ERROR: "+sNZDUSD+" is "+iBars(sNZDUSD,0)); return(-1);}


//いずれかの通貨ペアのバーの本数が2本以上増えたら、すべて再描画する。
static int EURUSDbar=0,USDJPYbar=0,USDCHFbar=0,GBPUSDbar=0,AUDUSDbar=0,USDCADbar=0,NZDUSDbar=0;

bool RefreshChart = false;
if(iBars(sEURUSD,0)-EURUSDbar > 1) RefreshChart = true;
if(iBars(sUSDJPY,0)-USDJPYbar > 1) RefreshChart = true;
if(iBars(sUSDCHF,0)-USDCHFbar > 1) RefreshChart = true;
if(iBars(sGBPUSD,0)-GBPUSDbar > 1) RefreshChart = true;
if(iBars(sAUDUSD,0)-AUDUSDbar > 1) RefreshChart = true;
if(iBars(sUSDCAD,0)-USDCADbar > 1) RefreshChart = true;
if(iBars(sNZDUSD,0)-NZDUSDbar > 1) RefreshChart = true;

EURUSDbar = iBars(sEURUSD,0);
USDJPYbar = iBars(sUSDJPY,0);
USDCHFbar = iBars(sUSDCHF,0);
GBPUSDbar = iBars(sGBPUSD,0);
AUDUSDbar = iBars(sAUDUSD,0);
USDCADbar = iBars(sUSDCAD,0);
NZDUSDbar = iBars(sNZDUSD,0);

if(RefreshChart) { Comment("KU-CHART Refreshed..");return(2);}

Comment("");
return(1);
}

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

int WriteHistoryHeader(string MySymbol)
{
// hst ファイルのヘッダを書く
string c_copyright;
int i_digits = 2;
int i_unused[13] = {0};
int version = 400;
int FileHandle;

if(DoNotOverwrite){
FileHandle = FileOpenHistory(MySymbol + Period()+".hst", FILE_BIN|FILE_WRITE|FILE_READ);
}else{
FileHandle = FileOpenHistory(MySymbol + Period()+".hst", FILE_BIN|FILE_WRITE);
}

//既にファイルがあればヘッダを書かない。
if(DoNotOverwrite && FileSize(FileHandle)>0 ){
//Print("Header "+MySymbol+" skipped");
FileClose(FileHandle);
return (0);
}
//Print("Header "+MySymbol+" wrote..");
FileSeek(FileHandle,0, SEEK_CUR);
c_copyright = "(C)opyright 2003, MetaQuotes Software Corp.";
FileWriteInteger(FileHandle, version, LONG_VALUE);
FileWriteString(FileHandle, c_copyright, 64);
FileWriteString(FileHandle, MySymbol, 12);
FileWriteInteger(FileHandle, Period(), LONG_VALUE);
FileWriteInteger(FileHandle, i_digits, LONG_VALUE);
FileWriteInteger(FileHandle, 0, LONG_VALUE); //timesign
FileWriteInteger(FileHandle, 0, LONG_VALUE); //last_sync
FileWriteArray(FileHandle, i_unused, 0, ArraySize(i_unused));
FileFlush(FileHandle);
FileClose(FileHandle);
return (0);
}

//+------------------------------------------------------------------+
int WriteHistoryAll(string MySymbol,double &data[])
{
// 初回は、全データを書き出す
int FileHandle = FileOpenHistory(MySymbol + Period()+".hst", FILE_BIN|FILE_WRITE|FILE_READ);

//追加データが既に書かれていたらスキップ
if(DoNotOverwrite && FileSize(FileHandle)>HEADER_BYTE){
//Print("WriteHistoryAll "+MySymbol+" skipped "+ FileSize(FileHandle));
FileClose(FileHandle);
return (0);
}
//Print("WriteHistoryAll "+MySymbol+" wrote... "+ FileSize(FileHandle));

FileSeek(FileHandle,FileSize(FileHandle), SEEK_CUR);

//1本目はO=H=L=C
FileWriteInteger(FileHandle, Time[MaxBars], LONG_VALUE);//4
FileWriteDouble(FileHandle, data[MaxBars], DOUBLE_VALUE);//8
FileWriteDouble(FileHandle, data[MaxBars], DOUBLE_VALUE);
FileWriteDouble(FileHandle, data[MaxBars], DOUBLE_VALUE);
FileWriteDouble(FileHandle, data[MaxBars], DOUBLE_VALUE);
FileWriteDouble(FileHandle, Volume[MaxBars], DOUBLE_VALUE);

//2本目以降は、始値=前の足の終値
for(int i=MaxBars-1;i>=0;i--){
double o,h,l,c;
o = data[i+1];//前の足の終値
c = data[i];
h = MathMax(o,c);
l = MathMin(o,c);

FileWriteInteger(FileHandle, Time[i], LONG_VALUE);
FileWriteDouble(FileHandle, o, DOUBLE_VALUE);
FileWriteDouble(FileHandle, l, DOUBLE_VALUE);
FileWriteDouble(FileHandle, h, DOUBLE_VALUE);
FileWriteDouble(FileHandle, c, DOUBLE_VALUE);
FileWriteDouble(FileHandle, Volume[i], DOUBLE_VALUE);
}
FileFlush(FileHandle);
FileClose(FileHandle);
return (0);
}
//+------------------------------------------------------------------+
int WriteHistory(string MySymbol,double &data[],int back)
{
// 2回目からは少し戻って上書きしつつ書き足す
int FileHandle = FileOpenHistory(MySymbol + Period()+".hst", FILE_BIN|FILE_WRITE|FILE_READ);

if(DoNotOverwrite && FileSize(FileHandle) < HEADER_BYTE+DATA_BYTE*back ){
//戻れない。
//back = 0;
//Print("WriteHistory Re-write WriteHistoryAll "+MySymbol);
WriteHistoryAll(MySymbol,data);
}

FileSeek(FileHandle,FileSize(FileHandle)-DATA_BYTE*back, SEEK_CUR);
double oldOpen[2],oldHigh[2],oldLow[2],oldTime[2];
double tmp;
int i;

//2本(1本)分のデータを読み直す。
for(i=1;i>=0;i--){
oldTime[i] = FileReadInteger(FileHandle, LONG_VALUE);
oldOpen[i] = FileReadDouble(FileHandle, DOUBLE_VALUE);
oldLow[i] = FileReadDouble(FileHandle, DOUBLE_VALUE);
oldHigh[i] = FileReadDouble(FileHandle, DOUBLE_VALUE);

FileReadDouble(FileHandle, DOUBLE_VALUE);
FileReadDouble(FileHandle, DOUBLE_VALUE);
}

//データを読んだので、もう一度戻る。
if(oldTime[1] == Time[1])
FileSeek(FileHandle,FileSize(FileHandle)-DATA_BYTE*back, SEEK_SET);

for(i=1;i>=0;i--){
FileWriteInteger(FileHandle, Time[i], LONG_VALUE);
double o,h,l,c;
o = data[i];
h = data[i];
l = data[i];
c = data[i];
if(oldOpen[i] > 0 && oldTime[i] == Time[i]){
o = oldOpen[i];
h = MathMax(oldOpen[i],MathMax(oldHigh[i],c));
l = MathMin(oldOpen[i],MathMin(oldLow[i],c));
}

FileWriteDouble(FileHandle, o, DOUBLE_VALUE);
FileWriteDouble(FileHandle, l, DOUBLE_VALUE);
FileWriteDouble(FileHandle, h, DOUBLE_VALUE);
FileWriteDouble(FileHandle, c, DOUBLE_VALUE);
FileWriteDouble(FileHandle, Volume[i], DOUBLE_VALUE);
}
FileFlush(FileHandle);
FileClose(FileHandle);
return (0);
}

//+------------------------------------------------------------------+
int UpdateChartWindow(string MySymbol)
{
int hwnd = 0;

hwnd = WindowHandle(MySymbol, Period());
if(hwnd!= 0) {
if (IsDllsAllowed() == false) {
//DLL calls must be allowed
Alert("ERROR: [Allow DLL imports] NOT Checked.");
return (-1);
}
if (PostMessageA(hwnd,WM_COMMAND,CHART_CMD_UPDATE_DATA,0) == 0) {
//PostMessage failed, chart window closed
hwnd = 0;
} else {
//PostMessage succeed
return (0);
}
}
//window not found or PostMessage failed
return (-1);
}
//+------------------------------------------------------------------+




コメントを投稿する






Vodafone絵文字 i-mode絵文字 Ezweb絵文字(絵文字)


forex tester2 販売
Forex Tester 2の購入はこちらから。
カレンダー
07 2017/08 09
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
カテゴリー
フリーエリア



最新記事
最新CM
[09/04 Tyroneket]
[08/24 名無しのリーク]
[06/17 名無しのリーク]
[04/30 kob]
[04/29 TimhyTevy]
[04/16 toko]
[01/10 vzgwwzhisz]
[01/09 よしあき]
[12/09 pcvrhhtbnc]
[12/03 Arofukoe]
最新TB
RSS
ブログ内検索
アーカイブ
最古記事
プロフィール
HN:
fx練習生
年齢:
42
性別:
男性
誕生日:
1975/04/03
職業:
夢は専業トレーダー
趣味:
fx
自己紹介:
fxの専業トレーダーになって経済的自由と時間的自由を手に入れたいです。
自分で売買ルールを作成してテストして自信をもってリアルトレードしたいです。
P R