Advertisement
saisri

trend find (use with trend find macd afl)

Oct 22nd, 2012
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. /* Trend catching System
  2.  
  3. 2012, Oct 6th - Modified and integrated By KelvinHand with the given AFL source
  4. * BandStop - Done by Rajandran R
  5. Author of www.marketcalls.in
  6. BBands_Stop_v1.mq4 by igorad2004@list.ru
  7. translation in Amibroker AFL, E.M.Pottasch, 2011
  8.  
  9.  
  10. Reference Guides from
  11. - http://www.traderji.com/metatrader/53910-trend-catching-system.html
  12. - http://www.fxfisherman.com/forums/forex-metatrader/trading-systems/6630-trend-catching-system-perfect.html
  13.  
  14. */
  15.  
  16.  
  17. _SECTION_BEGIN("Price Chart");
  18. bgTop = ParamColor("BgTop", colorBlack);
  19. bgBot = ParamColor("BgBottom", colorBlack);
  20. SetChartBkGradientFill( bgTop ,bgBot, colorBlack);
  21.  
  22. pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi",2);
  23. cBull = ParamColor("Price Bull", colorLime);
  24. CBear = ParamColor("Price Bear", colorRed);
  25. cLine = ParamColor("Price Line", colorWhite);
  26.  
  27.  
  28. SetChartOptions(0,chartShowArrows|chartShowDates);
  29. _N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
  30.  
  31. ThisStyle = styleCandle;
  32. ThisTitle = "";
  33.  
  34. _O=O; _C=C; _H=H; _L=L;
  35.  
  36. ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));
  37.  
  38.  
  39. switch (pStyle )
  40. {
  41.  
  42. case "Solid Candle":
  43. SetBarFillColor( ThisColor );
  44. break;
  45.  
  46.  
  47. case "Bar":
  48. ThisStyle = styleBar;
  49. break;
  50.  
  51. case "Line":
  52. ThisStyle = styleLine;
  53. ThisColor = cLine;
  54. break;
  55.  
  56.  
  57. case "Heikin-Ashi":
  58. _C = (O+H+L+C)/4;
  59. _O = AMA( Ref( _C, -1 ), 0.5 );
  60. _H = Max( H, Max( _C, _O ) );
  61. _L = Min( L, Min( _C, _O ) );
  62.  
  63. ThisColor = IIf(_C >= _O,CBull, CBear);
  64. SetBarFillColor( ThisColor );
  65.  
  66. ThisColor = IIf(_C >= _O,cLine, cLine);
  67. ThisTitle = "Heikin-Ashi";
  68. break;
  69.  
  70. default:
  71. SetBarFillColor( ThisColor );
  72. ThisColor = cLine;
  73.  
  74. break;
  75.  
  76. }
  77.  
  78. PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle);
  79. GraphXSpace = 8;
  80.  
  81. _SECTION_END();
  82.  
  83.  
  84. _SECTION_BEGIN("BandStop");
  85. /* Done by Rajandran R */
  86. /* Author of www.marketcalls.in */
  87. // BBands_Stop_v1.mq4 by igorad2004@list.ru
  88. // translation in Amibroker AFL, E.M.Pottasch, 2011
  89.  
  90. // Modified By KelvinHand
  91.  
  92. Length=Param("Length",20, 2); // Bollinger Bands Period
  93. Deviation=Param("Deviation",2);
  94. // Deviation was 2
  95. MoneyRisk=Param("Money Risk", 1);
  96.  
  97. LineStyle=ParamToggle("Display line mode", "No|Yes", 1); // Display line mode: 0-no,1-yes
  98. cUpTrendLine = ParamColor("UpTrendLine", ColorRGB(65,105,225));
  99. cDnTrendLine = ParamColor("DownTrendLine", colorRed);
  100.  
  101.  
  102.  
  103.  
  104.  
  105. // Offset Factor
  106. TurnedUp=Nz(StaticVarGet("TurnedUp"));
  107. TurnedDown=Nz(StaticVarGet("TurnedDown"));
  108. SoundON = ParamToggle("Sound","Off|On",1);
  109.  
  110.  
  111. procedure CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown)
  112. {
  113. global UpTrendLine;
  114. global DownTrendLine;
  115. global smax;
  116. global smin;
  117.  
  118. UpTrendLine=Null;
  119. DownTrendLine=Null;
  120. smax=Null;
  121. smin=Null;
  122. trend=0;
  123.  
  124.  
  125. for (i=Length+1; i<BarCount; i++)
  126. {
  127. smax[i]=bbtop[i];
  128. smin[i]=bbbot[i];
  129. if (C[i]>smax[i-1]) trend=1;
  130. if (C[i]<smin[i-1]) trend=-1;
  131. if(trend>0 && smin[i]<smin[i-1]) smin[i]=smin[i-1];
  132. if(trend<0 && smax[i]>smax[i-1]) smax[i]=smax[i-1];
  133. bsmax[i]=smax[i]+0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
  134. bsmin[i]=smin[i]-0.5*(MoneyRisk-1)*(smax[i]-smin[i]);
  135. if(trend>0 && bsmin[i]<bsmin[i-1]) bsmin[i]=bsmin[i-1];
  136. if(trend<0 && bsmax[i]>bsmax[i-1]) bsmax[i]=bsmax[i-1];
  137. if (trend>0)
  138. {
  139. UpTrendLine[i]=bsmin[i];
  140. if (SoundON==True && !TurnedUp && i==BarCount-1 && IsEmpty(UpTrendLine[i-1]))
  141. {
  142. Say("Bollinger Bands going Up");
  143. TurnedUp=StaticVarSet("TurnedUp",1);
  144. TurnedDown=StaticVarSet("TurnedDown",0);
  145.  
  146. }
  147. }
  148.  
  149. if (trend<0)
  150. {
  151. DownTrendLine[i]=bsmax[i];
  152. if (SoundON==True && !TurnedDown && i==BarCount-1 && IsEmpty(DownTrendLine[i-1]))
  153. {
  154. Say("Bollinger Bands going Down");
  155. TurnedUp=StaticVarSet("TurnedUp",0);
  156. TurnedDown=StaticVarSet("TurnedDown",1);
  157. }
  158. } //if (trend<0)
  159. } //for
  160. } //procedure
  161.  
  162. bbtop=BBandTop(C,Length,Deviation);
  163. bbbot=BBandBot(C,Length,Deviation);
  164.  
  165. CalcTrend_proc(bbtop,bbbot,Length,MoneyRisk,SoundON,TurnedUp,TurnedDown);
  166. UpTrendSigNal=UpTrendLine AND IsEmpty(Ref(UpTrendLine,-1));
  167. DownTrendSigNal=DownTrendLine AND IsEmpty(Ref(DownTrendLine,-1));
  168.  
  169. DisplayStyle = styleNoLabel|styleDots|styleNoTitle;
  170. if(LineStyle == 0) DisplayStyle |= styleNoLine;
  171.  
  172.  
  173. Plot(UpTrendLine,"UPTRENDLINE",cUpTrendLine,DisplayStyle);
  174. Plot(DownTrendLine,"DOWNTRENDLINE",cDnTrendLine,DisplayStyle) ;
  175.  
  176. PlotShapes(IIf(UpTrendSignal,shapeCircle,shapeNone),cUpTrendLine,0,bbbot,0);
  177. PlotShapes(IIf(DownTrendSignal,shapeCircle,shapeNone),cDnTrendLine,0,bbtop,0);
  178. _SECTION_END();
  179.  
  180. _SECTION_BEGIN("Wave Channel");
  181.  
  182. cOutLine = ParamColor("Outer Line", colorWhite);
  183. cMidLine = ParamColor("Mid Line", colorGrey40);
  184.  
  185. Plot( MA(C, 34), "", cMidLine, styleNoLabel);
  186. Plot( MA(H, 34), "", cOutLine, styleThick|styleNoLabel);
  187. Plot( MA(L, 34), "", cOutLine, styleThick|styleNoLabel);
  188.  
  189.  
  190. _SECTION_END();
  191.  
  192. _SECTION_BEGIN("WMA Rainbow");
  193.  
  194. cOutLine = ParamColor("Outline", colorBlue);
  195. cInnerLine = ParamColor("Innerline", colorDarkBlue);
  196.  
  197.  
  198. Plot( WMA(C, 2), "", cOutLine, styleThick|styleNoLabel);
  199. Plot( WMA(C, 8), "", cOutLine, styleThick|styleNoLabel);
  200.  
  201. Plot( WMA(C, 3), "", cInnerLine, styleNoLabel);
  202. Plot( WMA(C, 4), "", cInnerLine, styleNoLabel);
  203. Plot( WMA(C, 5), "", cInnerLine, styleNoLabel);
  204. Plot( WMA(C, 6), "", cInnerLine, styleNoLabel);
  205. Plot( WMA(C, 7), "", cInnerLine, styleNoLabel);
  206.  
  207.  
  208. _SECTION_END();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement