: | : | :期货程序化 | :期货程序化研究 | :期货量化学习 | :期货量化 |
返回列表 发帖

【 ZigZag Fibonacci Plus】

【 ZigZag Fibonacci Plus】

  1. inputs:  
  2.         RetraceType( 1 ) , { Choose: 1 Pnts, 2 Pct }
  3.         RetracePnts( 5 ) ,
  4.         RetracePct( 5 ) ,
  5.         ShowZigZagLines( True ) ,
  6.         ShowSwingPointLines( True ) ,
  7.         ZigZagLineColor( Magenta ) ,
  8.         ZigZagLineWidth( 1 ),
  9.         SwingHighColor( Black ) ,
  10.         SwingLowColor (Red ) ,
  11.         SwingLineStyle( Tool_Dotted ),
  12.         VertOffset( 0.25 ),
  13.         DecimalPlaces( 2 ),

  14.         {HamFon Fib inputs}
  15.         ShowOpenLine (False), ExtRight(True),
  16.         TextColor(LightGray),
  17.         HiLoColor (Magenta), OuterFibColor (DarkGreen),
  18.         MidColor(Magenta), InnerFibColor(Red), FibPlusColor(DarkGray), OpenColor (Darkbrown);
  19.         
  20. variables:
  21.         NewSwingPrice( 0 ) ,
  22.         LastSwingPrice(0 ) ,
  23.         SwingPrice( High ) , { used as a convenient 2-element array }
  24.         SwingDate( Date ) , { used as a convenient 2-element array }
  25.         SwingTime( Time ) , { used as a convenient 2-element array }
  26.         RetraceFctrUp( 1 + RetracePct * .01 ),
  27.         RetraceFctrDn( 1 - RetracePct * .01 ),
  28.         TLDir( 0 ), { TLDir = -1 implies prev TL dn, +1 implies prev TL up }
  29.         SaveSwing( false ) ,
  30.         AddTL( false ) ,
  31.         UpdateTL( false ) ,
  32.         TLRef( 0 ) ,
  33.     TLSwing( 0 ),
  34.         PeakTextRef( 0 ) ,
  35.     PeakStr("") ,

  36.         {HamFon variables inputs}
  37.         TLCreated (false), Redraw (false), Loop (0), Diff(0),
  38.         ArrayMax (11);

  39. vars: showDebug(FALSE);

  40. arrays: TrendLine[11] (0), DayValue[11] (0), FibText[11](0), FibLabel[11](" ");
  41.         

  42. //Create initial fib lines
  43. if CurrentBar = 1 then begin
  44.                 for loop=0 to ArrayMax begin {added Color for visual differentiation}
  45.                         if loop <= ArrayMax then begin
  46.                                 
  47.                                 TrendLine[loop] = TL_New (Date[1], Time[1], Low, Date, Time, Low);
  48.                                 If (loop = 4)  then
  49.                                         TL_SetColor (TrendLine[loop], MidColor)
  50.                                 else if (loop = 0) or (Loop = 1) then
  51.                                         TL_SetColor (TrendLine[loop], HiLoColor)
  52.                                 else if (loop = 3 ) or (loop = 5 ) then
  53.                                         TL_SetColor (TrendLine[loop], InnerFibColor)
  54.                                 else if (Loop = 2) or (loop = 6) then
  55.                                         TL_SetColor (Trendline[loop], OuterFibColor)
  56.                             {else if (Loop > 7) then
  57.                                         TL_setcolor(Trendline[loop], red)}

  58.                                 else TL_SetColor (TrendLine[loop], FibPlusColor);

  59.                                 TL_SetExtLeft (TrendLine[loop], false);
  60.                                 TL_SetExtRight (TrendLine[loop], True);
  61.                                 if loop = 4 then
  62.                                         TL_SetStyle(TrendLine[loop],Tool_dotted);
  63.                                 FibText[loop] = Text_New(Date, Time, Low, " " ) ;
  64.                                 Text_SetColor(FibText[loop], TextColor) ;
  65.                         end; // if loop
  66.                 end; // for loop

  67.         FibLabel[0] = "1" ; {Max Swing }
  68.         FibLabel[1] = "0" ; { Min Swing }

  69.         FibLabel[2] = ".236" ;
  70.         FibLabel[3] = ".382" ;
  71.         FibLabel[4] = ".5" ;
  72.         FibLabel[5] = ".618" ;
  73.         FibLabel[6] = ".764" ;
  74.         FibLabel[7] = ".886" ;
  75.         FibLabel[8] = "1.23" ;
  76.         FibLabel[9] = "1.5" ;
  77.         FibLabel[10] = "1.62" ;
  78.         FibLabel[11] = "2.00" ;

  79. end; //if currentbar


  80. { Candidate swings are just-confirmed, 3-bar (Str=1), SwingHi's and SwingLo's }

  81. NewSwingPrice = SwingHigh( 1, High, 1, 2 ) ;
  82. if NewSwingPrice  <> -1 then
  83.         begin
  84.         if ( RetraceType = 1 and TLDir <= 0 and NewSwingPrice >= SwingPrice + RetracePnts ) or
  85.            ( RetraceType = 2 and TLDir <= 0 and NewSwingPrice >= SwingPrice * RetraceFctrUp ) then
  86.                 { prepare to add new up TL }
  87.                 begin
  88.                 SaveSwing = true ;
  89.                 AddTL = true ;
  90.                 TLDir = 1 ;
  91.                 end
  92.         else if TLDir = 1 and NewSwingPrice >= SwingPrice then
  93.                 { prepare to update prev up TL }
  94.                 begin
  95.                 SaveSwing = true ;
  96.                 UpdateTL = true ;
  97.                 end ;
  98.         end
  99. else
  100. begin
  101.         NewSwingPrice = SwingLow( 1, Low, 1, 2 ) ;
  102.         if NewSwingPrice <> -1 then
  103.                 begin
  104.                 if ( RetraceType = 1 and TLDir >= 0 and NewSwingPrice <= SwingPrice - RetracePnts ) or
  105.                    ( RetraceType = 2 and TLDir >= 0 and NewSwingPrice <= SwingPrice * RetraceFctrDn ) then
  106.                         { prepare to add new dn TL }
  107.                         begin
  108.                         SaveSwing = true ;
  109.                         AddTL = true ;
  110.                         TLDir = -1 ;
  111.                         end
  112.                 else if TLDir = -1 and NewSwingPrice <= SwingPrice then
  113.                         { prepare to update prev dn TL }
  114.                         begin
  115.                         SaveSwing = true;
  116.                         UpdateTL = true ;
  117.                         end ;
  118.                 end ;
  119.         end ;

  120. if SaveSwing then
  121. { save new swing and reset SaveSwing }
  122. begin
  123.         SwingPrice = NewSwingPrice ;
  124.         SwingDate = Date[1] ;
  125.         SwingTime = Time[1] ;
  126. //        SaveSwing = false ;
  127. end ;

  128. if (showDebug) then
  129.         print(" AddTL === ", AddTL, "  UpdateTL == ", UpdateTL, "SaveSwing == ", SaveSwing, " TL Dir = ", TLDir);

  130. if AddTL then
  131. { add new TL and reset AddTL }
  132. begin
  133.         PeakTextRef = Text_New(Date, Time, Close, " ") ;
  134.         Text_SetColor(PeakTextRef, TextColor ) ;

  135.         if ShowZigZagLines then
  136.         begin
  137.                 TLRef = TL_New( SwingDate, SwingTime, SwingPrice, SwingDate[1], SwingTime[1],
  138.                  SwingPrice[1] ) ;
  139.                 Text_SetStyle(PeakTextRef, 2, 2 );
  140.                 TL_SetExtLeft( TLRef, false ) ;
  141.                 TL_SetExtRight( TLRef, false ) ;
  142.                 TL_SetSize( TLRef, ZigZagLineWidth ) ;
  143.                 TL_SetColor( TLRef, ZigZagLineColor ) ;
  144.                 LastSwingPrice = SwingPrice[1];
  145.         end ;

  146.         if ShowSwingPointLines then
  147.         begin
  148.                 TLSwing = TL_New( Date[1], Time[1], SwingPrice, Date, Time, SwingPrice ) ;
  149.                 if TLDir = -1 then
  150.                         TL_SetColor( TLSwing, SwingLowColor )
  151.                 else
  152.                         TL_SetColor( TLSwing, SwingHighColor ) ;                        
  153.                 TL_SetStyle( TLSwing, SwingLineStyle ) ;
  154.                 TL_SetExtLeft( TLSwing, False ) ;
  155.                 TL_SetExtRight( TLSwing, False ) ;
  156.         end ;

  157.         if TLDir = -1 then
  158.                 PeakStr = "" + NumToStr(SwingPrice,DecimalPlaces) + " / " + NumToStr(LastSwingPrice - SwingPrice, DecimalPlaces )
  159.         else
  160.                 PeakStr =  "" + NumToStr(SwingPrice,DecimalPlaces) + " / " + NumToStr(SwingPrice - LastSwingPrice, DecimalPlaces ) ;

  161.         Text_SetString(PeakTextRef, PeakStr );

  162.         if TLDir = -1 then
  163.                 Text_SetLocation(PeakTextRef, SwingDate, SwingTime, SwingPrice - VertOffset )
  164.         else
  165.                 Text_SetLocation(PeakTextRef, SwingDate, SwingTime, SwingPrice + VertOffset );

  166.         AddTL = false ;

  167. end
  168.         else if UpdateTL then
  169.         { update prev TL and reset UpdateTL }
  170.         begin
  171.         if ShowZigZagLines then
  172.                 TL_SetEnd( TLRef, SwingDate, SwingTime, SwingPrice ) ;

  173.         if ShowSwingPointLines then
  174.                 begin
  175.                 TL_SetEnd( TLSwing, SwingDate, SwingTime, SwingPrice ) ;
  176.                 TL_SetBegin( TLSwing, SwingDate, SwingTime, SwingPrice ) ;
  177.                 end ;
  178.         if TLDir = -1 then
  179.                 PeakStr = "" + NumToStr(SwingPrice,DecimalPlaces) + " / " + NumToStr(LastSwingPrice - SwingPrice, DecimalPlaces )
  180.         else PeakStr = "" + NumToStr(SwingPrice,DecimalPlaces) + " / " + NumToStr(SwingPrice - LastSwingPrice, DecimalPlaces ) ;
  181.         Text_SetString( PeakTextRef, PeakStr );
  182.         if TLDir = -1 then
  183.                 Text_SetLocation(PeakTextRef, SwingDate, SwingTime, SwingPrice - VertOffset)
  184.         else
  185.                 Text_SetLocation(PeakTextRef, SwingDate, SwingTime, SwingPrice + VertOffset);
  186.         UpdateTL = false ;
  187. end ;



  188.         {*************  HamFons'  FIB POINTS Code:
  189. goal is to call the  LAST SWING HI AND LAST SWING LO  from ABOVE CODE
  190. and draw Fib points between them *****************}

  191. if (showDebug) then
  192.         print("SaveSwing == ", SaveSwing, " TL Dir = ", TLDir);

  193. //Update Fib lines
  194. if SaveSwing then begin
  195.         if TLDir = -1 then
  196.         begin
  197.                 DayValue[0] = Swingprice;
  198.                 DayValue[1] = LastSwingprice;
  199.         end
  200.         else
  201.         begin
  202.                 DayValue[1] = Swingprice;
  203.                 DayValue[0] = LastSwingprice;
  204.         end ;

  205.                 Diff = DayValue[0] - DayValue[1];
  206. if (showDebug) then
  207.          print("Day0 = ", DayValue[0], " DayMax= ", DayValue[1], " Diff =", Diff, " TLDir = ", TLDir);

  208.                 DayValue[2] = DayValue[1] + Diff * .236;
  209.                 DayValue[3] = DayValue[1] + Diff * .382;
  210.                 DayValue[4] = DayValue[1] + Diff * .5;
  211.                 DayValue[5] = DayValue[1] + Diff * .618;
  212.                 DayValue[6] = DayValue[1] + Diff * .764;
  213.                 DayValue[7] = DayValue[1] + Diff * .886;
  214.                 DayValue[8] = DayValue[1] + Diff * 1.23;
  215.                 DayValue[9] = DayValue[1] + Diff * 1.5;
  216.                 DayValue[10] = DayValue[1] + Diff * 1.62;
  217.                 DayValue[11] = DayValue[1] + Diff * 2.00;

  218.         for loop=0 to ArrayMax begin
  219.                 { SetEnd before SetBegin }
  220.                 if TrendLine[loop] > 0 then begin
  221.                         TL_SetEnd (TrendLine[loop], Date, Time, DayValue[loop]);
  222.                         TL_SetBegin (TrendLine[loop], Date, Time, DayValue[loop]);
  223.                         end; // if TrendLine
  224.         end; // for loop

  225.         SaveSwing = False ;
  226. end ; // if SaveSwing

  227.         for loop=0 to ArrayMax begin

  228. if (showDebug) then               
  229.         print("Dayvalue[",Loop,"]= ", DayValue[Loop]);

  230.                 if FibText[loop] > 0 then begin
  231.                         Text_SetLocation(FibText[loop],Date,Time +1, Dayvalue[loop]);
  232.                         if TLDir = -1 then
  233.                                 Text_SetString(FibText[loop],NumToStr(DayValue[loop],DecimalPlaces) + " / " + FibLabel[loop] )
  234.                         else
  235.                                 Text_SetString(FibText[loop],NumToStr(DayValue[loop],DecimalPlaces) + " / " + FibLabel[loop] ) ;
  236.                         end ;
  237.         end;
复制代码

论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
 
期货论坛 - 版权/免责声明   1.本站发布源码(包括函数、指标、策略等)均属开放源码,用意在于让使用者学习程序化语法撰写,使用者可以任意修改语法內容并调整参数。仅限用于个人学习使用,请勿转载、滥用,严禁私自连接实盘账户交易
  2.本站发布资讯(包括文章、视频、历史记录、教材、评论、资讯、交易方案等)均系转载自网络主流媒体,内容仅为作者当日个人观点,本网转载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。本网不对该类信息或数据做任何保证。不对您构成任何投资建议,不能依靠信息而取代自身独立判断,不对因使用本篇文章所诉信息或观点等导致的损失承担任何责任。
  3.本站发布资源(包括书籍、杂志、文档、软件等)均从互联网搜索而来,仅供个人免费交流学习,不可用作商业用途,本站不对显示的内容承担任何责任。请在下载后24小时内删除。如果喜欢,请购买正版,谢谢合作!
  4.龙听期货论坛原创文章属本网版权作品,转载须注明来源“龙听期货论坛”,违者本网将保留追究其相关法律责任的权力。本论坛除发布原创文章外,亦致力于优秀财经文章的交流分享,部分文章推送时若未能及时与原作者取得联系并涉及版权问题时,请及时联系删除。联系方式:http://www.qhlt.cn/thread-262-1-1.html
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

返回列表