Advertisement
saisri

retracement levels

Jul 18th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.07 KB | None | 0 0
  1. _SECTION_BEGIN("Background");
  2. SetChartOptions(0,chartShowArrows|chartShowDates);
  3. SetChartBkColor(ParamColor("Outer panel",colorGrey40)); // color of outer border
  4. SetChartBkGradientFill( ParamColor("Inner panel upper",colorGrey40),ParamColor("Inner panel lower",colorBlack));
  5. tchoice=Param("Title Selection ",2,1,2,1);
  6.  
  7. Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price Style",styleCandle, maskPrice));
  8.  
  9. //////////////////////////////////////////////////////////////////
  10. _SECTION_BEGIN("Fib Retracements");
  11. fibs = ParamToggle("Plot Fibs","Off|On",1);
  12. pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
  13. HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
  14. pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
  15. LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
  16. Back = Param ("Extend Left = 2",1,1,500,1);
  17. Fwd = Param("Plot Forward", 0, 0, 500, 1);
  18. text = ParamToggle("Plot Text","Off|On",1);
  19. hts = Param ("Text Shift", -33.5,-50,50,0.10);
  20. style =ParamStyle("Line Style",styleLine,styleNoLabel);
  21. x = BarIndex();
  22. pRp = PeakBars( H, pctH, 1) == 0;
  23. yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
  24. xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
  25. pSp = TroughBars( L, pctL, 1) == 0;
  26. ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
  27. xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
  28. Delta = yRp0 - ySp0;
  29.  
  30. function fib(ret)
  31. {
  32. retval = (Delta * ret);
  33. Fibval = IIf(ret < 1.0
  34. AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
  35. AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
  36. AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
  37. AND xSp0 > xRp0, ySp0 + retval, Null))));
  38. return FibVal;
  39. }
  40.  
  41. x0 = Min(xSp0,xRp0)-Back;
  42. x1 = (BarCount -1);
  43. //////////////////////////////////////////////////////////////////
  44. r236 = fib(0.236); r236I = LastValue (r236,1);
  45. r382 = fib(0.382); r382I = LastValue (r382,1);
  46. r050 = fib(0.50); r050I = LastValue (r050,1);
  47. r618 = fib(0.618); r618I = LastValue (r618,1);
  48. r786 = fib(0.786); r786I = LastValue (r786,1);
  49. e127 = fib(1.27); e127I = LastValue (e127,1);
  50. e162 = fib(1.62); e162I = LastValue (e162,1);
  51. e200 = fib(2.00); e200I = LastValue (e200,1);
  52. e262 = fib(2.62); e262I = LastValue (e262,1);
  53. e424 = fib(4.24); e424I = LastValue (e424,1);
  54. //////////////////////////////////////////////////////////////////
  55. p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
  56. p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
  57. color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
  58. color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
  59. //////////////////////////////////////////////////////////////////
  60. numbars = LastValue(Cum(Status("barvisible")));
  61. fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
  62. //////////////////////////////////////////////////////////////////
  63. if(fibs==1)
  64. {
  65. Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
  66. Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
  67. Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
  68. Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
  69. Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
  70. Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
  71. Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
  72. Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
  73. Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
  74. Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
  75. Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
  76. Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
  77. }
  78. //////////////////////////////////////////////////////////////////
  79. if(text==1)
  80. {
  81. PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
  82. PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
  83. PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
  84. PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
  85. PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
  86. PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
  87. PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
  88. PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
  89. PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
  90. PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
  91. PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
  92. PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
  93. }
  94. _SECTION_END();
  95. //////////////////////////////////////////////////////////////////
  96. if (tchoice==1 )
  97. {
  98. _N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open: %g, High: %g, Low: %g, Close: %g {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
  99. }
  100. //////////////////////////////////////////////////////////////////
  101. if (tchoice==2 )
  102. {
  103. Title = EncodeColor(colorWhite)+ Date() + " Tick = " + EncodeColor(5) + Interval()+
  104. EncodeColor(colorWhite) + " Open = " + EncodeColor(colorWhite) + O +
  105. EncodeColor(colorWhite) + " High = " + EncodeColor(5) + H +
  106. EncodeColor(colorWhite) + " Low = " + EncodeColor(colorRed) + L +
  107. EncodeColor(colorWhite) + " Close = " + EncodeColor(colorWhite) + C + "\n" +
  108. EncodeColor( colorWhite) +"_______________"+"\n"+
  109. EncodeColor( colorWhite) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
  110. EncodeColor( colorWhite) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
  111. EncodeColor( colorWhite) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
  112. EncodeColor( colorWhite) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
  113. EncodeColor( colorWhite) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
  114. EncodeColor( colorYellow) + " Res = " + EncodeColor(32)+ p100 + " " +"\n"+
  115. EncodeColor( colorWhite) + " 78% = " + EncodeColor(42)+ r786 + " " +"\n"+
  116. EncodeColor( colorWhite) + " 62% = " + EncodeColor(43)+ r618 + " " +"\n"+
  117. EncodeColor( colorWhite) + " 50% = " + EncodeColor(41)+ r050 + " " +"\n"+
  118. EncodeColor( colorWhite) + " 38% = " + EncodeColor(44)+ r382 + " " +"\n"+
  119. EncodeColor( colorWhite) + " 23% = " + EncodeColor(45)+ r236+ " " +"\n"+
  120. EncodeColor( colorYellow) + " Sup = " + EncodeColor(34)+ p00 + " " ;
  121. }
  122. GraphXSpace=5;
  123.  
  124. SetChartOptions(1, chartShowDates); // put dates at bottom of chart
  125.  
  126. pr = Param("Elliot Wave minimum % move", 2, 1, 100);
  127. // Beginner Elliot Wave stuff
  128. EWpk = PeakBars(H, pr, 1) == 0;
  129. EWtr = TroughBars(L, pr, 1) == 0;
  130.  
  131. // Intermediate Elliot Wave stuff
  132. zz = Zig(C, pr);
  133. zzHi = Zig(H, pr);
  134. zzLo = Zig(L, pr);
  135. Avg = (zzHi+zzLo)/2;
  136.  
  137. // Advanced Elliot Wave stuff
  138. RetroSuccessSecret = IIf(EWpk, zzHi, IIf(EWtr, zzLo, IIf(Avg > Ref(Avg,-1), H, L)));
  139. EW = Zig(RetroSuccessSecret, pr);
  140.  
  141. // Plot on price chart
  142. /*Plot(C, "Close", colorBlack, styleCandle);*/
  143. Plot(EW, "EW", colorWhite, styleLine);
  144.  
  145. // Plot buy and sell arrows
  146. Buy = TroughBars(EW, pr, 1) == 0;
  147. Sell = PeakBars(EW, pr, 1) ==0;
  148. Buy = ExRem(Buy, Sell);
  149. Sell = ExRem(Sell, Buy);
  150. PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
  151. PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,0,L,-15);
  152. PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
  153. PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
  154. PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
  155. PlotShapes(IIf(Sell,shapeSmallCircle,shapeNone),colorWhite,0,SellPrice,0);
  156.  
  157. AlertIf( Buy , "SOUND C:\\Windows\\Media\\Notify.wav", "Audio alert", 2 );
  158. AlertIf( Sell, "SOUND C:\\Windows\\Media\\Tada.wav", "Audio alert", 2 );
  159.  
  160. _SECTION_BEGIN("Elliot Fractals");
  161.  
  162. /*
  163. The basic definition of an 'up' fractal is a bar high that is both higher than the two bars immediately preceding it
  164. and higher than the two bars immediately following it.
  165. The lows of the bars are NOT considered in determining the up fractal progression.
  166.  
  167. If two bars in the progression have equal highs followed by two consecutive bars with lower highs,
  168. then a total of six bars rather than the usual five bars will make up the progression.
  169. The first High becomes the counting fractal. Reverse for 'down' fractals.
  170.  
  171. The 5 bar formation works best on Daily or longer time frame charts.For intraday data charts we often use 9 bar, 13 bar and 21 bar formations for fractal counting
  172. */
  173. Up5BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND Ref(H,1) < H AND Ref(H,2) < H;
  174. Up6BarFractal = Ref(H,-2) < H AND Ref(H,-1) < H AND (H == Ref(H,1)) AND Ref(H,2) < H AND Ref(H,3) < H;
  175. Down5BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND Ref(L,1) > L AND Ref(L,2) > L;
  176. Down6BarFractal = Ref(L,-2) > L AND Ref(L,-1) > L AND (L == Ref(L,1)) AND Ref(L,2) > L AND Ref(L,3) > L;
  177.  
  178. //TODO: More filtering: Show only troughs that are around atrough in trix(9).
  179.  
  180. PlotShapes( IIf(Down5BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
  181. PlotShapes( IIf(Down6BarFractal ,shapeSmallUpTriangle,0) ,colorBlack, 0, L,-12);
  182.  
  183. PlotShapes( IIf(Up5BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
  184. PlotShapes( IIf(Up6BarFractal ,shapeSmallDownTriangle,0) ,colorBlack, 0, H,-12);
  185.  
  186. Up = (Up5BarFractal OR Up6BarFractal);
  187. Down = (Down5BarFractal OR Down6BarFractal);
  188. //Removing false fractals:
  189. DownSignal = Flip(Ref(Up,-1), Ref(Down,-1));
  190. UpSignal = Flip(Ref(Down,-1), Ref(Up,-1));
  191.  
  192. LastHigh[0] = H[0];
  193. LastLow[0] = L[0];
  194.  
  195. LastLowIndex = 0;
  196. LastHighIndex = 0;
  197. Valid = 0;
  198. for (i=1; i < BarCount; i++)
  199. {
  200.  
  201. LastHigh[i] = LastHigh[i-1];
  202. LastLow[i] = LastLow[i-1];
  203. if (Up[i])
  204. {
  205. Valid[i] = True;
  206. if (DownSignal[i])
  207. {
  208. //Sequence of 2 Up Fractals. Validate only the higher one.
  209. Valid[i] = H[i] >= H[LastHighIndex];
  210. Valid[LastHighIndex] = H[LastHighIndex] > H[i];
  211. }
  212. LastHigh[i] = Max(H[i], H[LastHighIndex ]);
  213. LastHighIndex = i;
  214. }
  215.  
  216. if (Down[i])
  217. {
  218. Valid[i] = True;
  219. if (UpSignal[i])
  220. {
  221. //Sequence of 2 Down Fractals. Validate only the lower one.
  222. Valid[i] = L[i] <= L[LastLowIndex];
  223. Valid[LastLowIndex] = L[LastLowIndex] < L[i];
  224. }
  225.  
  226. LastLow[i] = Min(L[i], L[LastLowIndex]);
  227. LastLowIndex = i;
  228. }
  229. }
  230.  
  231. TrixN = Trix(9);
  232. TroughLow = Ref(TrixN, -3) > TrixN AND Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN AND Ref(TrixN, 3) > TrixN;
  233. TroughHigh = Ref(TrixN, -3) < TrixN AND Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN AND Ref(TrixN, 3) < TrixN;
  234. //TroughLow = Ref(TrixN, -2) > TrixN AND Ref(TrixN, -1) > TrixN AND Ref(TrixN, 1) > TrixN AND Ref(TrixN, 2) > TrixN;
  235. //TroughHigh = Ref(TrixN, -2) < TrixN AND Ref(TrixN, -1) < TrixN AND Ref(TrixN, 1) < TrixN AND Ref(TrixN, 2) < TrixN;
  236. ZeroValid = Cross(TrixN, 0) OR Cross(0, TrixN) OR Ref(Cross(TrixN, 0),1) OR Ref(Cross(0, TrixN),1);
  237. ValidLow = TroughLow OR Ref(TroughLow, 1) OR Ref(TroughLow, 2) OR Ref(TroughLow, 3) OR Ref(TroughLow, 4);// OR Ref(TroughLow, 5));
  238. ValidHigh = TroughHigh OR Ref(TroughHigh, 1) OR Ref(TroughHigh, 2) OR Ref(TroughHigh, 3) OR Ref(TroughHigh, 4);// OR Ref(TroughHigh, 5));
  239.  
  240. //Plot(LastHigh-10 ,"LastHigh", colorBlue, styleLine);
  241. //Plot(LastLow-10 ,"LastLow ", colorRed, styleLine);
  242. //Plot(Valid*5 + 10 ,"LastLow ", colorGreen, styleLine | styleThick);
  243.  
  244. //PlotShapes( IIf(Down AND Valid,shapeSmallUpTriangle,0) ,colorGreen, 0, L,-12);
  245. //PlotShapes( IIf(Up AND Valid,shapeSmallDownTriangle,0) ,colorRed, 0, H,-12);
  246. Maxi = Up AND (ValidHigh OR ZeroValid);
  247. Mini = Down AND (ValidLow OR ZeroValid);
  248. PlotShapes( IIf(Down AND (ValidLow OR ZeroValid),shapeSmallUpTriangle,0) ,colorBlue, 0, L,-12);
  249. PlotShapes( IIf(Up AND (ValidHigh OR ZeroValid),shapeSmallDownTriangle,0) ,colorOrange, 0, H,-12);
  250. //Plot(UpSignal*3+5,"UpSignal", colorBlue, styleLine| styleThick);
  251. //Plot(DownSignal*3 ,"DownSignal", colorRed, styleLine| styleThick);
  252.  
  253. /*
  254. LastMaxi = 0;
  255. LastMini = 0;
  256. ElliotLines = 0;
  257. State = 0;
  258. for (i=1; i < BarCount; i++)
  259. {
  260. State[i] = State[i-1];
  261. if (Maxi[i])
  262. {
  263. State[i] = 1;//down
  264. }
  265.  
  266. if (Mini[i])
  267. {
  268. State[i] = 2;
  269. }
  270.  
  271. }
  272.  
  273. PlotShapes(IIf(State > 0, shapeSmallCircle, 0), IIf(State == 1, colorRed, colorBlue), 0, IIf(State == 1, H, L), -5);
  274. */
  275. //Line = LineArray( x0, y0, x1, y1, 1 );
  276. //Plot( Line, "Trend line", colorBlue );
  277.  
  278. /*
  279. Wave B
  280. Usually 50% of Wave A
  281. Should not exceed 75% of Wave A
  282. Wave C
  283. either 1 x Wave A
  284. or 1.62 x Wave A
  285. or 2.62 x Wave A
  286. */
  287. function CorrectiveRatios(StartPrice, A, B, C, RatioDelta, Delta)
  288. {
  289.  
  290. ALength = abs(startPrice - A); BLength = abs(A-B);
  291. CLength = abs(B-C);
  292.  
  293. Ratio1 = BLength / CLength ;
  294. Cond1 = Ration1 >= 0.5 - RatioDelta AND ratio1 <= 0.75 + RatioDelta;
  295. Cond2 = abs(Clength - ALength) < Delta OR abs(Clength - 1.62 * ALength) < Delta OR abs(CLength - 2.62 * ALength) < Delta;
  296.  
  297. return Cond1 AND Cond2;
  298. }
  299.  
  300. function ImpulseRules(StartPrice, One, Two, Three, Four, Five)
  301. {
  302. //Wave 2 should be beneath wave 1 start:
  303. Cond1 = Two > StartPrice AND Two < One;
  304. //Wave 4 - the same:
  305. Cond2 = Four > Two AND Four < Three;
  306. //Wave 5 should be <= wave 3
  307. Cond3 = abs(Three-Two) >= abs(Five - Four);
  308. //Wave 1 should be smaller than wave five, making wave 3 the biggest:
  309. Cond4 = abs(StartPrice - One) < abs(Five - Four);
  310. return Cond1 AND Cond2 AND Cond3 AND Cond4;
  311. }
  312. _SECTION_END();
  313.  
  314.  
  315. _SECTION_BEGIN("Ribbon");
  316. uptrend=PDI()>MDI()AND Signal()<MACD();
  317. downtrend=MDI()>PDI()AND Signal()>MACD();
  318.  
  319.  
  320. Plot( 1, /*efines the height of the ribbon in percent of pane width */"ribbon",
  321. IIf( uptrend, colorGreen, IIf( downtrend, colorRed,IIf(Signal()<MACD(), colorYellow, 0 ))), /* choose color */
  322. styleOwnScale|styleArea|styleNoLabel, -1, 100 );
  323. _SECTION_END();
  324.  
  325.  
  326. _SECTION_BEGIN("Price With Regression Channel");
  327.  
  328.  
  329. // Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below
  330.  
  331. P = ParamField("Price field",-1);
  332. Daysback = Param("Period for Liner Regression Line",21,1,240,1);
  333. shift = Param("Look back period",0,0,240,1);
  334.  
  335.  
  336. // =============================== Math Formula =============================================================
  337.  
  338. x = Cum(1);
  339. lastx = LastValue( x ) - shift;
  340. aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
  341. bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
  342. y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );
  343.  
  344.  
  345. // ==================Plot the Linear Regression Line ==========================================================
  346.  
  347.  
  348. LRColor = ParamColor("LR Color", colorCycle );
  349. LRStyle = ParamStyle("LR Style");
  350.  
  351. LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
  352. Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); // styleDots );
  353.  
  354. // ========================== Plot 1st SD Channel ===============================================================
  355.  
  356. SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
  357. SD = SDP/2;
  358.  
  359. width = LastValue( Ref(SD*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
  360. SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
  361. SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;
  362.  
  363. SDColor = ParamColor("SD Color", colorCycle );
  364. SDStyle = ParamStyle("SD Style");
  365.  
  366. Plot( SDU , "Upper Lin Reg", SDColor,SDStyle );
  367. Plot( SDL , "Lower Lin Reg", SDColor,SDStyle );
  368.  
  369. // ========================== Plot 2d SD Channel ===============================================================
  370.  
  371. SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
  372. SD2 = SDP2/2;
  373.  
  374. width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
  375. SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
  376. SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;
  377.  
  378. SDColor2 = ParamColor("2 SD Color", colorCycle );
  379. SDStyle2 = ParamStyle("2 SD Style");
  380.  
  381. Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 );
  382. Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 );
  383.  
  384. // ============================ End Indicator Code ==============================================================
  385.  
  386. _SECTION_END();
  387.  
  388.  
  389. _SECTION_BEGIN("trailing stop atr");
  390. function vstop_func(tr)
  391. {
  392. trailArray[ 0 ] = C[ 0 ]; // initialize
  393. for( i = 1; i < BarCount; i++ )
  394. {
  395. prev = trailArray[ i - 1 ];
  396.  
  397. if (C[ i ] > prev AND C[ i - 1 ] > prev)
  398. {
  399. trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
  400. }
  401. else if (C[ i ] < prev AND C[ i - 1 ] < prev)
  402. {
  403. trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
  404. }
  405. else if (C[ i ] > prev)
  406. {
  407. trailArray[ i ] = C[ i ] - tr[ i ];
  408. }
  409. else
  410. {
  411. trailArray[ i ] = C[ i ] + tr[ i ];
  412. }
  413. }
  414. return trailArray;
  415. }
  416.  
  417. per = Param("per",20, 5, 150, 1);
  418. mult = Param("mult",0.5, 0.5, 4, 0.05);
  419. tr = mult * ATR(per);
  420. trailArray = vstop_func(tr);
  421. //trailArray = Ref(trailArray,-1);
  422.  
  423. //LISTING 1: Zero-lag moving average
  424.  
  425. function ZeroLagMA( data, periods )
  426. {
  427. EMA1 = EMA( data, periods );
  428. EMA2 = EMA( EMA1, periods );
  429. Diff = EMA1 - EMA2;
  430. return EMA1 + Diff;
  431. }
  432.  
  433. Periods = Param("Periods", 20, 2, 100 );
  434.  
  435. //Plot( ZeroLagMA( Close, Periods ), "ZeroLagMA-"+Periods, colorYellow, styleDashed );
  436.  
  437. TrailStop = HHV( C - 2 * ATR(10), 15 );
  438. ProfitTaker = EMA( H, 13 ) + 2 * ATR(10);
  439.  
  440. _SECTION_BEGIN("ProjHL");
  441. //Function pembulatan
  442. function bulat(Lo)
  443. {
  444. return (
  445. IIf(Lo<= 200,round(Lo/1)*1,
  446. IIf(Lo<= 500,round(Lo/5)*5,
  447. IIf(Lo<=2000,round(Lo/10)*10,
  448. IIf(Lo<=5000,round(Lo/25)*25,
  449. IIf(Lo> 5000,round(Lo/50)*50,0)))))
  450. );
  451. }
  452.  
  453. GfxSetOverlayMode(0);
  454. GfxSelectFont("Arial",9, 700);
  455. GfxSetTextColor( colorRose );
  456. GfxSetBkMode(0); // transparent
  457. GfxTextOut("PivHL = " + (H+L)/2, 250, 45);
  458. GfxTextOut("Diff = " + (C-((H+L)/2)), 350, 45);
  459. GfxSetTextColor( colorYellow );
  460. GfxTextOut("TStop = " + bulat(TrailStop), 450, 45);
  461. GfxTextOut("TPrc = " + bulat(ProfitTaker), 550, 45);
  462.  
  463.  
  464.  
  465. // PIVOT Calculation
  466. p = bulat( H+ L + C )/3;
  467. GfxSetTextColor( colorLightOrange );
  468. GfxTextOut("Pivot = " +bulat(p), 350, 60);
  469.  
  470.  
  471. rph1=(H+C+2*L)/2-L;
  472. rph2=(2*H+L+C)/2-L;
  473. rph3=(H+L+2*C)/2-L;
  474. rpl1=(H+C+2*L)/2-H;
  475. rpl2=(2*H+L+C)/2-H;
  476. rpl3=(H+L+2*C)/2-H;
  477. rph=IIf((C<O),rph1,IIf((C>O),rph2,IIf((C==O),rph3,0)));
  478. rpl=IIf((C<O),rpl1,IIf((C>O),rpl2,IIf((C==O),rpl3,0)));
  479. GfxSetTextColor( colorBrightGreen );
  480. GfxTextOut("Proj-H = " + bulat(rph), 250, 60);
  481. GfxSetTextColor( colorCustom12 );
  482. GfxTextOut("Proj-L = " + bulat(rpl), 450, 60);
  483. GfxSetTextColor( colorOrange );
  484. GfxTextOut("Trail = " + bulat(trailArray), 550, 60);
  485.  
  486. //2 Week New High-New Low
  487. HI = High > Ref(HHV(High,10),-1);
  488. LI = Low < Ref(LLV(Low,10),-1);
  489. HIV1= Ref(HHV(High,10),-1);
  490. LIV1=Ref(LLV(Low,10),-1);
  491. Variable = WriteIf(H>HIV1,"High",WriteIf(L<LIV1,"Low","Neutral"));
  492. GfxSetTextColor( colorSkyblue );
  493. GfxTextOut("2 WHL: " + HIV1+" : "+LIV1+ " " + Variable,290,75);
  494. _SECTION_END();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement