Drawing2PointLinkedBase.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. using MuchInfo.Chart.Data.Interfaces;
  2. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  3. using System;
  4. using System.Diagnostics;
  5. namespace MuchInfo.Chart.WPF.Primitives.Drawing
  6. {
  7. public abstract class Drawing2PointLinkedBase : Drawing2PointBase
  8. {
  9. protected Drawing2PointLinkedBase()
  10. {
  11. }
  12. public abstract override bool CanPlotOnAllSymbols();
  13. protected ILineDataSetWithUid GetLinkedPlot()
  14. {
  15. bool flag = this.mLastScale != null && this.mLastScale.AllPlots.Count > 0;
  16. ILineDataSetWithUid result;
  17. if (flag)
  18. {
  19. PlotBase plotBase = this.mLastScale.AllPlots[0];
  20. flag = (plotBase is LinePlot);
  21. if (flag)
  22. {
  23. result = ((LinePlot)plotBase).LinePlot_4866();
  24. return result;
  25. }
  26. }
  27. result = null;
  28. return result;
  29. }
  30. protected void CalcHighLowForPoints(DateTime date1, DateTime date2, ref float High, ref float Low)
  31. {
  32. ILineDataSet linkedPlot = this.GetLinkedPlot();
  33. bool flag = linkedPlot == null;
  34. checked
  35. {
  36. if (!flag)
  37. {
  38. int num = -1;
  39. int num2 = -1;
  40. DateTime dateTime = date1;
  41. DateTime dateTime2 = date2;
  42. flag = (DateTime.Compare(dateTime, dateTime2) > 0);
  43. if (flag)
  44. {
  45. DateTime dateTime3 = dateTime;
  46. dateTime = dateTime2;
  47. dateTime2 = dateTime3;
  48. }
  49. int num3 = linkedPlot.DataPoints.Count - 1;
  50. while (true)
  51. {
  52. int arg_E8_0 = num3;
  53. int num4 = 0;
  54. if (arg_E8_0 < num4)
  55. {
  56. break;
  57. }
  58. flag = (num2 == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime2) <= 0);
  59. if (flag)
  60. {
  61. num2 = num3;
  62. }
  63. flag = (num == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime) <= 0);
  64. if (flag)
  65. {
  66. num = num3;
  67. }
  68. flag = (num2 >= 0 && num >= 0);
  69. if (flag)
  70. {
  71. break;
  72. }
  73. num3 += -1;
  74. }
  75. flag = (num == -1 || num2 == -1);
  76. if (!flag)
  77. {
  78. int arg_10B_0 = num;
  79. int num5 = num2;
  80. int num6 = arg_10B_0;
  81. while (true)
  82. {
  83. int arg_24B_0 = num6;
  84. int num4 = num5;
  85. if (arg_24B_0 > num4)
  86. {
  87. break;
  88. }
  89. flag = (num6 == num);
  90. if (flag)
  91. {
  92. bool flag2 = linkedPlot.DataPoints[num6] is IOHLCDataPoint;
  93. if (flag2)
  94. {
  95. High = ((IOHLCDataPoint)linkedPlot.DataPoints[num6]).High;
  96. Low = ((IOHLCDataPoint)linkedPlot.DataPoints[num6]).Low;
  97. }
  98. else
  99. {
  100. High = linkedPlot.DataPoints[num6].Value;
  101. Low = linkedPlot.DataPoints[num6].Value;
  102. }
  103. }
  104. else
  105. {
  106. bool flag2 = linkedPlot.DataPoints[num6] is IOHLCDataPoint;
  107. if (flag2)
  108. {
  109. High = Math.Max(High, ((IOHLCDataPoint)linkedPlot.DataPoints[num6]).High);
  110. Low = Math.Min(Low, ((IOHLCDataPoint)linkedPlot.DataPoints[num6]).Low);
  111. }
  112. else
  113. {
  114. High = Math.Max(High, linkedPlot.DataPoints[num6].Value);
  115. Low = Math.Min(Low, linkedPlot.DataPoints[num6].Value);
  116. }
  117. }
  118. num6++;
  119. }
  120. }
  121. }
  122. }
  123. }
  124. protected void CalcRegressionForPoints(DateTime Date1, DateTime Date2, ref float Val1, ref float Val2)
  125. {
  126. ILineDataSet linkedPlot = this.GetLinkedPlot();
  127. bool flag = linkedPlot == null;
  128. checked
  129. {
  130. if (!flag)
  131. {
  132. int num = -1;
  133. int num2 = -1;
  134. DateTime dateTime = Date1;
  135. DateTime dateTime2 = Date2;
  136. bool flag2 = false;
  137. flag = (DateTime.Compare(dateTime, dateTime2) > 0);
  138. if (flag)
  139. {
  140. flag2 = true;
  141. DateTime dateTime3 = dateTime;
  142. dateTime = dateTime2;
  143. dateTime2 = dateTime3;
  144. }
  145. int num3 = linkedPlot.DataPoints.Count - 1;
  146. while (true)
  147. {
  148. int arg_F3_0 = num3;
  149. int num4 = 0;
  150. if (arg_F3_0 < num4)
  151. {
  152. break;
  153. }
  154. flag = (num2 == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime2) <= 0);
  155. if (flag)
  156. {
  157. num2 = num3;
  158. }
  159. flag = (num == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime) <= 0);
  160. if (flag)
  161. {
  162. num = num3;
  163. }
  164. flag = (num2 >= 0 && num >= 0);
  165. if (flag)
  166. {
  167. break;
  168. }
  169. num3 += -1;
  170. }
  171. flag = (num == -1 || num2 == -1);
  172. if (!flag)
  173. {
  174. int num5 = num2 - num + 1;
  175. flag = (num5 == 0);
  176. if (!flag)
  177. {
  178. int arg_12F_0 = num;
  179. int num6 = num2;
  180. int num7 = arg_12F_0;
  181. double num9 = 0;
  182. double num10 = 0;
  183. double num11 = 0;
  184. double num12 = 0;
  185. while (true)
  186. {
  187. int arg_19D_0 = num7;
  188. int num4 = num6;
  189. if (arg_19D_0 > num4)
  190. {
  191. break;
  192. }
  193. int num8 = num7 - num + 1;
  194. unchecked
  195. {
  196. num9 += (double)num8;
  197. num10 += (double)linkedPlot.DataPoints[num7].Value;
  198. num11 += (double)(linkedPlot.DataPoints[num7].Value * (float)num8);
  199. num12 += Math.Pow((double)num8, 2.0);
  200. }
  201. num7++;
  202. }
  203. unchecked
  204. {
  205. flag = ((double)num5 * num12 - Math.Pow(num9, 2.0) == 0.0);
  206. if (!flag)
  207. {
  208. double num13 = ((double)num5 * num11 - num9 * num10) / ((double)num5 * num12 - Math.Pow(num9, 2.0));
  209. double num14 = (num10 - num13 * num9) / (double)num5;
  210. flag = flag2;
  211. if (flag)
  212. {
  213. Val2 = (float)(num13 * 1.0 + num14);
  214. Val1 = (float)(num13 * (double)num5 + num14);
  215. }
  216. else
  217. {
  218. Val1 = (float)(num13 * 1.0 + num14);
  219. Val2 = (float)(num13 * (double)num5 + num14);
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. protected float CalcRaffRegressionForPoints(DateTime Date1, DateTime Date2, ref float Val1, ref float Val2)
  229. {
  230. ILineDataSet linkedPlot = this.GetLinkedPlot();
  231. bool flag = linkedPlot == null;
  232. checked
  233. {
  234. float result = 0f;
  235. if (!flag)
  236. {
  237. int num = -1;
  238. int num2 = -1;
  239. DateTime dateTime = Date1;
  240. DateTime dateTime2 = Date2;
  241. bool flag2 = false;
  242. flag = (DateTime.Compare(dateTime, dateTime2) > 0);
  243. if (flag)
  244. {
  245. flag2 = true;
  246. DateTime dateTime3 = dateTime;
  247. dateTime = dateTime2;
  248. dateTime2 = dateTime3;
  249. }
  250. int num3 = linkedPlot.DataPoints.Count - 1;
  251. while (true)
  252. {
  253. int arg_F8_0 = num3;
  254. int num4 = 0;
  255. if (arg_F8_0 < num4)
  256. {
  257. break;
  258. }
  259. flag = (num2 == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime2) <= 0);
  260. if (flag)
  261. {
  262. num2 = num3;
  263. }
  264. flag = (num == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime) <= 0);
  265. if (flag)
  266. {
  267. num = num3;
  268. }
  269. flag = (num2 >= 0 && num >= 0);
  270. if (flag)
  271. {
  272. break;
  273. }
  274. num3 += -1;
  275. }
  276. flag = (num == -1 || num2 == -1);
  277. if (!flag)
  278. {
  279. int num5 = num2 - num + 1;
  280. flag = (num5 == 0);
  281. if (!flag)
  282. {
  283. int arg_134_0 = num;
  284. int num6 = num2;
  285. int num7 = arg_134_0;
  286. double num9 = 0;
  287. double num10 = 0;
  288. double num11 = 0;
  289. double num12 = 0;
  290. while (true)
  291. {
  292. int arg_1A2_0 = num7;
  293. int num4 = num6;
  294. if (arg_1A2_0 > num4)
  295. {
  296. break;
  297. }
  298. int num8 = num7 - num + 1;
  299. unchecked
  300. {
  301. num9 += (double)num8;
  302. num10 += (double)linkedPlot.DataPoints[num7].Value;
  303. num11 += (double)(linkedPlot.DataPoints[num7].Value * (float)num8);
  304. num12 += Math.Pow((double)num8, 2.0);
  305. }
  306. num7++;
  307. }
  308. unchecked
  309. {
  310. flag = ((double)num5 * num12 - Math.Pow(num9, 2.0) == 0.0);
  311. if (!flag)
  312. {
  313. double num13 = ((double)num5 * num11 - num9 * num10) / ((double)num5 * num12 - Math.Pow(num9, 2.0));
  314. double num14 = (num10 - num13 * num9) / (double)num5;
  315. flag = flag2;
  316. if (flag)
  317. {
  318. Val2 = (float)(num13 * 1.0 + num14);
  319. Val1 = (float)(num13 * (double)num5 + num14);
  320. }
  321. else
  322. {
  323. Val1 = (float)(num13 * 1.0 + num14);
  324. Val2 = (float)(num13 * (double)num5 + num14);
  325. }
  326. float num15 = 0f;
  327. int arg_257_0 = num;
  328. int num16 = num2;
  329. int num17 = arg_257_0;
  330. while (true)
  331. {
  332. int arg_328_0 = num17;
  333. int num4 = num16;
  334. if (arg_328_0 > num4)
  335. {
  336. break;
  337. }
  338. float num18 = (float)(num13 * (double)checked(num17 - num + 1) + num14);
  339. flag = (linkedPlot.DataPoints[num17] is IOHLCDataPoint);
  340. float num19;
  341. float num20;
  342. if (flag)
  343. {
  344. num19 = Math.Abs(num18 - ((IOHLCDataPoint)linkedPlot.DataPoints[num17]).High);
  345. num20 = Math.Abs(num18 - ((IOHLCDataPoint)linkedPlot.DataPoints[num17]).Low);
  346. }
  347. else
  348. {
  349. num19 = Math.Abs(num18 - linkedPlot.DataPoints[num17].Value);
  350. num20 = Math.Abs(num18 - linkedPlot.DataPoints[num17].Value);
  351. }
  352. num15 = Math.Max(num15, Math.Max(num19, num20));
  353. checked
  354. {
  355. num17++;
  356. }
  357. }
  358. result = num15;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. return result;
  365. }
  366. }
  367. protected float StandardDeviationBetweenPoints(DateTime Date1, DateTime Date2)
  368. {
  369. ILineDataSet linkedPlot = this.GetLinkedPlot();
  370. bool flag = linkedPlot == null;
  371. checked
  372. {
  373. float result = 0f;
  374. if (!flag)
  375. {
  376. int num = -1;
  377. int num2 = -1;
  378. DateTime dateTime = Date1;
  379. DateTime dateTime2 = Date2;
  380. flag = (DateTime.Compare(dateTime, dateTime2) > 0);
  381. if (flag)
  382. {
  383. DateTime dateTime3 = dateTime;
  384. dateTime = dateTime2;
  385. dateTime2 = dateTime3;
  386. }
  387. int num3 = linkedPlot.DataPoints.Count - 1;
  388. while (true)
  389. {
  390. int arg_F3_0 = num3;
  391. int num4 = 0;
  392. if (arg_F3_0 < num4)
  393. {
  394. break;
  395. }
  396. flag = (num2 == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime2) <= 0);
  397. if (flag)
  398. {
  399. num2 = num3;
  400. }
  401. flag = (num == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime) <= 0);
  402. if (flag)
  403. {
  404. num = num3;
  405. }
  406. flag = (num2 >= 0 && num >= 0);
  407. if (flag)
  408. {
  409. break;
  410. }
  411. num3 += -1;
  412. }
  413. flag = (num == -1 || num2 == -1);
  414. if (!flag)
  415. {
  416. int num5 = num2 - num + 1;
  417. flag = (num5 == 0);
  418. if (!flag)
  419. {
  420. int arg_12F_0 = num;
  421. int num6 = num2;
  422. int num7 = arg_12F_0;
  423. double num8 = 0;
  424. while (true)
  425. {
  426. int arg_15A_0 = num7;
  427. int num4 = num6;
  428. if (arg_15A_0 > num4)
  429. {
  430. break;
  431. }
  432. unchecked
  433. {
  434. num8 += (double)linkedPlot.DataPoints[num7].Value;
  435. }
  436. num7++;
  437. }
  438. double num9 = num8 / (double)num5;
  439. int arg_168_0 = num;
  440. int num10 = num2;
  441. int num11 = arg_168_0;
  442. double num12 = 0;
  443. while (true)
  444. {
  445. int arg_1A3_0 = num11;
  446. int num4 = num10;
  447. if (arg_1A3_0 > num4)
  448. {
  449. break;
  450. }
  451. unchecked
  452. {
  453. num12 += Math.Pow((double)linkedPlot.DataPoints[num11].Value - num9, 2.0);
  454. }
  455. num11++;
  456. }
  457. num12 = Math.Abs(num12 / (double)num5);
  458. result = (float)Math.Sqrt(num12);
  459. }
  460. }
  461. }
  462. return result;
  463. }
  464. }
  465. protected float StandardErrorBetweenPoints(DateTime Date1, DateTime Date2)
  466. {
  467. ILineDataSet linkedPlot = this.GetLinkedPlot();
  468. bool flag = linkedPlot == null;
  469. checked
  470. {
  471. float result = 0f;
  472. if (!flag)
  473. {
  474. int num = -1;
  475. int num2 = -1;
  476. DateTime dateTime = Date1;
  477. DateTime dateTime2 = Date2;
  478. flag = (DateTime.Compare(dateTime, dateTime2) > 0);
  479. if (flag)
  480. {
  481. DateTime dateTime3 = dateTime;
  482. dateTime = dateTime2;
  483. dateTime2 = dateTime3;
  484. }
  485. int num3 = linkedPlot.DataPoints.Count - 1;
  486. while (true)
  487. {
  488. int arg_F3_0 = num3;
  489. int num4 = 0;
  490. if (arg_F3_0 < num4)
  491. {
  492. break;
  493. }
  494. flag = (num2 == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime2) <= 0);
  495. if (flag)
  496. {
  497. num2 = num3;
  498. }
  499. flag = (num == -1 && DateTime.Compare(linkedPlot.DataPoints[num3].Date, dateTime) <= 0);
  500. if (flag)
  501. {
  502. num = num3;
  503. }
  504. flag = (num2 >= 0 && num >= 0);
  505. if (flag)
  506. {
  507. break;
  508. }
  509. num3 += -1;
  510. }
  511. flag = (num == -1 || num2 == -1);
  512. if (!flag)
  513. {
  514. int num5 = num2 - num + 1;
  515. flag = (num5 == 0);
  516. if (!flag)
  517. {
  518. int arg_12F_0 = num;
  519. int num6 = num2;
  520. int num7 = arg_12F_0;
  521. double num8 = 0;
  522. while (true)
  523. {
  524. int arg_15A_0 = num7;
  525. int num4 = num6;
  526. if (arg_15A_0 > num4)
  527. {
  528. break;
  529. }
  530. unchecked
  531. {
  532. num8 += (double)linkedPlot.DataPoints[num7].Value;
  533. }
  534. num7++;
  535. }
  536. double num9 = num8 / (double)num5;
  537. int arg_168_0 = num;
  538. int num10 = num2;
  539. int num11 = arg_168_0;
  540. double num12 = 0;
  541. while (true)
  542. {
  543. int arg_1A3_0 = num11;
  544. int num4 = num10;
  545. if (arg_1A3_0 > num4)
  546. {
  547. break;
  548. }
  549. unchecked
  550. {
  551. num12 += Math.Pow((double)linkedPlot.DataPoints[num11].Value - num9, 2.0);
  552. }
  553. num11++;
  554. }
  555. num12 = Math.Abs(num12 / (double)num5);
  556. result = (float)(Math.Sqrt(num12) / Math.Sqrt((double)num5));
  557. }
  558. }
  559. }
  560. return result;
  561. }
  562. }
  563. }
  564. }