忍者ブログ

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

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

カテゴリー:プログラム

[PR]

×

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


GNU GLOBAL source code tagging system

GNU GLOBAL source code tagging system


の実行ファイルの置き場が変更になっていることに気付いた。

http://adoxa.110mb.com/global/index.html

だったのが

http://adoxa.3eeweb.com/global/

になっていた。

ただの個人用メモです。
PR

TDateTime型、DT_DATE型、DATE データ型、 COleDateTime クラス

ForexTester2では時間にTDateTime型を使用しています。double型です。
DATE データ型、 COleDateTime クラスと同等だと思われます。

Visual c++ でTDateTime型を年月日に変換する方法がわからなかったので自分で作ってみました。
秒は0秒であることが前提です。


  int cnt;
  char datMon[12]={31,28,31,30,31,30,31,31,30,31,30,31};

  int day = (int)time;
  day -= 1;
  cnt = 1900;
  while (1) {
   if (isLeapYear(cnt)) {
    if (day <= 366) {
     break;
    }
    day -= 366;
   } else {
    if (day <= 365) {
     break;
    }
    day -= 365;
   }
   cnt++;
  }
  year = cnt;

  datMon[1] += isLeapYear(cnt);
  cnt = 0;
  while (1) {
   if (datMon[cnt++] < day) {
    day -= datMon[cnt - 1];
   } else {
    break;
   }
  }

  mon = cnt;
  mday = day;

  int work = (int)(((double)time - (int)time) * 24 * 60 + 0.5);
  hour = work / 60;
  min = work % 60;


 

なんとなくできてそうです。

MSVCP100.dll、MSVCR100.dll を必要としないビルド方法

これまで販売してきたインディケーターのdll((Dynamic Link Library,ダイナミックリンクライブラリ)は
Microsoft Visual C++ 2010 Expressで作成しており
Microsoft Visual C++ 2010 シリーズをインストールするか
Microsoft Visual C++ 2010 再頒布可能パッケージ(いわゆる ランタイムライブラリ)
をインストールしないと実行できませんでした。

もしどちらもインストールしていないとForexTester2を起動するときに
「MSVCP100.dllが見つからないため、このアプリケーションを開始できませんでした。」
のようなメッセージが表示されインディケーターが読み込まれませんでした。


これまではMSVCP100.dllが必須と思っていましたが
今になってプロジェクトの構成プロパティにランタイムライブラリの項目がありマルチスレッド(/MT)
にするとMSVCP100.dll、MSVCR100.dllが不要となることに気づきました。






今までの設定
 

作成されたdllをdumpbin.exeで見ると
>dumpbin /DEPENDENTS /IMPORTS Bollinger_Band_Width.dll Microsoft (R) COFF/PE Dumper Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file Bollinger_Band_Width.dll File Type: DLL Image has the following dependencies: MSVCP100.dll MSVCR100.dll KERNEL32.dll Section contains the following imports: MSVCP100.dll 10003040 Import Address Table 10003618 Import Name Table 0 time date stamp 0 Index of first forwarder reference 28C ?_Xlength_error@std@@YAXPBD@Z MSVCR100.dll 10003048 Import Address Table 10003620 Import Name Table 0 time date stamp 0 Index of first forwarder reference 1C5 _amsg_exit 131 __CppXcptFilter 2B1 _initterm_e 221 _except_handler4_common 102 ?terminate@@YAXXZ EE ?_type_info_dtor_internal_method@type_info@@QAEXXZ 153 __clean_type_info_names_internal 2B0 _initterm 219 _encoded_null 334 _malloc_crt 3C9 _onexit 323 _lock 15B __dllonexit 48D _unlock 63 ??2@YAPAXI@Z 65 ??3@YAXPAX@Z 5C4 malloc 58B free 24 ??0exception@std@@QAE@ABV01@@Z 22 ??0exception@std@@QAE@ABQBD@Z 5D ??1exception@std@@UAE@XZ 10D ?what@exception@std@@UBEPBDXZ 1FB _crt_debugger_hook 5D3 memset 121 _CxxThrowException 13A __CxxFrameHandler3 11B _CIsqrt KERNEL32.dll 10003000 Import Address Table 100035D8 Import Name Table 0 time date stamp 0 Index of first forwarder reference CA DecodePointer 2EC InterlockedExchange 279 GetSystemTimeAsFileTime 1C1 GetCurrentProcessId 1C5 GetCurrentThreadId 293 GetTickCount 3A7 QueryPerformanceCounter 300 IsDebuggerPresent 4A5 SetUnhandledExceptionFilter 4D3 UnhandledExceptionFilter 1C0 GetCurrentProcess 4C0 TerminateProcess 2E9 InterlockedCompareExchange 4B2 Sleep EA EncodePointer Summary 1000 .data 1000 .rdata 1000 .reloc 1000 .rsrc 2000 .text
3つのdllを必要としています。


今日気づいた設定
 

dumpbin.exeでみてみると

>dumpbin /DEPENDENTS /IMPORTS Bollinger_Band_Width.dll Microsoft (R) COFF/PE Dumper Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file Bollinger_Band_Width.dll File Type: DLL Image has the following dependencies: KERNEL32.dll Section contains the following imports: KERNEL32.dll 1000C000 Import Address Table 1000EA84 Import Name Table 0 time date stamp 0 Index of first forwarder reference 202 GetLastError 2CF HeapFree 2CB HeapAlloc EA EncodePointer CA DecodePointer 1C5 GetCurrentThreadId 186 GetCommandLineA 3B1 RaiseException 4C0 TerminateProcess 1C0 GetCurrentProcess 4D3 UnhandledExceptionFilter 4A5 SetUnhandledExceptionFilter 300 IsDebuggerPresent 2CD HeapCreate 2CE HeapDestroy 245 GetProcAddress 218 GetModuleHandleW 119 ExitProcess 525 WriteFile 264 GetStdHandle 214 GetModuleFileNameW 4B2 Sleep 2D4 HeapSize 4C5 TlsAlloc 4C7 TlsGetValue 4C8 TlsSetValue 4C6 TlsFree 2EF InterlockedIncrement 473 SetLastError 2EB InterlockedDecrement 46F SetHandleCount 2E3 InitializeCriticalSectionAndSpinCount 1F3 GetFileType 263 GetStartupInfoW D1 DeleteCriticalSection 213 GetModuleFileNameA 161 FreeEnvironmentStringsW 511 WideCharToMultiByte 1DA GetEnvironmentStringsW 3A7 QueryPerformanceCounter 293 GetTickCount 1C1 GetCurrentProcessId 279 GetSystemTimeAsFileTime 339 LeaveCriticalSection EE EnterCriticalSection 33F LoadLibraryW 2D2 HeapReAlloc 418 RtlUnwind 172 GetCPInfo 168 GetACP 237 GetOEMCP 30A IsValidCodePage 32D LCMapStringW 367 MultiByteToWideChar 269 GetStringTypeW 304 IsProcessorFeaturePresent Summary 3000 .data 4000 .rdata 2000 .reloc 1000 .rsrc B000 .text
MSVCP100.dll、MSVCR100.dllが不要となっています。

サイズが13kbから68kbに増えましたが問題ではないです。

それよりも 再頒布可能パッケージをインストールしてなくてトラブルことのほうが問題です。

今後は できるだけ再頒布可能パッケージが不要のdllを販売していこうと思います。


MFTの調査

ForexTester2用にMTF(マルチタイムフレーム,Multi Time Frame)の
インディケーターを作成するための調査をしてみます。
以下の関数を実行して出力を確認してみました。
EXPORT void __stdcall Calculate(int index) { char buf[255], i; unsigned short time[] = { PERIOD_M1, PERIOD_M5, PERIOD_M15, 30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1 }; for (i = 0; i < sizeof(time)/sizeof(short); i++) { sprintf(buf, "Bars()=%d, timeframe=%d, iTime(%d)=%f, iTime(%d)=%f", Bars(), time[i], index, iTime(Symbol(), time[i], index), index + 1, iTime(Symbol(), time[i], index + 1)); Print(buf); } }


以下は1分足でバーを1本目から6本目まで表示させた時の出力です。

 2001.01.03 08:03:00  Bars()=1, timeframe=1, iTime(0)=36894.335417, iTime(1)=0.000000
 2001.01.03 08:03:00  Bars()=1, timeframe=5, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:03:00  Bars()=1, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:03:00  Bars()=1, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:03:00  Bars()=1, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:03:00  Bars()=1, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:03:00  Bars()=1, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:03:00  Bars()=1, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=1, iTime(1)=36894.335417, iTime(2)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=5, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=15, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=30, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=60, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=240, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=1440, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=10080, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=1, iTime(0)=36894.336111, iTime(1)=36894.335417
 2001.01.03 08:04:00  Bars()=2, timeframe=5, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:04:00  Bars()=2, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=1, iTime(1)=36894.336111, iTime(2)=36894.335417
 2001.01.03 08:05:00  Bars()=3, timeframe=5, iTime(1)=36894.333333, iTime(2)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=15, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=30, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=60, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=240, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=1440, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=10080, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=1, iTime(0)=36894.336806, iTime(1)=36894.336111
 2001.01.03 08:05:00  Bars()=3, timeframe=5, iTime(0)=36894.336806, iTime(1)=36894.333333
 2001.01.03 08:05:00  Bars()=3, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:05:00  Bars()=3, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=1, iTime(1)=36894.336806, iTime(2)=36894.336111
 2001.01.03 08:07:00  Bars()=4, timeframe=5, iTime(1)=36894.333333, iTime(2)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=15, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=30, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=60, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=240, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=1440, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=10080, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=1, iTime(0)=36894.338194, iTime(1)=36894.336806
 2001.01.03 08:07:00  Bars()=4, timeframe=5, iTime(0)=36894.336806, iTime(1)=36894.333333
 2001.01.03 08:07:00  Bars()=4, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:07:00  Bars()=4, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000
 2001.01.03 08:07:30  Bars()=4, timeframe=1, iTime(0)=36894.338194, iTime(1)=36894.336806
 2001.01.03 08:07:30  Bars()=4, timeframe=5, iTime(0)=36894.336806, iTime(1)=36894.333333
 2001.01.03 08:07:30  Bars()=4, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:07:30  Bars()=4, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:07:30  Bars()=4, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:07:30  Bars()=4, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:07:30  Bars()=4, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:07:30  Bars()=4, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=1, iTime(1)=36894.338194, iTime(2)=36894.336806
 2001.01.03 08:08:00  Bars()=5, timeframe=5, iTime(1)=36894.333333, iTime(2)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=15, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=30, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=60, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=240, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=1440, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=10080, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=1, iTime(0)=36894.338889, iTime(1)=36894.338194
 2001.01.03 08:08:00  Bars()=5, timeframe=5, iTime(0)=36894.336806, iTime(1)=36894.333333
 2001.01.03 08:08:00  Bars()=5, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:08:00  Bars()=5, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000
 2001.01.03 08:08:30  Bars()=5, timeframe=1, iTime(0)=36894.338889, iTime(1)=36894.338194
 2001.01.03 08:08:30  Bars()=5, timeframe=5, iTime(0)=36894.336806, iTime(1)=36894.333333
 2001.01.03 08:08:30  Bars()=5, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:08:30  Bars()=5, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:08:30  Bars()=5, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:08:30  Bars()=5, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:08:30  Bars()=5, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:08:30  Bars()=5, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=1, iTime(1)=36894.338889, iTime(2)=36894.338194
 2001.01.03 08:09:00  Bars()=6, timeframe=5, iTime(1)=36894.333333, iTime(2)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=15, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=30, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=60, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=240, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=1440, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=10080, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=1, iTime(0)=36894.339583, iTime(1)=36894.338889
 2001.01.03 08:09:00  Bars()=6, timeframe=5, iTime(0)=36894.336806, iTime(1)=36894.333333
 2001.01.03 08:09:00  Bars()=6, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:09:00  Bars()=6, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1, iTime(0)=36894.339583, iTime(1)=36894.338889
 2001.01.03 08:09:30  Bars()=6, timeframe=5, iTime(0)=36894.336806, iTime(1)=36894.333333
 2001.01.03 08:09:30  Bars()=6, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000

以下は1分足でバーを6本目まで表示させた状態でインディケーターを読み込んだ出力です。

 2001.01.03 08:09:30  Bars()=6, timeframe=1, iTime(5)=36894.335417, iTime(6)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=5, iTime(5)=0.000000, iTime(6)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=15, iTime(5)=0.000000, iTime(6)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=30, iTime(5)=0.000000, iTime(6)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=60, iTime(5)=0.000000, iTime(6)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=240, iTime(5)=0.000000, iTime(6)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1440, iTime(5)=0.000000, iTime(6)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=10080, iTime(5)=0.000000, iTime(6)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1, iTime(4)=36894.336111, iTime(5)=36894.335417
 2001.01.03 08:09:30  Bars()=6, timeframe=5, iTime(4)=0.000000, iTime(5)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=15, iTime(4)=0.000000, iTime(5)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=30, iTime(4)=0.000000, iTime(5)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=60, iTime(4)=0.000000, iTime(5)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=240, iTime(4)=0.000000, iTime(5)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1440, iTime(4)=0.000000, iTime(5)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=10080, iTime(4)=0.000000, iTime(5)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1, iTime(3)=36894.336806, iTime(4)=36894.336111
 2001.01.03 08:09:30  Bars()=6, timeframe=5, iTime(3)=0.000000, iTime(4)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=15, iTime(3)=0.000000, iTime(4)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=30, iTime(3)=0.000000, iTime(4)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=60, iTime(3)=0.000000, iTime(4)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=240, iTime(3)=0.000000, iTime(4)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1440, iTime(3)=0.000000, iTime(4)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=10080, iTime(3)=0.000000, iTime(4)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1, iTime(2)=36894.338194, iTime(3)=36894.336806
 2001.01.03 08:09:30  Bars()=6, timeframe=5, iTime(2)=0.000000, iTime(3)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=15, iTime(2)=0.000000, iTime(3)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=30, iTime(2)=0.000000, iTime(3)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=60, iTime(2)=0.000000, iTime(3)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=240, iTime(2)=0.000000, iTime(3)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1440, iTime(2)=0.000000, iTime(3)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=10080, iTime(2)=0.000000, iTime(3)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1, iTime(1)=36894.338889, iTime(2)=36894.338194
 2001.01.03 08:09:30  Bars()=6, timeframe=5, iTime(1)=36894.333333, iTime(2)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=15, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=30, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=60, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=240, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1440, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=10080, iTime(1)=0.000000, iTime(2)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1, iTime(0)=36894.339583, iTime(1)=36894.338889
 2001.01.03 08:09:30  Bars()=6, timeframe=5, iTime(0)=36894.336806, iTime(1)=36894.333333
 2001.01.03 08:09:30  Bars()=6, timeframe=15, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=30, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=60, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=240, iTime(0)=36894.333333, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=1440, iTime(0)=36894.000000, iTime(1)=0.000000
 2001.01.03 08:09:30  Bars()=6, timeframe=10080, iTime(0)=36892.000000, iTime(1)=0.000000


わかったこと
timeframeが小さいもののほうがiTime()の戻り値が大きい。
完成した足の時間だから細かい足ほど大きくなるのはあたりまえか。

Bars()が増えると同時にindex=1となる。
Bars()が増えたときに初めて前の足の終値が確定(前の足が完成)するからですね。
index=0のときは確定していない値なので何も処理しないほうが潔くていいかもしれないです。

indexの値で大きい時間枠にアクセスしてはいけない。
大きい時間枠の足を1つづつ過去にさかのぼって
小さい時間枠より大きい時間枠が小さくなった足を利用する感じですかね。

30分の定義値が無いですが使えるようですね。
50分にしてみたら使えなかったので30は使えそうですね。

興味のある方はいろいろ自分で試してください。そのほうが身につきます。
分かりにくかったけど今日はこの辺で。


Forex Tester2 で少し嵌った

ForexTester2のインディケーターを作成している時に少し嵌りました。

何故かバー(ロウソク足)が1本増える度に
全てのバーを再描画するようにCalculateが呼べれまくりました。


原因は
IndicatorBuffers(0);
だと思われます。
ダミーのバッファを作成して
IndicatorBuffers(1);
とすれば起こらなくなりました。

TIndexBuffer を使用しない場合でも最低1つは作成して登録しておかないと駄目みたいです。
登録するとプロパティに表示されるのが気に入らないです。


Access violation

Forex Tester2 のインディケーターを作成したのですが
動作確認しようとしたら変なエラーが表示されて実行不可能でした。




エラー内容
exception number    : 1
exception class     : EAccessViolation
exception message   : Access violation at address 00602E5E in module 'ForexTester.exe'. Read of address 00000008.



いろいろやってみましたが原因は

IndicatorBuffers(0);

を実行していなかったためでした。


バッファを使用しない場合でも引数を0で実行しておかないと駄目みたいです。










ds_ColoredCandles を試してみた

SetIndexStyle関数の引数で指定できる ds_ColoredCandles を使用してみました。
ds_ColoredCandles で4つのバッファを使用してロウソク足を表示できます。

例としてサブウインドウにUSDJPYのロウソク足を表示するインディケーターを作ってみました。
以下はプログラムコードです。
library RousokuTest; uses SysUtils, Interfaces, DateUtils, graphics, IndicatorInterfaceUnit, TechnicalFunctions; var HIGH,LOW,OPEN,CLOSE: TIndexBuffer; procedure Init; stdcall; begin IndicatorShortName('Rousoku Test'); SetOutputWindow(ow_SeparateWindow); HIGH := CreateIndexBuffer; LOW := CreateIndexBuffer; OPEN := CreateIndexBuffer; CLOSE := CreateIndexBuffer; IndicatorBuffers(4); SetIndexBuffer(0, OPEN); SetIndexStyle(0, ds_None, psSolid, 1, clLime); SetIndexLabel(0, 'Up bar color'); SetIndexBuffer(1, HIGH); SetIndexStyle(1, ds_None, psSolid, 1, clBlack); SetIndexLabel(1, 'Up bar fill color'); SetIndexBuffer(2, LOW); SetIndexStyle(2, ds_None, psSolid, 1, clLime); SetIndexLabel(2, 'Down bar color'); SetIndexBuffer(3, CLOSE); SetIndexStyle(3, ds_ColoredCandles, psSolid, 1, clWhite); SetIndexLabel(3, 'Down bar fill color'); end; procedure Calculate(index: integer); stdcall; begin OPEN[index] := iOpen('USDJPY',TimeFrame,index); HIGH[index] := iHigh('USDJPY',TimeFrame,index); LOW[index] := iLow('USDJPY',TimeFrame,index); CLOSE[index] := iClose('USDJPY',TimeFrame,index); end; exports Init, Calculate; end.

4つ目のバッファだけに ds_ColoredCandles を指定したら表示できました。
最初の3つのバッファは色の指定だけが影響を与えると思われます。
USDJPY の始値、高値、安値、終値をバッファに設定していますが別の通貨の組み合わせを設定しても面白いかもしれません。
4つ目のバッファのプロパティを変更することで実線を点線にしたり線の太さを変更したりできます。
 
以下はUSDJPYのチャートのサブウィンドウに表示した例です。

Forex Tester 2の購入はこちらから。


SetIndexStyle関数の調査


SetIndexStyle関数の第2引数でds_Fillとds_HistogramFillの使用方法が
わからなかったのでいろいろ試してみました。

両方とも2つのバッファを使用します。
バッファが1つだけのとき指定してもds_Lineと同じか何も表示されないです。

以下は2つのバッファにいろいろスタイルを組み合わせた例です。

1つ目のバッファに ds_Fill を指定しても意味が無いようです。



2つ目にds_Fillを設定した場合は1つ目がds_Fillでもds_Lineでもds_Sectionでも同じようです。
でもds_Sectionが歯抜けの場合はどうなるか面倒なので試していません。







2つ目にds_Fillを設定した場合は1つ目がds_Noneでもds_HistogramFillでも同じようです。





ds_Histogramとds_Fillの組み合わせでも表示できました。使用することは無いでしょう。



ds_Symbolとds_Fillの組み合わせでも表示できました。歯抜けの場合どうなるかわかりません。



2つ目にds_HistogramFillを設定した場合は1つ目がds_Fillでもds_Lineでもds_Sectionでも同じようです。







ds_HistogramFillとds_Histogramの組み合わせも可能でした。



ds_HistogramFillとds_Symbolの組み合わせも可能でした。


2つ目にds_HistogramFillを設定した場合は1つ目がds_Noneでもds_HistogramFillでも同じようです。






歯抜けのバッファの場合も試してみたら
両方のバッファに値の存在する時間だけ縦線が表示されました。

ds_Fillはds_HistogramFillとds_Lineのセットみたいな感じですね。

 

以上暇なことをしてみました。


Forex Tester 2の購入はこちらから。

売買シグナルを表示

オシレーターウィンドウに売買シグナルを表示してみます。

単純に1時と13時に買いシグナル、7時と19時に売りシグナルを表示してみます。

コードは以下です。
library SymbolTest; uses SysUtils, Interfaces, DateUtils, graphics, IndicatorInterfaceUnit, TechnicalFunctions; var BUY: TIndexBuffer; SELL: TIndexBuffer; procedure Init; stdcall; begin IndicatorShortName('Symbol Test'); SetOutputWindow(ow_SeparateWindow); SetFixedMinMaxValues(-1, 24); SetEmptyValue(100); BUY := CreateIndexBuffer; SELL := CreateIndexBuffer; IndicatorBuffers(2); SetIndexBuffer(0, BUY); SetIndexStyle(0, ds_Symbol, psSolid, 1, clRed); SetIndexSymbol(0, 241, 0, 0); SetIndexBuffer(1, SELL); SetIndexStyle(1, ds_Symbol, psSolid, 1, clBlue); SetIndexSymbol(1, 242, 0, 0); end; procedure Calculate(index: integer); stdcall; begin if (BUY[index] < 24) or (SELL[index] < 24) then exit; if HourOf(Time(index)) = 1 then BUY[index] := 1; if HourOf(Time(index)) = 13 then BUY[index] := 13; if HourOf(Time(index)) = 7 then SELL[index] := 7; if HourOf(Time(index)) = 19 then SELL[index] := 19; end; exports Init, Calculate; end.


SetIndexStyle関数でds_Symbolを指定して
SetIndexSymbol関数で文字を指定します。
シンボルを表示したい時だけバッファに値を設定します。
指定した値の位置にシンボルが表示されます。

実行結果です。

週の始めは7時のデータが無いので空白になっています。

SetIndexSymbol関数の第2引数ではWingdings の文字が指定可能です。

Wingdings  シンボル一覧
  32 ! 33 " 34 # 35 $ 36 % 37 & 38 ' 39
( 40 ) 41 * 42 + 43 , 44 - 45 . 46 / 47
0 48 1 49 2 50 3 51 4 52 5 53 6 54 7 55
8 56 9 57 : 58 ; 59 < 60 = 61 > 62 ? 63
@ 64 A 65 B 66 C 67 D 68 E 69 F 70 G 71
H 72 I 73 J 74 K 75 L 76 M 77 N 78 O 79
P 80 Q 81 R 82 S 83 T 84 U 85 V 86 W 87
X 88 Y 89 Z 90 [ 91 \ 92 ] 93 ^ 94 _ 95
` 96 a 97 b 98 c 99 d 100 e 101 f 102 g 103
h 104 i 105 j 106 k 107 l 108 m 109 n 110 o 111
p 112 q 113 r 114 s 115 t 116 u 117 v 118 w 119
x 120 y 121 z 122 { 123 | 124 } 125 ~ 126  127
128  129 130 ƒ 131 132 133 134 135
ˆ 136 137 Š 138 139 Œ 140  141 Ž 142  143
 144 145 146 147 148 149 150 151
˜ 152 153 š 154 155 œ 156  157 ž 158 Ÿ 159
  160 ¡ 161 ¢ 162 £ 163 ¤ 164 ¥ 165 ¦ 166 § 167
¨ 168 © 169 ª 170 « 171 ¬ 172 ­ 173 ® 174 ¯ 175
° 176 ± 177 ² 178 ³ 179 ´ 180 µ 181 182 · 183
¸ 184 ¹ 185 º 186 » 187 ¼ 188 ½ 189 ¾ 190 ¿ 191
À 192 Á 193 Â 194 Ã 195 Ä 196 Å 197 Æ 198 Ç 199
È 200 É 201 Ê 202 Ë 203 Ì 204 Í 205 Î 206 Ï 207
Ð 208 Ñ 209 Ò 210 Ó 211 Ô 212 Õ 213 Ö 214 × 215
Ø 216 Ù 217 Ú 218 Û 219 Ü 220 Ý 221 Þ 222 ß 223
à 224 á 225 â 226 ã 227 ä 228 å 229 æ 230 ç 231
è 232 é 233 ê 234 ë 235 ì 236 í 237 î 238 ï 239
ð 240 ñ 241 ò 242 ó 243 ô 244 õ 245 ö 246 ÷ 247
ø 248 ù 249 ú 250 û 251 ü 252 ý 253 þ 254 ÿ 255


SetIndexStyle関数で指定できるds_Sectionとds_Lineの違いを調べてみました。
先ほどのプログラムのds_Symbolをds_Sectionとds_Lineに変更してみました。
ds_Lineでは何も表示されませんでした。隣のバッファが空の時は線を引かないようです。


ds_Histogram では表示できました。


少しだけデバッグしてみました

少しだけデバッグコードを仕込んでデバッグしてみました。

print関数でTerminalに文字列を出力することができます。
C:\ForexTester2\LOGS\ForexTester.log にも同じ内容が記録されます。

Init関数、Calculate関数が呼ばれるタイミング、
Calculate関数の引数indexの値、
HOURバッファの初期値、
ロウソク足増加時のバッファの変化について確認しました。



library HourDisp; uses SysUtils, Interfaces, DateUtils, graphics, IndicatorInterfaceUnit, TechnicalFunctions; var HOUR: TIndexBuffer; procedure Init; stdcall; begin print('initinit'); IndicatorShortName('Hour'); SetOutputWindow(ow_SeparateWindow); SetFixedMinMaxValues(-1, 24); SetEmptyValue(100); AddLevel(13, psDashDot, 1, clYellow); AddLevel(20, psDot, 1, clBlue); HOUR := CreateIndexBuffer; IndicatorBuffers(1); SetIndexBuffer(0, HOUR); end; procedure Calculate(index: integer); stdcall; begin if HOUR[index] < 24 then exit; HOUR[index] := HourOf(Time(index)); print('index='+IntToStr(index)+ ' | HOUR[2]='+FloatToStr(HOUR[2])+ ' | HOUR[1]='+FloatToStr(HOUR[1])+ ' | HOUR[0]='+FloatToStr(HOUR[0])); end; exports Init, Calculate; end.


実行した結果です。


最初にInit関数を実行しています。

バッファの初期値が100となっているので
SetEmptyValue関数で設定した値がバッファの初期値のようです。

Calculate関数の引数を9から0にデクリメントしながら10回実行しています。
右端がHOUR[0]になるようです。



ローソク足が1本増えると元々のHOUR[0]の値がHOUR[1]にコピーされています。
左端がHOUR[10]となって右端がHOUR[0]となっています。
勝手にシフトされているようです。

if HOUR[index] < 24 then exit;
この処理で設定済みのバッファは上書きしないようにしています。
Calculate関数が毎分実行されて
Logが多くなるのを防いでいます。
forex tester2 販売
Forex Tester 2の購入はこちらから。
カレンダー
03 2024/04 05
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
カテゴリー
フリーエリア



最新記事
最新CM
最新TB
RSS
ブログ内検索
アーカイブ
最古記事
プロフィール
HN:
fx練習生
年齢:
49
性別:
男性
誕生日:
1975/04/03
職業:
夢は専業トレーダー
趣味:
fx
自己紹介:
fxの専業トレーダーになって経済的自由と時間的自由を手に入れたいです。
自分で売買ルールを作成してテストして自信をもってリアルトレードしたいです。
P R