2012年10月14日

Cipher常用函數

以下是個人常函數, 以及寫法,
隨著進步會跟著改變


更新日期:20120906


Main
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>int aBarOnce(int aBarOnce_time)
{
if (iTime(NULL,aBarOnce_time,0)==Time0) return(-1);
Time0=iTime(NULL,aBarOnce_time,0);
return(0);
}
</code></pre>
Notice:
Use this function in sub-functions, not just use this under "Start()".

Reference
In MT4, the strategy calculates every tick.
It requires a lots of resource.
So this is a function to make MT4 calculate per bar rather than tick.
And even more, I want to choose time period.

1.First, for example.
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>
int start()
{
Print(Time0);
}
</code></pre>

It results every tick, notice second row.
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>15:46:39 2012.01.25 11:20 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:20 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:20 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:20 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:20 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:20 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:20 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:21 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:21 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:21 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:21 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:21 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:21 test EURUSD,M5: 1327490400
15:46:39 2012.01.25 11:21 test EURUSD,M5: 1327490400
</code></pre>

2.Next we set a parameter Time0
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>datetime Time0;
int start()
{
if (Time[0]==Time0) return(-1);
Time0=Time[0];
Print(Time0);
}
</code></pre>

Then it calculates each bar, as follow:
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>15:52:19 2012.01.25 01:00 test EURUSD,M5: 1327453200
15:52:19 2012.01.25 01:05 test EURUSD,M5: 1327453500
15:52:19 2012.01.25 01:10 test EURUSD,M5: 1327453800
15:52:19 2012.01.25 01:15 test EURUSD,M5: 1327454100
15:52:19 2012.01.25 01:20 test EURUSD,M5: 1327454400
15:52:19 2012.01.25 01:25 test EURUSD,M5: 1327454700
15:52:19 2012.01.25 01:30 test EURUSD,M5: 1327455000
</code></pre>


3.The follow function aBarOnce(int aBarOnce_time)can set custom bar.
But notice there is a global variable.
datetime Time0;
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>int start()
{
if (aBarOnce(5)&amp;lt;0) return(-1);
Print(aBarOnce(5));
}
//+------------------------------------------------------------------+
int aBarOnce(int aBarOnce_time)
{
if (iTime(NULL,aBarOnce_time,0)==Time0) return(-1);
Time0=iTime(NULL,aBarOnce_time,0);
return(0);
}
</code></pre>

results
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>
16:16:27 2012.01.25 00:25 test EURUSD,M5: -1
16:16:27 2012.01.25 00:30 test EURUSD,M5: -1
16:16:27 2012.01.25 00:35 test EURUSD,M5: -1
16:16:27 2012.01.25 00:40 test EURUSD,M5: -1
16:16:27 2012.01.25 00:45 test EURUSD,M5: -1
16:16:27 2012.01.25 00:50 test EURUSD,M5: -1
16:16:27 2012.01.25 00:55 test EURUSD,M5: -1
</code></pre>

沒有留言:

張貼留言