Advertisement
Guest User

pretty_oscillators

a guest
Oct 13th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1. oscillator = rsi(20);
  2.  
  3. lowBound = 40;
  4. highBound = 60;
  5.  
  6. oscilMax = 80;
  7. oscilMin = 20;
  8.  
  9.  
  10. /*
  11.    -------------------------------------------------------------------
  12.                       HIGH BOUNDARY of PLOT
  13.      PLOT `oscillator`, fill to zero with color/hatch, then plot
  14.      `highBound` line and fill to zero with Green
  15.    -------------------------------------------------------------------
  16. */
  17. // first plot the oscillator
  18. // if you want color filled zone, use :
  19. plot(oscillator, "Choppiness Index", colorRed|50, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
  20. // if you dont want a color filled zone, use :
  21. //plot(oscillator, "Choppiness Index", colorLightGray);
  22.  
  23. // hatch underneath it
  24. SetHatchBrush("BackwardDiagonal", colorRed); // hatch zone under index curve
  25. Plot(highBound, "", colorWhite|255, ChartLine, StyleDotted|StyleNoScale|StyleWidth0); // erase all under `highBound` horiz line
  26.  
  27. /*
  28.    -------------------------------------------------------------------
  29.                       LOW BOUNDARY of PLOT
  30.      PLOT segments of `lowBound` line where `choppiness` < `lowBound`
  31.      and fill to zero with Green
  32.      (we have to segment so as not to erase the previous plot of
  33.       highbound color fill/hatch)
  34.    -------------------------------------------------------------------
  35. */
  36. // determine segments
  37. a = iff(oscillator <= lowBound, lowBound, 0);
  38.  
  39. // if you wish to fill the zone with a single color instead of hatching it,
  40. // replace following line with : Plot(a, "", colorGreen|55, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
  41. // otherwise, use Plot(a, "", colorGreen, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
  42.  
  43. Plot(a, "", colorGreen|50, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
  44.  
  45. // hatch the zone (comment out if you do not want to hatch)
  46. SetHatchBrush("BackwardDiagonal", colorGreen); // hatch zone under index curve
  47.  
  48. // erase all under `oscillator` in the zone where `oscillator` < `lowBound`
  49. b = iff(oscillator <= lowBound, oscillator, 0);
  50. Plot(b, "", colorWhite|255, ChartLine, StyleDotted|StyleNoScale|StyleWidth0);
  51.  
  52. /*
  53.    -------------------------------------------------------------------
  54.                       MAIN CURVE
  55.      Finally, plot the whole curve again, and adapt colors of its
  56.      sections.
  57.    -------------------------------------------------------------------
  58. */
  59.  
  60. // refresh the oscillator line
  61. plot(oscillator, "Choppiness Index", colorDarkGray);
  62. // optionally : overwrite lowBound portion with custom color
  63. testLow =  oscillator < lowBound and oscillator[-1] < lowBound; // in order to have fastcross segments colored
  64. updatecolor(testLow, colorDarkGreen);
  65. testHigh =  oscillator > highBound and oscillator[-1] > highBound; // in order to have fastcross segments colored
  66. updatecolor(testHigh, colorDarkRed);
  67.  
  68.  
  69.  
  70. // finally plot the `highBound` and `lowBound` lines
  71. Plot(highBound, 'high', colorLightGray, ChartLine,StyleDashed); // `highBound` horiz line
  72. Plot(lowBound, 'low', colorLightGray, ChartLine,StyleDashed);
  73.  
  74. // and the oscilMax & oscilMin so as to frame the region
  75. Plot(oscilMax, "", colorTransparent);
  76. Plot(oscilMin, "", colorTransparent);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement