Advertisement
retesere20

SwingIndiCalculation NT8 C#

Jul 26th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #region Swing Indi Calculation
  2.  
  3. public class SwingIndiClass
  4. {
  5. //export fix
  6. MAX max99999999; MIN min99999999;
  7.  
  8. //public string ticksToString
  9. // pp.formedSwing("Low", this, Low, Strength, displace);
  10. public bool formedSwing(string type, NinjaTrader.NinjaScript.Indicators.Indicator indi, ISeries<double> h_l, int swingLength, int displace)
  11. {
  12. bool res=false;
  13. if( type == "High" )
  14. {
  15. var m = indi.MAX(h_l, swingLength);
  16. res = h_l[displace+0+swingLength] >= m[displace+0] && h_l[displace+0+swingLength] > m[displace+0+swingLength+1];
  17.  
  18. }
  19. else if ( type == "Low" )
  20. {
  21. var m = indi.MIN(h_l, swingLength);
  22. res = h_l[displace+0+swingLength] <= m[displace+0] && h_l[displace+0+swingLength] < m[displace+0+swingLength+1];
  23. }
  24. return res;
  25. }
  26.  
  27. internal bool isSwing(string type, PriceSeries highs_or_lows, int strength , bool equal_counts ){
  28. int index= strength;
  29. return isSwing_static( type, highs_or_lows, index, strength , equal_counts );
  30. }
  31.  
  32.  
  33. internal bool isSwing(string type, PriceSeries highs_or_lows, int index, int strength , bool equal_counts ){
  34. return isSwing_static( type, highs_or_lows, index, strength , equal_counts );
  35. }
  36.  
  37. internal static bool isSwing_static(string type, PriceSeries highs_or_lows, int index, int strength , bool equal_counts )
  38. {
  39. if(index< strength) {
  40. throw new Exception("Index should be more than strengh");
  41. }
  42.  
  43. int dir = type=="top" ? 1 : -1;
  44.  
  45. bool peak_also = false;
  46. //if(equal_counts) peak_also=true;
  47. for( int i=1; i<=strength; i++){
  48. if( highs_or_lows[index] * dir < highs_or_lows[index+i] * dir || highs_or_lows[index] * dir < highs_or_lows[index-i] * dir ){
  49. return false;
  50. }
  51. if(!equal_counts){
  52. if( highs_or_lows[index] * dir > highs_or_lows[index+i] * dir || highs_or_lows[index] * dir > highs_or_lows[index-i] * dir ){
  53. peak_also=true;
  54. }
  55. }
  56. }
  57. if(peak_also) return true;
  58. return false;
  59. }
  60. }
  61. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement