Advertisement
saisri

all in one with rj

Aug 17th, 2012
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 125.80 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. _SECTION_BEGIN("Fibo Retrace and Extensions");
  12. fibs = ParamToggle("Plot Fibs","Off|On",1);
  13. pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
  14. HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
  15. pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
  16. LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
  17. Back = Param ("Extend Left = 2",1,1,500,1);
  18. Fwd = Param("Plot Forward", 0, 0, 500, 1);
  19. text = ParamToggle("Plot Text","Off|On",1);
  20. hts = Param ("Text Shift", -33.5,-50,50,0.10);
  21. style =ParamStyle("Line Style",styleLine,styleNoLabel);
  22. x = BarIndex();
  23. pRp = PeakBars( H, pctH, 1) == 0;
  24. yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
  25. xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
  26. pSp = TroughBars( L, pctL, 1) == 0;
  27. ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
  28. xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
  29. Delta = yRp0 - ySp0;
  30.  
  31. function fib(ret)
  32. {
  33. retval = (Delta * ret);
  34. Fibval = IIf(ret < 1.0
  35. AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
  36. AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
  37. AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
  38. AND xSp0 > xRp0, ySp0 + retval, Null))));
  39. return FibVal;
  40. }
  41.  
  42. x0 = Min(xSp0,xRp0)-Back;
  43. x1 = (BarCount -1);
  44.  
  45. r236 = fib(0.236); r236I = LastValue (r236,1);
  46. r382 = fib(0.382); r382I = LastValue (r382,1);
  47. r050 = fib(0.50); r050I = LastValue (r050,1);
  48. r618 = fib(0.618); r618I = LastValue (r618,1);
  49. r786 = fib(0.786); r786I = LastValue (r786,1);
  50. e127 = fib(1.27); e127I = LastValue (e127,1);
  51. e162 = fib(1.62); e162I = LastValue (e162,1);
  52. e200 = fib(2.00); e200I = LastValue (e200,1);
  53. e262 = fib(2.62); e262I = LastValue (e262,1);
  54. e424 = fib(4.24); e424I = LastValue (e424,1);
  55.  
  56. p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
  57. p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
  58. color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
  59. color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
  60.  
  61. numbars = LastValue(Cum(Status("barvisible")));
  62. fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
  63.  
  64. if(fibs==1)
  65. {
  66. Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
  67. Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
  68. Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
  69. Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
  70. Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
  71. Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
  72. Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
  73. Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
  74. Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
  75. Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
  76. Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
  77. Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
  78. }
  79.  
  80. if(text==1)
  81. {
  82. PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
  83. PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
  84. PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
  85. PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
  86. PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
  87. PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
  88. PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
  89. PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
  90. PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
  91. PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
  92. PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
  93. PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
  94. }
  95. _SECTION_END();
  96.  
  97. _SECTION_BEGIN("traing sl");
  98.  
  99. function vstop_func(trBull,trBear)
  100. {
  101. trailArray[ 0 ] = C[ 0 ]; // initialize
  102. for( i = 1; i < BarCount; i++ )
  103. {
  104. prev = trailArray[ i - 1 ];
  105.  
  106. if (C[ i ] > prev AND C[ i - 1 ] > prev)
  107. {
  108. trailArray[ i ] = Max(prev,C[ i ] - trBull[ i ]);
  109. }
  110. else if (C[ i ] < prev AND C[ i - 1 ] < prev)
  111. {
  112. trailArray[ i ] = Min(prev,C[ i ] + trBear[ i ]);
  113. }
  114. else if (C[ i ] > prev)
  115. {
  116. trailArray[ i ] = C[ i ] - trBull[ i ];
  117. }
  118. else
  119. {
  120. trailArray[ i ] = C[ i ] + trBear[ i ];
  121. }
  122. }
  123. return trailArray;
  124. }
  125.  
  126. per = Param("per",20, 1, 150, 1);
  127. multBull = Param("multBull",2, 1, 4, 0.05);
  128. multBear = Param("multBear",2, 1, 4, 0.05);
  129.  
  130. trBull = multBull * ATR(per);
  131. trBear = multBear * ATR(per);
  132.  
  133. trailArray = vstop_func(trBull,trBear);
  134. s0=trailArray;
  135.  
  136. s1= s0 > C ;
  137. s2= s0 <C ;
  138. ccresult1 = WriteIf( s1,"cu", "");
  139. ccresult2 = WriteIf( s2,"cd", "");
  140.  
  141. GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorRed);
  142. GfxSetTextColor( ParamColor("Color",colorRed) );
  143. Hor=Param("Horizontal Position",40,10,1200,1);
  144. Ver=Param("Vertical Position",90,100,50,50);
  145.  
  146. if ( ccresult1 =="cu")
  147.  
  148.  
  149. {
  150. GfxTextOut(""+s0,Hor , Ver );
  151. }
  152. else
  153.  
  154. GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorGreen );
  155. GfxSetTextColor( ParamColor("Color",colorGreen) );
  156. Hor=Param("Horizontal Position",75,10,1200,1);
  157. Ver=Param("Vertical Position",185,100,50,50);
  158.  
  159. if ( ccresult2 =="")
  160.  
  161. {
  162. GfxTextOut(""+s0,Hor , Ver );
  163. }
  164. _SECTION_END();
  165.  
  166. _SECTION_BEGIN("traing s2");
  167.  
  168. s0=trailArray;
  169.  
  170. s1= s0 > C ;
  171. s2= s0 <C ;
  172. ccresult1 = WriteIf( s1,"cu", "");
  173. ccresult2 = WriteIf( s2,"cd", "");
  174.  
  175. GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorBrightGreen );
  176. GfxSetTextColor( ParamColor("Color",colorBrightGreen) );
  177. Hor=Param("Horizontal Position",40,10,1200,1);
  178. Ver=Param("Vertical Position",60,100,50,50);
  179.  
  180. if ( ccresult2 =="cd")
  181.  
  182.  
  183. {
  184. GfxTextOut(""+s0,Hor , Ver );
  185. }
  186. else
  187.  
  188. GfxSelectFont("arial", 13, 700 ); GfxSetBkMode( colorWhite );
  189. GfxSetTextColor( ParamColor("Color",colorWhite) );
  190. Hor=Param("Horizontal Position",75,10,1200,1);
  191. Ver=Param("Vertical Position",185,100,50,50);
  192.  
  193. if ( ccresult1 =="")
  194.  
  195. {
  196. GfxTextOut(""+s0,Hor , Ver );
  197. }
  198.  
  199. _SECTION_END();
  200.  
  201.  
  202.  
  203. _SECTION_END();
  204.  
  205. _SECTION_BEGIN("buycircle");
  206. GfxSelectFont( "Arial", 1, 100 );
  207. GfxSetBkMode( 1 );
  208. GfxSetTextColor( colorBlack );
  209. GfxSelectPen( colorBlack, 1 );
  210. if ( ccresult2 =="cd")
  211. {
  212. GfxSelectSolidBrush( ColorRGB(0,255,0) );
  213. }
  214. else
  215. {
  216. GfxSelectSolidBrush( ColorRGB(0,0,94) );
  217. }
  218. GfxCircle( 20,70,7 );
  219.  
  220. _SECTION_END();
  221. _SECTION_BEGIN("sellcircle");
  222. GfxSelectFont( "Arial", 10, 100 );
  223. GfxSetBkMode( 1 );
  224. GfxSetTextColor( colorBlue );
  225. GfxSelectPen( colorBlue, 1 );
  226. if ( ccresult1 =="cu")
  227. {
  228. GfxSelectSolidBrush( ColorRGB(255,0,0) );
  229. }
  230. else
  231. {
  232. GfxSelectSolidBrush( ColorRGB(0,0,94) );
  233. }
  234.  
  235. GfxCircle( 20,100,7 );
  236. _SECTION_END();
  237.  
  238. _SECTION_BEGIN("system Ticker");
  239. function GetSecondNum()
  240. {
  241. Time = Now( 4 );
  242. Seconds = int( Time % 100 );
  243. Minutes = int( Time / 100 % 100 );
  244. Hours = int( Time / 10000 % 100 );
  245. SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
  246. return SecondNum;
  247. }
  248. RequestTimedRefresh( 1 );
  249. //----------------------------------------------------------------------------
  250. //----------------------------------------------------------------------------
  251. TimeFrame = Interval();
  252. SecNumber = GetSecondNum();
  253. Newperiod = SecNumber % TimeFrame == 0;
  254. SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
  255. SecsToGo = TimeFrame - SecsLeft;
  256.  
  257. x=Param(" xposn",10,100,1000,1000);
  258. y=Param(" yposn",15,40,1000,1);
  259.  
  260. GfxSelectSolidBrush( colorPink );
  261. GfxSelectPen( colorBlack, 2 );
  262. if ( NewPeriod )
  263. {
  264. GfxSelectSolidBrush( colorBlack );
  265. GfxSelectPen( colorBlack, 2 );
  266. Say( "New candle" );
  267. }
  268. GfxRoundRect( x+55, y+17, x-4, y-2, 0, 0 );
  269. GfxSetBkMode(1);
  270. GfxSelectFont( "Arial", 9, 700, False );
  271. GfxSetTextColor( colorBlack );
  272. GfxTextOut( "" +SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y );
  273. _SECTION_END();
  274.  
  275. _SECTION_BEGIN("Magnified Market Price");
  276. FS=Param("Font Size",30,30,100,1);
  277. GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
  278. GfxSetBkMode( colorGreen );
  279. GfxSetTextColor( ParamColor("Color",colorGreen) );
  280. Hor=Param("Horizontal Position",10,800,800,800);
  281. Ver=Param("Vertical Position",120,27,27,27);
  282. GfxTextOut(""+C,Hor , Ver );
  283. YC=TimeFrameGetPrice("C",inDaily,-1);
  284. DD=Prec(C-YC,2);
  285. xx=Prec((DD/YC)*100,2);
  286. GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
  287. GfxSetBkMode( colorGreen );
  288. GfxSetTextColor(ParamColor("Color",colorGreen) );
  289. GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
  290. _SECTION_END();
  291.  
  292. _SECTION_BEGIN( "Chart Settings" );
  293. SetChartOptions( 0, chartShowArrows | chartShowDates );
  294. SetChartBkColor( ParamColor( "Outer Panel", colorPaleBlue ) );
  295. SetChartBkGradientFill( ParamColor( "Upper Chart", 1 ), ParamColor( "Lower Chart", 23 ) );
  296. _SECTION_END();
  297.  
  298.  
  299. _SECTION_BEGIN( "Pilihan Charts" );
  300.  
  301. TSFC = ParamToggle( "TSFC", "Hide|Show", 0 );
  302. TREND = ParamToggle( "TREND", "Hide|Show", 0 );
  303. CHART = ParamToggle( "CHART", "Hide|Show", 0 );
  304. SR = ParamToggle( "SR" , "Hide|Show", 0 );
  305. SILVER = ParamToggle( "SILVER", "Hide|Show", 0 );
  306. NICK_MA = ParamToggle( "NICK_MA", "Hide|Show", 0 );
  307. ZIGZAG = ParamToggle( "ZIGZAG", "Hide|Show", 0 );
  308. STREND = ParamToggle( "SUPER TREND", "Hide|Show", 0 );
  309. TSR = ParamToggle( "TSR", "Hide|Show", 0 );
  310. BOLLINGER = ParamToggle( "BOLLINGER", "Show|Hide", 1 );
  311. CHALOKE = ParamToggle( "CHALOKE", "Hide|Show", 0 );
  312. INTRA_TREND = ParamToggle( "INTRA_TREND", "Hide|Show", 0 );
  313. EKEKO = ParamToggle( "EKEKO", "Hide|Show", 0 );
  314. CANDLE_PIVOT_TRENDLINES = ParamToggle( "CANDLE_PIVOT_TRENDLINES", "Hide|Show", 0 );
  315. ISFANDI = ParamToggle( "ISFANDI", "Hide|Show", 0 );
  316. PEAK_VALLEY = ParamToggle( "PEAK_VALLEY", "Hide|Show", 0 );
  317. AUTO_FIBO = ParamToggle( "AUTO_FIBO", "Hide|Show", 0 );
  318. NEED = ParamToggle( "NEED", "Hide|Show", 0 );
  319. FLOWER = ParamToggle( "FLOWER", "Hide|Show", 0 );
  320.  
  321. _SECTION_END();
  322.  
  323.  
  324.  
  325. if ( CHART == 1 )
  326. {
  327. _SECTION_BEGIN( "CHART" );
  328.  
  329. Plot( C, "", colorWhite, styleCandle | styleThick );
  330. _SECTION_END();
  331. }
  332.  
  333.  
  334.  
  335. if ( TSFC == 1 )
  336. {
  337.  
  338. _SECTION_BEGIN( "TSFC" );
  339.  
  340. JSB_InitLib();
  341.  
  342. Phase = Param( "Phase", 1, 1, 200, 1, 0 );
  343. T1 = Param( "T", 3, 1, 200, 1, 0 );
  344.  
  345. Y = C;
  346. Displacement = Param( "Displacement", 1, -50, 50 );
  347.  
  348.  
  349. TSFC = LinRegSlope( Y, T1 ) + ( ( T1 * Sum( Cum( 1 ) * Y, T1 ) - Sum( Cum( 1 ), T1 ) * Sum( Y, T1 ) ) / ( T1 * Sum( ( Cum( 1 ) ^ 2 ), T1 ) -
  350. ( Sum( Cum( 1 ), T1 ) ^ 2 ) ) * Cum( 1 ) + ( MA( Y, T1 ) - MA( Cum( 1 ), T1 ) * ( T1 * Sum( Cum( 1 ) * Y, T1 ) -
  351. Sum( Cum( 1 ), T1 ) * Sum( Y, T1 ) ) / ( T1 * Sum( ( Cum( 1 ) ^ 2 ), T1 ) - ( Sum( Cum( 1 ), T1 ) ^ 2 ) ) ) );
  352.  
  353.  
  354.  
  355.  
  356. AA = JSB_JMA( TSFC, T1, Phase );
  357. Plot( C, "", colorWhite, styleCandle | styleThick );
  358. Plot( AA, "", colorYellow, styleLine | styleThick | styleDots, 0, 0, Displacement );
  359.  
  360. _SECTION_END();
  361.  
  362. }
  363.  
  364. if ( SR == 1 )
  365. {
  366.  
  367.  
  368. _SECTION_BEGIN( "SR " );
  369.  
  370. //sbrAll
  371.  
  372. SetBarsRequired( 100, 0 );
  373. xx = Cum( 1 );
  374. nbar = Param( "nbar", 5, 2, 50, 1 );
  375.  
  376. PHigh = H > Ref( HHV( H, nbar ), -1 ) AND Ref( HHV( H, nbar ), nbar ) <= H;
  377. PHighPrice = ValueWhen( PHigh, H );
  378. PLow = L < Ref( LLV( L, nbar ), -1 ) AND Ref( LLV( L, nbar ), nbar ) >= L;
  379. PLowPrice = ValueWhen( PLow, L );
  380.  
  381. startval_L = ValueWhen( PLow, L, 1 );
  382. endval_L = ValueWhen( PLow, L, 0 );
  383. startbar_L = ValueWhen( PLow, xx, 1 );
  384. endbar_L = ValueWhen( PLow, xx, 0 );
  385. aa_L = ( endval_L - startval_L ) / ( endbar_L - startbar_L );
  386. bb_L = startval_L;
  387. trendline_L = aa_L * ( xx - startbar_L ) + bb_L;
  388. dtrendline_L = trendline_L - Ref( trendline_L, -1 );
  389.  
  390. startval_L_extend = ValueWhen( PLow, L, 2 );
  391. endval_L_extend = ValueWhen( PLow, L, 1 );
  392. startbar_L_extend = ValueWhen( PLow, xx, 2 );
  393. endbar_L_extend = ValueWhen( PLow, xx, 1 );
  394. aa_L_extend = ( endval_L_extend - startval_L_extend ) / ( endbar_L_extend - startbar_L_extend );
  395. bb_L_extend = startval_L;
  396. trendline_L_extend = aa_L_extend * ( xx - startbar_L ) + endval_L_extend;
  397.  
  398. dtrendline_L_extend = trendline_L_extend - Ref( trendline_L_extend, -1 );
  399. dtrendline_L_extend = IIf( PLow, Ref( dtrendline_L, -1 ), dtrendline_L_extend );
  400.  
  401. startval_L_extend2 = ValueWhen( PLow, L, 3 );
  402. endval_L_extend2 = ValueWhen( PLow, L, 2 );
  403. startbar_L_extend2 = ValueWhen( PLow, xx, 3 );
  404. endbar_L_extend2 = ValueWhen( PLow, xx, 2 );
  405. aa_L_extend2 = ( endval_L_extend2 - startval_L_extend2 ) / ( endbar_L_extend2 - startbar_L_extend2 );
  406. bb_L_extend2 = endval_L_extend2;
  407. trendline_L_extend2 = aa_L_extend2 * ( xx - endbar_L_extend2 ) + endval_L_extend2;
  408.  
  409. dtrendline_L_extend2 = trendline_L_extend2 - Ref( trendline_L_extend2, -1 );
  410. dtrendline_L_extend2 = IIf( PLow, Ref( dtrendline_L_extend, -1 ), dtrendline_L_extend2 );
  411.  
  412. startval_H = ValueWhen( PHigh, H, 1 );
  413. endval_H = ValueWhen( PHigh, H, 0 );
  414. startbar_H = ValueWhen( PHigh, xx, 1 );
  415. endbar_H = ValueWhen( PHigh, xx, 0 );
  416. aa_H = ( endval_H - startval_H ) / ( endbar_H - startbar_H );
  417. bb_H = startval_H;
  418. trendline_H = aa_H * ( xx - startbar_H ) + bb_H;
  419. dtrendline_H = trendline_H - Ref( trendline_H, -1 );
  420.  
  421. startval_H_extend = ValueWhen( PHigh, H, 2 );
  422. endval_H_extend = ValueWhen( PHigh, H, 1 );
  423. startbar_H_extend = ValueWhen( PHigh, xx, 2 );
  424. endbar_H_extend = ValueWhen( PHigh, xx, 1 );
  425. aa_H_extend = ( endval_H_extend - startval_H_extend ) / ( endbar_H_extend - startbar_H_extend );
  426. bb_H_extend = startval_H;
  427. trendline_H_extend = aa_H_extend * ( xx - startbar_H ) + endval_H_extend;
  428. dtrendline_H_extend = trendline_H_extend - Ref( trendline_H_extend, -1 );
  429. dtrendline_H_extend = IIf( PHigh, Ref( dtrendline_H, -1 ), dtrendline_H_extend );
  430.  
  431. startval_H_extend2 = ValueWhen( PHigh, H, 3 );
  432. endval_H_extend2 = ValueWhen( PHigh, H, 2 );
  433. startbar_H_extend2 = ValueWhen( PHigh, xx, 3 );
  434. endbar_H_extend2 = ValueWhen( PHigh, xx, 2 );
  435. aa_H_extend2 = ( endval_H_extend2 - startval_H_extend2 ) / ( endbar_H_extend2 - startbar_H_extend2 );
  436. bb_H_extend2 = endval_H_extend2;
  437. trendline_H_extend2 = aa_H_extend2 * ( xx - endbar_H_extend2 ) + endval_H_extend2;
  438.  
  439. dtrendline_H_extend2 = trendline_H_extend2 - Ref( trendline_H_extend2, -1 );
  440. dtrendline_H_extend2 = IIf( PHigh, Ref( dtrendline_H_extend, -1 ), dtrendline_H_extend2 );
  441.  
  442. tld = ParamToggle( "All trendlines", "Show|Hide", 1 );
  443.  
  444. if ( tld )
  445. {
  446.  
  447. trendline_L = IIf( dtrendline_L > 0, trendline_L, Null );
  448. trendline_L_extend = IIf( dtrendline_L_extend > 0, trendline_L_extend, Null );
  449. trendline_L_extend2 = IIf( dtrendline_L_extend2 > 0, trendline_L_extend2, Null );
  450. trendline_H = IIf( dtrendline_H < 0, trendline_H, Null );
  451. trendline_H_extend = IIf( dtrendline_H_extend < 0, trendline_H_extend, Null );
  452. trendline_H_extend2 = IIf( dtrendline_H_extend2 < 0, trendline_H_extend2, Null );
  453. }
  454.  
  455. trendline_L_extend2 = IIf( BarsSince( Plow ) <= nbar, trendline_L_extend2, Null );
  456.  
  457. trendline_H_extend2 = IIf( BarsSince( PHigh ) <= nbar, trendline_H_extend2, Null );
  458.  
  459. GraphXSpace = 5;
  460. SetChartOptions( 0, chartShowDates );
  461. chartflag = ParamToggle( "Heikin Ashi", "show|hide", 1 );
  462.  
  463. if ( chartFlag )
  464. {
  465. Plot( C, "", colorWhite, styleBar );
  466. }
  467. else
  468. {
  469. HaClose = ( O + H + L + C ) / 4;
  470. HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
  471. HaHigh = Max( H, Max( HaClose, HaOpen ) );
  472. HaLow = Min( L, Min( HaClose, HaOpen ) );
  473. PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "Modified " + Name(), colorWhite, styleBar );
  474. }
  475.  
  476. PlotShapes( shapeHollowStar*PLow, colorYellow, 0, L, -10 );
  477.  
  478. PlotShapes( shapeHollowStar*PHigh, colorRed, 0, H, 10 );
  479.  
  480. Plot( trendline_L, "", colorBrightGreen, styleLine );
  481.  
  482. Plot( IIf( BarsSince( Plow ) <= nbar, trendline_L_extend, Null ), "", colorLightGrey, styleNoLine | styleDots | styleThick );
  483. Plot( IIf( BarsSince( Plow ) > nbar, trendline_L_extend, Null ), "", colorBrightGreen, styleNoLine | styleDots | styleThick );
  484.  
  485. Plot( IIf( BarsSince( Plow ) <= nbar, trendline_L_extend2, Null ), "", colorDarkGreen, styleNoLine | styleDots | styleThick );
  486.  
  487. Plot( trendline_H, "", colorRed, styleLine );
  488.  
  489. Plot( IIf( BarsSince( PHigh ) <= nbar, trendline_H_extend, Null ), "", colorLightGrey, styleNoLine | styleDots | styleThick );
  490. Plot( IIf( BarsSince( PHigh ) > nbar, trendline_H_extend, Null ), "", colorOrange, styleNoLine | styleDots | styleThick );
  491.  
  492. Plot( IIf( BarsSince( PHigh ) <= nbar, trendline_H_extend2, Null ), "", colorOrange, styleNoLine | styleDots | styleThick );
  493.  
  494.  
  495. signalFlag = ParamToggle( "Possible Signals", "show|hide", 1 );
  496.  
  497. if ( signalFlag )
  498. {
  499.  
  500. Buy = ( !IsEmpty( trendline_H_extend ) AND Cross( C, trendline_H_extend ) AND BarsSince( PHigh ) > nbar ) OR
  501. ( !IsEmpty( trendline_H_extend2 ) AND Cross( C, trendline_H_extend2 ) AND !PHigh ) OR
  502. ( PHigh AND C > trendline_H_extend2 AND Ref( C, -1 ) < Ref( trendline_H_extend, -1 ) AND !IsEmpty( trendline_H_extend ) AND !IsEmpty( trendline_H_extend2 ) );
  503. BuyPrice = C;
  504. Short = ( !IsEmpty( trendline_L_extend ) AND Cross( trendline_L_extend, C ) AND BarsSince( PLow ) > nbar ) OR
  505. ( !IsEmpty( trendline_L_extend2 ) AND Cross( trendline_L_extend2, C ) AND !PLow ) OR
  506. ( PLow AND C < trendline_L_extend2 AND Ref( C, -1 ) > Ref( trendline_L_extend, -1 ) AND !IsEmpty( trendline_L_extend ) AND !IsEmpty( trendline_L_extend2 ) );
  507. ShortPrice = C;
  508. Sell = 0;
  509. Cover = 0;
  510. }
  511.  
  512. _SECTION_END();
  513. }
  514.  
  515.  
  516.  
  517. if ( SILVER == 1 )
  518. {
  519.  
  520. CHART == 0;
  521. _SECTION_BEGIN( "SILVER" );
  522. Col_1 = IIf( EMA( RSI( 39 ), 30 ) > Ref( EMA( RSI( 39 ), 30 ), -1 ), colorGreen, colorOrange );
  523.  
  524. Plot( C, "", col_1, styleCandle + styleThick );
  525. _SECTION_END();
  526.  
  527. _SECTION_BEGIN( "guppy" );
  528. e3 = EMA( Close, 3 );
  529. e5 = EMA( Close, 5 );
  530. e8 = EMA( Close, 8 );
  531. e10 = EMA( Close, 10 );
  532. e12 = EMA( Close, 12 );
  533. e15 = EMA( Close, 15 );
  534.  
  535. e30 = EMA( Close, 30 );
  536. e35 = EMA( Close, 35 );
  537. e40 = EMA( Close, 40 );
  538. e45 = EMA( Close, 45 );
  539. e50 = EMA( Close, 50 );
  540. e55 = EMA( Close, 55 );
  541. e60 = EMA( Close, 60 );
  542. Buy_guppy = e3 > e60;
  543. Sell_guppy = e60 > e3;
  544. Buy_guppy = ExRem ( Buy_guppy, Sell_guppy );
  545. Sell_guppy = ExRem( Sell_guppy, Buy_guppy );
  546. PlotShapes( Buy_guppy*shapeHollowSmallUpTriangle, colorYellow );
  547. PlotShapes( Sell_guppy*shapeHollowSmallDownTriangle , colorYellow );
  548.  
  549. Plot ( e3, "", colorBlue, styleThick );
  550. Plot ( e5, "", colorBlue, styleThick );
  551. Plot ( e8, "", colorBlue, styleThick );
  552. Plot ( e10, "", colorBlue, styleNoLabel );
  553. Plot ( e12, "", colorBlue, styleNoLabel );
  554. Plot ( e15, "", colorBlue, styleNoLabel );
  555.  
  556. Plot ( e30, "", colorYellow, styleThick );
  557. Plot ( e35, "", colorRed, styleNoLabel + styleThick );
  558. Plot ( e40, "", colorRed, styleNoLabel + styleThick );
  559. Plot ( e45, "", colorRed, styleNoLabel + styleThick );
  560. Plot ( e50, "", colorRed, styleNoLabel + styleThick );
  561. Plot ( e55, "", colorRed, styleNoLabel + styleThick );
  562. Plot ( e60, "", colorRed, styleNoLabel + styleThick );
  563.  
  564. _SECTION_END();
  565.  
  566. _SECTION_BEGIN( "rsi de ema" );
  567.  
  568. Buy_rsi = EMA( RSI( 21 ), 3 ) > EMA( RSI( 21 ), 34 );
  569. Sell_rsi = EMA( RSI( 21 ), 34 ) > EMA( RSI( 21 ), 3 );
  570.  
  571. Buy = Buy_rsi AND Buy_guppy;
  572. Sell = sell_rsi AND sell_guppy;
  573. Buy = ExRem( Buy, Sell );
  574. Sell = ExRem( Sell, Buy );
  575.  
  576.  
  577.  
  578. _SECTION_END();
  579.  
  580. _SECTION_BEGIN( "Tops and bottom" );
  581.  
  582. pd = Param( "Periods", 13, 5, 144, 1 );
  583. pds = 2 * pd - 1;
  584. aa = Close - Ref( Close, -1 );
  585. uu = EMA( Max( 0, aa ), pds );
  586. dd = EMA( ( Max( 0, 0 - aa ) ), pds );
  587.  
  588. rf = IIf( C > 2, 1000, 10000 );
  589.  
  590. c1 = Param( "Upper Level", 70, 50, 90, 1 );
  591. qq1 = 100 / ( 100 - c1 ) - 1;
  592. ff1 = qq1 * dd - uu;
  593. ff2 = ff1 / qq1;
  594. f1 = Max( ff1, ff2 );
  595. UL = Close + f1 * ( pds - 1 ) / 2;
  596. UL = IIf( UL > C, floor( UL * rf ), ceil( UL * rf ) ) / rf;
  597.  
  598. c2 = Param( "Equilibrium", 50, 50, 50, 0 );
  599. qq2 = 100 / ( 100 - c2 ) - 1;
  600. ff = dd - uu;
  601. MM = Close + ff * ( pds - 1 ) / 2;
  602. MM = IIf( MM > C, floor( MM * rf ), ceil( MM * rf ) ) / rf;
  603.  
  604. c3 = Param( "Lower Level", 30, 10, 50, 1 );
  605. qq3 = 100 / ( 100 - c3 ) - 1;
  606. ff1 = qq3 * dd - uu;
  607. ff2 = ff1 / qq3;
  608. f3 = Min( ff1, ff2 );
  609. LL = Close + f3 * ( pds - 1 ) / 2;
  610. LL = IIf( LL > C, floor( LL * rf ), ceil( LL * rf ) ) / rf;
  611.  
  612. band = Param( "band width", 4, 0, 15, 0.25 );
  613. mmu = MM + band;
  614. mmd = MM - band;
  615.  
  616.  
  617. X = Cross( C, LL );
  618. Y = Cross( UL, C );
  619.  
  620. Buy1 = X ;
  621. Sell1 = Y ;
  622.  
  623. PlotShapes( shapeCircle*Buy1, colorRed, 0, L, -15 );
  624. PlotShapes( shapeCircle*Sell1, colorGreen, 0, H, -15 );
  625.  
  626. Filter = Buy1 OR Sell1 ;
  627. AddTextColumn( FullName(), "Name" );
  628. AddColumn( Buy1, "Buy" );
  629. AddColumn( Sell1, "sell" );
  630.  
  631.  
  632. dist = 1.5 * ATR( 10 );
  633.  
  634. for ( i = 0; i < BarCount; i++ )
  635. {
  636.  
  637. if ( Buy_guppy[i] )
  638. PlotText( "Buy @ \n" + C[i] , i, L[ i ] - dist[i], colorYellow, colorGreen );
  639.  
  640. if ( Sell_guppy[i] )
  641. PlotText( "Sell@ \n" + C[i], i, H[ i ] + dist[i], colorYellow, colorRed );
  642.  
  643. if ( Sell1[i] )
  644. PlotText( "Top" , i, H[ i ] + dist[i], colorGreen, colorYellow );
  645.  
  646. if ( Buy1[i] )
  647. PlotText( "Bottom", i, L[ i ] - dist[i], colorRed, colorYellow );
  648.  
  649.  
  650. }
  651.  
  652. PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -40 );
  653.  
  654. PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -50 );
  655. PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -45 );
  656. PlotShapes( IIf( Sell, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
  657. PlotShapes( IIf( Sell, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
  658. PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45 );
  659.  
  660. _SECTION_END();
  661. SellPrice = ValueWhen( Sell_guppy, C, 1 );
  662. BuyPrice = ValueWhen( Buy_guppy, C, 1 );
  663. Long = Flip( Buy_guppy, Sell_guppy );
  664. Shrt = Flip( Sell_guppy, Buy_guppy );
  665.  
  666. _SECTION_BEGIN( "Pivot calc" );
  667.  
  668. TimeFrameSet( in15Minute*2 );
  669. DH = Ref( H, -1 );
  670. DL = Ref( L, -1 );
  671. DC = Ref( C, -1 );
  672.  
  673.  
  674. pd = ( DH + DL + DC ) / 3;
  675. sd1 = ( 2 * pd ) - DH;
  676. sd2 = pd - ( DH - DL );
  677. sd3 = Sd1 - ( DH - DL );
  678. rd1 = ( 2 * pd ) - DL;
  679. rd2 = pd + ( DH - DL );
  680. rd3 = rd1 + ( DH - DL );
  681.  
  682. TimeFrameRestore();
  683.  
  684. _SECTION_END();
  685.  
  686.  
  687. Title =
  688. EncodeColor( colorWhite ) + "Linkon's Silver" + " - " + Name() + " - " + EncodeColor( colorRed ) + Interval( 2 )
  689. + EncodeColor( colorWhite ) + " - " + Date() + " - "
  690. + "\n"
  691.  
  692. + EncodeColor( colorYellow ) + "Op-" + O + " " + "Hi-" + H + " " + "Lo-" + L + " " + "Cl-" + C + " " + "Vol= " + WriteVal( V )
  693. + "\n"
  694. + WriteIf ( Sell_guppy , " EXIT LONG / Reverse Signal at " + C + "\n", "" )
  695. + WriteIf ( Buy_guppy , " EXIT SHORT / Reverse Signal at " + C + "\n", "" )
  696.  
  697. + WriteIf( Sell_guppy , "Total Profit / Loss for the Last Trade Rs." + ( C - BuyPrice ) + "", "" ) +
  698. WriteIf( Buy_guppy , "Total Profit / Loss for the Last trade Rs." + ( SellPrice - C ) + "", "" ) +
  699. WriteIf( Long AND NOT Buy_guppy, EncodeColor( colorLime ) + "Trade : Long - Entry price Rs." + ( BuyPrice ) + " Tgt : " + UL, "" ) +
  700. WriteIf( shrt AND NOT Sell_guppy, EncodeColor( colorRed ) + "Trade : Short - Entry price Rs." + ( SellPrice ) + " Tgt : " + LL, "" ) + "\n" +
  701. WriteIf( Long AND NOT Buy_guppy, "Current Profit / Loss Rs." + ( C - BuyPrice ) + "", "" ) +
  702. WriteIf( shrt AND NOT Sell_guppy, "Current Profit / Loss Rs." + ( SellPrice - C ) + "", "" )
  703. + EncodeColor( colorBrightGreen ) + "\n R3 : " + EncodeColor( colorWhite ) + RD3
  704. + EncodeColor( colorBrightGreen ) + "\n R2 : " + EncodeColor( colorWhite ) + RD2
  705. + EncodeColor( colorBrightGreen ) + "\n R1 : " + EncodeColor( colorWhite ) + RD1 + EncodeColor( colorBrightGreen ) + " UP TGT : " + EncodeColor( colorWhite ) + UL
  706. + EncodeColor( colorBlue ) + "\n Pivot : " + EncodeColor( colorWhite ) + pd + EncodeColor( colorBlue ) + " MIDPOINT : " + EncodeColor( colorWhite ) + MM
  707. + EncodeColor( colorRed ) + "\n S1 : " + EncodeColor( colorWhite ) + SD1 + EncodeColor( colorRed ) + " BOT TGT : " + EncodeColor( colorWhite ) + LL
  708. + EncodeColor( colorRed ) + "\n S2 : " + EncodeColor( colorWhite ) + SD2
  709. + EncodeColor( colorRed ) + "\n S3 : " + EncodeColor( colorWhite ) + SD3
  710. ;
  711.  
  712.  
  713. SetChartBkGradientFill( ParamColor( "Inner panel upper", colorYellow ), ParamColor( "Inner panel lower", colorYellow ) );
  714.  
  715. _SECTION_BEGIN( "Magnified Market Price" );
  716.  
  717. FS = Param( "Font Size", 28, 11, 100, 1 );
  718. GfxSelectFont( "Arial", FS, 700, italic = False, underline = False, True );
  719. GfxSetBkMode( colorWhite );
  720. GfxSetTextColor( ParamColor( "Color", colorViolet ) );
  721. Hor = Param( "Horizontal Position", 766, 1, 1200, 1 );
  722. Ver = Param( "Vertical Position", 1, 1, 1, 1 );
  723. GfxTextOut( "" + C, Hor , Ver );
  724. YC = TimeFrameGetPrice( "C", inDaily, -1 );
  725. DD = Prec( C - YC, 2 );
  726. xx = Prec( ( DD / YC ) * 100, 2 );
  727. GfxSelectFont( "Arial", 12, 700, italic = False, underline = False, True );
  728. GfxSetBkMode( colorWhite );
  729. GfxSetTextColor( ParamColor( "Color", colorViolet ) );
  730. GfxTextOut( "" + DD + " (" + xx + "%)", Hor + 5, Ver + 45 );
  731. _SECTION_END();
  732.  
  733. }
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740. if ( TREND == 1 )
  741. {
  742. _SECTION_BEGIN( "TREND" );
  743.  
  744. Plot( C, "", colorWhite, styleCandle | styleThick );
  745. P = ParamField( "Price field", -1 );
  746. Daysback = Param( "Period for Liner Regression Line", 21, 1, 240, 1 );
  747. shift = Param( "Look back period", 0, 0, 240, 1 );
  748.  
  749.  
  750.  
  751.  
  752. x = Cum( 1 );
  753. lastx = LastValue( x ) - shift;
  754. aa = LastValue( Ref( LinRegIntercept( p, Daysback ), -shift ) );
  755. bb = LastValue( Ref( LinRegSlope( p, Daysback ), -shift ) );
  756. y = Aa + bb * ( x - ( Lastx - DaysBack + 1 ) );
  757.  
  758.  
  759.  
  760.  
  761.  
  762. LRColor = ParamColor( "LR Color", colorCycle );
  763. LRStyle = ParamStyle( "LR Style" );
  764.  
  765. LRLine = IIf( x > ( lastx - Daysback ) AND BarIndex() < Lastx, y, Null );
  766. Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE );
  767.  
  768.  
  769.  
  770. SDP = Param( "Standard Deviation", 1.5, 0, 6, 0.1 );
  771. SD = SDP / 2;
  772.  
  773. z = ( GetPerformanceCounter() / 100 ) % 256;
  774. anim = ColorHSB( ( z ) % 256, 255, Param( "Brightness", 75, 0, 255, 1 ) );
  775. RequestTimedRefresh( 1 );
  776.  
  777.  
  778. width = LastValue( Ref( SD * StDev( p, Daysback ), -shift ) );
  779. SDU = IIf( x > ( lastx - Daysback ) AND BarIndex() < Lastx, y + width , Null ) ;
  780. SDL = IIf( x > ( lastx - Daysback ) AND BarIndex() < Lastx, y - width , Null ) ;
  781.  
  782. SDColor = ParamColor( "SD Color", colorCycle );
  783. SDStyle = ParamStyle( "SD Style" );
  784.  
  785. Plot( SDU , "Upper Lin Reg", colorYellow, SDStyle );
  786. Plot( SDL , "Lower Lin Reg", colorYellow, SDStyle );
  787.  
  788. PlotOHLC( O, SDU, SDL, C , _DEFAULT_NAME(), anim, styleCloud );
  789.  
  790.  
  791.  
  792. SDP2 = Param( "2d Standard Deviation", 2.0, 0, 6, 0.1 );
  793. SD2 = SDP2 / 2;
  794.  
  795. width2 = LastValue( Ref( SD2 * StDev( p, Daysback ), -shift ) );
  796. SDU2 = IIf( x > ( lastx - Daysback ) AND BarIndex() < Lastx, y + width2 , Null ) ;
  797. SDL2 = IIf( x > ( lastx - Daysback ) AND BarIndex() < Lastx, y - width2 , Null ) ;
  798.  
  799. SDColor2 = ParamColor( "2 SD Color", colorCycle );
  800. SDStyle2 = ParamStyle( "2 SD Style" );
  801.  
  802. Plot( SDU2 , "Upper Lin Reg", SDColor2, SDStyle2 );
  803. Plot( SDL2 , "Lower Lin Reg", SDColor2, SDStyle2 );
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810. _SECTION_END();
  811. }
  812.  
  813.  
  814. if ( NICK_MA == 1 )
  815. {
  816. _SECTION_BEGIN( "NICK_MA" );
  817. SetBarsRequired( 200, 0 );
  818.  
  819. GraphXSpace = 5;
  820. k = Optimize( "K", Param( "K", 1, 0.01, 5, 0.25 ), 0.01, 5, 0.25 ) ;
  821. Per = Optimize( "atr", Param( "atr", 4, 3, 20, 1 ), 3, 20, 1 );
  822. HACLOSE = ( O + H + L + C ) / 4;
  823. HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
  824. HaHigh = Max( H, Max( HaClose, HaOpen ) );
  825. HaLow = Min( L, Min( HaClose, HaOpen ) );
  826. j = Haclose;
  827.  
  828. f = ATR( 14 );
  829.  
  830. rfsctor = WMA( H - L, Per );
  831.  
  832. revers = k * rfsctor;
  833.  
  834. Trend = 1;
  835. NW[0] = 0;
  836.  
  837.  
  838. for ( i = 1; i < BarCount; i++ )
  839. {
  840. if ( Trend[i-1] == 1 )
  841. {
  842. if ( j[i] < NW[i-1] )
  843. {
  844. Trend[i] = -1;
  845. NW[i] = j[i] + Revers[i];
  846. }
  847. else
  848. {
  849. Trend[i] = 1;
  850.  
  851. if ( ( j[i] - Revers[i] ) > NW[i-1] )
  852. {
  853. NW[i] = j[i] - Revers[i];
  854. }
  855. else
  856. {
  857. NW[i] = NW[i-1];
  858. }
  859. }
  860. }
  861.  
  862. if ( Trend[i-1] == -1 )
  863. {
  864. if ( j[i] > NW[i-1] )
  865. {
  866. Trend[i] = 1;
  867. NW[i] = j[i] - Revers[i];
  868. }
  869. else
  870. {
  871. Trend[i] = -1;
  872.  
  873. if ( ( j[i] + Revers[i] ) < NW[i-1] )
  874. {
  875. NW[i] = j[i] + Revers[i];
  876. }
  877. else
  878. {
  879. NW[i] = NW[i-1];
  880. }
  881. }
  882. }
  883. }
  884.  
  885. JSB_InitLib();
  886.  
  887. Length = Param( "Length ", 1, 1, 500, 1 );
  888. Phase = Param( "Phase", 1, 1, 1000, 1 );
  889. Color = IIf( Trend == 1, colorYellow, colorBrown );
  890.  
  891. JSB_NW = JSB_JMA( NW, Length, Phase );
  892. Color_NW = IIf( C >= JSB_NW, colorWhite, colorRed );
  893.  
  894. PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), Color, styleBar | styleThick );
  895. Color = IIf( Trend == 1, 27, 4 );
  896. Plot( JSB_NW, "", Color_NW, styleLine | styleThick );
  897.  
  898. Buy = Cover = Cross( j, JSB_NW );
  899. Sell = Short = Cross( JSB_NW, j );
  900. SellPrice = ValueWhen( Sell, C, 1 );
  901. BuyPrice = ValueWhen( Buy, C, 1 );
  902. Long = Flip( Buy, Sell );
  903. Shrt = Flip( Sell, Buy );
  904. _SECTION_END();
  905.  
  906. acc = Param( "Acceleration", 0.02, 0, 1, 0.001 );
  907. accm = Param( "Max. acceleration", 0.2, 0, 1, 0.001 );
  908. Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorYellow ), ParamStyle( "Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
  909.  
  910. _SECTION_BEGIN( "Title" );
  911.  
  912. if ( Status( "action" ) == actionIndicator )
  913. (
  914. Title = EncodeColor( colorWhite ) + "NICK MA Swing System" + " - " + Name() + " - " + EncodeColor( colorRed ) + Interval( 2 ) + EncodeColor( colorWhite ) +
  915. " - " + Date() + " - " + "\n" + EncodeColor( colorYellow ) + "Op-" + O + " " + "Hi-" + H + " " + "Lo-" + L + " " +
  916. "Cl-" + C + " " + "Vol= " + WriteVal( V ) + "\n" +
  917. EncodeColor( colorLime ) +
  918. WriteIf ( Buy , " ALI?A GIDIYOR / SINYALLE TERS " + C + " ", "" ) + EncodeColor( colorRed ) +
  919. WriteIf ( Sell , " SATI? S?NYAL? / SINYALLE TERS " + C + " ", "" ) + "\n" + EncodeColor( colorWhite ) +
  920. WriteIf( Sell , "SON TRADEDE TOPLAM KAR/ZARAR" + ( C - BuyPrice ) + "", "" ) +
  921. WriteIf( Buy , "SON TRADEDE TOPLAM KAR/ZARAR" + ( SellPrice - C ) + "", "" ) +
  922. WriteIf( Long AND NOT Buy, "Trade : UZUN G?R?? F?YAT" + ( BuyPrice ), "" ) +
  923. WriteIf( shrt AND NOT Sell, "Trade : KISA G?R?? F?YAT" + ( SellPrice ), "" ) + "\n" +
  924. WriteIf( Long AND NOT Buy, "GEร‡ERL? KAR/ZARAR." + ( C - BuyPrice ) + "", "" ) +
  925. WriteIf( shrt AND NOT Sell, "GEร‡ERL? KAR/ZARAR." + ( SellPrice - C ) + "", "" ) );
  926.  
  927. PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -40 );
  928.  
  929. PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -50 );
  930.  
  931. PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -45 );
  932.  
  933. PlotShapes( IIf( Sell, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
  934.  
  935. PlotShapes( IIf( Sell, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
  936.  
  937. PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45 );
  938. }
  939.  
  940. _SECTION_END();
  941.  
  942. if ( ZIGZAG == 1 )
  943. {
  944. _SECTION_BEGIN( "ZIGZAG" );
  945. zz0 = Zig( Close, 7 );
  946. zz1 = Ref( zz0, -1 );
  947. zz2 = Ref( zz0, -2 );
  948. tr = ValueWhen( zz0 > zz1 AND zz1 < zz2, zz1 );
  949. pk = ValueWhen( zz0 < zz1 AND zz1 > zz2, zz1 );
  950. PU = tr + abs( tr ) * 0.05;
  951. PD = pk - abs( pk ) * 0.05;
  952. res = IIf( Close >= PU AND zz0 > zz1, 1,
  953. IIf( Close <= PD AND zz0 < zz1, -1, 0 ) );
  954. res = ValueWhen( res != 0, res );
  955. Buy = res == 1 AND Ref( res, -1 ) == -1;
  956. Sell = res == -1 AND Ref( res, -1 ) == 1;
  957. Short = Sell;
  958. Cover = Buy;
  959.  
  960. Plot( zz0, "ZigZag", colorYellow, styleThick );
  961. Plot( Close, "Price", colorBrightGreen, styleCandle | styleThick );
  962.  
  963. PlotShapes( Buy * shapeUpArrow, colorGreen );
  964. PlotShapes( Sell * shapeDownArrow, colorRed );
  965.  
  966. Plot( Flip( Buy, Sell ), "Trade", 12, styleArea | styleOwnScale, 0, 1 );
  967. _SECTION_END();
  968. }
  969.  
  970.  
  971. if ( STREND == 1 )
  972. {
  973.  
  974. _SECTION_BEGIN( "STREND" );
  975.  
  976. ZAMAN = Param( "ZAMAN", 20, 1, 2000, 1 );
  977. mtOpen = LinearReg( Open, ZAMAN ); // calculate moving trend from open
  978. mtHigh = LinearReg( High, ZAMAN ); // calculate moving trend from open
  979. mtLow = LinearReg( Low, ZAMAN ); // calculate moving trend from open
  980. mtClose = LinearReg( Close, ZAMAN ); // calculate moving trend from open
  981. // plot surrogate chart
  982. PlotOHLC( mtOpen, mtHigh, mtLow, mtClose, "Surrogate", colorWhite, styleCandle );
  983. _SECTION_END();
  984.  
  985. _SECTION_BEGIN( "DESTEK D?RENร‡ " );
  986.  
  987.  
  988.  
  989. SetBarsRequired( sbrAll, sbrAll );
  990. xx = Cum( 1 );
  991. nbar = Param( "nbar", 5, 2, 50, 1 );
  992.  
  993. PHigh = mtHigh > Ref( HHV( mtHigh, nbar ), -1 ) AND Ref( HHV( mtHigh, nbar ), nbar ) <= mtHigh;
  994. PHighPrice = ValueWhen( PHigh, mtHigh );
  995. PLow = mtLow < Ref( LLV( mtLow, nbar ), -1 ) AND Ref( LLV( mtLow, nbar ), nbar ) >= mtLow;
  996. PLowPrice = ValueWhen( PLow, mtLow );
  997.  
  998. startval_L = ValueWhen( PLow, mtLow, 1 );
  999. endval_L = ValueWhen( PLow, mtLow, 0 );
  1000. startbar_L = ValueWhen( PLow, xx, 1 );
  1001. endbar_L = ValueWhen( PLow, xx, 0 );
  1002. aa_L = ( endval_L - startval_L ) / ( endbar_L - startbar_L );
  1003. bb_L = startval_L;
  1004. trendline_L = aa_L * ( xx - startbar_L ) + bb_L;
  1005. dtrendline_L = trendline_L - Ref( trendline_L, -1 );
  1006.  
  1007. startval_L_extend = ValueWhen( PLow, mtLow, 2 );
  1008. endval_L_extend = ValueWhen( PLow, mtLow, 1 );
  1009. startbar_L_extend = ValueWhen( PLow, xx, 2 );
  1010. endbar_L_extend = ValueWhen( PLow, xx, 1 );
  1011. aa_L_extend = ( endval_L_extend - startval_L_extend ) / ( endbar_L_extend - startbar_L_extend );
  1012. bb_L_extend = startval_L;
  1013. trendline_L_extend = aa_L_extend * ( xx - startbar_L ) + endval_L_extend;
  1014.  
  1015. dtrendline_L_extend = trendline_L_extend - Ref( trendline_L_extend, -1 );
  1016. dtrendline_L_extend = IIf( PLow, Ref( dtrendline_L, -1 ), dtrendline_L_extend );
  1017.  
  1018. startval_L_extend2 = ValueWhen( PLow, mtLow, 3 );
  1019. endval_L_extend2 = ValueWhen( PLow, mtLow, 2 );
  1020. startbar_L_extend2 = ValueWhen( PLow, xx, 3 );
  1021. endbar_L_extend2 = ValueWhen( PLow, xx, 2 );
  1022. aa_L_extend2 = ( endval_L_extend2 - startval_L_extend2 ) / ( endbar_L_extend2 - startbar_L_extend2 );
  1023. bb_L_extend2 = endval_L_extend2;
  1024. trendline_L_extend2 = aa_L_extend2 * ( xx - endbar_L_extend2 ) + endval_L_extend2;
  1025.  
  1026. dtrendline_L_extend2 = trendline_L_extend2 - Ref( trendline_L_extend2, -1 );
  1027. dtrendline_L_extend2 = IIf( PLow, Ref( dtrendline_L_extend, -1 ), dtrendline_L_extend2 );
  1028.  
  1029. startval_H = ValueWhen( PHigh, mtHigh, 1 );
  1030. endval_H = ValueWhen( PHigh, mtHigh, 0 );
  1031. startbar_H = ValueWhen( PHigh, xx, 1 );
  1032. endbar_H = ValueWhen( PHigh, xx, 0 );
  1033. aa_H = ( endval_H - startval_H ) / ( endbar_H - startbar_H );
  1034. bb_H = startval_H;
  1035. trendline_H = aa_H * ( xx - startbar_H ) + bb_H;
  1036. dtrendline_H = trendline_H - Ref( trendline_H, -1 );
  1037.  
  1038. startval_H_extend = ValueWhen( PHigh, mtHigh, 2 );
  1039. endval_H_extend = ValueWhen( PHigh, mtHigh, 1 );
  1040. startbar_H_extend = ValueWhen( PHigh, xx, 2 );
  1041. endbar_H_extend = ValueWhen( PHigh, xx, 1 );
  1042. aa_H_extend = ( endval_H_extend - startval_H_extend ) / ( endbar_H_extend - startbar_H_extend );
  1043. bb_H_extend = startval_H;
  1044. trendline_H_extend = aa_H_extend * ( xx - startbar_H ) + endval_H_extend;
  1045. dtrendline_H_extend = trendline_H_extend - Ref( trendline_H_extend, -1 );
  1046. dtrendline_H_extend = IIf( PHigh, Ref( dtrendline_H, -1 ), dtrendline_H_extend );
  1047.  
  1048. startval_H_extend2 = ValueWhen( PHigh, mtHigh, 3 );
  1049. endval_H_extend2 = ValueWhen( PHigh, mtHigh, 2 );
  1050. startbar_H_extend2 = ValueWhen( PHigh, xx, 3 );
  1051. endbar_H_extend2 = ValueWhen( PHigh, xx, 2 );
  1052. aa_H_extend2 = ( endval_H_extend2 - startval_H_extend2 ) / ( endbar_H_extend2 - startbar_H_extend2 );
  1053. bb_H_extend2 = endval_H_extend2;
  1054. trendline_H_extend2 = aa_H_extend2 * ( xx - endbar_H_extend2 ) + endval_H_extend2;
  1055.  
  1056. dtrendline_H_extend2 = trendline_H_extend2 - Ref( trendline_H_extend2, -1 );
  1057. dtrendline_H_extend2 = IIf( PHigh, Ref( dtrendline_H_extend, -1 ), dtrendline_H_extend2 );
  1058.  
  1059. tld = ParamToggle( "All trendlines", "Show|Hide", 1 );
  1060.  
  1061. if ( tld )
  1062. {
  1063.  
  1064. trendline_L = IIf( dtrendline_L > 0, trendline_L, Null );
  1065. trendline_L_extend = IIf( dtrendline_L_extend > 0, trendline_L_extend, Null );
  1066. trendline_L_extend2 = IIf( dtrendline_L_extend2 > 0, trendline_L_extend2, Null );
  1067. trendline_H = IIf( dtrendline_H < 0, trendline_H, Null );
  1068. trendline_H_extend = IIf( dtrendline_H_extend < 0, trendline_H_extend, Null );
  1069. trendline_H_extend2 = IIf( dtrendline_H_extend2 < 0, trendline_H_extend2, Null );
  1070. }
  1071.  
  1072. trendline_L_extend2 = IIf( BarsSince( Plow ) <= nbar, trendline_L_extend2, Null );
  1073.  
  1074. trendline_H_extend2 = IIf( BarsSince( PHigh ) <= nbar, trendline_H_extend2, Null );
  1075.  
  1076. GraphXSpace = 5;
  1077. SetChartOptions( 0, chartShowDates );
  1078. chartflag = ParamToggle( "Heikin Ashi", "show|hide", 1 );
  1079.  
  1080. if ( chartFlag )
  1081. {
  1082. }
  1083. else
  1084. {
  1085. HaClose = ( O + H + L + C ) / 4;
  1086. HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
  1087. HaHigh = Max( mtHigh, Max( HaClose, HaOpen ) );
  1088. HaLow = Min( mtLow, Min( HaClose, HaOpen ) );
  1089. PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "Modified " + Name(), colorWhite, styleBar );
  1090. }
  1091.  
  1092. PlotShapes( shapeHollowStar*PLow, colorYellow, 0, mtLow, -10 );
  1093.  
  1094. PlotShapes( shapeHollowStar*PHigh, colorRed, 0, mtHigh , 10 );
  1095.  
  1096. Plot( trendline_L, "", colorBrightGreen, styleLine );
  1097.  
  1098. Plot( IIf( BarsSince( Plow ) <= nbar, trendline_L_extend, Null ), "", colorLightGrey, styleNoLine | styleDots | styleThick );
  1099. Plot( IIf( BarsSince( Plow ) > nbar, trendline_L_extend, Null ), "", colorBrightGreen, styleNoLine | styleDots | styleThick );
  1100.  
  1101. Plot( IIf( BarsSince( Plow ) <= nbar, trendline_L_extend2, Null ), "", colorDarkGreen, styleNoLine | styleDots | styleThick );
  1102.  
  1103. Plot( trendline_H, "", colorRed, styleLine );
  1104.  
  1105. Plot( IIf( BarsSince( PHigh ) <= nbar, trendline_H_extend, Null ), "", colorLightGrey, styleNoLine | styleDots | styleThick );
  1106. Plot( IIf( BarsSince( PHigh ) > nbar, trendline_H_extend, Null ), "", colorOrange, styleNoLine | styleDots | styleThick );
  1107.  
  1108. Plot( IIf( BarsSince( PHigh ) <= nbar, trendline_H_extend2, Null ), "", colorOrange, styleNoLine | styleDots | styleThick );
  1109.  
  1110.  
  1111. signalFlag = ParamToggle( "Possible Signals", "show|hide", 1 );
  1112.  
  1113. if ( signalFlag )
  1114. {
  1115.  
  1116. Buy = ( !IsEmpty( trendline_H_extend ) AND Cross( mtClose, trendline_H_extend ) AND BarsSince( PHigh ) > nbar ) OR
  1117. ( !IsEmpty( trendline_H_extend2 ) AND Cross( mtClose, trendline_H_extend2 ) AND !PHigh ) OR
  1118. ( PHigh AND mtClose > trendline_H_extend2 AND Ref( mtClose, -1 ) < Ref( trendline_H_extend, -1 ) AND !IsEmpty( trendline_H_extend ) AND !IsEmpty( trendline_H_extend2 ) );
  1119. BuyPrice = mtClose;
  1120. Short = ( !IsEmpty( trendline_L_extend ) AND Cross( trendline_L_extend, mtClose ) AND BarsSince( PLow ) > nbar ) OR
  1121. ( !IsEmpty( trendline_L_extend2 ) AND Cross( trendline_L_extend2, C ) AND !PLow ) OR
  1122. ( PLow AND mtClose < trendline_L_extend2 AND Ref( mtClose, -1 ) > Ref( trendline_L_extend, -1 ) AND !IsEmpty( trendline_L_extend ) AND !IsEmpty( trendline_L_extend2 ) );
  1123. ShortPrice = mtClose;
  1124. Sell = 0;
  1125. Cover = 0;
  1126.  
  1127. _SECTION_BEGIN( "VAP" );
  1128.  
  1129. PlotVAPOverlayA( Buy , Param( "Lines", 300, 100, 1000, 1 ), Param( "Width", 100, 1, 100, 1 ), ParamColor( "Color", colorGold ), ParamToggle( "Side", "Left|Right" ) | 2 * ParamToggle( "Style", "Fill|Lines", 0 ) | 4*ParamToggle( "Z-order", "On top|Behind", 1 ) );
  1130. Plot( plow, "", colorLime, styleHistogram | styleDashed | styleOwnScale );
  1131. Plot( phigh, "", colorRed, styleHistogram | styleDashed | styleOwnScale );
  1132.  
  1133.  
  1134. _SECTION_END();
  1135.  
  1136. _SECTION_BEGIN( " EXPLORE" );
  1137.  
  1138. AL = ( !IsEmpty( trendline_H_extend ) AND Cross( mtClose, trendline_H_extend ) AND BarsSince( PHigh ) > nbar ) OR
  1139. ( !IsEmpty( trendline_H_extend2 ) AND Cross( mtClose, trendline_H_extend2 ) AND !PHigh ) OR
  1140. ( PHigh AND mtClose > trendline_H_extend2 AND Ref( mtClose, -1 ) < Ref( trendline_H_extend, -1 ) AND !IsEmpty( trendline_H_extend ) AND !IsEmpty( trendline_H_extend2 ) );
  1141. BuyPrice = mtClose;
  1142.  
  1143. SAT = ( !IsEmpty( trendline_L_extend ) AND Cross( trendline_L_extend, mtClose ) AND BarsSince( PLow ) > nbar ) OR
  1144. ( !IsEmpty( trendline_L_extend2 ) AND Cross( trendline_L_extend2, C ) AND !PLow ) OR
  1145. ( PLow AND mtClose < trendline_L_extend2 AND Ref( mtClose, -1 ) > Ref( trendline_L_extend, -1 ) AND !IsEmpty( trendline_L_extend ) AND !IsEmpty( trendline_L_extend2 ) );
  1146. ShortPrice = mtClose;
  1147.  
  1148.  
  1149.  
  1150. AL_status = WriteIf( AL, "Al?? Yap", " " );
  1151.  
  1152. SAT_status = WriteIf( SAT, "Sat?? Yap", " " );
  1153.  
  1154. AL_col = IIf( AL, colorDarkGreen , colorWhite );
  1155.  
  1156. SAT_col = IIf( SAT, colorRed, colorWhite );
  1157. }
  1158.  
  1159. Filter = AL OR SAT;
  1160.  
  1161. AddColumn( C, "KAPANI?", 1.2, IIf( C > Ref( C, -1 ), colorBlue, colorRed ) );
  1162. AddTextColumn( AL_status, "ALI?", 1.2, colorWhite, Al_col );
  1163. AddTextColumn( SAT_status, "SATI?", 1.2, colorWhite, SAT_col );
  1164.  
  1165. _SECTION_END();
  1166. }
  1167.  
  1168. Kisa = Param( "KISA GรœN", 12, 1, 500, 1 );
  1169.  
  1170. Uzun = Param( "UZUN GรœN", 43, 1, 1000, 1 );
  1171. Tetik = Param( "TETIK GรœN", 21, 1, 50, 1 );
  1172.  
  1173. function KisaPeriodTopla( Kisa )
  1174. {
  1175. ka = Kisa;
  1176.  
  1177. for ( i = 1; i < Kisa; i++ )
  1178. {
  1179. ka = ka + i;
  1180. }
  1181.  
  1182. return ka;
  1183. }
  1184.  
  1185.  
  1186. function UzunPeriodTopla( Uzun )
  1187. {
  1188. au = Uzun;
  1189.  
  1190. for ( iu = 0; iu < Uzun; iu++ )
  1191. {
  1192. au = au + iu;
  1193. }
  1194.  
  1195. return au;
  1196. }
  1197.  
  1198.  
  1199. function TetikPeriodTopla( Tetik )
  1200. {
  1201. a = Tetik;
  1202.  
  1203. for ( i = 0; i < Tetik; i++ )
  1204. {
  1205. a = a + i;
  1206. }
  1207.  
  1208. return a;
  1209. }
  1210.  
  1211.  
  1212. function KisaGunTopla( Kisa )
  1213. {
  1214. a = Kisa;
  1215.  
  1216. kd = a * C;
  1217.  
  1218. for ( i = 0;i < Kisa;i++ )
  1219. {
  1220. b = Ref( C, -i );
  1221.  
  1222. if ( a > 0 )
  1223. a--;
  1224.  
  1225. kd = kd + ( a * b );
  1226. }
  1227.  
  1228. return kd;
  1229. }
  1230.  
  1231.  
  1232. function UzunGunTopla( Uzun )
  1233. {
  1234. au = Uzun;
  1235. ku = au * C;
  1236.  
  1237. for ( iu = 0;iu < Uzun;iu++ )
  1238. {
  1239. bu = Ref( C, -iu );
  1240.  
  1241. if ( au > 0 )
  1242. au--;
  1243.  
  1244. ku = ku + ( au * bu );
  1245. }
  1246.  
  1247. return ku;
  1248. }
  1249.  
  1250. Period12Toplam = KisaPeriodTopla( Kisa );
  1251. Day12Toplam = KisaGunTopla( Kisa );
  1252. LWMA12 = Day12Toplam / Period12Toplam;
  1253. Period43Toplam = UzunPeriodTopla( Uzun );
  1254. Day43Toplam = UzunGunTopla( Uzun );
  1255. LWMA43 = Day43Toplam / Period43Toplam;
  1256.  
  1257.  
  1258. function XDAY( Tetik )
  1259. {
  1260.  
  1261. X = ( ( 2 * LWMA12 ) - LWMA43 );
  1262. aX = Tetik;
  1263. kX = AX * X;
  1264.  
  1265. for ( iX = 0;iX < Tetik;iX++ )
  1266. {
  1267. bX = Ref( X, -iX );
  1268.  
  1269. if ( aX > 0 )
  1270. aX--;
  1271.  
  1272. kX = kX + ( aX * bX );
  1273. }
  1274.  
  1275. return kX;
  1276. }
  1277.  
  1278.  
  1279. if ( TSR == 1 )
  1280. {
  1281.  
  1282.  
  1283.  
  1284. XDayToplam = XDAY( Tetik );
  1285. XPeriodToplam = TetikPeriodTopla( Tetik );
  1286. TSR = ( XDayToplam / XPeriodToplam );
  1287.  
  1288.  
  1289. Plot( C, "Kapanis", colorGrey50, styleCandle );
  1290. tsrcolor = IIf( TSR > Ref( TSR, -1 ), colorLime, colorRed );
  1291. Plot( TSR, "TSR", tsrcolor, styleLine | styleThick );
  1292.  
  1293. _SECTION_END();
  1294.  
  1295.  
  1296. }
  1297.  
  1298.  
  1299.  
  1300. if ( BOLLINGER == 0 )
  1301. {
  1302. _SECTION_BEGIN( "BOLLINGER" );
  1303.  
  1304. DisplayBBColor = ParamToggle( "Display BB Color", "No,Yes", 1 );
  1305. BollPeriods = Param( "Periode", 20, 0, 200, 1 );
  1306. Width = Param( "Std. Dev.", 2, 0, 10, 0.05 );
  1307. ColorBB = ParamColor( "BB color", ColorRGB( 64, 0, 0 ) );
  1308. TOP = BBandTop( C, BollPeriods, Width );
  1309. BOTTOM = BBandBot( C, BollPeriods, Width );
  1310.  
  1311. ORT = ( TOP + BOTTOM ) / 2;
  1312. Plot( C, "", colorWhite, styleCandle | styleThick );
  1313. Plot( IIf( Bollinger, Null, BBandTop( C, BollPeriods, Width ) ), "BBTop" + _PARAM_VALUES(), ParamColor( "Color", colorDarkRed ), styleThick + styleNoLabel );
  1314. Plot( IIf( Bollinger, Null, BBandBot( C, BollPeriods, Width ) ), "BBBot" + _PARAM_VALUES(), ParamColor( "Color", colorDarkRed ), styleThick + styleNoLabel );
  1315. Plot( ORT, "", colorBrightGreen, styleThick + styleDots );
  1316.  
  1317.  
  1318. if ( Bollinger == 0 AND DisplayBBColor == 1 )
  1319. {
  1320. PlotOHLC( Null, BBandTop( C, BollPeriods, Width ), BBandBot( C, BollPeriods, Width ), Null, "", ColorBB, styleCloud + styleNoLabel );
  1321. }
  1322.  
  1323. _SECTION_END();
  1324. }
  1325.  
  1326.  
  1327. if ( CHALOKE == 1 )
  1328. {
  1329. _SECTION_BEGIN( "CHALOKE" );
  1330.  
  1331. Plot( C, "", colorWhite, styleCandle | styleThick );
  1332. GraphXSpace = 1;
  1333. P1 = Param( "ShortTerm Period", 9, 3, 15, 1 );
  1334. P2 = Param( "MidTerm Period", 15, 9, 24, 1 );
  1335. P3 = Param( "LongTerm Period", 24, 15, 50, 1 );
  1336. P4 = Param( "Invesment Term", 5, 1, 12, 1 );
  1337. P5 = Param( "ATR Period", 5, 1, 25, 1 );
  1338. Sm = 2 * P5 / 10;
  1339. ATRX = Sm * ATR( P4 );
  1340. S = EMA( C, P1 ) - ATRX;
  1341. M = EMA( C, P2 ) - ATRX;
  1342. lg = EMA( C, P3 ) - ATRX;
  1343.  
  1344. Sht = IIf( C == HHV( C, 3 ), S, Ref( EMA( C, 9 ), -1 ) - ATRX );
  1345. Mid = IIf( C == HHV( C, 3 ), M, Ref( EMA( C, 15 ), -1 ) - ATRX );
  1346. Lng = IIf( C == HHV( C, 3 ), Lg, Ref( EMA( C, 24 ), -1 ) - ATRX );
  1347.  
  1348. ColorSys3 = IIf( Sht > Mid AND C > Sht , colorBrightGreen , IIf( C < lng OR Sht < lng , colorRed,
  1349. IIf( BarsSince( Sht > Mid AND C > Sht ) < BarsSince( C < lng OR Sht < lng ) , colorBrightGreen , colorRed ) ) );
  1350.  
  1351. BuySys3 = ColorSys3 == colorBrightGreen AND Ref( ColorSys3, -1 ) != colorBrightGreen ;
  1352. SellSys3 = ColorSys3 == colorRed AND Ref( ColorSys3, -1 ) != colorRed ;
  1353.  
  1354.  
  1355.  
  1356. Tghlow = Trough( C, 1.5 );
  1357. PKHg = Peak( C, 1.5 );
  1358.  
  1359.  
  1360.  
  1361. Heading = "AUTO SEC Version 1.2";
  1362.  
  1363. SECUpColor = ParamColor( "SEC-UpColor", colorBrightGreen );
  1364. SECDnColor = ParamColor( "SEC-DownColor", colorRed );
  1365. SECLastColor = ParamColor( "SEC-LastColor", 10 );
  1366. BckGndColor = ParamColor( "BackGroundColor", colorYellow );
  1367. ZZSwitch = Param( "ZZSwitch", 0, 0, 1, 1 );
  1368. Sens = Param( "Sens", 5, 0.5, 15, 0.5 );
  1369. SECSwitch = Param( "SECSwitch", 1, 0, 1, 1 );
  1370.  
  1371. BarPK = BarsSince( Zig( C, Sens ) == Peak( C, Sens ) );
  1372. BarTGH = BarsSince( Zig( C, Sens ) == Trough( C, Sens ) );
  1373. Turnpoint = Min( BarPK, BarTGH );
  1374. x = Cum( 1 );
  1375. lastxL = LastValue( x );
  1376. DaysbackL = LastValue( Min( PeakBars( C, Sens, 1 ), TroughBars( C, Sens , 1 ) ) ) + 1;
  1377. Endbars = IIf( PeakBars( C, Sens, 1 ) < TroughBars( C, Sens, 1 ), LastValue( ValueWhen( C == LLV( C, DaysbackL ), X ) ), LastValue( ValueWhen( C == HHV( C, DaysbackL ), X ) ) );
  1378. BarsL = Min( PeakBars( C, Sens, 1 ), TroughBars( C, Sens, 1 ) ) ;
  1379.  
  1380. aaL = ValueWhen( Ref( Endbars, -1 ) != Ref( x, -1 ) AND Endbars == x , LinRegIntercept( Close, DaysbackL - ( LastValue( x ) - Endbars ) ) );
  1381. bbL = ValueWhen( Ref( Endbars, -1 ) != Ref( x, -1 ) AND Endbars == x , LinRegSlope( Close, DaysbackL - ( LastValue( x ) - Endbars ) ) );
  1382. eL = ValueWhen( Ref( Endbars, -1 ) != Ref( x, -1 ) AND Endbars == x , StdErr( C, DaysbackL - ( LastValue( x ) - Endbars ) ) );
  1383. SlopeL = LastValue( bbL );
  1384. LevelL = LastValue( aaL );
  1385. ErrL = LastValue( eL );
  1386.  
  1387. MbackL = LevelL + slopeL * ( BarsL ) ;
  1388. UbackL = MBackL + 2 * ErrL;
  1389. LbackL = MBackL - 2 * ErrL;
  1390. WL = ( UbackL - LbackL ) / sqrt( ( SlopeL * SlopeL ) + 1 );
  1391. AA = IIf( X > ( LastValue( x ) - DaysbackL ) AND MbackL != 0, MbackL, Null );
  1392. AA1 = IIf( X > ( LastValue( x ) - DaysbackL ) AND MbackL != 0, UbackL, Null );
  1393. AA2 = IIf( X > ( LastValue( x ) - DaysbackL ) AND MbackL != 0, LbackL, Null );
  1394.  
  1395. Plot( IIf( X > ( LastValue( x ) - DaysbackL ) AND MbackL != 0, MbackL, Null ) , "", SECLastColor, styleNoLabel );
  1396. Plot( IIf( X > ( LastValue( x ) - DaysbackL ) AND MbackL != 0, UbackL, Null ) , "", SECLastColor, styleNoLabel );
  1397. Plot( IIf( X > ( LastValue( x ) - DaysbackL ) AND MbackL != 0, LbackL, Null ) , "", SECLastColor, styleNoLabel );
  1398.  
  1399. PlotOHLC( AA1, AA2, AA1, AA2, "", 12, styleNoLabel | styleCloud, 0 );
  1400.  
  1401.  
  1402. _SECTION_END();
  1403. }
  1404.  
  1405. if ( INTRA_TREND == 1 )
  1406. {
  1407. _SECTION_BEGIN( "INTRA_TREND" );
  1408.  
  1409.  
  1410.  
  1411. SetChartOptions( 0, chartShowArrows | chartShowDates );
  1412. ScanLookBack = Param( "Scan Lookback", 2, 1, 25 );
  1413. fraction = IIf( StrRight( Name(), 3 ) == "", 3.2, 3.2 );
  1414.  
  1415. _SECTION_BEGIN( "Price" );
  1416. SetChartOptions( 0, chartShowArrows | chartShowDates );
  1417. _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
  1418. Plot( C, _DEFAULT_NAME(), colorWhite , styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
  1419. _SECTION_END();
  1420.  
  1421. _SECTION_BEGIN( "Up Trend Line" );
  1422.  
  1423. UTValue1 = LastValue( Trough( L, 0.5, 2 ) );
  1424. UTValue2 = LastValue( Trough( L, 0.5, 1 ) );
  1425. UTBar1 = BarCount - 1 - LastValue( TroughBars( L, 0.5 , 2 ) );
  1426. UTBar2 = BarCount - 1 - LastValue( TroughBars( L, 0.5 , 1 ) );
  1427. UpTrendLine = LineArray( UTBar1, UTValue1, UTBar2, UTValue2, 1 );
  1428. UTLine = LineArray( UTBar1, UTValue1, UTBar2, UTValue2, 0 );
  1429. Plot( UpTrendLine , _DEFAULT_NAME(), colorGreen, styleLine | styleNoTitle | styleNoLabel );
  1430. Plot( UTLine , _DEFAULT_NAME(), colorGreen, styleLine | styleNoTitle | styleNoLabel );
  1431.  
  1432. _SECTION_END();
  1433.  
  1434.  
  1435. _SECTION_BEGIN( "Down Trend Line" );
  1436.  
  1437. DTValue1 = LastValue( Peak( H, 0.5 , 2 ) );
  1438. DTValue2 = LastValue( Peak( H, 0.5 , 1 ) );
  1439. DTBar1 = BarCount - 1 - LastValue( PeakBars( H, 0.5 , 2 ) );
  1440. DTBar2 = BarCount - 1 - LastValue( PeakBars( H, 0.5 , 1 ) );
  1441. DownTrendLine = LineArray( DTBar1, DTValue1, DTBar2, DTValue2, 1 );
  1442. DTLine = LineArray( DTBar1, DTValue1, DTBar2, DTValue2, 0 );
  1443.  
  1444. Plot( DownTrendLine , _DEFAULT_NAME(), colorRed, styleLine | styleNoTitle | styleNoLabel );
  1445. Plot( DTLine , _DEFAULT_NAME(), colorRed, styleLine | styleNoTitle | styleNoLabel );
  1446.  
  1447. PlotText( "PV = " + WriteVal( DTValue2 , fraction ), LastValue( BarIndex() ) + 2, ( DTValue2 ), colorRed );
  1448. PlotText( "TV = " + WriteVal( UTValue2, fraction ), LastValue( BarIndex() ) + 2, UTValue2, colorGreen );
  1449. PlotOHLC( UpTrendLine , UpTrendLine , DownTrendLine , DownTrendLine , "", colorPaleBlue, styleCloud | styleNoRescale );
  1450.  
  1451. Plot( LineArray( DTBar2, DTValue2, BarCount, DTValue2, 0 ), "", colorRed );
  1452. Plot( LineArray( UTBar2, UTValue2, BarCount, UTValue2, 0 ), "", colorGreen );
  1453.  
  1454. _SECTION_END();
  1455.  
  1456. _SECTION_BEGIN( "Pivot" );
  1457.  
  1458. YH = TimeFrameGetPrice( "H", inDaily, -1 ); // yesterdays high
  1459. YL = TimeFrameGetPrice( "L", inDaily, -1 ); // low
  1460. YC = TimeFrameGetPrice( "C", inDaily, -1 ); // close
  1461. TO = TimeFrameGetPrice( "O", inDaily ); // current day open
  1462.  
  1463. //Normal Pivot
  1464. PP = ( YH + YL + YC ) / 3;
  1465. R1 = ( 2 * PP ) - YL;
  1466. R2 = PP + ( YH - YL );
  1467. R3 = YH + 2 * ( PP - YL );
  1468. S1 = ( 2 * PP ) - YH;
  1469. S2 = PP - ( YH - YL );
  1470. S3 = YL - 2 * ( YH - PP ) ;
  1471.  
  1472. _SECTION_END();
  1473.  
  1474. _SECTION_BEGIN( "Title" );
  1475.  
  1476. Title = EncodeColor( colorWhite ) + Date() + " Close = " + EncodeColor( colorRed ) + Close +
  1477. EncodeColor( colorWhite ) + " Open = " + EncodeColor( colorWhite ) + O +
  1478. EncodeColor( colorWhite ) + " High = " + EncodeColor( 5 ) + H +
  1479. EncodeColor( colorWhite ) + " Low = " + EncodeColor( colorRed ) + L +
  1480. EncodeColor( colorWhite ) + " Volume = " + EncodeColor( colorWhite ) + V + "\n\n" +
  1481. EncodeColor( colorWhite ) + "Pivot Point= " + EncodeColor( colorWhite ) + PP +
  1482. EncodeColor( colorWhite ) + " Day's Open= " + EncodeColor( colorWhite ) + TO + "\n\n" +
  1483. EncodeColor( colorGreen ) + "If days open is greater than Pivot Point, market is in uptrend and \n" + EncodeColor( colorGreen ) + "if days Open is less than Pivot Point, market is in downtrend" + "\n\n" +
  1484. EncodeColor( colorRed ) + "R1= " + EncodeColor( colorWhite ) + R1 +
  1485. EncodeColor( colorRed ) + " R2= " + EncodeColor( colorWhite ) + R2 +
  1486. EncodeColor( colorRed ) + " R3= " + EncodeColor( colorWhite ) + R3 + "\n" +
  1487. EncodeColor( colorGreen ) + "S1= " + EncodeColor( colorWhite ) + S1 +
  1488. EncodeColor( colorGreen ) + " S2= " + EncodeColor( colorWhite ) + S2 +
  1489. EncodeColor( colorGreen ) + " S3= " + EncodeColor( colorWhite ) + S3 + "\n" +
  1490. EncodeColor( colorWhite ) + "____ _____ _______ _______ _______" + "\n";
  1491.  
  1492. _SECTION_END();
  1493.  
  1494. _SECTION_BEGIN( "Target" );
  1495.  
  1496. CBuy = Cross( C, DownTrendLine );
  1497. CSell = Cross( UpTrendLine , C );
  1498.  
  1499. baratbuy = ValueWhen( CBuy , BarIndex() ) ;
  1500. baratsell = ValueWhen( CSell , BarIndex() ) ;
  1501.  
  1502. PlotShapes( shapeUpTriangle* CBuy , colorBlue, O, L );
  1503. PlotShapes( shapeDownTriangle * CSell , colorRed, O, H );
  1504.  
  1505.  
  1506. _SECTION_END();
  1507.  
  1508. _SECTION_BEGIN( "Auto" );
  1509.  
  1510.  
  1511. Buy = ( CBuy ) AND ( ( BarCount - baratbuy ) <= ScanLookBack );
  1512. Sell = ( CSell ) AND ( ( BarCount - baratsell ) <= ScanLookBack ) ;
  1513.  
  1514. price = C[BarCount-1];
  1515.  
  1516. AlertIf( Buy, "", "Buy @" + C + " Price @ Trigger=" + price, 1 );
  1517. AlertIf( Sell, "", "Sell @" + C + " Price @ Trigger=" + price, 2 );
  1518.  
  1519. Filter = Buy OR Sell ;
  1520.  
  1521. Var = WriteIf( Buy, "BUY", WriteIf( Sell, "SELL", "" ) );
  1522.  
  1523. AddTextColumn( Var , "Buy/Sell", 1.2 , colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1524. AddColumn( price , "Price", 1.2, colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1525. AddColumn( C , "Price @ Trigger", 1.2, colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1526.  
  1527. stoploss = IIf( Buy, ( price * ( 1 - 0.01 ) ) , IIf( Sell, ( price * ( 1 + 0.01 ) ), 0 ) );
  1528. target1per = IIf( Buy, ( price * ( 1 + 0.01 ) ) , IIf( Sell, ( price * ( 1 - 0.01 ) ), 0 ) );
  1529. target15per = IIf( Buy, ( price * ( 1 + 0.015 ) ) , IIf( Sell, ( price * ( 1 - 0.015 ) ), 0 ) );
  1530. target2per = IIf( Buy, ( price * ( 1 + 0.02 ) ) , IIf( Sell, ( price * ( 1 - 0.02 ) ), 0 ) );
  1531.  
  1532. AddColumn( stoploss , "Stop Loss", 1.2, colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1533. AddColumn( target1per , "1% Target", 1.2, colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1534. AddColumn( target15per , "1.5% Target", 1.2, colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1535. AddColumn( target2per , "2% Target", 1.2, colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1536. AddColumn( V , "Volume", 1.2, colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1537.  
  1538. bardiff = BarCount - IIf( Buy, baratbuy, IIf( Sell, baratsell, 0 ) );
  1539. AddColumn( bardiff , "Bar Diff", 1.2, colorWhite, IIf( Buy, colorLime, IIf( Sell, colorOrange, colorWhite ) ) );
  1540.  
  1541.  
  1542. _SECTION_END();
  1543. _SECTION_END();
  1544. }
  1545.  
  1546.  
  1547.  
  1548.  
  1549. if ( EKEKO == 1 )
  1550. {
  1551. _SECTION_BEGIN( "EKEKO" );
  1552. //------------------------------------------------------------------------------
  1553. //
  1554. // price chart with trade calls for aroon + sar signs
  1555. //
  1556. //------------------------------------------------------------------------------
  1557.  
  1558. ScriptVersion = " explorativo del Main al 12 de set 2005";
  1559.  
  1560. //////////////////// PRECIO //////////////////////////////////////////////
  1561.  
  1562. Plot( C, "", colorWhite, styleCandle | styleNoLabel );
  1563.  
  1564. Filter = Close > 10;
  1565. AddColumn( Close, "Close" );
  1566.  
  1567. PositionSize = 100;
  1568.  
  1569. /////////////////////// MEDIAS MOVILES///////////////////
  1570.  
  1571. slope = Param( "slope", 2, 2, 100, 1 );
  1572. Color20 = IIf( LinRegSlope( MA( C, 20 ), slope ) < 0, colorRed, colorBrightGreen );
  1573. event1 = LinRegSlope( MA( C, 20 ), slope ) < 0;
  1574. Plot( MA( C, 20 ), "", Color20 , styleLine );
  1575. //Plot( event1, "", colorRose, styleArea|styleOwnScale);
  1576. Color50 = IIf( LinRegSlope( MA( C, 50 ), slope ) < 0, colorRed, colorBrightGreen );
  1577. Plot( MA( C, 50 ), "", Color50 , styleLine );
  1578. Color100 = IIf( LinRegSlope( MA( C, 100 ), slope ) < 0, colorRed, colorYellow );
  1579. Plot( MA( C, 100 ), "", Color100 , styleLine );
  1580. Color150 = IIf( LinRegSlope( MA( C, 150 ), slope ) < 0, colorRed, 10 );
  1581. Plot( MA( C, 150 ), "", Color150 , styleLine );
  1582.  
  1583. event1 = Cross( MA( C, 20 ), MA( C, 50 ) );
  1584. PlotShapes( IIf( event1 , shapeDigit1, 0 ) , 5, 0, L, -30 );
  1585.  
  1586. event2 = Cross( MA( C, 50 ), MA( C, 100 ) );
  1587. PlotShapes( IIf( event2 , shapeDigit2, 0 ) , 6, 0, L, -30 );
  1588.  
  1589. event3 = Cross( MA( C, 100 ), MA( C, 150 ) );
  1590. PlotShapes( IIf( event3 , shapeDigit3, 0 ) , 7, 0, L, -30 );
  1591.  
  1592. event4 = Cross( MA( C, 50 ), MA( C, 20 ) );
  1593. PlotShapes( IIf( event4 , shapeDigit4, 0 ) , 5, 0, H, 30 );
  1594.  
  1595. event5 = Cross( MA( C, 100 ), MA( C, 50 ) );
  1596. PlotShapes( IIf( event5 , shapeDigit5, 0 ) , 6, 0, H, 30 );
  1597.  
  1598. event6 = Cross( MA( C, 150 ), MA( C, 100 ) );
  1599. PlotShapes( IIf( event6 , shapeDigit6, 0 ) , 7, 0, H, 30 );
  1600.  
  1601. event7 = Cross( MA( C, 5 ), MA( C, 20 ) );
  1602. PlotShapes( IIf( event7 , shapeDigit7, 0 ) , 9, 0, L, -30 );
  1603.  
  1604.  
  1605. //////////////////////////////////MACD///////////////////////////////////
  1606.  
  1607. MACDRequired = 1;
  1608. FAST = Param( "FAST", 12, 0, 100, 1 );
  1609. SLOW = Param( "SLOW", 26, 0, 100, 1 );
  1610. SIG = Param( "SIG", 9, 0, 100, 1 );
  1611.  
  1612. MACDLine = MACD( FAST, SLOW );
  1613. MACDSignal = Signal( FAST, SLOW, SIG );
  1614. MACDHisto = MACDLine - MACDSignal;
  1615.  
  1616. MIN10 = Param( "X MACD10", 5, 1, 30, step = 0.1 );
  1617. MIN60 = Param( "X MACD60", 10, 1, 30, step = 0.1 );
  1618. MACDBACKBARS = Param( "Lookback MACD", 1, 1, 30, step = 1 );
  1619.  
  1620. MinDir = Param( "DirChange", 0.6, -5, 5, step = 0.01 );
  1621. NOEXCESS = Param( "Remove Excess Signals", 1, 0, 1, step = 1 );
  1622.  
  1623. if ( Interval() <= 600 )
  1624. MACDRequired = MIN10; // 10 minute +/-5 extreme
  1625.  
  1626. if ( Interval() >= 3600 )
  1627. MACDRequired = MIN60; // 60 minute +/- 10
  1628.  
  1629.  
  1630. /////////////////// HISTOGRAMA ////////////////////////////////
  1631.  
  1632. MACDHisto = MACDLine - MACDSignal;
  1633.  
  1634. HistDivUp = Cross( LinRegSlope( MACDHisto, 3 ), 0 );
  1635.  
  1636. HistDivDn = Cross( 0, LinRegSlope( MACDHisto, 3 ) );
  1637.  
  1638. HBuy = HistDivUp ;
  1639.  
  1640. HSell = HistDivDn ;
  1641.  
  1642.  
  1643. PlotShapes( IIf( HBuy , 3, 0 ) , colorBrightGreen, 0, L, -22 );
  1644.  
  1645. PlotShapes( IIf( HSell, 4, 0 ) , colorYellow, 0, H, -22 );
  1646.  
  1647.  
  1648. ////////////////////// AROON //////////////////////////////////
  1649.  
  1650. Period = Param( "Aroon Period", 14, 1, 100, 1 );
  1651.  
  1652. LLVBarsSince = LLVBars( L, Period ) + 1;
  1653.  
  1654. HHVBarsSince = HHVBars( H, Period ) + 1;
  1655.  
  1656. AD = 100 * ( Period - LLVBarsSince ) / ( Period - 1 );
  1657.  
  1658. AU = 100 * ( Period - HHVBarsSince ) / ( Period - 1 );
  1659.  
  1660. AO = AU - AD;
  1661.  
  1662. MINAROONOSC = Param( "AO ", 45, 0, 100, step = 0.1 );
  1663.  
  1664. MINAROONSIG = Param( "AV ", 99.9, 0, 100, step = 0.1 );
  1665.  
  1666. MINAROONOSC = Optimize( "Aroon Osc ", MINAROONOSC, 0, 100, step = 1 );
  1667.  
  1668. MINAROONSIG = Optimize( "Aroon Value", MINAROONSIG, 0, 100, step = 1 );
  1669.  
  1670. event1 = Cross( MINAROONSIG, AD ) AND AO <= -MINAROONOSC;
  1671.  
  1672. event2 = Cross( MINAROONSIG, AU ) AND AO >= MINAROONOSC;
  1673.  
  1674. // Include MACD / Signal Cross
  1675. AroonMACD = MACD() >= Signal();
  1676.  
  1677. event3 = Cross( MINAROONSIG, AU ) AND AO >= MINAROONOSC AND AroonMACD > 0;
  1678.  
  1679. event4 = Cross( MINAROONSIG, AD ) AND AO <= -MINAROONOSC ;
  1680.  
  1681. //if(AroonBuy[BarCount-1]) PlotShapes( ( AroonBuy OR AroonSell )+5 ,IIf( AroonBuy, colorPaleGreen, colorPink ), 0 );
  1682. event5 = Cross( AO, 0 );
  1683.  
  1684. event6 = Cross( 0, AO );
  1685.  
  1686. event7 = Cross( AO, -50 );
  1687.  
  1688. event8 = Cross( 0, AO );
  1689.  
  1690. event9 = Cross( AU, AD );
  1691.  
  1692. event10 = Cross( AD, AU );
  1693.  
  1694. //Plot(AU ,"AU" ,colorBrightGreen,styleLine);
  1695. //Plot(AD,"AD" ,colorRed ,styleLine);
  1696. //Plot(AO ,"Osc",Coloryellow,styleLine+styleOwnScale);
  1697.  
  1698. AroonBuy = event9;
  1699.  
  1700. AroonSell = event10;
  1701.  
  1702. PlotShapes( IIf( AroonBuy , 5, 0 ) , colorBrightGreen, 0, L );
  1703.  
  1704. PlotShapes( IIf( AroonSell, 6, 0 ) , colorYellow, 0, H );
  1705.  
  1706.  
  1707. //////////////////////////////// DMI //////////////////////////////////
  1708.  
  1709. MACDLine = MACD( FAST, SLOW );
  1710.  
  1711. range = Param( "R ADX ", 14, 1, 50, step = 1 );
  1712.  
  1713. //Prefs(49);
  1714.  
  1715. MINADX = Param( "X ADX ", 30, 1, 50, step = 0.1 );
  1716.  
  1717. ADXBACKBARS = Param( "LB ADX", 3, 1, 30, step = 1 );
  1718.  
  1719.  
  1720. // Find the direction of ADX
  1721. ADXTipDirA = LinRegSlope( ADX( range ), 2 ); // Short term direction change
  1722.  
  1723. ADXTipDir = LinRegSlope( ADXTipDirA * 4, 3 ); // Short term direction change
  1724.  
  1725. ADXFastDir = LinRegSlope( ADX( range ), 3 ); // Medium
  1726.  
  1727. ADXSlowDir = LinRegSlope( ADX( range ), 6 ); // Longer
  1728.  
  1729. // Direction *CHANGE* of ADX at the 'extremes'
  1730. ADXSlopeUp = Cross( ADXTipDir, 0 ) AND ADX( range ) < 20;
  1731.  
  1732. ADXSlopeDn = Cross( 0, ADXTipDir ) AND ADX( range ) > MINADX;
  1733.  
  1734. ADXHistory = ADX( range );
  1735.  
  1736. ADXBuy1 = ADXFastDir > 0 AND ADX( range ) > 20 AND ( PDI( range ) > MDI( range ) ) AND MACDLine > 0;//TrendUp
  1737.  
  1738. ADXSell2 = ADXFastDir > 0 AND ADX( range ) > 20 AND ( MDI( range ) > PDI( range ) ) AND MACDLine < 0; //TrendDown
  1739.  
  1740. ADXBuy3 = ADXSlowDir > 0; //AND ADX(range)< 20 AND ( PDI(range)>MDI(range));//WarnUp
  1741.  
  1742. ADXSell4 = ADXSlowDir > 0; //AND ADX(range)< 20 AND ( MDI(range)>PDI(range));//WarnDn
  1743.  
  1744.  
  1745. ADXBuy5 = ADX( range ) > MDI( range ) AND MDI( range ) > 30;//MDIX
  1746.  
  1747. ADXSell6 = ADX( range ) > PDI( range ) AND PDI( range ) > 30;//PDIX
  1748.  
  1749. ADXBuy7 = BarsSince( ADXTipDir < MinDIR ) < BarsSince( ADXBuy1 ) + ADXBACKBARS AND ADX( range ) > MINADX;
  1750.  
  1751. ADXSell8 = BarsSince( ADXTipDir < MinDIR ) < BarsSince( ADXSell6 ) + ADXBACKBARS AND ADX( range ) > MINADX;
  1752.  
  1753. ADXBuy9 = BarsSince( MACDLine < -MACDRequired ) < MACDBACKBARS ; // AND HistDivUp;
  1754.  
  1755. ADXSell10 = BarsSince( MACDLine > MACDRequired ) < MACDBACKBARS; // AND HistDivDn;
  1756.  
  1757. ADXBuy11 = ADXBuy5 AND ADXSlopeDn;
  1758.  
  1759. ADXSell12 = ADXSell6 AND ADXSlopeDn;
  1760.  
  1761. ADXBuy13 = ADXBuy5 AND ADXTipDir < 0 AND Peak( ADXHistory, 0.5, 1 ) > ADX( range ); //AND ADXSlopeDn;
  1762.  
  1763. ADXSell14 = ADXSell6 AND ADXTipDir < 0 AND Peak( ADXHistory, 0.5, 1 ) > ADX( range ); //AND ADXSlopeDn;
  1764.  
  1765. ADXBuy15 = ADXBuy5 AND ADXTipDir < 0 AND ADXHistory[BarCount-10] < ADX( range ); //AND ADXSlopeDn;
  1766.  
  1767. ADXSell16 = ADXSell6 AND ADXTipDir < 0 AND ADXHistory[BarCount-10] < ADX( range ); //AND ADXSlopeDn;
  1768.  
  1769. ADXBuy17 = ADXBuy5 AND ADXSlopeDn;
  1770.  
  1771. ADXBuy18 = Cross( PDI( range ), MDI( range ) );
  1772.  
  1773. ADXSell19 = Cross( MDI( range ), PDI( range ) );
  1774.  
  1775. ADXBuy = ADXBuy18;
  1776.  
  1777. ADXSell = ADXSell19;
  1778.  
  1779. // Remove excess Buy/Sell Signals from ADX Based Signals
  1780. if ( NOEXCESS )
  1781. ADXBuy = ExRemSpan( ADXBuy, 5 );
  1782.  
  1783. if ( NOEXCESS )
  1784. ADXSell = ExRemSpan( ADXSell, 5 );
  1785.  
  1786.  
  1787. PlotShapes( IIf( ADXBuy , 5, 0 ) , colorYellow, 0 );
  1788.  
  1789. PlotShapes( IIf( ADXSell, 6, 0 ) , colorWhite, 0 );
  1790.  
  1791.  
  1792. ////////////////////// BOLLINGER BANDS ///////////////////////
  1793.  
  1794. TopBand = BBandTop( Close, 20, 2 );
  1795.  
  1796. LowBand = BBandBot( Close, 20, 2 );
  1797.  
  1798. dirup = ( BarsSince( Low < LowBand ) < 5 );
  1799.  
  1800. dirdn = ( BarsSince( High > TopBand ) < 5 );
  1801.  
  1802. BBBuy = 0;
  1803.  
  1804. BBSell = 0;
  1805.  
  1806. ///////////////////// ORDEN DE COMPRA ////////////////////////////////////
  1807.  
  1808. //Buy = AroonBuy;
  1809. //Sell = AroonSell;
  1810.  
  1811. // Remove excess Buy/Sell Signals
  1812.  
  1813. //Short = Sell;
  1814. //Cover = Buy;
  1815.  
  1816. //if(NOEXCESS) Buy = ExRemSpan( Buy, 1 );
  1817. //if(NOEXCESS) Sell = ExRemSpan( Sell, 1 );
  1818.  
  1819. //PlotShapes( IIf(Buy ,1,0) ,colorBlue, 0,Graph0,-18 );
  1820. //PlotShapes( IIf(Sell,2,0) ,colorYellow, 0,Graph0,-18 );
  1821.  
  1822. //////////////////REGRESION LINEAL ///////////////////////////////////
  1823.  
  1824. LookBack = Param( "Lookback (RegressionChannel)", 72, 1, 300 );
  1825.  
  1826. NH = LastValue( HHVBars( High, LookBack ) ); // lookback period - can be set by the user if necessary
  1827.  
  1828. NL = LastValue( LLVBars( Low , LookBack ) ); // lookback period - can be set by the user if necessary
  1829.  
  1830. N = 0;
  1831.  
  1832. if ( NL > NH )
  1833. {
  1834. N = NL;
  1835. }
  1836. else
  1837. {
  1838. N = NH;
  1839. }
  1840.  
  1841. Start = 1;
  1842.  
  1843. X = Cum( Start ); // Set up the x cordinate array of the Linear Regression Line
  1844. Y = Close; // Set the y co-ordinate of the Linear Regression line
  1845.  
  1846. /* Calculate the slope (bconst) and the y intercept (aconst) of the line */
  1847.  
  1848. SUMX = LastValue( Sum( X, N ) );
  1849. SUMY = LastValue( Sum( Y, N ) );
  1850. SUMXY = LastValue( Sum( X * Y, N ) );
  1851. SUMXSqd = LastValue( Sum( X * X, N ) );
  1852. SUMSqdX = LastValue( SUMX * SUMX );
  1853.  
  1854. bconst = ( N * SUMXY - SUMX * SUMY ) / ( N * SUMXSqd - SUMSqdX );
  1855. aconst = ( SUMY - bconst * ( SUMX ) ) / N;
  1856.  
  1857. /* Force the x value to be very negative so the graph does not apear before the
  1858. lookback period */
  1859.  
  1860. Domain = IIf ( X > LastValue( X ) - N, 1 , -1e10 );
  1861. Xvar = X * Domain;
  1862.  
  1863. /* Linear Regression Line */
  1864.  
  1865. Yvar = aconst + bconst * Xvar;
  1866.  
  1867. Plot( Yvar + LastValue( HHV( High - Yvar, N ) ), "Upper Channel", colorWhite, styleLine | styleNoLabel );
  1868. Plot( Yvar, "Middle Channel", colorWhite, styleLine | styleNoLabel );
  1869. Plot( Yvar - LastValue( HHV( Yvar - Low , N ) ), "Lower Channel", colorWhite, styleLine | styleNoLabel );
  1870.  
  1871.  
  1872.  
  1873. ///////////////// SAR ////////////////////////////////////////////////
  1874.  
  1875. IAF = 0.02; // acceleration factor
  1876. MaxAF = 0.2; // max acceleration
  1877.  
  1878. psar = Close; // initialize
  1879. long = 1; // assume long for initial conditions
  1880. af = IAF; // init acelleration factor
  1881. ep = Low[ 0 ]; // init extreme point
  1882. hp = High [ 0 ];
  1883. lp = Low [ 0 ];
  1884.  
  1885. for ( i = 2; i < BarCount; i++ )
  1886. {
  1887. if ( long )
  1888. {
  1889. psar [ i ] = psar [ i-1 ] + af * ( hp - psar [ i-1 ] );
  1890. }
  1891. else
  1892. {
  1893. psar [ i ] = psar [ i-1 ] + af * ( lp - psar [ i-1 ] );
  1894. }
  1895.  
  1896. reverse = 0;
  1897.  
  1898. //check for reversal
  1899.  
  1900. if ( long )
  1901. {
  1902. if ( Low [ i ] < psar [ i ] )
  1903. {
  1904. long = 0;
  1905. reverse = 1; // reverse position to Short
  1906. psar [ i ] = hp; // SAR is High point in prev trade
  1907. lp = Low [ i ];
  1908. af = IAF;
  1909. }
  1910. }
  1911. else
  1912. {
  1913. if ( High [ i ] > psar [ i ] )
  1914. {
  1915. long = 1;
  1916. reverse = 1; //reverse position to long
  1917. psar [ i ] = lp;
  1918. hp = High [ i ];
  1919. af = IAF;
  1920. }
  1921. }
  1922.  
  1923. if ( reverse == 0 )
  1924. {
  1925. if ( long )
  1926. {
  1927. if ( High [ i ] > hp )
  1928. {
  1929. hp = High [ i ];
  1930. af = af + IAF;
  1931.  
  1932. if ( af > MaxAF )
  1933. af = MaxAF;
  1934. }
  1935.  
  1936. if ( Low[ i - 1 ] < psar[ i ] )
  1937. psar[ i ] = Low[ i - 1 ];
  1938.  
  1939. if ( Low[ i - 2 ] < psar[ i ] )
  1940. psar[ i ] = Low[ i - 2 ];
  1941. }
  1942. else
  1943. {
  1944. if ( Low [ i ] < lp )
  1945. {
  1946. lp = Low [ i ];
  1947. af = af + IAF;
  1948.  
  1949. if ( af > MaxAF )
  1950. af = MaxAF;
  1951. }
  1952.  
  1953. if ( High[ i - 1 ] > psar[ i ] )
  1954. psar[ i ] = High[ i - 1 ];
  1955.  
  1956. if ( High[ i - 2 ] > psar[ i ] )
  1957. psar[ i ] = High[ i - 2 ];
  1958.  
  1959. }
  1960. }
  1961. }
  1962.  
  1963. Plot( psar, "SAR", colorSkyblue, styleDots | styleNoLine | styleThick );
  1964.  
  1965.  
  1966.  
  1967.  
  1968. ///////////// COMENTARIOS DE INTERPRETACION ///////////////////
  1969.  
  1970. if ( SelectedValue( ADXBuy1 ) OR SelectedValue( ADXSell2 ) )
  1971. {
  1972. if ( SelectedValue( ADXBuy1 ) )
  1973. {
  1974. printf( "We're in a uptrend." );
  1975. };
  1976.  
  1977. if ( SelectedValue( ADXSell2 ) )
  1978. {
  1979. printf( "We're in a downtrend." );
  1980. };
  1981. }
  1982. else
  1983. {
  1984. printf( "Falling ADX - watch for MACD Histogram Divergence" );
  1985.  
  1986. if ( SelectedValue( HistDivUp ) )
  1987. printf( "(currently UP)" );
  1988.  
  1989. if ( SelectedValue( HistDivDn ) )
  1990. printf( "(currently DOWN)" );
  1991. }
  1992.  
  1993. if ( SelectedValue( ADXFastDir ) > 0 )
  1994. {
  1995. if ( SelectedValue( ADXBuy5 ) )
  1996. printf( "Wait for retest of low, and then ADX turn down" );
  1997.  
  1998. if ( SelectedValue( ADXSell6 ) )
  1999. printf( "Wait for retest of high, and then ADX turn down" );
  2000. }
  2001.  
  2002.  
  2003. WriteIf( BBBuy , "Bollinger Buy Signal (usually good until 20EMA)", "" );
  2004.  
  2005. WriteIf( BBSell , "Bollinger Sell Signal (usually good until 20EMA)", "" );
  2006.  
  2007. WriteIf( ADXBuy3 , "Watch out - could be a beginning uptrend.", "" );
  2008. WriteIf( ADXSell4 , "Watch out - could be a beginning downtrend.", "" );
  2009.  
  2010. WriteIf( ADXBuy1 AND MACDLine < 1 AND HistDivDn, "*WARNING* Trend could fail to begin !", "" );
  2011. WriteIf( ADXSell2 AND MACDLine > -1 AND HistDivUp, "*WARNING* Trend could fail to begin !", "" );
  2012.  
  2013.  
  2014. WriteIf( ADX( range ) < 20 , "Trading range, weak direction - watch for Histogram Divergences", "" );
  2015.  
  2016.  
  2017. WriteIf( True , " ------- DEBUG -------", "" );
  2018. WriteIf( HistDivUp , "Histogram divergence up ", "Hup wait" );
  2019. WriteIf( HistDivDn , "Histogram divergence down", "Hdn wait" );
  2020. WriteIf( ADXSlopeUp , "ADX Up ", "Aup wait" );
  2021. WriteIf( ADXSlopeDn , "ADX Dn ", "Adn wait" );
  2022. WriteIf( MDI( range ) > 30 , "MDI", "DMI wait" );
  2023. WriteIf( PDI( range ) > 30 , "PDI", "DMI wait" );
  2024. WriteIf( ADXBuy5 , "MDI-X", "DMI wait" );
  2025. WriteIf( ADXSell6 , "PDI-X", "DMI wait" );
  2026. _SECTION_END();
  2027. }
  2028.  
  2029. if ( CANDLE_PIVOT_TRENDLINES == 1 )
  2030. {
  2031. _SECTION_BEGIN( "CANDLE_PIVOT_TRENDLINES" );
  2032.  
  2033. /////// advance trenlines with candle pivots ///////////////////
  2034. SetChartOptions( 0, chartShowArrows | chartShowDates );
  2035. _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} ,{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
  2036. Plot( C, "", IIf( O >= C, colorOrange, colorGreen ), styleCandle );
  2037. SetChartBkGradientFill( ParamColor( "Inner panel upper", colorBlack ), ParamColor( "Inner panel lower", colorBlack ) );
  2038. _N( Title = EncodeColor( colorWhite ) + StrFormat( " {{NAME}} - {{INTERVAL}} {{DATE}} Open:%g,high:%g,low:%g, Close:%g ,{{VALUES}}", O, H, L, C ) );
  2039. /////////////////////////////////////////////////////////////////////////////////////////////
  2040. farback = Param( "How Far back to go", 100, 50, 5000, 10 );
  2041. nBars = Param( "Number of bars", 12, 5, 40 );
  2042. aHPivs = H - H;
  2043. aLPivs = L - L;
  2044. aHPivHighs = H - H;
  2045. aLPivLows = L - L;
  2046. aHPivIdxs = H - H;
  2047. aLPivIdxs = L - L;
  2048. nHPivs = 0;
  2049. nLPivs = 0;
  2050. lastHPIdx = 0;
  2051. lastLPIdx = 0;
  2052. lastHPH = 0;
  2053. lastLPL = 0;
  2054. curPivBarIdx = 0;
  2055. aHHVBars = HHVBars( H, nBars );
  2056. aLLVBars = LLVBars( L, nBars );
  2057. aHHV = HHV( H, nBars );
  2058. aLLV = LLV( L, nBars );
  2059. aVisBars = Status( "barvisible" );
  2060. nLastVisBar = LastValue( Highest( IIf( aVisBars, BarIndex(), 0 ) ) );
  2061. _TRACE( "Last visible bar: " + nLastVisBar );
  2062. curBar = ( BarCount - 1 );
  2063. curTrend = "";
  2064.  
  2065. if ( aLLVBars[curBar] < aHHVBars[curBar] )
  2066. {
  2067. curTrend = "D";
  2068. }
  2069.  
  2070. else
  2071. {
  2072. curTrend = "U";
  2073. }
  2074.  
  2075. for ( i = 0; i < farback; i++ )
  2076. {
  2077. curBar = ( BarCount - 1 ) - i;
  2078.  
  2079. if ( aLLVBars[curBar] < aHHVBars[curBar] )
  2080. {
  2081. if ( curTrend == "U" )
  2082. {
  2083. curTrend = "D";
  2084. curPivBarIdx = curBar - aLLVBars[curBar];
  2085. aLPivs[curPivBarIdx] = 1;
  2086. aLPivLows[nLPivs] = L[curPivBarIdx];
  2087. aLPivIdxs[nLPivs] = curPivBarIdx;
  2088. nLPivs++;
  2089. }
  2090. }
  2091. else
  2092. {
  2093. if ( curTrend == "D" )
  2094. {
  2095. curTrend = "U";
  2096. curPivBarIdx = curBar - aHHVBars[curBar];
  2097. aHPivs[curPivBarIdx] = 1;
  2098. aHPivHighs[nHPivs] = H[curPivBarIdx];
  2099. aHPivIdxs[nHPivs] = curPivBarIdx;
  2100. nHPivs++;
  2101. }
  2102. }
  2103. }
  2104.  
  2105. curBar = ( BarCount - 1 );
  2106.  
  2107. candIdx = 0;
  2108. candPrc = 0;
  2109. lastLPIdx = aLPivIdxs[0];
  2110. lastLPL = aLPivLows[0];
  2111. lastHPIdx = aHPivIdxs[0];
  2112. lastHPH = aHPivHighs[0];
  2113.  
  2114. if ( lastLPIdx > lastHPIdx )
  2115. {
  2116. candIdx = curBar - aHHVBars[curBar];
  2117. candPrc = aHHV[curBar];
  2118.  
  2119. if ( lastHPH < candPrc AND candIdx > lastLPIdx AND candIdx < curBar )
  2120. {
  2121. aHPivs[candIdx] = 1;
  2122.  
  2123. for ( j = 0; j < nHPivs; j++ )
  2124. {
  2125. aHPivHighs[nHPivs - j] = aHPivHighs[nHPivs - ( j + 1 )];
  2126. aHPivIdxs[nHPivs - j] = aHPivIdxs[nHPivs - ( j + 1 )];
  2127. }
  2128.  
  2129. aHPivHighs[0] = candPrc;
  2130.  
  2131. aHPivIdxs[0] = candIdx;
  2132. nHPivs++;
  2133. }
  2134. }
  2135.  
  2136. else
  2137. {
  2138. candIdx = curBar - aLLVBars[curBar];
  2139. candPrc = aLLV[curBar];
  2140.  
  2141. if ( lastLPL > candPrc AND candIdx > lastHPIdx AND candIdx < curBar )
  2142. {
  2143. aLPivs[candIdx] = 1;
  2144.  
  2145. for ( j = 0; j < nLPivs; j++ )
  2146. {
  2147. aLPivLows[nLPivs - j] = aLPivLows[nLPivs - ( j + 1 )];
  2148. aLPivIdxs[nLPivs - j] = aLPivIdxs[nLPivs - ( j + 1 )];
  2149. }
  2150.  
  2151. aLPivLows[0] = candPrc;
  2152.  
  2153. aLPivIdxs[0] = candIdx;
  2154. nLPivs++;
  2155. }
  2156. }
  2157.  
  2158. for ( k = 0; k < nHPivs; k++ )
  2159. {
  2160. _TRACE( "High pivot no. " + k + " at barindex: " + aHPivIdxs[k] + ", " + WriteVal( ValueWhen( BarIndex() == aHPivIdxs[k], DateTime(), 1 ), formatDateTime ) + ", " + aHPivHighs[k] );
  2161. }
  2162.  
  2163. a1 = ahpivs == 1;
  2164.  
  2165. a2 = alpivs == 1;
  2166. PlotShapes( a1 *shapeSmallCircle, colorRed, 0, H, Offset = 5 );
  2167. PlotShapes( a2 *shapeSmallCircle, colorGreen, 0, L, Offset = -5 );
  2168. //////////////////////////////////////////////////////
  2169.  
  2170. Para = ParamToggle( "Plot Parallel Lines", "Off,On" );
  2171. ColorS = ParamColor( "Support", colorLime );
  2172. ColorR = ParamColor( "Resistance", colorRed );
  2173. x = Cum( 1 );
  2174. s1 = L;
  2175. s11 = H;
  2176. pS = a2 == 1;
  2177.  
  2178.  
  2179.  
  2180. endt = LastValue( ValueWhen( ps, x, 1 ) );
  2181. startt = LastValue( ValueWhen( ps, x, 2 ) );
  2182. ends = LastValue( ValueWhen( ps, S1, 1 ) );
  2183. starts = LastValue( ValueWhen( ps, S1, 2 ) );
  2184. dtS = endt - startt;
  2185. aS = ( endS - startS ) / dtS;
  2186. bS = endS;
  2187. trendlineS = aS * ( x - endt ) + bS;
  2188. g3 = IIf( x > startt - 10, trendlineS, Null );
  2189. Plot( g3, "", colors, styleThick );
  2190. pR = a1 == 1;
  2191. endt1 = LastValue( ValueWhen( pr, x, 1 ) );
  2192. startt1 = LastValue( ValueWhen( pr, x, 2 ) );
  2193. endr = LastValue( ValueWhen( pr, S11, 1 ) );
  2194. startr = LastValue( ValueWhen( pr, S11, 2 ) );
  2195. dtR = endt1 - startt1;
  2196. aR = ( endR - startR ) / dtR;
  2197. bR = endR;
  2198. trendlineR = aR * ( x - endt1 ) + bR;
  2199. g4 = IIf( x > startT1 - 10, trendlineR, Null );
  2200. Plot( g4, "", colorr, styleThick );
  2201.  
  2202. acd = log( endr / startr ) / ( endt1 - startt1 );
  2203. res1 = exp( ( x - endt1 ) * acd ) * endr;
  2204. RRL = ROC( res1, 1 );
  2205. bcd = log( ends / starts ) / ( endt - startt );
  2206. sup1 = exp( ( x - endt ) * bcd ) * ends;
  2207. RSL = ROC( sup1, 1 );
  2208.  
  2209. Low_Value = LastValue( Ref( LLV( L, endt1 - startt1 ), -( x - endt1 ) ) );
  2210. x2 = LastValue( ValueWhen( L == Low_Value & x > startt1 & x < endt1, x ) );
  2211. PLL = IIf( LastValue( x ) - x2 > 5, exp( ( x - x2 ) * acd ) * Low_Value, Null );
  2212. Hi_Value = LastValue( Ref( HHV( H, endt - startt ), -( x - endt ) ) );
  2213. x3 = LastValue( ValueWhen( H == Hi_Value & x > startt & x < endt, x ) );
  2214. PHL = IIf( LastValue( x ) - x3 > 5, exp( ( x - x3 ) * bcd ) * Hi_Value, Null );
  2215. SLabs = sup1 - Ref( sup1, -1 );
  2216. RLabs = res1 - Ref( res1, -1 );
  2217. ROC2SL = ( SLabs / C ) * 100;
  2218. ROC2RL = ( RLabs / C ) * 100;
  2219. PLLd = abs( ( LastValue( C ) / LastValue( PLL ) ) - 1 ) < 0.01 * 100;
  2220. PHLd = abs( ( LastValue( C ) / LastValue( PHL ) ) - 1 ) < 0.01 * 100;
  2221. barvisible = Status( "barvisible" );
  2222. firstvisiblebar = barvisible & NOT
  2223. Ref( barvisible, -1 );
  2224. HHvisible = LastValue( HighestSince( firstvisiblebar, High ) );
  2225. LLvisible = LastValue( LowestSince( firstvisiblebar, Low ) );
  2226. RaH = HHvisible * 1.05;
  2227. RaL = LLVisible * 0.95;
  2228. AnZ = starts == 0 OR ends == 0 OR startr == 0 OR endr == 0;
  2229. PLplot = IIf( x - x2 >= 0 & abs( LastValue( L / PLL ) - 1 ) < abs( LastValue( ( 100 / 1000 ) * ATR( 14 ) ) ) & PLL > RaL & PLL < RaH & NOT AnZ, PLL, IIf( x - x2 >= 0 & RaL == 0 & PLLd & abs( LastValue( L / PLL ) - 1 ) < abs( LastValue( ( 100 / 1000 ) * ATR( 14 ) ) ) & NOT AnZ, PLL, Null ) );
  2230. PHplot = IIf( x - x3 >= 0 & abs( LastValue( H / PHL ) - 1 ) < abs( LastValue( ( 100 / 1000 ) * ATR( 14 ) ) ) & PHL > RaL & PHL < RaH & NOT AnZ, PHL, IIf( x - x3 >= 0 & RaL == 0 & PHLd & abs( LastValue( H / PHL ) - 1 ) < abs( LastValue( ( 100 / 1000 ) * ATR( 14 ) ) ) & NOT AnZ, PHL, Null ) );
  2231. Plot( IIf( Para, PLplot, Null ), " ", colorr, styleDashed, maskDefault + styleNoRescale );
  2232. Plot( IIf( Para, PHplot, Null ), " ", colors, styleDashed, maskDefault + styleNoRescale );
  2233.  
  2234. _SECTION_END();
  2235. }
  2236.  
  2237. if ( ISFANDI == 1 )
  2238. {
  2239. _SECTION_BEGIN( "ISFANDI" );
  2240. SRswitch = ParamToggle( "Sup / Res Lines", "On,Off" );
  2241. CHLswitch = ParamToggle( "Hi Low / Close", "Hi Low,Close" );
  2242. NoLines = Param( "No of Lines", 3, 1, 10, 1 );
  2243. Sen = Param( "Sensitivity", 5, 1, 100, 1 );
  2244. Rcolor = ParamColor( "Res Color", colorDarkGreen );
  2245. Rstyle = ParamStyle( "Res Style", styleLine );
  2246. Scolor = ParamColor( "Sup Color", colorBrown );
  2247. Sstyle = ParamStyle( "Sup Style", styleLine );
  2248. y = 0;
  2249. x = 0;
  2250.  
  2251. for ( i = 1; i < NoLines + 1 ; i++ )
  2252. {
  2253. Y[i] = LastValue( Peak( IIf( CHLswitch, C, H ), Sen, i ) );
  2254. x[i] = BarCount - 1 - LastValue( PeakBars( IIf( CHLswitch, C, H ), Sen, i ) );
  2255. Line = LineArray( x[i], y[i], Null, y[i], 1 );
  2256. Plot( IIf( SRswitch, Null, Line ), "", Rcolor, Rstyle );
  2257. Y[i] = LastValue( Trough( IIf( CHLswitch, C, L ), Sen, i ) );
  2258. x[i] = BarCount - 1 - LastValue( TroughBars( IIf( CHLswitch, C, L ), Sen, i ) );
  2259. Line = LineArray( x[i], y[i], Null, y[i], 1 );
  2260. Plot( IIf( SRswitch, Null, Line ), "", Scolor, Sstyle );
  2261. }
  2262.  
  2263. _SECTION_END();
  2264.  
  2265. _SECTION_BEGIN( "Detecting double tops and bottoms" );
  2266. /* Detecting double tops and bottoms*/
  2267. percdiff = 5; /* peak detection threshold */
  2268. fwdcheck = 5; /* forward validity check */
  2269. mindistance = 10;
  2270. validdiff = percdiff / 400;
  2271. PK = Peak( H, percdiff, 1 ) == High;
  2272. TR = Trough( L, percdiff, 1 ) == Low;
  2273. x = Cum( 1 );
  2274. XPK1 = ValueWhen( PK, x, 1 );
  2275. XPK2 = ValueWhen( PK, x, 2 );
  2276. xTR1 = ValueWhen( Tr, x, 1 );
  2277. xTr2 = ValueWhen( Tr, x, 2 );
  2278. peakdiff = ValueWhen( PK, H, 1 ) / ValueWhen( PK, H, 2 );
  2279. Troughdiff = ValueWhen( tr, L, 1 ) / ValueWhen( tr, L, 2 );
  2280. doubletop = PK AND abs( peakdiff - 1 ) < validdiff AND ( Xpk1 - Xpk2 ) > mindistance AND High > HHV( Ref( H, fwdcheck ), fwdcheck - 1 );
  2281. doubleBot = tr AND abs( troughdiff - 1 ) < validdiff AND ( Xtr1 - Xtr2 ) > mindistance AND Low < LLV( Ref( L, fwdcheck ), fwdcheck - 1 );
  2282. Buy = doubletop;
  2283. Sell = doublebot;
  2284.  
  2285. for ( i = 0; i < BarCount; i++ )
  2286. {
  2287. if ( Buy[i] )
  2288. PlotText( "Double TOP " , i, L[ i ], colorYellow );
  2289.  
  2290. if ( Sell[i] )
  2291. PlotText( "Double BOT" , i, H[ i ], colorWhite );
  2292. }
  2293.  
  2294. WriteIf( Highest( doubletop ) == 1, "AmiBroker has detected some possible
  2295.  
  2296. double top patterns for " + Name() + "\nLook for green arrows on the price
  2297. chart.", "There are no double top patterns for " + Name() );
  2298. WriteIf( Highest( doublebot ) == 1, "AmiBroker has detected some possible double
  2299. bottom patterns for " + Name() + "\nLook for red arrows on the price
  2300. chart.", "There are no double bottom patterns for " + Name() );
  2301. _SECTION_END();
  2302.  
  2303. _SECTION_BEGIN( "Isfandi Technical Viewer" );
  2304. //Plot(C,"",ParamColor( "Color", colorBlue ),ParamStyle("Style") );
  2305. //---- pivot points
  2306. GfxSetBkColor( colorBlack );
  2307. GfxSetTextColor( colorGrey50 );
  2308. GfxSelectFont( "Edwardian Script ITC", 25, 500, True );
  2309. GfxTextOut( "Isfandi Present ", 760 , 0 );
  2310. DayH = TimeFrameGetPrice( "H", inDaily, -1 );// yesterdays high
  2311. DayL = TimeFrameGetPrice( "L", inDaily, -1 );//low
  2312. DayC = TimeFrameGetPrice( "C", inDaily, -1 );//close
  2313. DayO = TimeFrameGetPrice( "O", inDaily );// current day open
  2314. HiDay = TimeFrameGetPrice( "H", inDaily );
  2315. LoDay = TimeFrameGetPrice( "L", inDaily );
  2316. PP = ( DayH + DayL + DayO + DayO ) / 4 ;
  2317. R1 = ( 2 * PP ) - DayL;
  2318. S1 = ( 2 * PP ) - DayH;
  2319. R2 = PP + R1 - S1;
  2320. S2 = PP + S1 - R1;
  2321. R3 = R2 + ( R1 - PP );
  2322. S3 = S2 - ( PP - S1 );
  2323. // OTHER INDICATOR
  2324. MOMETUM = RSI( 14 );
  2325. radius = 0.1 * Status( "pxheight" ); // get pixel height of the chart and use 45% for pie chart radius
  2326. textoffset = 0.1 * radius;
  2327. GfxSelectFont( "Arial", 9, 500, True );
  2328. GfxSetTextColor( colorGrey50 );
  2329. GfxTextOut( "-- PIVOT POINT --", textoffset , 86 );
  2330. GfxSetTextColor( colorGrey50 );
  2331. GfxTextOut( "-- SIGNAL --", textoffset , 188 );
  2332. GfxSetTextColor( colorGrey50 );
  2333. GfxTextOut( "-- TREND --", textoffset , 286 );
  2334. GfxSelectFont( "Arial", 9 );
  2335. GfxSetTextColor( colorGreen );
  2336. GfxTextOut( "R1 =" + R1, textoffset + 1, 120 );
  2337. GfxSetTextColor( colorLime );
  2338. GfxTextOut( "R2 = " + R2, textoffset + 1, 105 );
  2339. GfxSetTextColor( colorWhite );
  2340. GfxTextOut( "PP = " + PP, textoffset + 1, 135 );
  2341. GfxSetTextColor( colorOrange );
  2342. GfxTextOut( "S1 = " + S1, textoffset + 1, 150 );
  2343. GfxSetTextColor( colorRed );
  2344. GfxTextOut( "S2 = " + S2, textoffset + 1, 165 );
  2345. GfxSelectFont( "Arial", 9 );
  2346. _SECTION_END();
  2347. //////////////////////////////////////////////////////////////////////
  2348. _SECTION_BEGIN( "Elder Impulse" );
  2349. GfxSelectFont( "Arial", 9, 500, True );
  2350. ///////////////////////////////////////////////////
  2351. SetChartOptions( 0, chartShowArrows | chartShowDates );
  2352. EnableTextOutput( False );
  2353. // User-defined parameter for EMA periods
  2354. EMA_Type = Param( "EMA-1, TEMA-2, JMA-3", 2, 1, 3, 1 );
  2355. EMA_prds = Param( "EMA_periods", 7, 1, 30, 1 );
  2356. Std_MACD = Param( "Standard MACD? No-0, Yes-1", 1, 0, 1, 1 );
  2357. Plot_fashion = Param( "Bar+Arrows-1, Impulse Bars-2", 2, 1, 2, 1 );
  2358. // Allow user to define Weekly and Monthly Ribbon Location and Height
  2359. WR_P1 = Param( "Weekly Ribbon Location", 5.2, -1000, 1000, 0.1 );
  2360. WR_P2 = Param( "Weekly Ribbon Height", 199, -0.001, 500, 0.1 );
  2361. //MR_P1 = Param("Monthly Ribbon Location", 5.2, -1000, 1000, 0.1);
  2362. //MR_P2 = Param("Monthly Ribbon Height", 199, -0.001, 500, 0.1);
  2363. // Compute EMA and MACD Histogram
  2364.  
  2365. if ( EMA_Type == 1 )
  2366. {
  2367. DayEMA = EMA( Close, EMA_prds );
  2368. }
  2369.  
  2370. if ( EMA_Type == 2 )
  2371. {
  2372. DayEMA = TEMA( Close, EMA_prds );
  2373. }
  2374.  
  2375. Histogram = MACD() - Signal();
  2376.  
  2377. // Determine if we have an Impulse UP, DOWN or None
  2378. Impulse_Up = DayEMA > Ref( DayEMA, -1 ) AND Histogram > Ref( Histogram, -1 );
  2379. Impulse_Down = DayEMA < Ref( DayEMA, -1 ) AND Histogram < Ref( Histogram, -1 );
  2380. Impulse_None = ( NOT Impulse_UP ) AND ( NOT Impulse_Down );
  2381. // Compute Weekly MACD and determine whether rising or falling
  2382. TimeFrameSet( inWeekly );
  2383.  
  2384. if ( Std_MACD == 0 )
  2385. {
  2386. MACD_val = MACD( 5, Cool );
  2387. Signal_val = Signal( 5, 8, 5 );
  2388. }
  2389. else
  2390. {
  2391. MACD_val = MACD( 12, 26 );
  2392. Signal_val = Signal( 12, 26, 9 );
  2393. }
  2394.  
  2395. Hist_in_w = MACD_val - Signal_val;
  2396.  
  2397. wh_rising = Hist_in_w > Ref( Hist_in_w, -1 );
  2398. wh_falling = Hist_in_w < Ref( Hist_in_w, -1 );
  2399. wh_none = ( NOT wh_rising ) AND ( NOT wh_falling );
  2400. TimeFrameRestore();
  2401. // Now get Monthly MACD Histogram....
  2402. TimeFrameSet( inMonthly );
  2403. MACD_val = MACD( 5, 8 );
  2404. Signal_val = Signal( 5, 8, 5 );
  2405. Hist_in_m = MACD_val - Signal_val;
  2406. mh_rising = Hist_in_m > Ref( Hist_in_m, -1 );
  2407. mh_falling = Hist_in_m < Ref( Hist_in_m, -1 );
  2408. TimeFrameRestore();
  2409. wh_rising = TimeFrameExpand( wh_rising, inWeekly, expandLast );
  2410. wh_falling = TimeFrameExpand( wh_falling, inWeekly, expandLast );
  2411. wh_none = TimeFrameExpand( wh_none, inWeekly, expandLast );
  2412. mh_rising = TimeFrameExpand( mh_rising, inMonthly, expandLast );
  2413. mh_falling = TimeFrameExpand( mh_falling, inMonthly, expandLast );
  2414. kol = IIf( wh_rising, colorBrightGreen, IIf( wh_falling, colorRed, IIf( wh_none, colorCustom11, colorLightGrey ) ) );
  2415. mkol = IIf( mh_rising, colorBlue, IIf( mh_falling, colorYellow, colorLightGrey ) );
  2416.  
  2417. if ( Plot_fashion == 1 )
  2418. {
  2419. }
  2420. else
  2421. {
  2422. bar_kol = IIf( impulse_UP, colorBrightGreen, IIf( impulse_Down, colorRed, colorCustom11 ) );
  2423. }
  2424.  
  2425. Impulse_State = WriteIf( Impulse_Up, "Bulllish", WriteIf( Impulse_Down, "Bearish", "Neutral" ) );
  2426.  
  2427. GfxSetTextColor( colorOrange );
  2428. GfxTextOut( "IMPULSE STATE = " + Impulse_State, textoffset + 1, 305 );
  2429. // Set the background color for Impulse Status Column
  2430. Impulse_Col = IIf( Impulse_Up, colorGreen, IIf( Impulse_Down, colorRed, colorGrey40 ) );
  2431. // Determine Weekly Trend. Display as Text Column
  2432. Weekly_Trend = WriteIf( wh_rising, "Rising", WriteIf( wh_falling, "Falling", "Flat!" ) );
  2433. Weekly_Col = IIf( wh_rising, colorGreen, IIf( wh_falling, colorRed, colorLightGrey ) );
  2434. GfxSetTextColor( colorRed );
  2435. GfxTextOut( "WEEKLT TREND = " + Weekly_Trend, textoffset + 1, 323 );
  2436. // Determine Monthly Trend. Display as Text Column
  2437. Monthly_Trend = WriteIf( mh_rising, "Rising", WriteIf( mh_falling, "Falling", "Flat!" ) );
  2438. Monthly_Col = IIf( mh_rising, colorGreen, IIf( mh_falling, colorRed, colorLightGrey ) );
  2439. GfxSetTextColor( colorBlue );
  2440. GfxTextOut( "MONTHLY TREND = " + Monthly_Trend, textoffset + 1, 340 );
  2441. // Determine how many bars has the current state existed
  2442. bars_in_bull = Min( BarsSince( impulse_none ), BarsSince( impulse_down ) );
  2443. bars_in_bear = Min( BarsSince( impulse_up ), BarsSince( impulse_none ) );
  2444. bars_in_neut = Min( BarsSince( impulse_down ), BarsSince( impulse_up ) );
  2445. // Set a single variable to show number of bars in current state depending upon
  2446. // actual Impulse Status - Bullish, Bearish or Neutral
  2447. bars_in_state = IIf( Impulse_Up, bars_in_bull, IIf( Impulse_down, bars_in_bear, bars_in_neut ) );
  2448. //weekly pivot
  2449. k1 = -1;
  2450. SetChartBkColor( 16 ) ;
  2451. k = IIf( ParamList( "select type", "daily|next day" ) == "daily", -1, 0 );
  2452. k1 = -1;
  2453. TimeFrameSet( inDaily );
  2454. day_h = LastValue( Ref( H, K ) );
  2455. day_l = LastValue( Ref( L, K ) );
  2456. day_c = LastValue( Ref( C, K ) );
  2457. TimeFrameRestore();
  2458. // day
  2459. DH = Day_h;
  2460. DL = Day_L;
  2461. DC = Day_C;
  2462. // DAY PIVOT Calculation
  2463. pd = ( DH + DL + DC ) / 3;
  2464. sd1 = ( 2 * pd ) - DH;
  2465. sd2 = pd - ( DH - DL );
  2466. sd3 = Sd1 - ( DH - DL );
  2467. rd1 = ( 2 * pd ) - DL;
  2468. rd2 = pd + ( DH - DL );
  2469. rd3 = rd1 + ( DH - DL );
  2470. WriteVal( StochK( 39 ) - StochK( 12 ) );
  2471. GfxSelectFont( "Arial", 8 );
  2472. _SECTION_END();
  2473. _SECTION_BEGIN( "STOCHASTIC" );
  2474. GfxSelectFont( "Arial", 9, 500, True );
  2475. periods = Param( "Periods", 15, 1, 200, 1 );
  2476. Ksmooth = Param( "%K avg", 3, 1, 200, 1 );
  2477. a = StochK( periods , Ksmooth );
  2478. Dsmooth = Param( "%D avg", 3, 1, 200, 1 );
  2479. b = StochD( periods , Ksmooth, DSmooth );
  2480. Buy = Cross( a, b );
  2481. Sell = Cross( b, a );
  2482. STOCH = WriteIf( a > b , "Up", "Down" );
  2483. GfxSetTextColor( colorLightOrange );
  2484. GfxTextOut( "Stochastic = " + STOCH, textoffset + 1, 239 );
  2485. GfxSelectFont( "Arial", 8 );
  2486. _SECTION_BEGIN( "Van K Tharp Efficient Stocks" );
  2487. // Mark Keitel 12-05
  2488. // Van K Tharp Efficient Stocks
  2489. GfxSelectFont( "Arial", 9, 500, True );
  2490. ATRD180 = ATR( 180 );
  2491. ATRD90 = ATR( 90 );
  2492. ATRD45 = ATR( 45 );
  2493. ATRD20 = ATR( 20 );
  2494. ATRD5 = ATR( 5 );
  2495. DifferenceD180 = Close - Ref( Close, -180 );
  2496. DifferenceD90 = Close - Ref( Close, -90 );
  2497. DifferenceD45 = Close - Ref( Close, -45 );
  2498. DifferenceD20 = Close - Ref( Close, -20 );
  2499. DifferenceD5 = Close - Ref( Close, -5 );
  2500. EfficiencyD180 = IIf( ATRD180 != 0, DifferenceD180 / ATRD180, 1 );
  2501. EfficiencyD90 = IIf( ATRD90 != 0, DifferenceD90 / ATRD90, 1 );
  2502. EfficiencyD45 = IIf( ATRD45 != 0, DifferenceD45 / ATRD45, 1 );
  2503. EfficiencyD20 = IIf( ATRD20 != 0, DifferenceD20 / ATRD20, 1 );
  2504. EfficiencyD5 = IIf( ATRD5 != 0, DifferenceD5 / ATRD5, 1 );
  2505. Averageeff = ( EfficiencyD180 + EfficiencyD90 + EfficiencyD45 +
  2506. EfficiencyD20 ) / 4;
  2507. //Plot( averageeff, "AvgEff", colorLightBlue, styleLine );
  2508. x = Param ( "Add Results to a Watchlist? Yes = 1, No = 2" , 2 , 1 , 2 , 1 ) ; // select whether to add results to watchlist or not
  2509. y = Param( "Set Watchlist Number", 25, 2, 60, 1 ); // sets the watchlist number, but reserves the first 2 and last 4 watchlists
  2510. // -------- Parameter Variables for Exploration --------------------------------
  2511. TCH = Param( "High close value ", 20, 5, 300, 0.5 );
  2512. TCL = Param( "Low close value " , 5, 1, 10, 0.25 );
  2513. AVP = Param( "Period for Avg Vol " , 21, 10, 240, 1 );
  2514. SV = Param( "Stock minimum Avg Vol " , 125000, 50000, 1000000, 500000 );
  2515. // -------------- Organize the exploration results ------------------------------------
  2516. P = Param( "Period for Price Delta Comparisons", 1, 1, 120, 1 );
  2517. P1 = Param( "Period for Other Delta Comparisons", 3, 1, 120, 1 );
  2518. PATR = Param( "Period for ATR", 5, 1, 21, 1 );
  2519. PADX = Param( "Period for ADX", 14, 3, 34, 1 );
  2520. PRSI = Param( "Period for RSI", 13, 3, 34, 1 );
  2521. ADX_TREND = WriteIf( PDI( PADX ) > MDI( PADX ), "_ TREND UP", "_TREND DOWN" );
  2522. GfxSetTextColor( colorRed );
  2523. GfxTextOut( "RSI(14) = " + MOMETUM + ADX_TREND , textoffset + 1, 223 );
  2524. ADX_14 = ADX( 14 );
  2525. GfxSetTextColor( colorLightBlue );
  2526. GfxTextOut( "ADX_TREND = " + ADX_14 + ADX_TREND, textoffset + 1, 207 );
  2527. _SECTION_END();
  2528. _SECTION_BEGIN( "SmoothHeikin MA Swing" );
  2529. SetBarsRequired( 200, 0 );
  2530. GraphXSpace = 1;
  2531. SetChartOptions( 0, chartShowArrows | chartShowDates );
  2532. k = Param( "K", 1.5, 1, 5, 0.1 );
  2533. Per = Param( "ATR", 3, 1, 30, 0.50 );
  2534. k1 = Optimize( "K", 1, 0.1, 5, 0.1 );
  2535. Per1 = Optimize( "ATR", 3, 1, 30, 0.50 );
  2536. HACLOSE = ( O + H + L + C ) / 4;
  2537. HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
  2538. HaHigh = Max( H, Max( HaClose, HaOpen ) );
  2539. HaLow = Min( L, Min( HaClose, HaOpen ) );
  2540. //PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "" + Name(), colorBlack, styleCandle | styleNoLabel );
  2541. j = Haclose;
  2542. //================================================== ================================================== ===================
  2543. //=========================Indicator================ ================================================== ============================
  2544. f = ATR( 14 );
  2545.  
  2546. rfsctor = WMA( H - L, Per );
  2547.  
  2548. revers = k * rfsctor;
  2549.  
  2550. Trend = 1;
  2551. NW[0] = 0;
  2552.  
  2553.  
  2554. for ( i = 1; i < BarCount; i++ )
  2555. {
  2556. if ( Trend[i-1] == 1 )
  2557. {
  2558. if ( j[i] < NW[i-1] )
  2559. {
  2560. Trend[i] = -1;
  2561. NW[i] = j[i] + Revers[i];
  2562. }
  2563. else
  2564. {
  2565. Trend[i] = 1;
  2566.  
  2567. if ( ( j[i] - Revers[i] ) > NW[i-1] )
  2568. {
  2569. NW[i] = j[i] - Revers[i];
  2570. }
  2571. else
  2572. {
  2573. NW[i] = NW[i-1];
  2574. }
  2575. }
  2576. }
  2577.  
  2578. if ( Trend[i-1] == -1 )
  2579. {
  2580. if ( j[i] > NW[i-1] )
  2581. {
  2582. Trend[i] = 1;
  2583. NW[i] = j[i] - Revers[i];
  2584. }
  2585. else
  2586. {
  2587. Trend[i] = -1;
  2588.  
  2589. if ( ( j[i] + Revers[i] ) < NW[i-1] )
  2590. {
  2591. NW[i] = j[i] + Revers[i];
  2592. }
  2593. else
  2594. {
  2595. NW[i] = NW[i-1];
  2596. }
  2597. }
  2598. }
  2599. }
  2600.  
  2601. //===============system================
  2602.  
  2603. Plot( NW, "", IIf( Trend == 1, 27, 4 ), 4 );
  2604.  
  2605. Buy = Cover = Cross( j, nw );
  2606.  
  2607. Sell = Short = Cross( nw, j );
  2608.  
  2609. SWING = WriteIf( j > nw, "UPTREND", "DOWNTREND" );
  2610.  
  2611. GfxSetTextColor( colorGreen );
  2612.  
  2613. GfxTextOut( "SWING = " + SWING, textoffset + 1, 256 );
  2614.  
  2615. GfxSelectFont( "Arial", 8 );
  2616.  
  2617. shape = Buy * shapeCircle + Sell * shapeCircle;
  2618.  
  2619. //PlotShapes( shape, IIf( Buy, colorGreen, colorOrange ), 0, IIf( Buy, Low-f, High+f));
  2620.  
  2621.  
  2622. _SECTION_END();
  2623.  
  2624.  
  2625. _SECTION_BEGIN( "Intraday MA Oprekan Isfandi" );
  2626.  
  2627. Periods = Param( "Periods", 15, 2, 200, 1, 10 );
  2628.  
  2629. CG = MA( C, Periods );
  2630.  
  2631. Plot( CG, "MA", IIf( CG <= Low, ParamColor( "Color_U", colorRed ), ParamColor( "Color_D", colorOrange ) ), styleThick = 13 );
  2632.  
  2633. amv0 = Volume * ( O + C ) / 2;
  2634.  
  2635. Life_line = Sum( amv0, 88 ) / Sum( Volume, 88 );
  2636.  
  2637. Plot( Life_line, "Life_line", ParamColor( "Color", colorBlack ), ParamStyle( "Style" ) );
  2638.  
  2639. FL = HHV( CG, 2 );
  2640.  
  2641. support = HHV( CG, 2 );
  2642.  
  2643. FS = CG - ( FL - CG );
  2644.  
  2645. Plot( support, "support_line", colorRed, styleThick = 12 );
  2646.  
  2647. Plot( FS, "", colorDarkGreen, styleThick = 12 );
  2648.  
  2649. _SECTION_END();
  2650.  
  2651.  
  2652. _SECTION_BEGIN
  2653. ( "BW Fractal" );
  2654.  
  2655. CondUpFractal =
  2656.  
  2657. (
  2658. Ref( H, -2 ) < H AND Ref( H, -1 ) < H AND Ref( H, 1 ) < H AND Ref( H, 2 ) < H ) OR
  2659.  
  2660. (
  2661. Ref( H, -3 ) < H AND Ref( H, -2 ) < H AND Ref( H, -1 ) == H AND Ref( H, 1 ) < H AND Ref( H, 2 ) < H ) OR
  2662.  
  2663. (
  2664. Ref( H, -4 ) < H AND Ref( H, -3 ) < H AND Ref( H, -2 ) == H AND Ref( H, -1 ) == H AND Ref( H, 1 ) < H AND Ref( H, 2 ) < H ) OR
  2665.  
  2666. (
  2667. Ref( H, -4 ) < H AND Ref( H, -3 ) < H AND Ref( H, -2 ) == H AND Ref( H, -1 ) == H AND Ref( H, 1 ) < H AND Ref( H, 2 ) < H ) OR
  2668.  
  2669. (
  2670. Ref( H, -6 ) < H AND Ref( H, -5 ) < H AND Ref( H, -4 ) == H AND Ref( H, -3 ) < H AND Ref( H, -2 ) == H AND Ref( H, -1 ) < H AND Ref( H, 1 ) < H AND Ref( H, 2 ) < H );
  2671.  
  2672. UpFractal =
  2673. ValueWhen( CondUpFractal, H, 1 );
  2674.  
  2675. PlotShapes
  2676. ( CondUpFractal*shapeHollowSmallCircle, colorYellow, Layer = 0, UpFractal, Offset = 0 );
  2677.  
  2678. CondDownFractal =
  2679.  
  2680. (
  2681. Ref( L, -2 ) > L AND Ref( L, -1 ) > L AND Ref( L, 1 ) > L AND Ref( L, 2 ) > L ) OR
  2682.  
  2683. (
  2684. Ref( L, -3 ) > L AND Ref( L, -2 ) > L AND Ref( L, -1 ) == L AND Ref( L, 1 ) > L AND Ref( L, 2 ) > L ) OR
  2685.  
  2686. (
  2687. Ref( L, -4 ) > L AND Ref( L, -3 ) > L AND Ref( L, -2 ) == L AND Ref( L, -1 ) == L AND Ref( L, 1 ) > L AND Ref( L, 2 ) > L ) OR
  2688.  
  2689. (
  2690. Ref( L, -4 ) > L AND Ref( L, -3 ) > L AND Ref( L, -2 ) == L AND Ref( L, -1 ) == L AND Ref( L, 1 ) > L AND Ref( L, 2 ) > L ) OR
  2691.  
  2692. (
  2693. Ref( L, -6 ) > L AND Ref( L, -5 ) > L AND Ref( L, -4 ) == L AND Ref( L, -3 ) > L AND Ref( L, -2 ) == L AND Ref( L, -1 ) > L AND Ref( L, 1 ) > L AND Ref( L, 2 ) > L );
  2694.  
  2695. DownFractal =
  2696. ValueWhen( CondDownFractal, L, 1 );
  2697.  
  2698. PlotShapes
  2699. ( CondDownFractal*shapeHollowSmallCircle, colorYellow, Layer = 0, DownFractal, Offset = 0 );
  2700.  
  2701. PlotShapes
  2702. ( Cross( C, UpFractal )*shapeUpArrow, colorRed, Layer = 0, L );
  2703.  
  2704. PlotShapes
  2705. ( Cross( DownFractal, C )*shapeDownArrow, colorBlue, Layer = 0, H );
  2706.  
  2707. Plot
  2708. ( Ref( UpFractal, 2 ), "Up Fractal", ParamColor( "Up Fractal Color", colorRed ),
  2709. ParamStyle
  2710. ( "Up Fractal Style", styleDashed ) );
  2711.  
  2712. Plot
  2713. ( Ref( DownFractal, 2 ), "Down Fractal", ParamColor( "Down Fractal Color", colorBlue ), ParamStyle( "Down Fractal Style", styleDashed ) );
  2714.  
  2715. Plot( Max( HHV( H, 3 ), Ref( UpFractal, 2 ) ), "Up Fractal", ParamColor( "Up Fractal Color", colorRed ), ParamStyle( "Up Fractal Style", styleDashed ) );
  2716.  
  2717. Plot( Max( HHV( H, 3 ), Ref( UpFractal, 2 ) ), "Down Fractal", ParamColor( "Down Fractal Color", colorBlue ), ParamStyle( "Down Fractal Style", styleDashed ) );
  2718.  
  2719. _SECTION_END
  2720. ();
  2721.  
  2722. GraphZOrder = 1;
  2723.  
  2724. _SECTION_BEGIN( "Chart Settings" );
  2725.  
  2726. p_color_bkgnd = ParamColor( "Background color", colorLightGrey );
  2727.  
  2728. // for intraday, you probably don't want log... set default to be linear
  2729. p_logscale = ParamToggle( "Axis type (control with this)", "Linear|Logarithmic", 0 );
  2730.  
  2731. p_Colorbars = ParamToggle( "Price display color?", "Mono|Color", 0 );
  2732.  
  2733. p_PriceColor = ParamColor( "Price mono color", colorWhite );
  2734.  
  2735. p_PriceStyle = ParamStyle( "Price Style", styleThick );
  2736.  
  2737. SetChartBkColor( p_color_bkgnd );
  2738.  
  2739. StaticVarSet( "L_color_bkgnd", p_color_bkgnd );
  2740.  
  2741. L_color_mono = p_PriceColor;
  2742.  
  2743. // change this later
  2744. if ( IsNull( StaticVarGet( "L_color_bkgnd" ) ) )
  2745. {
  2746. L_color_bkgnd = p_color_bkgnd;
  2747. }
  2748. else
  2749. {
  2750. L_color_bkgnd = StaticVarGet( "L_color_bkgnd" );
  2751. }
  2752.  
  2753. // We need to know whether we are log scale or not
  2754. // so set it ourselves then change the toggle the chart for log/linear and
  2755. // use the it for trendline calculations etc.
  2756. // If we had used the log/linear parameter on the "Axis and Grid menu"
  2757. // then we have to remember to change the log/linear calculation.
  2758. SetChartOptions( 0, chartShowArrows | chartShowDates );
  2759.  
  2760. if ( p_logscale == 1 )
  2761. {
  2762. SetChartOptions( 2, chartLogarithmic, chartGridMiddle | chartGridMargins );
  2763. }
  2764. else
  2765. {
  2766. SetChartOptions( 3, chartLogarithmic, !( chartGridMiddle | chartGridMargins ) );
  2767. }
  2768.  
  2769. Visiblebars = Status( "barvisible" );
  2770.  
  2771.  
  2772. _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +
  2773. WriteVal( V, 1.0 ) + "\n{{VALUES}}",
  2774. O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
  2775.  
  2776.  
  2777. // Start of variables used to control color of bars/indicators
  2778. BullishBar = H > Ref( H, -1 ) AND L > Ref( L, -1 );
  2779. BearishBar = H < Ref( H, -1 ) AND L < Ref( L, -1 );
  2780.  
  2781. if ( p_Colorbars == 1 )
  2782. {
  2783. PriceColor = IIf( BullishBar, colorLime, IIf( BearishBar, colorRed, colorBlue ) );
  2784. }
  2785. else
  2786. {
  2787. PriceColor = L_color_mono;
  2788. }
  2789.  
  2790. _SECTION_END();
  2791.  
  2792. // for pricefield and set initial scaling
  2793. Plot( C, "", PriceColor, styleNoTitle | p_PriceStyle | GetPriceStyle() );
  2794.  
  2795.  
  2796.  
  2797. //================================================== ==================================
  2798. _SECTION_BEGIN( "Volume Price Analysis - V.1.2" );
  2799. SetChartOptions( 0, chartShowArrows | chartShowDates );
  2800. //================================================== =====================================
  2801. DTL = Param( "Linear regression period", 60, 10, 100, 10 );
  2802. wbf = Param( "WRB factor", 1.5, 1.3, 2.5, .1 );
  2803. nbf = Param( "NRB factor", 0.7, 0.3, 0.9, 0.1 );
  2804. TL = LinRegSlope( MA( C, DTL ), 2 );
  2805. Vlp = Param( "Volume lookback period", 30, 20, 300, 10 );
  2806. Vrg = MA( V, Vlp );
  2807. St = StDev( Vrg, Vlp );
  2808. Vp3 = Vrg + 3 * st;
  2809. Vp2 = Vrg + 2 * st;;
  2810. Vp1 = Vrg + 1 * st;;
  2811. Vn1 = Vrg - 1 * st;
  2812. Vn2 = Vrg - 2 * st;
  2813. rg = ( H - L );
  2814. arg = Wilders( rg, 30 );
  2815. wrb = rg > ( wbf * arg );
  2816. nrb = rg < ( nbf * arg );
  2817. Vl = V < Ref( V, -1 ) AND V < Ref( V, -2 );
  2818. upbar = C > Ref( C, -1 );
  2819. dnbar = C < Ref( C, -1 );
  2820. Vh = V > Ref( V, -1 ) AND Ref( V, -1 ) > Ref( V, -2 );
  2821. Cloc = C - L;
  2822. x = rg / Cloc;
  2823. x1 = IIf( Cloc == 0, arg, x );
  2824. Vb = V > Vrg OR V > Ref( V, -1 );
  2825. ucls = x1 < 2;
  2826. dcls = x1 > 2;
  2827. mcls = x1<2.2 AND x1>1.8 ;
  2828. Vlcls = x1 > 4;
  2829. Vhcls = x1 < 1.35;
  2830. j = MA( C, 5 );
  2831. TLL = LinRegSlope( j, 40 ) ;
  2832. Tlm = LinRegSlope( j, 15 ) ;
  2833. tls = LinRegSlope( j, 5 );
  2834. mp = ( H + L ) / 2;
  2835. _SECTION_END();
  2836. //================================================== ========================================
  2837. _SECTION_BEGIN( "VSA" );
  2838. utbar = wrb AND dcls AND tls > 0 ;
  2839. utcond1 = Ref( utbar, -1 ) AND dnbar ;
  2840. utcond2 = Ref( utbar, -1 ) AND dnbar AND V > Ref( V, -1 );
  2841. utcond3 = utbar AND V > 2 * Vrg;
  2842. trbar = Ref( V, -1 ) > Vrg AND Ref( upbar, -1 ) AND Ref( wrb, -1 ) AND dnbar AND dcls AND wrb AND tll > 0 AND H == HHV( H, 10 );
  2843. Hutbar = Ref( upbar, -1 ) AND Ref( V, -1 ) > 1.5 * Vrg AND dnbar AND dcls AND NOT wrb AND NOT utbar;
  2844. Hutcond = Ref( Hutbar, -1 ) AND dnbar AND dcls AND NOT utbar;
  2845. tcbar = Ref( upbar, -1 ) AND H == HHV( H, 5 )AND dnbar AND ( dcls OR mcls ) AND V > vrg AND NOT wrb AND NOT Hutbar ;
  2846. Scond1 = ( utcond1 OR utcond2 OR utcond3 ) ;
  2847. Scond2 = Ref( scond1, -1 ) == 0;
  2848. scond = scond1 AND scond2;
  2849. stdn0 = tll<0 AND V>Ref( V, -1 ) AND Ref( dnbar, -1 ) AND upbar AND ( ucls OR mcls ) AND tls < 0 AND tlm < 0;
  2850. stdn = V > Ref( V, -1 ) AND Ref( dnbar, -1 ) AND upbar AND ( ucls OR mcls ) AND tls < 0 AND tlm < 0;
  2851. stdn1 = tll<0 AND V>( vrg * 1.5 ) AND Ref( dnbar, -1 ) AND upbar AND ( ucls OR mcls )AND tls < 0 AND tlm < 0;
  2852. stdn2 = tls < 0 AND Ref( V, -1 )<Vrg AND upbar AND vhcls AND V>Vrg;
  2853. bycond1 = stdn OR stdn1;
  2854. bycond = upbar AND Ref( bycond1, -1 );
  2855. stvol = L == LLV( L, 5 ) AND ( ucls OR mcls ) AND V > 1.5 * Vrg AND tll < 0;
  2856. ndbar = upbar AND nrb AND Vl AND dcls ;
  2857. nsbar = dnbar AND nrb AND Vl AND dcls ;
  2858. nbbar = C > Ref( C, -1 ) AND Vl AND nrb AND x1 < 2;
  2859. nbbar = IIf( C > Ref( C, -1 ) AND V < Ref( V, -1 ) AND V < Ref( V, -2 ) AND x1 < 1.1, 1, 0 );
  2860. lvtbar = vl AND L < Ref( L, -1 ) AND ucls;
  2861. lvtbar1 = V < Vrg AND L < Ref( L, -1 ) AND ucls AND tll > 0 AND tlm > 0 AND wrb;
  2862. lvtbar2 = Ref( Lvtbar, -1 ) AND upbar AND ucls;
  2863. dbar = V > 2 * Vrg AND dcls AND upbar AND tls > 0 AND tlm > 0 AND NOT Scond1 AND NOT utbar;
  2864. eftup = H > Ref( H, -1 ) AND L > Ref( L, -1 ) AND C > Ref( C, -1 ) AND C >= ( ( H - L ) * 0.7 + L ) AND rg > arg AND V > Ref( V, -1 );
  2865. eftupfl = Ref( eftup, -1 ) AND ( utbar OR utcond1 OR utcond2 OR utcond3 );
  2866. eftdn = H < Ref( H, -1 ) AND L < Ref( L, -1 ) AND C < Ref( C, -1 ) AND C <= ( ( H - L ) * 0.25 + L ) AND rg > arg AND V > Ref( V, -1 );
  2867. _SECTION_END();
  2868.  
  2869. _SECTION_BEGIN( "Commentary" );
  2870. Vpc = utbar OR utcond1 OR utcond2 OR utcond3 OR stdn0 OR stdn1 OR stdn2 OR stdn OR lvtbar1 OR Lvtbar OR Lvtbar2 OR Hutbar OR Hutcond OR ndbar OR stvol OR tcbar;
  2871.  
  2872. if ( Status( "action" ) == actionCommentary )
  2873. (
  2874. printf ( "=========================" + "\n" ) );
  2875.  
  2876. printf ( "VOLUME PRICE ANALYSIS" + "\n" );
  2877.  
  2878. printf ( "" + "\n" );
  2879.  
  2880. printf ( "=========================" + "\n" );
  2881.  
  2882. printf ( Name() + " - " + Interval( 2 ) + " - " + Date() + " - " + "\n" + "High-" + H + "\n" + "Low-" + L + "\n" + "Open-" + O + "\n" +
  2883. "Close-" + C + "\n" + "Volume= " + WriteVal( V ) + "\n" );
  2884.  
  2885. WriteIf( Vpc, "=======================", "" );
  2886.  
  2887. WriteIf( Vpc, "VOLUME ANALYSIS COMMENTARY:\n", "" );
  2888.  
  2889. WriteIf( utbar , "Up-thrusts are designed to catch stops and to mislead as many traders as possible.
  2890. They are normally seen after there has been weakness in the background. The market makers know that the
  2891. market is weak, so the price is marked up to catch stops, encourage traders to go long in a weak market,
  2892. AND panic traders that are already Short into covering their very good position.", "" ) +
  2893. WriteIf( utcond3, "This upthrust bar is at high volume.This is a sure sign of weakness. One may even seriously
  2894. consider ending the Longs AND be ready to reverse", "" ) + WriteIf( utbar OR utcond3, " Also note that A wide spread
  2895. down-bar that appears immediately after any up-thrust, tends to confirm the weakness (the market makers are
  2896. locking in traders into poor positions).
  2897. With the appearance of an upthrust you should
  2898. certainly be paying attention to your trade AND your stops. On many upthrusts you will find that the market will
  2899. 'test' almost immediately.", "" ) + WriteIf( utcond1 , "A wide spread down bar following a Upthrust Bar.
  2900. This confirms weakness. The Smart Money is locking in Traders into poor positions", "" );
  2901.  
  2902. WriteIf( utcond2 , "Also here the volume is high( Above Average).This is a sure sign of weakness. The Smart Money is
  2903. locking in Traders into poor positions", "" ) + WriteIf( stdn, "Strength Bar. The stock has been in a down Trend. An upbar
  2904. with higher Volume closing near the High is a sign of strength returning. The downtrend is likely to reverse soon. ", "" ) +
  2905. WriteIf( stdn1, "Here the volume is very much above average. This makes this indication more stronger. ", "" ) +
  2906. WriteIf( bycond, "The previous bar saw strength coming back. This upbar confirms strength. ", "" ) +
  2907. WriteIf( Hutbar, " A pseudo Upthrust. This normally appears after an Up Bar with above average volume. This looks like an upthrust bar
  2908. closing down near the Low. But the Volume is normally Lower than average. this is a sign of weakness.If the Volume is High then weakness
  2909. increases. Smart Money is trying to trap the retailers into bad position. ", "" ) +
  2910. WriteIf( Hutcond, "A downbar after a pseudo Upthrust Confirms weakness. If the volume is above average the weakness is increased. ", "" ) +
  2911. WriteIf( Lvtbar2, "The previous bar was a successful Test of supply. The current bar is a upbar with higher volume. This confirms strength", "" ) +
  2912. WriteIf( dbar, "A wide range, high volume bar in a up trend closing down is an indication the Distribution is in progress. The smart money
  2913. is Selling the stock to the late Comers rushing to Buy the stock NOT to be Left Out Of a Bullish move. ", "" ) +
  2914. WriteIf( Lvtbar2, "The previous bar was a successful Test of supply. The current bar is a upbar with higher volume. This confirms strength", "" ) +
  2915. WriteIf( tcbar, "The stock has been moving up on high volume. The current bar is a Downbar with high volume. Indicates weakness and probably end of the up move", "" ) +
  2916. WriteIf( eftup, "Effort to Rise bar. This normally found in the beginning of a Markup Phase and is bullish sign.These may be found at the top of an Upmove as the Smart money makes a
  2917. last effort to move the price to the maximum", "" ) +
  2918. WriteIf( eftdn, "Effort to Fall bar. This normally found in the beginning of a Markdown phase.", "" ) +
  2919. WriteIf( nsbar, "No Supply. A no supply bar indicates supply has been removed and the Smart money can markup the price. It is better to wait for confirmation", "" ) +
  2920. WriteIf( stvol, "Stopping Volume. This will be an downbar during a bearish period closing towards the Top accompanied by High volume.
  2921. A stopping Volume normally indicates that smart money is absorbing the supply which is a Indication that they are Bullishon the MArket.
  2922. Hence we Can expect a reversal in the down trend. ", "" ) +
  2923. WriteIf( ndbar, "No Demand
  2924. Brief Description:
  2925. Any up bar which closes in the middle OR Low, especially if the Volume has fallen off,
  2926. is a potential sign of weakness.
  2927. Things to Look Out for:
  2928. if the market is still strong, you will normally see signs of strength in the next few bars,
  2929. which will most probably show itself as a:
  2930. * Down bar with a narrow spread, closing in the middle OR High.
  2931. * Down bar on Low Volume.", "" );
  2932.  
  2933. _SECTION_END();
  2934.  
  2935. //================================================== ================================================== ================================================== ================================
  2936. //TITLE
  2937. _SECTION_BEGIN( "Title" );
  2938.  
  2939. if ( Status( "action" ) == actionIndicator )
  2940. (
  2941. Title = EncodeColor( colorWhite ) + "Volume Price Analysis" + " - " + Name() + " - " + EncodeColor( colorRed ) + Interval( 2 ) + EncodeColor( colorWhite ) +
  2942. " - " + Date() + " - " + EncodeColor( colorLime ) + "Volume= " + WriteVal( V ) + "--" + EncodeColor( colorYellow ) + "\n" +
  2943. WriteIf ( utbar, " An Upthrust Bar. A sign of weakness. ", "" ) +
  2944. WriteIf ( utcond1, " A downbar after an Upthrust. Confirm weakness. ", "" ) +
  2945. WriteIf ( utcond2 AND NOT utcond1, " A High Volume downbar after an Upthrust. Confirm weakness.", "" ) +
  2946. WriteIf ( utcond3, "This upthrust at very High Voume, Confirms weakness", "" ) +
  2947. WriteIf ( stdn1, "Strength seen returning after a down trend. High volume adds to strength. ", "" ) +
  2948. WriteIf ( stdn0 AND NOT stdn, "Strength seen returning after a down trend. ", "" ) +
  2949. WriteIf ( stdn AND NOT stdn1, "Strength seen returning after a long down trend. ", "" ) +
  2950. WriteIf ( Lvtbar, "Test for supply. ", "" ) +
  2951. WriteIf ( Lvtbar2, "An Upbar closing near High after a Test confirms strength. ", "" ) +
  2952. WriteIf ( bycond, "An Upbar closing near High. Confirms return of Strength. ", "" ) +
  2953. WriteIf ( dbar, "A High Volume Up Bar closing down in a uptrend shows Distribution. ", "" ) +
  2954. WriteIf ( Hutbar, "Psuedo UpThrust. A Sign of Weakness. ", "" ) +
  2955. WriteIf ( Hutcond, "A Down Bar closing down after a Pseudo Upthrust confirms weakness. ", "" ) +
  2956. WriteIf ( Lvtbar1, "Test for supply in a uptrend. Sign of Strength. ", "" ) +
  2957. WriteIf ( stdn2, "High volume upbar closing on the high indicates strength. ", "" ) +
  2958. WriteIf ( Tcbar, "High volume Downbar after an upmove on high volume indicates weakness. ", "" ) +
  2959. WriteIf ( ndbar, "No Demand. A sign of Weakness. ", "" ) +
  2960. WriteIf ( nsbar, "No Supply. A sign of Strength. ", "" ) +
  2961. WriteIf ( eftup, "Effort to Rise. Bullish sign ", "" ) +
  2962. WriteIf ( eftdn, "Effort to Fall. Bearish sign ", "" ) +
  2963. WriteIf ( eftupfl, "Effort to Move up has failed. Bearish sign ", "" ) +
  2964. WriteIf ( stvol, "Stopping volume. Normally indicates end of bearishness is nearing. ", "" ) +
  2965. ( "\n Volume: " ) + WriteIf( V > Vp2, EncodeColor( colorLime ) + "Very High", WriteIf( V > Vp1, EncodeColor( colorLime ) + " High", WriteIf( V > Vrg, EncodeColor( colorLime ) + "Above Average",
  2966. WriteIf( V<Vrg AND V>Vn1, EncodeColor( colorRed ) + "Less than Average", WriteIf( V < Vn1, "Low", "" ) ) ) ) ) +
  2967. ( EncodeColor( colorYellow ) + " Spread: " ) + WriteIf( rg > ( arg * 2 ), EncodeColor( colorLime ) + " Wide", WriteIf( rg > arg, EncodeColor( colorLime ) + " Above Average", EncodeColor( colorRed ) + " Narrow" ) ) +
  2968. ( EncodeColor( colorYellow ) + " Close: " ) + WriteIf( Vhcls, EncodeColor( colorLime ) + "Very High", WriteIf( ucls, EncodeColor( colorLime ) + "High", WriteIf( mcls, EncodeColor( colorYellow ) + "Mid",
  2969. WriteIf( dcls, EncodeColor( colorRed ) + "Down", "Very Low" ) ) ) ) +
  2970. ( "\n Trend: " ) + WriteIf( tls > 0, EncodeColor( colorLime ) + " Short Term-UP", EncodeColor( colorRed ) + " Short Term-Down" ) +
  2971. WriteIf( tlm > 0, EncodeColor( colorLime ) + " MID Term-UP", EncodeColor( colorRed ) + " Mid Term-Down" ) +
  2972. WriteIf( tll > 0, EncodeColor( colorLime ) + " Long Term-Up", EncodeColor( colorRed ) + " Long term-Down" ) );
  2973.  
  2974. _SECTION_END();
  2975. }
  2976.  
  2977. if ( PEAK_VALLEY == 1 )
  2978. {
  2979. _SECTION_BEGIN( "PEAK_VALLEY" );
  2980. // E.M.Pottasch 09/06/10
  2981. nbar = Param( "nbar", 2, 1, 5, 1 );
  2982.  
  2983. PHigh = H > Ref( HHV( H, nbar ), -1 ) AND Ref( HHV( H, nbar ), nbar ) < H;
  2984. PHighPrice0 = ValueWhen( PHigh, H );
  2985. PHighPrice1 = IIf( PHighPrice0 AND BarsSince( PHigh ) > nbar, PHighPrice0, Null );
  2986. PHighPrice2 = IIf( PHighPrice0 AND BarsSince( PHigh ) <= nbar, PHighPrice0, Null );
  2987. PLow = L < Ref( LLV( L, nbar ), -1 ) AND Ref( LLV( L, nbar ), nbar ) > L;
  2988. PLowPrice0 = ValueWhen( PLow, L );
  2989. PLowPrice1 = IIf( PLowPrice0 AND BarsSince( Plow ) > nbar, PLowPrice0, Null );
  2990. PLowPrice2 = IIf( PLowPrice0 AND BarsSince( Plow ) <= nbar, PLowPrice0, Null );
  2991.  
  2992. GraphXSpace = 5;
  2993. SetChartOptions( 0, chartShowDates );
  2994. Plot( C, "\nLast", colorWhite, styleCandle );
  2995.  
  2996. Plot( PHighPrice1, "\nPHighPrice", colorOrange, styleThick );
  2997. Plot( PHighPrice2, "", colorOrange, styleDots | styleNoLine );
  2998. Plot( PLowPrice1, "\nPLowPrice", colorBrightGreen, styleThick );
  2999. Plot( PLowPrice2, "", colorBrightGreen, styleDots | styleNoLine );
  3000.  
  3001. Buy = H > PHighPrice0;
  3002. Sell = L < PLowPrice0;
  3003.  
  3004. Buy = ExRem( Buy, Sell );
  3005. Sell = ExRem( Sell, Buy );
  3006.  
  3007. PlotShapes( IIf( Buy , shapeSmallUpTriangle, shapeNone ) , colorGreen, 0, L, -30 );
  3008. PlotShapes( IIf( Sell, shapeSmallDownTriangle, shapeNone ) , colorOrange, 0, H, -25 );
  3009. _SECTION_END();
  3010. }
  3011.  
  3012.  
  3013. if ( FLOWER == 1 )
  3014. {
  3015.  
  3016. _SECTION_BEGIN( "Flower" );
  3017. Title = StrFormat( "\\c02 {{NAME}} | {{DATE}} | Open : %g | High : %g | Low : %g | Close : %g | Change = %.1f%% | Volume = " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
  3018. _SECTION_END();
  3019.  
  3020.  
  3021. _SECTION_BEGIN( "Sup/Res Detail" );
  3022. SupResPeriod = Param( "LookBack Period", 50, 0, 200, 1 );
  3023. SupResPercentage = Param( "Percentage", 100, 0, 200, 1 );
  3024. PricePeriod = Param( "Price Period", 16, 0, 200, 1 );
  3025. SupportLinecolor = ParamColor( "Support Color", colorGreen );
  3026. SupportLinestyle = ParamStyle( "Support Style", styleThick | 8 | styleNoLabel );
  3027. ResistanceLinecolor = ParamColor( "Resistance Color", colorRed );
  3028. Resistancestyle = ParamStyle( "Resistance Style", styleThick | 8 | styleNoLabel );
  3029. _SECTION_END();
  3030.  
  3031. _SECTION_BEGIN( "Line Detail" );
  3032. OverBought = Param( "OverBought Above", 200, 0, 400, 1 );
  3033. OverSold = Param( "OverSold Bellow", -200, -400, 0, 1 );
  3034. _SECTION_END();
  3035.  
  3036. _SECTION_BEGIN( "Trend Bought/Sold Detail" );
  3037. Smoother = Param( "Trend Smoother", 5, 5, 20 );
  3038. upcolor = ParamColor( "UpTrend Color", colorGreen );
  3039. Downcolor = ParamColor( "DownTrend Color", colorRed );
  3040. _SECTION_END();
  3041.  
  3042. _SECTION_BEGIN( "Circle Detail" );
  3043. Warningcolor = ParamColor( "Warning/Watch Signal", colorBlue );
  3044. WatchColor = ParamColor( "Accumulation Zone", colorWhite );
  3045. EntryColor = ParamColor( "Entry Signal", colorAqua );
  3046. ProfitTakeColor = ParamColor( "Distribution Zone", colorYellow );
  3047. ExitColor = ParamColor( "Exit Signal", colorRed );
  3048. _SECTION_END();
  3049.  
  3050. _SECTION_BEGIN( "Swing Sup/Res" );
  3051. Lookback = SupResPeriod;
  3052. PerCent = SupResPercentage;
  3053. Pds = PricePeriod;
  3054. Var = MACD();
  3055. Up = IIf( Var > Ref( Var, -1 ), abs( Var - Ref( Var, -1 ) ), 0 );
  3056. Dn = IIf( Var < Ref( Var, -1 ), abs( Var - Ref( Var, -1 ) ), 0 );
  3057. Ut = Wilders( Up, Pds );
  3058. Dt = Wilders( Dn, Pds );
  3059. RSIt = 100 * ( Ut / ( Ut + Dt ) );
  3060. A1 = RSIt;
  3061. B2 = RSI( pds );
  3062. C3 = CCI( pds );
  3063. D4 = StochK( pds );
  3064. E5 = StochD( pds );
  3065. F6 = MFI( pds );
  3066. G7 = Ultimate( pds );
  3067. H8 = ROC( C, pds );
  3068. Osc = C3;
  3069. Value1 = Osc;
  3070. Value2 = HHV( Value1, Lookback );
  3071. Value3 = LLV( Value1, Lookback );
  3072. Value4 = Value2 - Value3;
  3073. Value5 = Value4 * ( PerCent / 100 );
  3074. ResistanceLine = Value3 + Value5;
  3075. SupportLine = Value2 - Value5;
  3076. baseline = IIf( Osc < 100 AND Osc > 10 , 50 , IIf( Osc < 0 , 0, 0 ) );
  3077. Plot( ResistanceLine, "", SupportLinecolor, SupportLinestyle );
  3078. Plot( SupportLine, "", ResistanceLinecolor, Resistancestyle );
  3079. _SECTION_END();
  3080.  
  3081. _SECTION_BEGIN( "Entry/Exit Detail" );
  3082. n = Smoother;
  3083. ys1 = ( High + Low + Close * 2 ) / 4;
  3084. rk3 = EMA( ys1, n );
  3085. rk4 = StDev( ys1, n );
  3086. rk5 = ( ys1 - rk3 ) * 200 / rk4;
  3087. rk6 = EMA( rk5, n );
  3088. UP = EMA( rk6, n );
  3089. DOWN = EMA( up, n );
  3090. Oo = IIf( up < down, up, down );
  3091. Hh = Oo;
  3092. Ll = IIf( up < down, down, up );
  3093. Cc = Ll;
  3094. barcolor2 = IIf( Ref( oo, -1 ) < Oo AND Cc < Ref( Cc, -1 ), upcolor, IIf( up > down, upcolor, downcolor ) );
  3095. PlotOHLC( Oo, hh, ll, Cc, "Matrix - Accumulation or Bought/Distribution or Sold", barcolor2, styleCandle );
  3096. Buy = Cross( up, OverSold );
  3097. Sell = Cross( OverBought, up );
  3098. PlotShapes ( IIf( Buy, shapeSmallCircle, shapeNone ) , EntryColor, layer = 0, yposition = -220, offset = 1 );
  3099. PlotShapes ( IIf( Sell, shapeSmallCircle, shapeNone ) , ExitColor, layer = 0, yposition = 220, offset = 1 );
  3100. _SECTION_END();
  3101.  
  3102. _SECTION_BEGIN( "Overbought/Oversold/Warning Detail" );
  3103. n = Smoother;
  3104. ys1 = ( High + Low + Close * 2 ) / 4;
  3105. rk3 = EMA( ys1, n );
  3106. rk4 = StDev( ys1, n );
  3107. rk5 = ( ys1 - rk3 ) * 210 / rk4;
  3108. rk6 = EMA( rk5, n );
  3109. UP = EMA( rk6, n );
  3110. DOWN = EMA( up, n );
  3111. Oo = IIf( up < down, up, down );
  3112. Hh = Oo;
  3113. Ll = IIf( up < down, down, up );
  3114. Cc = Ll;
  3115. barcolor2 = IIf( Ref( oo, -1 ) < Oo AND Cc < Ref( Cc, -1 ), colorGreen, IIf( up > down, colorGreen, colorRed ) );
  3116. PlotOHLC( Oo, hh, ll, Cc, "", barcolor2, styleCandle | stylehidden );
  3117. UP = EMA( rk6, n );
  3118. UPshape = IIf( UP >= OverBought OR UP <= OverSold, shapeHollowSmallCircle, shapeNone );
  3119. UPColor = IIf( UP >= 210, ProfitTakeColor, IIf( UP <= -210, WatchColor, Warningcolor ) );
  3120. Plot( UP, "", colorGrey50, styleThick | stylehidden );
  3121. PlotShapes( UPShape, UPColor, 0, UP, 0 );
  3122. _SECTION_END();
  3123.  
  3124. _SECTION_BEGIN( "Plot Lines" );
  3125. Plot( OverBought, "", colorDarkGrey, styleLine | styleNoLabel );
  3126. Plot( 0, "", colorDarkGrey, styleDashed | styleNoLabel );
  3127. Plot( OverSold, "", colorDarkGrey, styleLine | styleNoLabel );
  3128. _SECTION_END();
  3129. }
  3130.  
  3131. if ( AUTO_FIBO == 1 )
  3132. {
  3133. _SECTION_BEGIN( "AUTO_FIBO" );
  3134. //SetChartBkGradientFill( ParamColor("BgTop", colorLightGrey),ParamColor("BgBottom", colorLightYellow));
  3135.  
  3136.  
  3137. //_SECTION_BEGIN("Price");
  3138. SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
  3139. _N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
  3140.  
  3141. Plot( C, "Close", ParamColor( "Color", colorWhite ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
  3142.  
  3143. if ( ParamToggle( "Tooltip shows", "All Values|Only Prices" ) )
  3144. {
  3145. ToolTip = StrFormat( "Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: " + NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
  3146. };
  3147.  
  3148.  
  3149.  
  3150. //Plot( C, "", IIf(Close > Open, colorGreen, colorRed), styleCandle + styleNoLabel);
  3151. _SECTION_END();
  3152.  
  3153. _SECTION_BEGIN( "Moving Average" );
  3154.  
  3155. x = Param( "EMA 1", 20, 1, 200, 1 );
  3156.  
  3157. y = Param( "EMA 2", 50, 1, 200, 1 );
  3158.  
  3159. z = Param( "EMA 3", 100, 1, 200, 1 );
  3160.  
  3161. zz = Param( "EMA 4", 200, 1, 200, 1 );
  3162.  
  3163. EMA20 = EMA( C, x );
  3164.  
  3165. EMA50 = EMA( C, y );
  3166.  
  3167. EMA100 = EMA( C, z );
  3168.  
  3169. EMA200 = EMA( C, zz );
  3170.  
  3171. Plot ( EMA ( C, x ), "EMA 20", ParamColor( "EMA20", colorRed ), styleDots + styleThick + styleNoLine + styleNoLabel, maskAll );
  3172.  
  3173. Plot ( EMA ( C, y ), "EMA 50", ParamColor( "EMA50", colorBlue ), styleDots + styleThick + styleNoLine + styleNoLabel, maskAll );
  3174.  
  3175. Plot ( EMA ( C, z ), "EMA 100", ParamColor( "EMA100", colorGold ), styleDots + styleThick + styleNoLine + styleNoLabel, maskAll );
  3176.  
  3177. Plot ( EMA ( C, zz ), "EMA 200", ParamColor( "EMA200", colorDarkGrey ), styleDots + styleThick + styleNoLine + styleNoLabel, maskAll );
  3178.  
  3179. SUT = EMA( C, 5 ) > EMA20;
  3180.  
  3181. SDT = EMA20 > EMA( C, 5 );
  3182.  
  3183. mut = EMA20 > EMA50;
  3184.  
  3185. mdt = EMA20 < EMA50;
  3186.  
  3187. _SECTION_END();
  3188.  
  3189. _SECTION_BEGIN( "Mid Term Price Trend" );
  3190.  
  3191.  
  3192. MPT = IIf( mut, colorGreen, IIf( mdt, colorRed, colorYellow ) );
  3193.  
  3194. Plot( 3, "", MPT, styleArea | styleOwnScale | styleNoLabel, 0, 100 );
  3195.  
  3196. _SECTION_END();
  3197.  
  3198. _SECTION_BEGIN( "Short Term Price Trend" );
  3199.  
  3200. SPT = IIf( EMA( C, 5 ) > EMA20, colorBrightGreen, IIf( EMA20 > EMA( C, 5 ), colorPink, colorYellow ) );
  3201.  
  3202. Plot( 6, "", SPT, styleArea | styleOwnScale | styleNoLabel, 0, 100 );
  3203.  
  3204. _SECTION_END();
  3205.  
  3206.  
  3207.  
  3208. //StochRSI Signal
  3209. R = 14;
  3210.  
  3211. S = 14;
  3212.  
  3213. Value1 = RSI( R );
  3214.  
  3215. SR = 100 * ( Value1 - LLV( Value1, S ) ) / ( HHV( Value1, S ) - LLV( Value1, S ) );
  3216.  
  3217. SR1 = Ref( SR, -1 );
  3218.  
  3219. sup = ( SR1 < 20 AND SR >= 20 AND sr < 80 ) AND SUT;
  3220.  
  3221. sdown = ( SR1 > 80 AND SR <= 80 AND sr > 20 ) AND SDT;
  3222.  
  3223. mup = ( SR1 < 20 AND SR >= 20 AND sr < 80 ) AND mut;
  3224.  
  3225. mdown = ( SR1 > 80 AND SR <= 80 AND sr > 20 ) AND mdt;
  3226.  
  3227. PlotShapes(
  3228. IIf( sup == 1, shapeUpArrow, shapeNone ),
  3229. colorSkyblue, 0, High, Offset = -35 );
  3230.  
  3231.  
  3232. PlotShapes(
  3233. IIf( sdown == 1, shapeDownArrow, shapeNone ),
  3234. colorPink, 0, High, Offset = -15 );
  3235.  
  3236. PlotShapes(
  3237. IIf( mup == 1, shapeUpArrow, shapeNone ),
  3238. colorGreen, 0, High, Offset = -45 );
  3239.  
  3240.  
  3241. PlotShapes(
  3242. IIf( mdown == 1, shapeDownArrow, shapeNone ),
  3243. colorRed, 0, High, Offset = -25 );
  3244.  
  3245.  
  3246.  
  3247. _SECTION_BEGIN( "Fib-R" );
  3248.  
  3249.  
  3250. // Get values for fib-R
  3251.  
  3252. StartBar = SelectedValue( BarIndex() );
  3253.  
  3254. FinishBar = EndValue( BarIndex() );
  3255.  
  3256. i = startbar;
  3257.  
  3258. period = FinishBar - StartBar;
  3259.  
  3260. Lo = LLV( L, period );
  3261.  
  3262. Hi = HHV( H, period );
  3263.  
  3264. Line0 = 0;
  3265.  
  3266. Line1 = 0;
  3267.  
  3268. Line2 = 0;
  3269.  
  3270. Line3 = 0;
  3271.  
  3272. Line4 = 0;
  3273.  
  3274. Line5 = 0;
  3275.  
  3276. Line100 = 0;
  3277.  
  3278. for ( i = startbar; i < finishbar; i++ )
  3279. {
  3280. if ( EndValue( C ) < SelectedValue( C ) )
  3281. {
  3282. Line0 = EndValue( Lo );
  3283. Line100 = EndValue( Hi );
  3284. Line1 = Line0 + abs( Line100 - Line0 ) * 0.236;
  3285. Line2 = Line0 + abs( Line100 - Line0 ) * 0.382;
  3286. Line3 = Line0 + abs( Line100 - Line0 ) * 0.5;
  3287. Line4 = Line0 + abs( Line100 - Line0 ) * 0.618;
  3288. Line5 = Line0 + abs( Line100 - Line0 ) * 0.768;
  3289. }
  3290. else
  3291. {
  3292. Line100 = EndValue( Lo );
  3293. Line0 = EndValue( Hi );
  3294. Line1 = Line0 - abs( Line100 - Line0 ) * 0.236;
  3295. Line2 = Line0 - abs( Line100 - Line0 ) * 0.382;
  3296. Line3 = Line0 - abs( Line100 - Line0 ) * 0.5;
  3297. Line4 = Line0 - abs( Line100 - Line0 ) * 0.618;
  3298. Line5 = Line0 - abs( Line100 - Line0 ) * 0.768;
  3299. }
  3300. }
  3301.  
  3302. // external fib lines begining fom selecetdbarindex()
  3303. fib0 = LineArray( startbar, Line0, finishbar, Line0, 0, 1 );
  3304.  
  3305. fib100 = LineArray( startbar, Line100, finishbar, Line100, 0, 1 );
  3306.  
  3307. // depth of middle lines
  3308. n = round( ( finishbar - startbar ) / 2 );
  3309.  
  3310. // middle lines
  3311. fib1 = LineArray( ( finishbar - n ), Line1, finishbar, Line1, 0, 1 );
  3312.  
  3313. fib2 = LineArray( ( finishbar - n ), Line2, finishbar, Line2, 0, 1 );
  3314.  
  3315. fib3 = LineArray( ( finishbar - n ), Line3, finishbar, Line3, 0, 1 );
  3316.  
  3317. fib4 = LineArray( ( finishbar - n ), Line4, finishbar, Line4, 0, 1 );
  3318.  
  3319. fib5 = LineArray( ( finishbar - n ), Line5, finishbar, Line5, 0, 1 );
  3320.  
  3321. Plot( fib0, "", colorBlack, styleNoLabel );
  3322.  
  3323. Plot( fib100, "", colorBlack, styleNoLabel );
  3324.  
  3325. //Plot(fib1,"23.6%", colorYellow+styleNoLine+styleDots);
  3326. Plot( fib2, "38.2%", ParamColor( "38.2% Color", colorGreen ), ParamStyle( "38.2% Style", styleLine + styleThick, maskAll ) );
  3327.  
  3328. Plot( fib3, "50%", ParamColor( "50% Color", colorGreen ), ParamStyle( "50% Style", styleLine + styleThick, maskAll ) );
  3329.  
  3330. Plot( fib4, "61.8%", ParamColor( "61.8% Color", colorAqua ), ParamStyle( "61.8% Style", styleThick + styleNoLine + styleDots, maskAll ) );
  3331.  
  3332. //Plot(fib5,"76.8%", colorGold,styleLine);
  3333.  
  3334. Title = Name() + " - " + FullName() + " - AUTO FIB-R " + " - RedLine = " + WriteVal( EMA20, 0.3 ) + " - BlueLine = " + WriteVal( EMA50, 0.3 ) + " - Yellowline = " + WriteVal( EMA100, 0.3 ) + " - BlackLine = " + WriteVal( EMA200, 0.3 );
  3335.  
  3336. _SECTION_END();
  3337.  
  3338. }
  3339.  
  3340.  
  3341. if ( NEED == 1 )
  3342. {
  3343.  
  3344. _SECTION_BEGIN( "NEED" );
  3345.  
  3346.  
  3347.  
  3348. _SECTION_BEGIN( "XAverage" );
  3349. Length = Param( "Length", 10, 1, 100, 1 );
  3350. AvgExp = AMA( C, 2 / ( Length + 1 ) );
  3351. ColMa = IIf( AvgExp > Ref( AvgExp, -3 ) , colorYellow, colorWhite );
  3352.  
  3353. Plot( AvgExp, "MA1", ColMa, styleThick, styleLine );
  3354. _SECTION_END();
  3355.  
  3356. _SECTION_BEGIN( "Heiken Ashi" );
  3357. Value1 = MA( C, 8 );
  3358.  
  3359. HaClose = ( O + H + L + C ) / 4;
  3360. HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
  3361. HaHigh = Max( H, Max( HaClose, HaOpen ) );
  3362. HaLow = Min( L, Min( HaClose, HaOpen ) );
  3363. xDiff = ( HaHigh - Halow ) * 10000;
  3364. SetBarFillColor( IIf( HaClose > HaOpen, colorBrightGreen, colorRed ) );
  3365. Cancolor = IIf( HaClose > Value1, colorBrightGreen, colorRed );
  3366. PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", Cancolor, styleCandle );
  3367. _SECTION_END();
  3368. _SECTION_END();
  3369. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement