コピペ: OmegaChart Fibonacciリトレースメント Fibonacci.cs 新規追加 ※差し替え その5

形式
Plain text
投稿日時
2018-08-19 21:13
公開期間
無期限
  1. using System;
  2. using System.Collections;
  3. using System.Drawing;
  4. using System.Text;
  5. using Zanetti.Data;
  6. using Travis.Storage;
  7. namespace Zanetti.UI
  8. {
  9. /// <summary>
  10. /// Fibonacci の概要の説明です。
  11. /// </summary>
  12. internal class Fibonacci
  13. {
  14. private PointF _pivot;
  15. private PointF _destination;
  16. private int _id; //SolidFibonacciからの作成時のみセット、それ以外は-1
  17. private LineDrawMode _mode;
  18. public enum LineDrawMode
  19. {
  20. Normal,
  21. Hilight,//☆Fibonacci 20180816 カンマ「,」追加
  22. Move//☆Fibonacci 20180816 追加
  23. }
  24. public Fibonacci(PointF p)
  25. {
  26. _pivot = p;
  27. _destination = p;
  28. _id = -1;
  29. }
  30. public Fibonacci(PointF p1, PointF p2)
  31. {
  32. _pivot = p1;
  33. _destination = p2;
  34. _id = -1;
  35. }
  36. //リサイズしたときなどの再計算
  37. public Fibonacci(DataFarm farm, int firstdateindex, SolidFibonacci fl, Trans value_to_y)
  38. {
  39. int p = Env.Layout.DatePitch;
  40. _pivot = new PointF((farm.DateToIndex(fl._date1) - firstdateindex) * p + p / 2, (float)value_to_y.TransValue(fl._value1));
  41. _destination = new PointF((farm.DateToIndex(fl._date2) - firstdateindex) * p + p / 2, (float)value_to_y.TransValue(fl._value2));
  42. _id = fl._id;
  43. }
  44. public PointF Pivot
  45. {
  46. get
  47. {
  48. return _pivot;
  49. }
  50. //☆Fibonacci 20180816 setは不要
  51. }
  52. public PointF Destination
  53. {
  54. get
  55. {
  56. return _destination;
  57. }
  58. set
  59. {
  60. _destination = value;
  61. }
  62. }
  63. public LineDrawMode DrawMode
  64. {
  65. get
  66. {
  67. return _mode;
  68. }
  69. set
  70. {
  71. _mode = value;
  72. }
  73. }
  74. public int ID
  75. {
  76. get
  77. {
  78. return _id;
  79. }
  80. }
  81. public void SetHighPriceAndLowPrice(DataFarm farm, Trans pricetrans, float x1, float x2, int FirstDateIndex)
  82. {
  83. var range_max = double.MinValue;//☆Fibonacci 20180816 新規追加
  84. var range_min = double.MaxValue;//☆Fibonacci 20180816 新規追加
  85. var y1 = double.MinValue;//☆Fibonacci 20180816 新規追加
  86. var y2 = double.MinValue;//☆Fibonacci 20180816 新規追加
  87. if (x1 > Env.Layout.ChartAreaWidth || x2 > Env.Layout.ChartAreaWidth)
  88. return;
  89. int ind1 = FirstDateIndex + (int)Math.Floor((double)Math.Min(x1, x2) / Env.Layout.DatePitch);
  90. int ind2 = FirstDateIndex + (int)Math.Floor((double)Math.Max(x1, x2) / Env.Layout.DatePitch);
  91. if (ind1 < 0) ind1 = 0;
  92. if (ind2 < 0) ind2 = 0;
  93. if (ind1 >= farm.FilledLength) ind1 = farm.FilledLength - 1;//☆Fibonacci 20180816 修正
  94. if (ind2 >= farm.FilledLength) ind2 = farm.FilledLength - 1;//☆Fibonacci 20180816 修正
  95. //最高値と最安値の株価
  96. range_max = Max(farm, ind1, ind2);//☆Fibonacci 20180816 修正
  97. range_min = Min(farm, ind1, ind2);//☆Fibonacci 20180816 修正
  98. //最高値と最安値の画面上の位置
  99. //var y1 = pricetrans.TransValue(_pivot.Y > _destination.Y ? Env.Preference.InverseChart ? range_max : range_min : Env.Preference.InverseChart ? range_min : range_max);//☆Fibonacci 20180816 コメントアウト
  100. //var y2 = pricetrans.TransValue(_pivot.Y > _destination.Y ? Env.Preference.InverseChart ? range_min : range_max : Env.Preference.InverseChart ? range_max : range_min);//☆Fibonacci 20180816 コメントアウト
  101. //☆Fibonacci 20180816 新規追加ここから
  102. if (_mode != Fibonacci.LineDrawMode.Move && _id < 0)//モードが移動モード、かつ引いたばかりのフィボナッチラインではない
  103. {
  104. //_pivot.Y > _destination.Y は下から上に引いた線の意味
  105. y1 = pricetrans.TransValue(_pivot.Y > _destination.Y ? Env.Preference.InverseChart ? range_max : range_min : Env.Preference.InverseChart ? range_min : range_max);//☆Fibonacci 20180816 変更
  106. y2 = pricetrans.TransValue(_pivot.Y > _destination.Y ? Env.Preference.InverseChart ? range_min : range_max : Env.Preference.InverseChart ? range_max : range_min);//☆Fibonacci 20180816 変更
  107. }
  108. else
  109. {
  110. y1 = _pivot.Y < _destination.Y ? Env.Preference.InverseChart ? _pivot.Y : _destination.Y : Env.Preference.InverseChart ? _destination.Y : _pivot.Y;
  111. y2 = _pivot.Y < _destination.Y ? Env.Preference.InverseChart ? _destination.Y : _pivot.Y : Env.Preference.InverseChart ? _pivot.Y : _destination.Y;
  112. }
  113. //ここまで
  114. //_pivot = new PointF(x1, (float)y1);//☆Fibonacci 20180816 コメントアウト
  115. //_destination = new PointF(x2, (float)y2);//☆Fibonacci 20180816 コメントアウト
  116. _pivot = new PointF(_pivot.X < _destination.X ? Math.Min(x1, x2) : Math.Max(x1, x2), _pivot.Y < _destination.Y ? (float)Math.Min(y1, y2) : (float)Math.Max(y1, y2));//☆Fibonacci 20180816 新規追加
  117. _destination = new PointF(_pivot.X < _destination.X ? Math.Max(x1, x2) : Math.Min(x1, x2), _pivot.Y < _destination.Y ? (float)Math.Max(y1, y2) : (float)Math.Min(y1, y2));//☆Fibonacci 20180816 新規追加
  118. }
  119. private double Max(DataFarm farm, int ind1, int ind2)
  120. {
  121. var pos = ind1;
  122. var max = double.MinValue;
  123. var last = ind2 > farm.FilledLength ? farm.FilledLength - 1 : ind2;
  124. try
  125. {
  126. while (pos <= last)
  127. {
  128. var a = BitConverter.ToInt32(farm.RawDataImage, pos * 32 + 4 * 2) * farm.Brand.PriceScale / (Env.Preference.AdjustSplit ? farm.CalcSplitRatio(BitConverter.ToInt32(farm.RawDataImage, pos * 32)) : 1);
  129. Console.WriteLine(pos);
  130. if (max < a) max = a;
  131. pos++;
  132. }
  133. }catch(Exception ex)
  134. {
  135. Console.WriteLine(ex.Message);
  136. }
  137. return max;
  138. }
  139. private double Min(DataFarm farm, int ind1, int ind2)
  140. {
  141. var pos = ind1;
  142. var min = double.MaxValue;
  143. var last = ind2 > farm.FilledLength ? farm.FilledLength - 1 : ind2;
  144. while (pos <= last)
  145. {
  146. var a = BitConverter.ToInt32(farm.RawDataImage, pos * 32 + 4 * 3) * farm.Brand.PriceScale / (Env.Preference.AdjustSplit ? farm.CalcSplitRatio(BitConverter.ToInt32(farm.RawDataImage, pos * 32)) : 1);
  147. if (min > a) min = a;
  148. pos++;
  149. }
  150. return min;
  151. }
  152. public Rectangle GetInclusion(Rectangle rect)
  153. {
  154. if (_pivot == _destination)
  155. return new Rectangle(new Point((int)_pivot.X, (int)_pivot.Y), new Size(0, 0));
  156. Point[] es = GetEdge(rect, new Point((int)_pivot.X, (int)_pivot.Y), new Point((int)_destination.X, (int)_destination.Y));
  157. return new Rectangle(Math.Min(es[0].X, es[1].X), Math.Min(es[0].Y, es[1].Y), Math.Abs(es[0].X - es[1].X), Math.Abs(es[0].Y - es[1].Y));
  158. }
  159. //十分に離した位置でないと線を確定させないようにする
  160. public bool PivotHasEnoughDistanceTo(PointF pt)
  161. {
  162. return Math.Abs(_pivot.X - pt.X) > 10 || Math.Abs(_pivot.Y - pt.Y) > 10;
  163. }
  164. //☆Fibonacci 20180816 Drawはまるまる書き直し ここから
  165. public void Draw(Trans pricetrans, Rectangle rect, IntPtr hdc)
  166. {
  167. Win32.POINT pt = new Win32.POINT();
  168. //Win32.SelectObject(hdc, _mode == LineDrawMode.Normal ? Env.Preference.FibonacciPen.Handle : Env.Preference.FibonacciBoldPen.Handle);//☆Fibonacci 20180816 コメントアウト
  169. //var fibo = new double[] { -2.618, -1.618, 0, .236, .382, .5, .618, .764, 1, 1.618, 2.618 };
  170. //var fibo = new double[] { 0, .236, .382, .5, .618, .764, 1 };
  171. var fibo = new double[] { 0, .382, .5, .618, 1 };
  172. foreach (var f in fibo)
  173. {
  174. Win32.SelectObject(hdc, f == 0 ? Env.Preference.FibonacciBoldPen.Handle : f == 1 ? Env.Preference.FibonacciPen.Handle : f == .5 ? Env.Preference.FibonacciPen.Handle : Env.Preference.FibonacciDottedPen.Handle);//☆Fibonacci 20180816 追加
  175. FibonacciDrawLines fdl = new FibonacciDrawLines(_pivot, _destination, f, fibo);
  176. fdl.Draw(pricetrans, rect, hdc, out pt);
  177. }
  178. }//ここまで
  179. //☆Fibonacci 20180816 追加
  180. private void DrawTheLine(IntPtr hdc, float px1, float px2, float py, double kabuka, string text, out Win32.POINT pt)
  181. {
  182. Win32.MoveToEx(hdc, (int)px1, (int)py, out pt);
  183. Win32.LineTo(hdc, (int)px2, (int)py);
  184. DrawText(hdc, (int)px2, (int)py, kabuka);
  185. DrawText(hdc, (int)px1 - 30, (int)py, text);
  186. }
  187. private void DrawText(IntPtr hdc, int x, int y, string s)
  188. {
  189. Win32.SetTextColor(hdc, Util.ToCOLORREF(Color.White));
  190. ChartUtil.DrawText(hdc, x + 3, y - 6, s);
  191. }
  192. private void DrawTheLine(IntPtr hdc, float px1, float px2, float py, double kabuka, out Win32.POINT pt)
  193. {
  194. Win32.MoveToEx(hdc, (int)px1, (int)py, out pt);
  195. Win32.LineTo(hdc, (int)px2, (int)py);
  196. DrawText(hdc, (int)px2, (int)py, kabuka);
  197. }
  198. private void DrawText(IntPtr hdc, int x, int y, double d)
  199. {
  200. Win32.SetTextColor(hdc, Util.ToCOLORREF(Color.White));
  201. ChartUtil.DrawText(hdc, x + 3, y - 6, string.Format("{0:N}", d));
  202. }
  203. //p1,p2がrectに入っているとき、p1からp2に伸ばした線とp2からp1に伸ばした線がそれぞれrectと交差するところを返す
  204. private static Point[] GetEdge(Rectangle rect, Point p1, Point p2)
  205. {
  206. Point[] result = new Point[2];
  207. ArrayList ar = GetAllEdges(rect, p1, p2);
  208. if (ar.Count == 2) return (Point[])ar.ToArray(typeof(Point));
  209. result[0] = (Point)(p1.X > p2.X ? ar[1] : ar[2]);
  210. result[1] = (Point)(p1.X > p2.X ? ar[2] : ar[1]);
  211. return result;
  212. }
  213. //p1とp2を結ぶ線がrectを構成する4直線と交差する点を返す。水平・垂直のときは2個になる
  214. private static ArrayList GetAllEdges(Rectangle rect, Point p1, Point p2)
  215. {
  216. ArrayList ar = new ArrayList();
  217. if (p1.X == p2.X)
  218. {
  219. ar.Add(new Point(p1.X, p1.Y < p2.Y ? rect.Bottom : rect.Top));
  220. ar.Add(new Point(p1.X, p1.Y > p2.Y ? rect.Bottom : rect.Top));
  221. return ar;
  222. }
  223. else if (p1.Y == p2.Y)
  224. {
  225. ar.Add(new Point(p1.X < p2.X ? rect.Right : rect.Left, p1.Y));
  226. ar.Add(new Point(p1.X > p2.X ? rect.Right : rect.Left, p1.Y));
  227. return ar;
  228. }
  229. LinearTrans lt = LinearTrans.Solve(p1.X, p1.Y, p2.X, p2.Y);
  230. ar.Add(new Point(rect.Left, (int)lt.TransValue(rect.Left)));
  231. ar.Add(new Point(rect.Right, (int)lt.TransValue(rect.Right)));
  232. ar.Add(new Point((int)lt.Inverse(rect.Top), rect.Top));
  233. ar.Add(new Point((int)lt.Inverse(rect.Bottom), rect.Bottom));
  234. //この4点をX座標の順に並べ、2番目と3番目が答え
  235. ar.Sort(new PointComparer());
  236. return ar;
  237. }
  238. private class PointComparer : IComparer
  239. {
  240. public int Compare(object x, object y)
  241. {
  242. return ((Point)x).X - ((Point)y).X;
  243. }
  244. }
  245. public SolidFibonacci ToSolid(DataFarm farm, int firstdateindex, Trans value_to_y)
  246. {
  247. SolidFibonacci fl = new SolidFibonacci();
  248. int ind1 = firstdateindex + (int)Math.Floor((double)_pivot.X / Env.Layout.DatePitch);
  249. int ind2 = firstdateindex + (int)Math.Floor((double)_destination.X / Env.Layout.DatePitch);
  250. LinearTrans tr = LinearTrans.Solve(ind1, _pivot.Y, ind2, _destination.Y);
  251. double y1 = _pivot.Y;
  252. if (ind1 >= farm.FilledLength)
  253. {
  254. ind1 = farm.FilledLength - 1;
  255. //y1 = tr.TransValue(ind1);//☆Fibonacci 20180816 コメントアウト freelineと違ってy軸、つまり株価は移動しなくていい
  256. }
  257. else if (ind1 < 0)
  258. {
  259. ind1 = 0;
  260. y1 = tr.TransValue(ind1);
  261. }
  262. fl._date1 = farm.GetByIndex(ind1).Date;
  263. fl._value1 = value_to_y.Inverse(y1);
  264. double y2 = _destination.Y;
  265. if (ind2 >= farm.FilledLength)
  266. {
  267. ind2 = farm.FilledLength - 1;
  268. //y2 = tr.TransValue(ind2);//☆Fibonacci 20180816 コメントアウト freelineと違ってy軸、つまり株価は移動しなくていい
  269. }
  270. else if (ind2 < 0)
  271. {
  272. ind2 = 0;
  273. y2 = tr.TransValue(0);
  274. }
  275. fl._date2 = farm.GetByIndex(ind2).Date;
  276. fl._value2 = value_to_y.Inverse(y2);
  277. //_id==-1は作ったばかりのフィボナッチで、0以上は既存フィボナッチ
  278. if (_id == -1)
  279. {
  280. fl._id = SolidFibonacci.NextID++;
  281. _id = fl._id;
  282. }
  283. else
  284. {
  285. fl._id = _id;
  286. }
  287. return fl;
  288. }
  289. //☆Fibonacci 20180816 変更 GetDistanceは全面的に書き直し
  290. public double GetDistance(Point p)
  291. {
  292. return Math.Min(GetDistanceUpside(p), GetDistanceDownside(p));
  293. }
  294. //☆Fibonacci 20180816 新規
  295. //最上部のフィボナッチラインとマウスカーソルとの直線距離
  296. //マウスカーソルがフィボナッチラインの幅内にあった場合のみ、マウスカーソルと最上部フィボナッチラインの縦幅を計測して返す
  297. public double GetDistanceUpside(Point p)
  298. {
  299. var y = Math.Min(_pivot.Y, _destination.Y);
  300. var xl = Math.Min(_pivot.X, _destination.X);
  301. var xr = Math.Max(_pivot.X, _destination.X);
  302. return (p.X < xl || xr < p.X) ? double.MaxValue : Math.Abs(y - p.Y);
  303. }
  304. //☆Fibonacci 20180816 新規
  305. //最下部のフィボナッチラインとマウスカーソルとの直線距離
  306. //マウスカーソルがフィボナッチラインの幅内にあった場合のみ、マウスカーソルと最下部フィボナッチラインの縦幅を計測して返す
  307. public double GetDistanceDownside(Point p)
  308. {
  309. var y = Math.Max(_pivot.Y, _destination.Y);
  310. var xl = Math.Min(_pivot.X, _destination.X);
  311. var xr = Math.Max(_pivot.X, _destination.X);
  312. return (p.X < xl || xr < p.X) ? double.MaxValue : Math.Abs(y - p.Y);
  313. }
  314. //両端を通る直線を ax+by+c=0, a^2+b^2=1 となる形式でa,b,cの配列で返す
  315. private double[] GetNormalizedParam()
  316. {
  317. double a, b, c;
  318. if (_pivot.X == _destination.X)
  319. {
  320. a = 1;
  321. b = 0;
  322. }
  323. else
  324. {
  325. double d = -(_pivot.Y - _destination.Y) / (double)(_pivot.X - _destination.X);
  326. b = Math.Sqrt(1 / (1 + d * d));
  327. a = b * d;
  328. }
  329. c = -(a * _pivot.X + b * _pivot.Y);
  330. return new double[] { a, b, c };
  331. }
  332. }
  333. internal class SolidFibonacci
  334. {
  335. public int _id;
  336. public int _code;
  337. public ChartFormat _targetFormat;
  338. public bool _logScale;
  339. public int _date1;
  340. public double _value1;
  341. public int _date2;
  342. public double _value2;
  343. private static int _nextID;
  344. public static int NextID
  345. {
  346. get
  347. {
  348. return _nextID;
  349. }
  350. set
  351. {
  352. _nextID = value;
  353. }
  354. }
  355. }
  356. internal class FibonacciCollection
  357. {
  358. private ArrayList _data;
  359. public FibonacciCollection()
  360. {
  361. _data = new ArrayList();
  362. }
  363. public int Count
  364. {
  365. get
  366. {
  367. return _data.Count;
  368. }
  369. }
  370. public void Add(AbstractBrand br, ChartFormat format, bool logScale, SolidFibonacci fl)
  371. {
  372. fl._code = br.Code;
  373. fl._targetFormat = format;
  374. fl._logScale = logScale;
  375. _data.Add(fl);
  376. }
  377. public SolidFibonacci[] Find(AbstractBrand br, ChartFormat format, bool logScale)
  378. {
  379. ArrayList t = new ArrayList();
  380. foreach (SolidFibonacci fl in _data)
  381. {
  382. if (fl._code == br.Code && fl._targetFormat == format && fl._logScale == logScale)
  383. t.Add(fl);
  384. }
  385. return (SolidFibonacci[])t.ToArray(typeof(SolidFibonacci));
  386. }
  387. public void ClearAll()
  388. {
  389. _data.Clear();
  390. }
  391. public void Clear(AbstractBrand br, ChartFormat format, bool logScale)
  392. {
  393. ArrayList temp = new ArrayList();
  394. IEnumerator ie = _data.GetEnumerator();
  395. while (ie.MoveNext())
  396. {
  397. SolidFibonacci fl = (SolidFibonacci)ie.Current;
  398. if (!(fl._code == br.Code && fl._targetFormat == format && fl._logScale == logScale))
  399. temp.Add(fl);
  400. }
  401. _data = temp;
  402. }
  403. public void Remove(int id)
  404. {
  405. for (int i = 0; i < _data.Count; i++)
  406. {
  407. SolidFibonacci l = (SolidFibonacci)_data[i];
  408. if (l._id == id)
  409. {
  410. _data.RemoveAt(i);
  411. break;
  412. }
  413. }
  414. }
  415. public void Load(StorageNode parent)
  416. {
  417. string t = parent["fibonacci-lines"];
  418. if (t == null) return;
  419. foreach (string ee in t.Split(','))
  420. {
  421. if (ee == null) continue;
  422. if (ee.Trim() == string.Empty) continue;
  423. SolidFibonacci fl = new SolidFibonacci();
  424. string[] e = ee.Split(':');
  425. fl._code = Int32.Parse(e[0]);
  426. switch (e[1])
  427. {
  428. case "D":
  429. fl._targetFormat = ChartFormat.Daily;
  430. fl._logScale = false;
  431. break;
  432. case "W":
  433. fl._targetFormat = ChartFormat.Weekly;
  434. fl._logScale = false;
  435. break;
  436. case "M":
  437. fl._targetFormat = ChartFormat.Monthly;
  438. fl._logScale = false;
  439. break;
  440. case "Y":
  441. fl._targetFormat = ChartFormat.Yearly;
  442. fl._logScale = false;
  443. break;
  444. case "DL":
  445. fl._targetFormat = ChartFormat.Daily;
  446. fl._logScale = true;
  447. break;
  448. case "WL":
  449. fl._targetFormat = ChartFormat.Weekly;
  450. fl._logScale = true;
  451. break;
  452. case "ML":
  453. fl._targetFormat = ChartFormat.Monthly;
  454. fl._logScale = true;
  455. break;
  456. case "YL":
  457. fl._targetFormat = ChartFormat.Yearly;
  458. fl._logScale = true;
  459. break;
  460. }
  461. fl._date1 = Int32.Parse(e[2]);
  462. fl._value1 = Double.Parse(e[3]);
  463. fl._date2 = Int32.Parse(e[4]);
  464. fl._value2 = Double.Parse(e[5]);
  465. fl._id = SolidFibonacci.NextID++;
  466. _data.Add(fl);
  467. }
  468. }
  469. public void SaveTo(StorageNode parent)
  470. {
  471. StringBuilder bld = new StringBuilder();
  472. foreach (SolidFibonacci sl in _data)
  473. {
  474. if (bld.Length > 0) bld.Append(",");
  475. String format;
  476. switch (sl._targetFormat)
  477. {
  478. case ChartFormat.Daily:
  479. default:
  480. format = "D";
  481. break;
  482. case ChartFormat.Weekly:
  483. format = "W";
  484. break;
  485. case ChartFormat.Monthly:
  486. format = "M";
  487. break;
  488. case ChartFormat.Yearly:
  489. format = "Y";
  490. break;
  491. }
  492. if (sl._logScale)
  493. {
  494. format += "L";
  495. }
  496. bld.Append(String.Format("{0}:{1}:{2}:{3:F2}:{4}:{5:F2}", sl._code, format, sl._date1, sl._value1, sl._date2, sl._value2));
  497. }
  498. parent["fibonacci-lines"] = bld.ToString();
  499. }
  500. }
  501. //☆Fibonacci 20180816 新規追加
  502. internal class FibonacciDrawLines
  503. {
  504. bool _log = false;
  505. PointF _pivot;
  506. PointF _dest;
  507. double _fibopos = .0;
  508. double[] _fibonacci;
  509. string _text = string.Empty;
  510. public FibonacciDrawLines(PointF pivot, PointF dest, double fibopos, double[] fibonacci)
  511. {
  512. _pivot = pivot;
  513. _dest = dest;
  514. _fibopos = fibopos;
  515. _fibonacci = fibonacci;
  516. }
  517. public void Draw(Trans pricetrans, Rectangle rect, IntPtr hdc, out Win32.POINT pt)
  518. {
  519. var k = retKabuka(pricetrans);
  520. var y = (int)retY(k, pricetrans);
  521. Win32.MoveToEx(hdc, (int)Math.Min(_pivot.X, _dest.X), y, out pt);
  522. Win32.LineTo(hdc, (int)Math.Max(_pivot.X, _dest.X), y);
  523. DrawText(hdc, (int)Math.Max(_pivot.X, _dest.X), y, k);
  524. DrawText(hdc, (int)Math.Min(_pivot.X, _dest.X) - 30, y, retText());
  525. }
  526. private string retText()
  527. {
  528. return _fibopos == 0 ? _pivot.Y < _dest.Y ? "100" : "0" : //マウスが上から下に動いてフィボナッチリトレースメントを作ったとき逆転させる
  529. _fibopos == 1 ? _pivot.Y < _dest.Y ? "0" : "100" : //マウスが上から下に動いてフィボナッチリトレースメントを作ったとき逆転させる
  530. string.Format("{0:00.0}", _fibopos * 100);//天底以外の数値(0.618とか)はretKabukaでハンドリングするのでここでは逆転させない
  531. }
  532. private double retKabuka(Trans pricetrans)
  533. {
  534. var ret = .0;
  535. if (_log)//対数チャートの場合
  536. {
  537. //上下逆転チャートではない、かつマウスを下から上に引いて作った、 もしくは上下逆転チャート、かつマウスを上から下に引いて作った
  538. if ((!Env.Preference.InverseChart && _pivot.Y > _dest.Y) || (Env.Preference.InverseChart && _pivot.Y < _dest.Y))
  539. {
  540. ret = _fibopos == 0 ? pricetrans.Inverse(Math.Min(_pivot.Y, _dest.Y))
  541. : _fibopos == 1 ? pricetrans.Inverse(Math.Max(_pivot.Y, _dest.Y))
  542. : pricetrans.Inverse(Math.Max(_pivot.Y, _dest.Y) - Math.Abs(_pivot.Y - _dest.Y) * _fibopos);
  543. }
  544. else
  545. {
  546. ret = _fibopos == 0 ? pricetrans.Inverse(Math.Min(_pivot.Y, _dest.Y))
  547. : _fibopos == 1 ? pricetrans.Inverse(Math.Max(_pivot.Y, _dest.Y))
  548. : pricetrans.Inverse(Math.Min(_pivot.Y, _dest.Y) + Math.Abs(_pivot.Y - _dest.Y) * _fibopos);
  549. }
  550. }
  551. else
  552. {
  553. var k1 = pricetrans.Inverse(Math.Min(_pivot.Y, _dest.Y));
  554. var k5 = pricetrans.Inverse(Math.Max(_pivot.Y, _dest.Y));
  555. //上下逆転チャートではない、かつマウスを下から上に引いて作った、 もしくは上下逆転チャート、かつマウスを上から下に引いて作った
  556. if ((!Env.Preference.InverseChart && _pivot.Y > _dest.Y) || (Env.Preference.InverseChart && _pivot.Y < _dest.Y))
  557. {
  558. ret = _fibopos == 0 ? k1 : _fibopos == 1 ? k5 : Math.Max(k1, k5) - Math.Abs(k1 - k5) * _fibopos;
  559. }
  560. else
  561. {
  562. ret = _fibopos == 0 ? k1 : _fibopos == 1 ? k5 : Math.Min(k1, k5) + Math.Abs(k1 - k5) * _fibopos;
  563. }
  564. }
  565. return ret;
  566. }
  567. private float retY(double k, Trans pricetrans)
  568. {
  569. var ret = 0F;
  570. if (_log)
  571. {
  572. ret = _fibopos == 0 ? Math.Min(_pivot.Y, _dest.Y)
  573. : _fibopos == 1 ? Math.Max(_pivot.Y, _dest.Y)
  574. : (float)(Math.Abs(_pivot.Y - _dest.Y) * _fibopos + Math.Min(_pivot.Y, _dest.Y));
  575. }
  576. else
  577. {
  578. ret = _fibopos == 0 ? Math.Min(_pivot.Y, _dest.Y)
  579. : _fibopos == 1 ? Math.Max(_pivot.Y, _dest.Y)
  580. : (float)pricetrans.TransValue(k);
  581. }
  582. return ret;
  583. }
  584. private void DrawText(IntPtr hdc, int x, int y, string s)
  585. {
  586. Win32.SetTextColor(hdc, Util.ToCOLORREF(Color.White));
  587. ChartUtil.DrawText(hdc, x + 3, y - 6, s);
  588. }
  589. private void DrawText(IntPtr hdc, int x, int y, double d)
  590. {
  591. Win32.SetTextColor(hdc, Util.ToCOLORREF(Color.White));
  592. ChartUtil.DrawText(hdc, x + 3, y - 6, string.Format("{0:N}", d));
  593. }
  594. }
  595. }
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト