Advertisement
saisri

bull and bear volume

Jul 15th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. _SECTION_BEGIN("BullBear Volume");
  2.  
  3. C1 = Ref(C, -1);
  4. uc = C > C1; dc = C <= C1;
  5. ud = C > O; dd = C <= O;
  6.  
  7. green = 1; blue = 2; yellow = 3; red = 4; white = 5;
  8. VType = IIf(ud,
  9. IIf(uc, green, yellow),
  10. IIf(dd,
  11. IIf(dc, red, blue), white));
  12.  
  13.  
  14. gv = IIf(VType == green, V, 0);
  15. yv = IIf(VType == yellow, V, 0);
  16. rv = IIf(VType == red, V, 0);
  17. bv = IIf(VType == blue, V, 0);
  18.  
  19. uv = gv + bv; uv1 = Ref(uv, -1); /* up volume */
  20. dv = rv + yv; dv1 = Ref(dv, -1); /* down volume */
  21.  
  22. /* create moving average period parameters */
  23. VolPer = Param("Adjust Vol. MA per.", 34, 1, 255, 1);
  24. ConvPer = Param("Adjust Conv. MA per.", 9, 1, 255, 1);
  25.  
  26. /* create triple exponential moving avearges of separate up and down volume moving averages */
  27. MAuv = TEMA(uv, VolPer ); mauv1 = Ref(mauv, -1);
  28. MAdv = TEMA(dv, VolPer ); madv1 = Ref(madv, -1);
  29. MAtv = TEMA(V, VolPer );//total volume
  30.  
  31. /* Switch for Horizontal lines indicating current level of positive and negative volume for ease in comparing to past highs/lows - toggle via parmameter window */
  32. OscillatorOnly = Param("Show Oscillator Only", 0, 0, 1, 1);
  33. CompareBullVolume = Param("Show Bull Level", 1, 0, 1, 1);
  34. if(CompareBullvolume AND !OscillatorOnly){
  35. Plot(SelectedValue(MAuv), "", colorAqua, styleLine);
  36. }
  37.  
  38. CompareBearVolume = Param("Show Bear Level", 1, 0, 1, 1);
  39. if(CompareBearVolume AND !OscillatorOnly){
  40. Plot(SelectedValue(MAdv), "", colorLime, styleLine);
  41. }
  42.  
  43. /* Volume Segment Switches - toggle via parameter window */
  44. bullvolume = Param("Show Bull Volume", 1, 0, 1, 1);
  45. bearvolume = Param("Show Bear Volume", 1, 0, 1, 1);
  46. totalvolume = Param("Show Total Volume", 1, 0, 1, 1);
  47.  
  48. /* plot volume lines and histograms if toggled on: */
  49. bearToFront = Param("Show Bear Vol in Front", 0, 0, 1, 1);
  50. if(bearToFront AND !OscillatorOnly){
  51. Plot(MAdv, "", colorRed, styleNoLabel);
  52. }
  53. if(bullvolume AND !OscillatorOnly){
  54. Plot(MAuv, "Average Bull Volume", colorBlue, styleThick+styleNoLabel);
  55. }
  56. if(bearvolume AND !OscillatorOnly){
  57. Plot(MAdv, "Average Bear Volume", colorRed, styleThick+styleNoLabel);
  58. }
  59. if(totalVolume AND !OscillatorOnly){
  60. Plot(MAtv, "Total Volume", colorYellow, styleNoLabel);
  61. PlotOHLC(0,MAtv,0,MAtv, "m", colorGrey50, styleCloud+styleNoLabel+styleNoTitle,Null,Null,Null,-4);
  62. }
  63. if(bullvolume AND !OscillatorOnly){
  64. Plot(MAuv, "Total Volume", colorWhite, styleNoLabel);
  65. PlotOHLC(0,MAuv,0,MAuv, "m", colorDarkBlue, styleCloud+styleNoLabel+styleNoTitle,Null,Null,Null,-3);
  66. }
  67. if(bearvolume AND !OscillatorOnly){
  68. Plot(MAdv, "Total Volume", colorWhite, styleNoLabel);
  69. PlotOHLC(0,MAdv,0,MAdv, "m", colorDarkRed, styleCloud+styleNoLabel+styleNoTitle,Null,Null,Null,-2);
  70.  
  71. }
  72.  
  73. Buy=Cross(MAuv,MAdv);
  74. Sell=Cross(MAdv,MAuv);
  75. PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBlue);
  76. PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);
  77. Filter=Buy OR Sell;
  78. Buy=ExRem(Buy,Sell); Sell=ExRem(Sell,Buy);
  79. AddColumn(Close,"Close");AddColumn(Volume,"Total Volume");AddColumn(Buy,"Buy"); AddColumn(Sell,"sell");
  80.  
  81. /* better visibility of zero line: */
  82. Plot(0, "", colorYellow, Null,Null,Null,Null,1);
  83.  
  84. /* Rise/Fall Convergence variables: */
  85. Converge = (TEMA(MAuv - MAdv, ConvPer));
  86. Converge1 = Ref(Converge, -1);
  87. ConvergeUp = Converge > Converge1;
  88. ConvergeOver = Converge > 0;
  89. rising = ConvergeUp AND ConvergeOver;
  90. falling = !ConvergeUp AND ConvergeOver;
  91.  
  92. /* Rise/Fall Convergence Oscillator Switch - toggle via parameter window - (provides a better view of resulting combination of battling bull/bear volume forces) */
  93. convergenceOscillator = Param("Show Oscillator", 0, 0, 1, 1);
  94. if(convergenceOscillator OR OscillatorOnly){
  95. Plot(Converge, "Amimals War", colorViolet, 1|styleLeftAxisScale|styleNoLabel|styleThick);
  96. Plot(0,"", colorYellow, 1|styleLeftAxisScale|styleNoLabel);
  97. }
  98.  
  99. /********************************************************
  100. Convergence Rise/Fall Shadows:
  101.  
  102. (provides a more easily visible display of rising and falling bull/bear volume convergence) - toggle via parameter window
  103.  
  104. -posiitive Volume exceeding negative Volume: Light shadow
  105. -negative volume exceeding positive volume: dark shadow
  106. -if you use standard gray background - best shadows are:
  107. -my greys: 14 = (216, 216, 216); 15 = (168, 168, 168));
  108. -best substitute? using AB color constants?
  109. -light: colorpalegreen; dark: colorRose;?
  110. -(depends on your color scheme - customize to your tastes)
  111. **********************************************************/
  112.  
  113. /* uncomment if you use my custom color greys: */
  114. riseFallColor = IIf(rising, 14,15); //my custom shadow greys
  115.  
  116. /* comment out if you use my custom color gray shadows: */
  117. /* riseFallColor = IIf(rising, colorPaleGreen,colorRose); */
  118.  
  119. /* Rise/Fall Convergence Plot Switch - toggle via parameter window */
  120. riseFallShadows = Param("Show RiseFallShadows", 0, 0, 1, 1);
  121. if(riseFallShadows){
  122. Plot(IIf(rising OR falling, 1, 0), "", riseFallColor, styleArea|styleOwnScale|styleNoLabel);
  123. }
  124. GraphXSpace = 0.5;
  125. _SECTION_END();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement