開拓者1分鐘圖里面取道5分鐘的數(shù)據(jù)的均線 源碼
作者:開拓者 TB 來源:cxh99.com 發(fā)布時間:2012年11月15日
- 內(nèi)容: 使用環(huán)境:
基本數(shù)據(jù)源為1分鐘,通過DataConvert可以轉化為對應的5分鐘數(shù)據(jù),有些朋友希望能夠在1分鐘圖里面取道5分鐘的數(shù)據(jù)的均線,效果要和單獨使用5分鐘的均線一樣。為此,提供以下函數(shù)。
1、新建一個用戶函數(shù),TransMinsData,返回值為數(shù)值型。
參數(shù)1:要計算的數(shù)據(jù)源。
參數(shù)2:想按N分鐘來處理,本例是5分鐘,不能大于60。
參數(shù)3:希望取多少個N分鐘前的數(shù)據(jù)。
- Params
- NumericSeries Price(1);
- Numeric nMinSet(5);
- Numeric MinsAgo(2);
- Vars
- NumericSeries barCnt;
- NumericSeries MinData;
- Numeric i;
- Numeric j;
- Numeric nIndex(0);
- Begin
- If(IntPart(Minute%nMinSet)==0)
- {
- barCnt = 1;
- }Else
- {
- barCnt = barCnt[1] + 1;
- }
- MinData = Price;
-
- If(MinsAgo == 0)
- {
- return MinData;
- }Else
- {
- For i = 1 To MinsAgo
- {
- If( i == 1)
- {
- j = 0;
- }Else
- {
- j = j + BarCnt[j];
- }
- If (j > CurrentBar ) Return InvalidNumeric;
- nIndex = nIndex + BarCnt[j];
- }
- Return MinData[nIndex];
- }
- End