Pastebin: フィボリトレースメント

214行貼付けました 使い方 Horizontal Lineを選択して、チャートの任意の場所をクリックすると水平線作成し「FreeLine」モードに戻る Fibonattiを選択して、高値をクリックしたままで安値までドラッグしてボタンを離すと5本線が描出されます 細かいところは忘れており、メモリ管理等問題があるかもしれません

Formato
Plain text
Post date
2015-05-19 18:20
Publication Period
Unlimited
  1. ①Env.csにライン種類の変数を作成
  2. public enum Linemode { FreeLine, Horizontal, Fibonacci };
  3. private static Linemode _linemode;
  4. public static Linemode LineMode {
  5. get { return _linemode; }
  6. set { _linemode = value ; }
  7. }
  8. ②command.csのCIDに追加
  9. ToggleFreeline,
  10. ToggleHorizontal,
  11. ToggleFibonatti,
  12. 「internal class CommandExec {」にライン変更コマンドを追加
  13. public static CommandResult ChangeLineMode( Env.Linemode mode) {
  14. Env.LineMode = mode;
  15. Env.Frame.Menu.MenuItems[1].MenuItems["LineMode"].MenuItems[ "FreeLine"].Checked = false ;
  16. Env.Frame.Menu.MenuItems[1].MenuItems["LineMode"].MenuItems[ "Horizontal"].Checked = false ;
  17. Env.Frame.Menu.MenuItems[1].MenuItems["LineMode"].MenuItems[ "Fibonatti"].Checked = false ;
  18. switch (mode)
  19. {
  20. case Env .Linemode.Horizontal:
  21. Env.Frame.SetStatusBarText("水平線の描画" , "Click Price");
  22. Env.Frame.Menu.MenuItems[1].MenuItems["LineMode"].MenuItems[ "Horizontal"].Checked = true;
  23. break;
  24. case Env .Linemode.Fibonacci:
  25. Env.Frame.SetStatusBarText("フィボナッチ リトレースメント" , "Click and Drag");
  26. Env.Frame.Menu.MenuItems[1].MenuItems["LineMode"].MenuItems[ "Fibonatti"].Checked = true;
  27. break;
  28. default:
  29. Env.Frame.SetStatusBarText("" , "");
  30. Env.Frame.Menu.MenuItems[1].MenuItems["LineMode"].MenuItems[ "FreeLine"].Checked = true;
  31. break;
  32. }
  33. RefreshChart();
  34. return CommandResult .Succeeded;
  35. }
  36. さらに「public CommandResult Exec() {」に以下を追加
  37. case CID .ToggleFreeline:
  38. return CommandExec .ChangeLineMode(Env.Linemode.FreeLine);
  39. case CID .ToggleHorizontal:
  40. return CommandExec .ChangeLineMode(Env.Linemode.Horizontal);
  41. case CID .ToggleFibonatti:
  42. return CommandExec .ChangeLineMode(Env.Linemode.Fibonacci);
  43. 「internal class CommandCollection : ICloneable {」の「private void Init(StorageNode keys) {」に以下を追加
  44. AddCommand( CID.ToggleFreeline, "Free Line" , keys, Keys.None);
  45. AddCommand( CID.ToggleHorizontal, "Horizontal Line" , keys, Keys.None);
  46. AddCommand( CID.ToggleFibonatti, "Fibonatti" , keys, Keys.None);
  47. ③ライン種類選択用のメニュー作成
  48. MainFrame.cs
  49. private ZMenuItem _menuLineMode;
  50. private ZMenuItem _menuFreeLine;
  51. private ZMenuItem _menuHorizontal;
  52. private ZMenuItem _menuFibonatti;
  53. さらに「InitializeComponent()」で各変数初期化を追加
  54. this._menuLineMode = new ZMenuItem();
  55. this._menuFreeLine = new ZMenuItem();
  56. this._menuHorizontal = new ZMenuItem();
  57. this._menuFibonatti = new ZMenuItem();
  58. // _menuView のメニューにこれを追加
  59. 「this._menuView.MenuItems.AddRange(」の中に , this._menuLineMode を追加
  60. 追加した位置番号に以下を追加(以下は9[10番目]に追加した例)
  61. this._menuLineMode.Index = 9;
  62. this._menuLineMode.MenuItems.AddRange(new ZMenuItem[] {
  63. this._menuFreeLine, this._menuHorizontal, this._menuFibonatti});
  64. this._menuLineMode.Text = "Line Mode" ;
  65. this._menuLineMode.Name = "LineMode" ;
  66. this._menuFreeLine.Index = 0;
  67. this._menuFreeLine.Text = "Free Line" ;
  68. this._menuFreeLine.Name = "FreeLine" ;
  69. this._menuFreeLine.Checked = true ;
  70. this._menuFreeLine.Click += new System.EventHandler( this.OnMenu);
  71. this._menuFreeLine.CID = CID .ToggleFreeline;
  72. this._menuHorizontal.Index = 1;
  73. this._menuHorizontal.Text = "Horizontal Line" ;
  74. this._menuHorizontal.Name = "Horizontal" ;
  75. this._menuHorizontal.Click += new System.EventHandler( this.OnMenu);
  76. this._menuHorizontal.CID = CID .ToggleHorizontal;
  77. this._menuFibonatti.Index = 2;
  78. this._menuFibonatti.Text = "Fibonatti Retracement" ;
  79. this._menuFibonatti.Name = "Fibonatti" ;
  80. this._menuFibonatti.Click += new System.EventHandler( this.OnMenu);
  81. this._menuFibonatti.CID = CID .ToggleFibonatti;
  82. これ以降のIndexの番号(元の9以降)を変更しておく
  83. ④FreeLine.csの「internal class FreeLine {」に変数等追加
  84.   private bool _price;
  85. public FreeLine(Point p1, Point p2, bool price) {
  86. _pivot = p1;
  87. _destination = p2;
  88. _id = -1;
  89. _price = price;
  90. }
  91. public bool Price {
  92. get { return _price; }
  93.   }
  94. public SolidFreeLine ToSolid(DataFarm farm, int firstdateindex, Trans value_to_y, bool showPrice){
  95. SolidFreeLine fl = ToSolid(farm, firstdateindex, value_to_y);
  96. fl.WithSpace = showPrice;
  97. return fl;
  98. }
  99. 「internal class SolidFreeLine {」に以下を追加
  100. private bool _withprice = false;
  101. public bool WithSpace {
  102. get { return _withprice; }
  103. set { _withprice = value ; }
  104. }
  105. ⑤ChartDrawing.csの「internal class ChartDrawing」に以下を追加
  106. public void FixFreeLine(FreeLine fl, bool showPrice){
  107.  Env.FreeLines.Add(_brand, Env .CurrentIndicators.Format, _pref.LogScale, fl.ToSolid(_brand.ReserveFarm(), _firstDateIndex, _priceTrans, showPrice));
  108. _freeLines.Add(fl);
  109. }
  110. ⑥ChartCanvas.cs
  111. ローカル変数追加
  112. private FreeLine _horizontalLine;
  113. private FreeLine [] _fibonattiLine;
  114. private int _posY;
  115. private Point [] _pointFibo;
  116. 「protected override void OnMouseDown( MouseEventArgs e) {」の以下をコメントまたは削除
  117. foreach (FreeLine line in _drawing.FreeLines)
  118. {
  119. if (line.DrawMode == FreeLine .LineDrawMode.Hilight && e.Button == MouseButtons.Left)
  120. {
  121. _diffX = line.Destination.X - line.Pivot.X;
  122. _diffY = line.Destination.Y - line.Pivot.Y;
  123. _destX = line.Destination.X;
  124. _destY = line.Destination.Y;
  125. _pivotX = line.Pivot.X;
  126. _pivotY = line.Pivot.Y;
  127. }
  128. }
  129.  _currentFreeLine = new FreeLine (new Point(e.X, e.Y));
  130. 以下に変更
  131. switch (Env .LineMode) {
  132. case Env .Linemode.Horizontal:
  133. _pointFibo = null;
  134. _fibonattiLine = null;
  135. _posY = e.Y;
  136. Commands. CommandExec.ChangeLineMode(Env .Linemode.FreeLine);
  137. _currentFreeLine = null;
  138. break;
  139. case Env .Linemode.Fibonacci:
  140. _fibonattiLine = new FreeLine [5];
  141. _pointFibo = new Point [2];
  142. _pointFibo[0] = new Point (e.X, e.Y);
  143. _currentFreeLine = null;
  144. int priceWidth = 60;
  145. _fibonattiLine[0] = new FreeLine (new Point(priceWidth, _pointFibo[0].Y), new Point(Env.Layout.ChartAreaWidth, _pointFibo[0].Y), true);
  146. _drawing.FixFreeLine(_fibonattiLine[0], true);
  147. break;
  148. default:
  149. _fibonattiLine = null;
  150. _pointFibo = null;
  151. _currentFreeLine = new FreeLine (new Point(e.X, e.Y));
  152. break;
  153. }
  154. 「protected override void OnMouseMove( MouseEventArgs ev) {」の
  155. 「//今引いている直線の再描画」の直後に以下を追加
  156. if (_fibonattiLine != null && _pointFibo != null)
  157. {
  158. _pointFibo[1] = new Point (ev.X, ev.Y);
  159. _fibonattiLine[4] = new FreeLine (_pointFibo[1]);
  160. Invalidate(_fibonattiLine[4].GetInclusion( this.ClientRectangle), false );
  161. _fibonattiLine[4].Destination = new Point (Env.Layout.ChartAreaWidth, _pointFibo[1].Y);
  162. }
  163. 「private void OnMouseUp( object sender, MouseEventArgs args) {」を以下にすべて変更
  164. private void OnMouseUp(object sender, MouseEventArgs args) {
  165. if(args.Button==MouseButtons .Right) {
  166. ContextMenu m = Env .Frame.CreateContextMenu();
  167. m.Show( this, new Point(args.X, args.Y));
  168. }
  169. else if (args.Button==MouseButtons.Left) {
  170. if(_currentFreeLine!=null ) {
  171. if(_drawing.FreeLineCount==10) {
  172. Util.Warning(Env .Frame, "線は1銘柄につき10本までしか引けません" );
  173. Invalidate();
  174. }
  175. else if (Env.FreeLines.Count==1000) {
  176. Util.Warning(Env .Frame, "線は全部で1000本までしか引けません" );
  177. Invalidate();
  178. }
  179. else if (_currentFreeLine.PivotHasEnoughDistanceTo(_currentFreeLine.Destination))
  180. {
  181. switch (Env .LineMode)
  182. {
  183. case Env .Linemode.Fibonacci:
  184. Commands. CommandExec.ChangeLineMode(Env .Linemode.FreeLine);
  185. break;
  186. default:
  187. _drawing.FixFreeLine(_currentFreeLine);
  188. break;
  189. }
  190. }
  191. _currentFreeLine = null;
  192. }
  193. else
  194. {
  195. switch (Env .LineMode)
  196. {
  197. case Env .Linemode.Fibonacci:
  198. if (_pointFibo != null )
  199. {
  200. _pointFibo[1] = new Point (args.X, args.Y);
  201. int priceWidth = 60;
  202. int[] y = new int[5];
  203. y[0] = _pointFibo[0].Y;
  204. y[4] = _pointFibo[1].Y;
  205. y[1] = System.Convert.ToInt32(y[0] + (y[4] - y[0]) * 0.382);
  206. y[2] = System.Convert.ToInt32(y[0] + (y[4] - y[0]) * 0.5);
  207. y[3] = System.Convert.ToInt32(y[0] + (y[4] - y[0]) * 0.618);
  208. for (int i = 1; i < 5; i++)
  209. {
  210. _fibonattiLine[i] = new FreeLine(new Point(priceWidth, y[i]), new Point (Env.Layout.ChartAreaWidth, y[i]), true);
  211. _drawing.FixFreeLine(_fibonattiLine[i], true);
  212. }
  213. _pointFibo = null;
  214. Commands. CommandExec.ChangeLineMode(Env .Linemode.FreeLine);
  215. }
  216. break;
  217. }
  218. }
  219. if (_drawing.RemoveHighlitedFreeLines()) Invalidate(); //削除されたやつがあればInvalidate
  220. }
  221. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text