Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Swing Indi Calculation
- public class SwingIndiClass
- {
- //export fix
- MAX max99999999; MIN min99999999;
- //public string ticksToString
- // pp.formedSwing("Low", this, Low, Strength, displace);
- public bool formedSwing(string type, NinjaTrader.NinjaScript.Indicators.Indicator indi, ISeries<double> h_l, int swingLength, int displace)
- {
- bool res=false;
- if( type == "High" )
- {
- var m = indi.MAX(h_l, swingLength);
- res = h_l[displace+0+swingLength] >= m[displace+0] && h_l[displace+0+swingLength] > m[displace+0+swingLength+1];
- }
- else if ( type == "Low" )
- {
- var m = indi.MIN(h_l, swingLength);
- res = h_l[displace+0+swingLength] <= m[displace+0] && h_l[displace+0+swingLength] < m[displace+0+swingLength+1];
- }
- return res;
- }
- internal bool isSwing(string type, PriceSeries highs_or_lows, int strength , bool equal_counts ){
- int index= strength;
- return isSwing_static( type, highs_or_lows, index, strength , equal_counts );
- }
- internal bool isSwing(string type, PriceSeries highs_or_lows, int index, int strength , bool equal_counts ){
- return isSwing_static( type, highs_or_lows, index, strength , equal_counts );
- }
- internal static bool isSwing_static(string type, PriceSeries highs_or_lows, int index, int strength , bool equal_counts )
- {
- if(index< strength) {
- throw new Exception("Index should be more than strengh");
- }
- int dir = type=="top" ? 1 : -1;
- bool peak_also = false;
- //if(equal_counts) peak_also=true;
- for( int i=1; i<=strength; i++){
- if( highs_or_lows[index] * dir < highs_or_lows[index+i] * dir || highs_or_lows[index] * dir < highs_or_lows[index-i] * dir ){
- return false;
- }
- if(!equal_counts){
- if( highs_or_lows[index] * dir > highs_or_lows[index+i] * dir || highs_or_lows[index] * dir > highs_or_lows[index-i] * dir ){
- peak_also=true;
- }
- }
- }
- if(peak_also) return true;
- return false;
- }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement