開拓者1分鐘圖里面取道5分鐘的數據的均線 源碼
作者:開拓者 TB 來源:cxh99.com 發布時間:2012年11月15日
- 內容: 使用環境:
基本數據源為1分鐘,通過DataConvert可以轉化為對應的5分鐘數據,有些朋友希望能夠在1分鐘圖里面取道5分鐘的數據的均線,效果要和單獨使用5分鐘的均線一樣。為此,提供以下函數。
1、新建一個用戶函數,TransMinsData,返回值為數值型。
參數1:要計算的數據源。
參數2:想按N分鐘來處理,本例是5分鐘,不能大于60。
參數3:希望取多少個N分鐘前的數據。
- 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