人人爽天天爽夜夜爽qc-人人爽天天爽夜夜爽曰-人人天天爱天天做天天摸-人人天天夜夜-色网站在线-色网站在线看

您現在的位置:程序化交易>> 期貨公式>> 交易開拓者(TB)>> 開拓者知識>>正文內容

“MtParabolicSAR,跨周期拋物線轉向ParabolicSAR函數”出爐 [開拓者 TB]

  • 咨詢內容: 本帖最后由 扶老二 于 2014-5-11 19:34 編輯

    “MtParabolicSAR,跨周期拋物線轉向ParabolicSAR函數”出爐

    有需要的帥哥美女拿去用吧,續貼到“追漲殺跌”的帖子里了:

    http://bbs.tb18.net/thread-15184-24-1.html

    有問題歡迎交流 QQ: 149561420
    1. //------------------------------------------------------------------------
    2. // MtParabolicSAR,跨周期拋物線轉向ParabolicSAR函數
    3. // 返回 當前bar的“周期索引”,比如當前在1分鐘周期里,折算成15分鐘周期的話,從凌晨00:00分鐘開始,第1根bar是1,第2根bar是2......第15根bar是15,第16根bar又變成1,......
    4. // 除了函數本身的返回值,還通過oParCl、oParOpen、oPosition、oTransition這四個引用參數把對應Bar的停損值、對應Bar的停損值下一根的停損值、對應Bar建議的持倉狀態(1 - 多頭,-1 - 空頭)、對應Bar的狀態是否發生反轉(1 或 -1 為反轉,0 為保持不變)
    5. // 版本 20140511_183500
    6. //------------------------------------------------------------------------

    7. Params
    8.     Numeric TimeFrame(1440);        //目標時間周期參數,參數說明參見MtBar
    9.     Numeric BarsBack(1);            //目標時間周期BAR偏移參數,說明見MtBar函數
    10.     Numeric AfStep(0.02);
    11.     Numeric AfLimit(0.2);
    12.     NumericRef oParClose;
    13.     NumericRef oParOpen;
    14.     NumericRef oPosition;
    15.     NumericRef oTransition;

    16. Vars
    17.     NumericSeries barCnt;
    18.     NumericSeries CurBar;
    19.     NumericSeries barCntSum;
    20.     NumericSeries HighHT;
    21.     NumericSeries LowHT;
    22.     Numeric CurTime;
    23.     Numeric PreTime;
    24.     bool condition(false);
    25.     Numeric n;
    26.     Numeric i;


    27.     NumericSeries Af(0);   
    28.     NumericSeries ParOpen(0);
    29.     NumericSeries ParClose(0);
    30.     NumericSeries Position(0);  
    31.     NumericSeries HHValue(0);
    32.     NumericSeries LLValue(0);
    33.     NumericSeries Transition(0);
    34.      
    35. Begin
    36.     if(TimeFrame == 40320) {                                        //月線
    37.         CurTime = Month;
    38.         PreTime = Month[1];
    39.     } else if(TimeFrame == 10080) {                                 //周線
    40.         CurTime = IntPart(DateDiff(19700105, TrueDate(0)) / 7);
    41.         PreTime = IntPart(DateDiff(19700105, TrueDate(1)) / 7);
    42.     } else {                                                        //其他時間周期
    43.         CurTime = IntPart((DateDiff(19700105, TrueDate(0)) * 1440 + Hour * 60 + Minute) / TimeFrame);
    44.         PreTime = IntPart((DateDiff(19700105, TrueDate(1)) * 1440 + Hour[1] * 60 + Minute[1]) / TimeFrame);
    45.     }

    46.     condition = CurTime != PreTime;

    47.     if(CurrentBar == 0) {                       //如果是第一根Bar, CurBar=0
    48.         barCnt = 0;
    49.         CurBar = 0;
    50.         HighHT = High[1];
    51.         LowHT = Low[1];
    52.         
    53.         Position = 1;
    54.         Transition = 1;
    55.         Af = AfStep;
    56.         HHValue = HighHT;
    57.         LLValue = LowHT;
    58.         ParClose = LLValue;
    59.         ParOpen = ParClose + Af * (HHValue - ParClose);
    60.         if(ParOpen > LowHT) {
    61.             ParOpen = LowHT;
    62.         }
    63.     } else {
    64.         if(condition) {                         //如果在目標周期下,屬于另一根K線,則CurBar加1
    65.             barCnt = 1;
    66.             CurBar = CurBar[1] + 1;
    67.             HighHT = High[1];
    68.             LowHT = Low[1];
    69.             for n = 2 to TimeFrame {
    70.                 HighHT = Max(HighHT, High[n]);
    71.                 LowHT = Min(LowHT, Low[n]);
    72.             }
    73.         } else {                                //如果在目標周期下,屬于同一根K線,則CurBar不變,但最高價和最低價要記錄價格的變化,成交量要累加
    74.             barCnt = barCnt[1] + 1;
    75.             CurBar = CurBar[1];
    76.             HighHT = Max(HighHT[1], High);
    77.             LowHT = Min(LowHT[1], Low);
    78.         }
    79.         
    80.         HHValue = Max(HHValue[1], HighHT);
    81.         LLValue = Min(LLValue[1], LowHT);

    82.         if(CurBar == 0) {
    83.             Position = 1;
    84.             Transition = 1;
    85.             Af = AfStep;
    86.             ParClose = LLValue;
    87.             ParOpen = ParClose + Af * (HHValue - ParClose);
    88.             if(ParOpen > LowHT) {
    89.                 ParOpen = LowHT;
    90.             }
    91.         } else {        
    92.             if(condition) {                       //正好切換到目標周期的下一根k線
    93.                 Transition = 0;

    94.                 if(Position[TimeFrame] == 1) {
    95.                     if(LowHT <= ParOpen[TimeFrame]) {
    96.                         Position = -1;
    97.                         Transition = -1;              
    98.                         ParClose = HHValue;
    99.                         HHValue = HighHT;
    100.                         LLValue  = LowHT;
    101.             
    102.                         Af = AfStep;
    103.                         ParOpen = ParClose + Af * (LLValue - ParClose);
    104.                            
    105.                         if(ParOpen < HighHT) {
    106.                             ParOpen = HighHT;
    107.                         }
    108.                         
    109.                         if(ParOpen < HighHT[TimeFrame]) {
    110.                             ParOpen = HighHT[TimeFrame];
    111.                         }
    112.                     } else {
    113.                         Position = Position[TimeFrame];
    114.                         ParClose = ParOpen[TimeFrame];                    
    115.                         if(HHValue > HHValue[TimeFrame] && Af[TimeFrame] < AfLimit) {
    116.                             if(Af[TimeFrame] + AfStep > AfLimit) {
    117.                                 Af = AfLimit;
    118.                             } else {
    119.                                 Af = Af[TimeFrame] + AfStep;
    120.                             }               
    121.                         } else {
    122.                             Af = Af[TimeFrame];
    123.                         }   
    124.                         ParOpen = ParClose + Af * (HHValue - ParClose);               
    125.             
    126.                         if(ParOpen > LowHT) {
    127.                             ParOpen = LowHT;
    128.                         }
    129.                         
    130.                         if(ParOpen > LowHT[TimeFrame]) {
    131.                             ParOpen = LowHT[TimeFrame];
    132.                         }
    133.                     }
    134.                 } else {
    135.                     if(HighHT >= ParOpen[TimeFrame]) {
    136.                         Position = 1;
    137.                         Transition = 1;
    138.                         
    139.                         ParClose = LLValue;
    140.                         HHValue = HighHT;
    141.                         LLValue  = LowHT;
    142.                         
    143.                         Af = AfStep;
    144.                         ParOpen = ParClose + Af * (HHValue - ParClose);
    145.                         if(ParOpen > LowHT) {
    146.                             ParOpen = LowHT;
    147.                         }
    148.                         
    149.                         if(ParOpen > LowHT[TimeFrame]) {
    150.                             ParOpen = LowHT[TimeFrame];
    151.                         }
    152.                     } else {
    153.                         Position = Position[TimeFrame];
    154.                         ParClose = ParOpen[TimeFrame];
    155.                            
    156.                         if(LLValue < LLValue[TimeFrame] && Af[TimeFrame] < AfLimit) {
    157.                             if(Af[TimeFrame] + AfStep > AfLimit) {
    158.                                 Af = AfLimit;
    159.                             } else {
    160.                                 Af = Af[TimeFrame] + AfStep;
    161.                             }
    162.                         } else {
    163.                             Af = Af[TimeFrame];
    164.                         }
    165.                         ParOpen = ParClose + Af * (LLValue - ParClose);
    166.             
    167.                         if(ParOpen < HighHT) {
    168.                             ParOpen = HighHT;
    169.                         }
    170.                         
    171.                         if(ParOpen < HighHT[TimeFrame]) {
    172.                             ParOpen = HighHT[TimeFrame];
    173.                         }
    174.                     }
    175.                 }   
    176.             }
    177.         }
    178.     }
    179.    
    180.     //上面的程序,在每根小周期的K線上,記錄了它所屬的大時間周期下的開高低收等值的變化。
    181.     //接下來,要把在大的時間周期級別上,屬于同一根K線的開高低收這些數據,記錄在這一組小周期K線的最后一根上。
    182.     barCntSum = barCnt;

    183.     if(BarsBack == 0) {             //如果Bar偏移參數為0,則取每根小周期K線上保留的大時間周期截止到這根小周期K線為止的BAR數據
    184.         barCntSum = 0;
    185.     } else if(BarsBack == 1) {      //如果Bar偏移參數為1,則取大時間周期的上一根K線的BAr數據
    186.         barCntSum = barCnt;
    187.     } else {                        //如果BAR偏移參數為其他,則取大時間周期的指定偏移后的那根K線的BAR數據
    188.         for i = 2 to BarsBack {
    189.             barCntSum = barCntSum + barCnt[barCntSum];
    190.         }
    191.     }

    192.     //最后將相應的K線數據作為引用參數返回
    193.     oParClose = ParClose[barCntSum];
    194.     oParOpen = ParOpen[barCntSum];
    195.     oPosition = Position[barCntSum];
    196.     oTransition = Transition[barCntSum];
    197.    
    198.     Return true;
    199. End

     

  • TB技術人員: 群主我用rb的日線跟此函數timeframe1440進行了對比發現不匹配

     

  • TB客服:
    duck_arrow 發表于 2014-5-13 15:12
    群主我用rb的日線跟此函數timeframe1440進行了對比發現不匹配

    跟tb自帶的ParabolicSAR函數比對發現不匹配。其實主要是tb自帶的ParabolicSAR函數代碼里High和Low都用的當前k線的數據導致,這是有問題的,當前k線還沒運行結束之前,High和Low都是未來的屬性,所以直接使用它,會導致實盤時候信號閃爍和使用了未來屬性,我修復了一下tb自帶的ParabolicSAR,用High[1]和Low[1]來取代High和Low,取名ParabolicSAR_ximen,請用以下代碼新建用戶函數,函數名叫ParabolicSAR_ximen,然后在不需要跨周期的時候,建議用ParabolicSAR_ximen來替換ParabolicSAR:
    1. //------------------------------------------------------------------------
    2. // 西門 ParabolicSAR_ximen
    3. // 描述 求拋物線轉向,修正系統默認用當前bar會導致閃爍的問題,采用[1]來做判斷依據,比系統默認函數更精確
    4. // 返回 True 或 false。除了函數本身的返回值,還通過oParCl、oParOpen、oPosition、oTransition這四個引用參數把對應Bar的停損值、對應Bar的停損值下一根的停損值、對應Bar建議的持倉狀態(1 - 多頭,-1 - 空頭)、對應Bar的狀態是否發生反轉(1 或 -1 為反轉,0 為保持不變)
    5. // 版本 20140511
    6. //------------------------------------------------------------------------


    7. Params
    8.     Numeric AfStep(0.02);
    9.     Numeric AfLimit(0.2);
    10.     NumericRef oParClose;
    11.     NumericRef oParOpen;
    12.     NumericRef oPosition;
    13.     NumericRef oTransition;
    14.    
    15. Vars
    16.     NumericSeries HighHT;
    17.     NumericSeries LowHT;

    18.     NumericSeries Af(0);   
    19.     NumericSeries ParOpen(0);
    20.     NumericSeries ParClose(0);
    21.     NumericSeries Position(0);  
    22.     NumericSeries HHValue(0);
    23.     NumericSeries LLValue(0);
    24.     NumericSeries Transition(0);

    25. Begin               
    26.     if(CurrentBar == 0) {
    27.                 HighHT = High;
    28.                 LowHT = Low;
    29.                
    30.         Position = 1;
    31.         Transition = 1;
    32.         Af = AfStep;
    33.         HHValue = HighHT;
    34.         LLValue = LowHT;
    35.         ParClose = LLValue;
    36.         ParOpen = ParClose + Af * ( HHValue - ParClose);
    37.         if(ParOpen > LowHT) {
    38.             ParOpen = LowHT;
    39.         }
    40.     } else {
    41.                 HighHT = High[1];
    42.                 LowHT = Low[1];
    43.                
    44.                 HHValue = Max(HHValue[1], HighHT);
    45.                 LLValue = Min(LLValue[1], LowHT);

    46.         Transition = 0;

    47.         if(Position[1] == 1) {
    48.             if(LowHT <= ParOpen[1]) {
    49.                 Position = -1;
    50.                 Transition = -1;              
    51.                 ParClose = HHValue;
    52.                 HHValue = HighHT;
    53.                 LLValue  = LowHT;
    54.    
    55.                 Af = AfStep;
    56.                 ParOpen = ParClose + Af * (LLValue - ParClose);
    57.                     
    58.                 if(ParOpen < HighHT) {
    59.                     ParOpen = HighHT;
    60.                 }
    61.                
    62.                 if(ParOpen < HighHT[1]) {
    63.                     ParOpen = HighHT[1];
    64.                 }
    65.             } else {
    66.                 Position = Position[1];
    67.                 ParClose = ParOpen[1];                    
    68.                 if(HHValue > HHValue[1] && Af[1] < AfLimit) {
    69.                     if(Af[1] + AfStep > AfLimit) {
    70.                         Af = AfLimit;
    71.                     } else {
    72.                         Af = Af[1] + AfStep;
    73.                     }               
    74.                 } else {
    75.                     Af = Af[1];
    76.                 }   
    77.                 ParOpen = ParClose + Af * (HHValue - ParClose);               
    78.    
    79.                 if(ParOpen > LowHT) {
    80.                     ParOpen = LowHT;
    81.                 }
    82.                
    83.                 if(ParOpen > LowHT[1]) {
    84.                     ParOpen = LowHT[1];
    85.                 }
    86.             }
    87.         } else {
    88.             if(HighHT >= ParOpen[1]) {
    89.                 Position = 1;
    90.                 Transition = 1;
    91.                
    92.                 ParClose = LLValue;
    93.                 HHValue = HighHT;
    94.                 LLValue  = LowHT;
    95.                
    96.                 Af = AfStep;
    97.                 ParOpen = ParClose + Af * (HHValue - ParClose);
    98.                 if(ParOpen > LowHT) {
    99.                     ParOpen = LowHT;
    100.                 }
    101.                
    102.                 if(ParOpen > LowHT[1]) {
    103.                     ParOpen = LowHT[1];
    104.                 }
    105.             } else {
    106.                 Position = Position[1];
    107.                 ParClose = ParOpen[1];
    108.                     
    109.                 if(LLValue < LLValue[1] && Af[1] < AfLimit) {
    110.                     if(Af[1] + AfStep > AfLimit) {
    111.                         Af = AfLimit;
    112.                     } else {
    113.                         Af = Af[1] + AfStep;
    114.                     }
    115.                 } else {
    116.                     Af = Af[1];
    117.                 }
    118.                 ParOpen = ParClose + Af * (LLValue - ParClose);
    119.    
    120.                 if(ParOpen < HighHT) {
    121.                     ParOpen = HighHT;
    122.                 }
    123.                
    124.                 if(ParOpen < HighHT[1]) {
    125.                     ParOpen = HighHT[1];
    126.                 }
    127.             }
    128.         }  
    129.     }   
    130.    
    131.     oParClose = ParClose;
    132.     oParOpen = ParOpen;
    133.     oPosition = Position;
    134.     oTransition = Transition;

    135.     Return True;
    136. End
    復制代碼下面是不跨周期的ParabolicSAR_ximen調用的例子:
    1. Params

    2. Vars       
    3.         Numeric oParCl;
    4.         Numeric oParOp;
    5.         Numeric oPosition;
    6.         Numeric oTransition;
    7.        
    8. begin
    9.         ParabolicSAR_ximen(0.02, 0.2, oParCl, oParOp, oPosition, oTransition);
    10.          
    11.         Commentary("oParCl:" + Text(oParCl));
    12.         Commentary("oParOp:" + Text(oParOp));
    13.         Commentary("oPosition:" + Text(oPosition));
    14.         Commentary("oTransition:" + Text(oTransition));
    15. End        
    復制代碼

 

有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友

可聯系技術人員 QQ: 1145508240  點擊這里給我發消息進行 有償 編寫!不貴!點擊查看價格!


【字體: 】【打印文章】【查看評論

相關文章

    沒有相關內容
主站蜘蛛池模板: 国产黄a三级三级看三级 | 超97在线观看精品国产 | 瑟瑟网站免费网站入口 | 午夜国产羞羞视频免费网站 | 国产精品福利午夜h视频 | 成 人网站免费 | 91精品久久久久久久99蜜桃 | 天天摸天天操 | 欧美日韩加勒比一区二区三区 | 欧美人成在线观看ccc36 | 最新日韩中文字幕 | 国产成人激情视频 | h片在线看| 免费欧美一级片 | 成年轻人网站色 免费看 | 国产成人精品久久一区二区三区 | 波多野结衣一区在线 | 成人一区视频 | 成人午夜性视频欧美成人 | 天天爆操 | 在线一级黄色片 | 国产免费黄色片 | 欧美精品国产精品 | 国产精品久久久久久久久久一区 | 午夜私人影院 | 天天干国产 | 91精品视频在线观看免费 | 午夜久久网 | 欧美精品免费在线 | 久久精品国产亚洲a不卡 | 日韩高清伦理片中字在线观看 | 国产a一级毛片午夜剧院 | 国内精品线在线观看 | 欧美日韩亚洲视频 | 成人毛片100部免费看 | 日本一区二区视频在线 | 欧美亚洲免费久久久 | 亚洲韩国日本欧美一区二区三区 | 国产日韩欧美在线播放 | 成人久久18免费游戏网站 | 成人国产第一区在线观看 |