Advertisement
saisri

Fib Retracements with trendlines

Aug 17th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.42 KB | None | 0 0
  1. _SECTION_BEGIN("Large Triggers");
  2. p3 = Param("TL 3 Periods", 80, 5, 100, 1);
  3. p4 = Param("TL 4 Periods", 20, 3, 100, 1);
  4. TL3 = LinearReg(C, p3);
  5. TL4 = EMA(TL3, p4);
  6. Col1 = IIf(TL3 > TL4, ParamColor("TLL Up Colour", colorBlue), ParamColor("TLL Dn Colour", colorRed));
  7. Plot(TL3, "TriggerLine 3", Col1, styleDots|styleThick|styleNoLabel);
  8. Plot(TL4, "TriggerLine 4", Col1, styleDots|styleThick|styleNoLabel);
  9. _SECTION_END();
  10.  
  11. /* Fibonacci Internal & External Retracements */
  12. // This is a Modified Version that shows Fibonacci 00% & 100% instead of WRONG Sup & Res
  13.  
  14. _SECTION_BEGIN("Background");
  15. SetChartOptions(0,chartShowArrows|chartShowDates);
  16. SetChartBkColor(ParamColor("Outer panel",colorBlack)); // color of outer border
  17. SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
  18. tchoice=Param("Title Selection ",2,1,2,1);
  19.  
  20. Plot(C, "", IIf(O>=C, colorRed, colorGreen), ParamStyle("Price Style",styleBar,maskPrice));
  21. //////////////////////////////////////////////////////////////////
  22. _SECTION_BEGIN("Fib Retracements");
  23. fibs = ParamToggle("Plot Fibs","Off|On",1);
  24. pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
  25. HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
  26. pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
  27. LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
  28. Back = Param ("Extend Left = 2",1,1,500,1);
  29. Fwd = Param("Plot Forward", 0, 0, 500, 1);
  30. text = ParamToggle("Plot Text","Off|On",1);
  31. hts = Param ("Text Shift", -33.5,-50,50,0.10);
  32. style =ParamStyle("Line Style",styleLine,styleNoLabel);
  33. x = BarIndex();
  34. pRp = PeakBars( H, pctH, 1) == 0;
  35. yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
  36. xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
  37. pSp = TroughBars( L, pctL, 1) == 0;
  38. ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
  39. xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
  40. Delta = yRp0 - ySp0;
  41.  
  42. function fib(ret)
  43. {
  44. retval = (Delta * ret);
  45. Fibval = IIf(ret < 1.0
  46. AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
  47. AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
  48. AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
  49. AND xSp0 > xRp0, ySp0 + retval, Null))));
  50. return FibVal;
  51. }
  52.  
  53. x0 = Min(xSp0,xRp0)-Back;
  54. x1 = (BarCount -1);
  55. //////////////////////////////////////////////////////////////////
  56. r236 = fib(0.236); r236I = LastValue (r236,1);
  57. r382 = fib(0.382); r382I = LastValue (r382,1);
  58. r050 = fib(0.50); r050I = LastValue (r050,1);
  59. r618 = fib(0.618); r618I = LastValue (r618,1);
  60. r786 = fib(0.786); r786I = LastValue (r786,1);
  61. e127 = fib(1.27); e127I = LastValue (e127,1);
  62. e162 = fib(1.62); e162I = LastValue (e162,1);
  63. e200 = fib(2.00); e200I = LastValue (e200,1);
  64. e262 = fib(2.62); e262I = LastValue (e262,1);
  65. e424 = fib(4.24); e424I = LastValue (e424,1);
  66. //////////////////////////////////////////////////////////////////
  67. p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
  68. p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
  69. color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
  70. color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
  71. //////////////////////////////////////////////////////////////////
  72. numbars = LastValue(Cum(Status("barvisible")));
  73. fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
  74. //////////////////////////////////////////////////////////////////
  75. if(fibs==1)
  76. {
  77. Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null,Null,Fwd);
  78. Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null,Null,Fwd);
  79. Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null,Null,Fwd);
  80. Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null,Null,Fwd);
  81. Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null,Null,Fwd);
  82. Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null,Null,Fwd);
  83. Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null,Null,Fwd);
  84. Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null,Null,Fwd);
  85. Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null,Null,Fwd);
  86. Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null,Null,Fwd);
  87. Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null,Null,Fwd);
  88. Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null,Null,Fwd);
  89. }
  90. //////////////////////////////////////////////////////////////////
  91. if(text==1)
  92. {
  93. PlotText(" 0% = " + WriteVal(p00,fraction),LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
  94. PlotText("23% = " + WriteVal(r236,fraction),LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
  95. PlotText("38% = " + WriteVal(r382,fraction),LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
  96. PlotText("50% = " + WriteVal(r050,fraction),LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
  97. PlotText("62% = " + WriteVal(r618,fraction),LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
  98. PlotText("78% = " + WriteVal(r786,fraction),LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
  99. PlotText("100% = " + WriteVal(p100,fraction),LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
  100. PlotText("127% = " + WriteVal(e127,fraction),LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
  101. PlotText("162% = " + WriteVal(e162,fraction),LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
  102. PlotText("200% = " + WriteVal(e200,fraction),LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
  103. PlotText("262% = " + WriteVal(e262,fraction),LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
  104. PlotText("424% = " + WriteVal(e424,fraction),LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
  105. }
  106. _SECTION_END();
  107. //////////////////////////////////////////////////////////////////
  108. if (tchoice==1 )
  109. {
  110. _N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}}
  111. {{Date}} Open: %g, High: %g, Low: %g, Close: %g
  112. {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
  113. }
  114. //////////////////////////////////////////////////////////////////
  115. if (tchoice==2 )
  116. {
  117. Title = EncodeColor(colorYellow) + "Fibonacci Retracements " + EncodeColor(colorWhite) + Name() + " " + EncodeColor(colorWhite)+ Date() + "Tick = " + EncodeColor(5) +
  118. Interval(2)+
  119. EncodeColor(colorWhite) + " Open = " + EncodeColor(colorWhite) + O +
  120. EncodeColor(colorWhite) + " High = " + EncodeColor(5) + H +
  121. EncodeColor(colorWhite) + " Low = " + EncodeColor(colorRed) + L +
  122. EncodeColor(colorWhite) + " Close = " + EncodeColor(colorWhite) + C + "\n"
  123. +
  124. EncodeColor( colorWhite) +"_______________"+"\n"+
  125. EncodeColor( colorWhite) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
  126. EncodeColor( colorWhite) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
  127. EncodeColor( colorWhite) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
  128. EncodeColor( colorWhite) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
  129. EncodeColor( colorWhite) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
  130. EncodeColor( Color100) + " 100% = " + EncodeColor(Color100) + p100 + " "+"\n"+
  131. EncodeColor( colorWhite) + "78.6% = " + EncodeColor(42)+ r786 + " " +"\n"+
  132. EncodeColor( colorWhite) + "61.8% = " + EncodeColor(43)+ r618 + " "+"\n"+
  133. EncodeColor( colorWhite) + "50% = " + EncodeColor(41)+ r050 + " "+"\n"+
  134. EncodeColor( colorWhite) + "38.2% = " + EncodeColor(44)+ r382 + " "+"\n"+
  135. EncodeColor( colorWhite) + "23.6% = " + EncodeColor(45)+ r236+ " " +"\n"+
  136. EncodeColor( Color00) + "00% = " + EncodeColor(Color00) + p00 + " " ;
  137. }
  138. GraphXSpace=5;
  139.  
  140. _SECTION_BEGIN("traing sl");
  141.  
  142. function vstop_func(trBull,trBear)
  143. {
  144. trailArray[ 0 ] = C[ 0 ]; // initialize
  145. for( i = 1; i < BarCount; i++ )
  146. {
  147. prev = trailArray[ i - 1 ];
  148.  
  149. if (C[ i ] > prev AND C[ i - 1 ] > prev)
  150. {
  151. trailArray[ i ] = Max(prev,C[ i ] - trBull[ i ]);
  152. }
  153. else if (C[ i ] < prev AND C[ i - 1 ] < prev)
  154. {
  155. trailArray[ i ] = Min(prev,C[ i ] + trBear[ i ]);
  156. }
  157. else if (C[ i ] > prev)
  158. {
  159. trailArray[ i ] = C[ i ] - trBull[ i ];
  160. }
  161. else
  162. {
  163. trailArray[ i ] = C[ i ] + trBear[ i ];
  164. }
  165. }
  166. return trailArray;
  167. }
  168.  
  169. per = Param("per",20, 1, 150, 1);
  170. multBull = Param("multBull",2, 1, 4, 0.05);
  171. multBear = Param("multBear",2, 1, 4, 0.05);
  172.  
  173. trBull = multBull * ATR(per);
  174. trBear = multBear * ATR(per);
  175.  
  176. trailArray = vstop_func(trBull,trBear);
  177. s0=trailArray;
  178.  
  179. s1= s0 > C ;
  180. s2= s0 <C ;
  181. ccresult1 = WriteIf( s1,"cu", "");
  182. ccresult2 = WriteIf( s2,"cd", "");
  183.  
  184. GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorRed);
  185. GfxSetTextColor( ParamColor("Color",colorRed) );
  186. Hor=Param("Horizontal Position",40,10,1200,1);
  187. Ver=Param("Vertical Position",290,100,50,50);
  188.  
  189. if ( ccresult1 =="cu")
  190.  
  191.  
  192. {
  193. GfxTextOut(""+s0,Hor , Ver );
  194. }
  195. else
  196.  
  197. GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorGreen );
  198. GfxSetTextColor( ParamColor("Color",colorGreen) );
  199. Hor=Param("Horizontal Position",75,10,1200,1);
  200. Ver=Param("Vertical Position",185,100,50,50);
  201.  
  202. if ( ccresult2 =="")
  203.  
  204. {
  205. GfxTextOut(""+s0,Hor , Ver );
  206. }
  207. _SECTION_END();
  208.  
  209. _SECTION_BEGIN("traing s2");
  210.  
  211. s0=trailArray;
  212.  
  213. s1= s0 > C ;
  214. s2= s0 <C ;
  215. ccresult1 = WriteIf( s1,"cu", "");
  216. ccresult2 = WriteIf( s2,"cd", "");
  217.  
  218. GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorBrightGreen );
  219. GfxSetTextColor( ParamColor("Color",colorBrightGreen) );
  220. Hor=Param("Horizontal Position",40,10,1200,1);
  221. Ver=Param("Vertical Position",240,100,50,50);
  222.  
  223. if ( ccresult2 =="cd")
  224.  
  225.  
  226. {
  227. GfxTextOut(""+s0,Hor , Ver );
  228. }
  229. else
  230.  
  231. GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorWhite );
  232. GfxSetTextColor( ParamColor("Color",colorWhite) );
  233. Hor=Param("Horizontal Position",75,10,1200,1);
  234. Ver=Param("Vertical Position",185,100,50,50);
  235.  
  236. if ( ccresult1 =="")
  237.  
  238. {
  239. GfxTextOut(""+s0,Hor , Ver );
  240. }
  241.  
  242. _SECTION_END();
  243.  
  244.  
  245.  
  246. _SECTION_END();
  247.  
  248. _SECTION_BEGIN("buycircle");
  249. GfxSelectFont( "Arial", 1, 100 );
  250. GfxSetBkMode( 1 );
  251. GfxSetTextColor( colorBlack );
  252. GfxSelectPen( colorBlack, 1 );
  253. if ( ccresult2 =="cd")
  254. {
  255. GfxSelectSolidBrush( ColorRGB(0,255,0) );
  256. }
  257. else
  258. {
  259. GfxSelectSolidBrush( ColorRGB(0,0,94) );
  260. }
  261. GfxCircle( 20,250,7 );
  262.  
  263. _SECTION_END();
  264. _SECTION_BEGIN("sellcircle");
  265. GfxSelectFont( "Arial", 10, 100 );
  266. GfxSetBkMode( 1 );
  267. GfxSetTextColor( colorBlue );
  268. GfxSelectPen( colorBlue, 1 );
  269. if ( ccresult1 =="cu")
  270. {
  271. GfxSelectSolidBrush( ColorRGB(255,0,0) );
  272. }
  273. else
  274. {
  275. GfxSelectSolidBrush( ColorRGB(0,0,94) );
  276. }
  277.  
  278. GfxCircle( 20,300,7 );
  279. _SECTION_END();
  280.  
  281. _SECTION_BEGIN("system Ticker");
  282. function GetSecondNum()
  283. {
  284. Time = Now( 4 );
  285. Seconds = int( Time % 100 );
  286. Minutes = int( Time / 100 % 100 );
  287. Hours = int( Time / 10000 % 100 );
  288. SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
  289. return SecondNum;
  290. }
  291. RequestTimedRefresh( 1 );
  292. //----------------------------------------------------------------------------
  293. //----------------------------------------------------------------------------
  294. TimeFrame = Interval();
  295. SecNumber = GetSecondNum();
  296. Newperiod = SecNumber % TimeFrame == 0;
  297. SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
  298. SecsToGo = TimeFrame - SecsLeft;
  299.  
  300. x=Param(" xposn",10,100,1000,1000);
  301. y=Param(" yposn",15,40,1000,1);
  302.  
  303. GfxSelectSolidBrush( colorPink );
  304. GfxSelectPen( colorBlack, 2 );
  305. if ( NewPeriod )
  306. {
  307. GfxSelectSolidBrush( colorBlack );
  308. GfxSelectPen( colorBlack, 2 );
  309. Say( "New candle" );
  310. }
  311. GfxRoundRect( x+55, y+17, x-4, y-2, 0, 0 );
  312. GfxSetBkMode(1);
  313. GfxSelectFont( "Arial", 9, 700, False );
  314. GfxSetTextColor( colorBlack );
  315. GfxTextOut( "" +SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y );
  316. _SECTION_END();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement