COCO研究院

 找回密碼
 註冊
搜索
查看: 7137|回復: 8

KAMAS system 1.0 for Amibroker

[複製鏈接]
發表於 10-6-11 16:22 | 顯示全部樓層 |閱讀模式
  1. _SECTION_BEGIN("BACK COLR");
  2. SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

  3. ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));

  4. _SECTION_END();

  5. // Two adjustable parameter "Buy sensitivity" and "Buy Finetune" provided to adjust entry points.
  6. // Two adjustable parameter "Sell sensitivity" and "Sell Finetune" provided to adjust Exit points.

  7. _SECTION_BEGIN("KAMA System 1.0");




  8. SetChartOptions(0,chartShowArrows|chartShowDates);
  9. Title = ("KAMA SYSTEM - " + Name()+" " + Date() +" "+Interval(2) +" "+ EncodeColor(colorLime)+",Open "+Open +" ,High "+H+" ,Low "+L+" ,Close "+C+" "+"{{VALUES}}");


  10. //{{VALUES}}"+ O+ H+ L+C);


  11. //_N(Title =StrFormat("{{Name}} - {{Interval}} {{Date}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));


  12. // Buy adjustments
  13. bs=Param("BUY Sensitivity",7,2,20,1);
  14. bf=Param("BUY Finetune",2,0.1,20,0.1);

  15. ///uncommentf for optimization
  16. //bs=Optimize("BUY Sensitivity",7,2,20,1);
  17. //bf=Optimize("BUY Finetune",2,0.1,20,0.1);
  18. // Sell Adjustments
  19. ss=Param("SELL Sensitivity",5,2,20,1);
  20. sf=Param("SELL Finetune",1,0.1,20,0.1);

  21. ///uncommentf for optimization
  22. ss=Optimize("SELL Sensitivity",5,2,20,1);
  23. sf=Optimize("SELL Finetune",1,0.1,20,0.1);


  24. //stock selection parameters
  25. MyCL = Param( "CL", 10, 10, 100, 10 );
  26. MyVK = Param( "VK", 30, 10, 100, 10 );
  27. MyTL = Param( "TL", 300, 100, 1000, 100 );
  28. //stock selection
  29. //TLM = EMA(C*V/100000,100) ;
  30. //include = C> MyCL AND V/1000> MyVK AND C*V/100000 > MyTL AND TLM > 0.333 * MyTL ;

  31. // common
  32. fast = 2/(2+1);
  33. slow = 2/(30+1);
  34. //BUY part
  35. dirb=abs(Close-Ref(Close,-bs));
  36. volb=Sum(abs(Close-Ref(Close,-1)),bs);
  37. ERb=dirb/volb;
  38. scb =( ERb*(fast-slow)+slow)^2;
  39. xb = AMA( C, scb );
  40. flb=bf*StDev(xb-Ref(xb,-1),20);
  41. j=xb-Ref(xb,-3);


  42. //SELL part
  43. dirs=abs(Close-Ref(Close,-ss));
  44. vols=Sum(abs(Close-Ref(Close,-1)),ss);
  45. ERs=dirs/vols;
  46. scs =( ERs*(fast-slow)+slow)^2;
  47. xs = AMA( C, scs );
  48. fls=sf*StDev(xs-Ref(xs,-1),20);
  49. k=Ref(Xs,-3)-Xs;

  50. Buy=Cross(j,flb) ;
  51. Sell=Cross(k,fls);
  52. mycolor=IIf(C>xb,colorLime,colorRed);
  53. Plot( C, "Close", mycolor,styleNoTitle | styleCandle );
  54. Plot(xb,"KAMA-BUY",colorRed,1);
  55. Plot(xs,"KAMA-SELL",colorOrange,1);
  56. Buy = ExRem(Buy,Sell);
  57. Sell = ExRem(Sell,Buy);

  58. shape = Buy * shapeUpArrow +Sell * shapeDownArrow ;

  59. PlotShapes( shape, IIf( Buy, colorLime, colorRed),0, IIf( Buy, Low, High ) );

  60. GraphXSpace = 5;
  61. dist = 1.5*ATR(20);

  62. for( i = 0; i < BarCount; i++ )
  63. {
  64. if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist[i], colorLime );
  65. if( Sell[i] ) PlotText( "sell\n@" + C[ i ], i, L[ i ]+dist[i], colorRed );
  66. }
  67. Filter= Buy OR Sell;

  68. PositionScore=100/C;
  69. PositionSize = - 20;
  70. SetBarsRequired(10000, 10000);
  71. SetFormulaName("KAMA System");

  72. _SECTION_END();

  73. _SECTION_BEGIN("IIR2");
  74. // IIR2.afl
  75. //
  76. // Documentation to describe what the function does.
  77. // Second order smoother
  78. // the function statement
  79. function IIR2( input, f0, f1, f2 )
  80. // the function body
  81. {
  82. result[ 0 ] = input[ 0 ];
  83. result[ 1 ] = input[ 1 ];
  84. for( i = 2; i < BarCount; i++ )
  85. {
  86. result[i] = f0 * input[i] + f1 * result[i-1] + f2 * result[i-2];
  87. }
  88. // the function returns a single value and exits.
  89. return result;
  90. }
  91. // The routine that calls the function.
  92. SmoothedClose = IIR2(Close, 0.2, 1.4, -0.6 );
  93. //Plot( Close, "Price", 2, styleCandle );
  94. Plot( SmoothedClose, "function example", colorRed );
  95. //Figure 8.1 IIR2
  96. _SECTION_END();

  97. _SECTION_BEGIN("GSMA");
  98. SetBarsRequired(100000,0);
  99. PI = 3.1415926;

  100. function jIIR2( input, f0, f1, f2 )
  101. {
  102. result[ 0 ] = input[ 0 ];
  103. result[ 1 ] = input[ 1 ];

  104. for( i = 2; i < BarCount; i++ )
  105. {
  106. result[ i ] = f0 * input[ i ] +
  107. f1 * result[ i - 1 ] +
  108. f2 * result[ i - 2 ];
  109. }

  110. return result;
  111. }

  112. function GSMA( input, Period )
  113. {
  114. N = 0;
  115. an = 2 * PI / Period;
  116. c0 = b0 = 1;
  117. c1 = b1 = b2 = a1 = a2 = gamma1 = 0;
  118. beta1 = 2.415 * ( 1- cos( an ) );
  119. alpha = -beta1 + sqrt( beta1 ^ 2 + 2 * beta1 );
  120. alpha1 = ( cos( an ) + sin( an ) - 1 )/cos( an );
  121. {
  122. fo = alpha ^ 2;
  123. f1 = 2 * ( 1- alpha ); f2 = -( 1 - alpha )*( 1 - alpha );
  124. }


  125. return jIIR2( input, fo,f1,f2);
  126. }
  127. period=Param("period",13,1,40,1);

  128. //Plot( Close, "Price", colorBlack, styleCandle );
  129. Plot( GSMA( C,period), "GSMA", colorLime );

  130. // Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below
  131. // Written by Patrick Hargus, with critical hints from Marcin Gorzynski, Amibroker.com Technical Support
  132. // Designed for use with AB 4.63 beta and above, using drag and drop feature.
  133. // Permits plotting a linear regression line of any price field available on the chart for a period determined by the user.
  134. // 2 Channels, based on a standard deviation each determined by the user, are plotted above and below the linear regression line.
  135. // A look back feature is also provided for examining how the indicator would have appeared on a chart X periods in the past.


  136. P = ParamField("Price field",-1);
  137. Daysback = Param("Period for Liner Regression Line",21,1,240,1);
  138. shift = Param("Look back period",0,0,240,1);


  139. // =============================== Math Formula =============================================================

  140. x = Cum(1);
  141. lastx = LastValue( x ) - shift;
  142. aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
  143. bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
  144. y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );


  145. // ==================Plot the Linear Regression Line ==========================================================


  146. LRColor = ParamColor("LR Color", colorCycle );
  147. LRStyle = ParamStyle("LR Style");

  148. LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );
  149. Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); // styleDots );

  150. // ========================== Plot 1st SD Channel ===============================================================

  151. SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1);
  152. SD = SDP/2;

  153. width = LastValue( Ref(SD*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
  154. SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ;
  155. SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ;

  156. SDColor = ParamColor("SD Color", colorCycle );
  157. SDStyle = ParamStyle("SD Style");

  158. Plot( SDU , "Upper Lin Reg", SDColor,SDStyle );
  159. Plot( SDL , "Lower Lin Reg", SDColor,SDStyle );

  160. // ========================== Plot 2d SD Channel ===============================================================

  161. SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1);
  162. SD2 = SDP2/2;

  163. width2 = LastValue( Ref(SD2*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE WIDTH OF THE CHANELS IS SET
  164. SDU2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ;
  165. SDL2 = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;

  166. SDColor2 = ParamColor("2 SD Color", colorCycle );
  167. SDStyle2 = ParamStyle("2 SD Style");

  168. Plot( SDU2 , "Upper Lin Reg", SDColor2,SDStyle2 );
  169. Plot( SDL2 , "Lower Lin Reg", SDColor2,SDStyle2 );

  170. // ============================ End Indicator Code ==============================================================

  171. //Fibonacci cluster

  172. _SECTION_BEGIN("Background");
  173. SetChartOptions(0,chartShowArrows|chartShowDates);
  174. SetChartBkColor(ParamColor("Outer panel",colorWhite)); // color of outer border
  175. SetChartBkGradientFill( ParamColor("Inner panel upper",colorWhite),ParamColor("Inner panel lower",colorWhite));
  176. tchoice=Param("Title Selection ",2,1,2,1);

  177. //Plot(C, "", IIf(O>=C, colorOrange, colorGreen), ParamStyle("Price Style",styleCandle,maskPrice));
  178. //////////////////////////////////////////////////////////////////
  179. _SECTION_BEGIN("Fib Retracements");
  180. fibs = ParamToggle("Plot Fibs","Off|On",1);
  181. pctH = Param ("Pivot Hi %", 0.325,0.001,2.0,0.002);
  182. HiLB = Param ("Hi LookBack",1,1,BarCount-1,1);
  183. pctL = Param ("Pivot Lo %", 0.325,0.001,2.0,0.002);
  184. LoLB = Param ("Lo LookBack",1,1,BarCount-1,1);
  185. Back = Param ("Extend Left = 2",1,1,500,1);
  186. Fwd = Param("Plot Forward", 0, 0, 500, 1);
  187. text = ParamToggle("Plot Text","Off|On",1);
  188. hts = Param ("Text Shift", -33.5,-50,50,0.10);
  189. style =ParamStyle("Line Style",styleLine,styleNoLabel);
  190. x = BarIndex();
  191. pRp = PeakBars( H, pctH, 1) == 0;
  192. yRp0 = SelectedValue(ValueWhen( pRp, H, HiLB));
  193. xRp0 = SelectedValue(ValueWhen( pRp, x, HiLB));
  194. pSp = TroughBars( L, pctL, 1) == 0;
  195. ySp0 = SelectedValue(ValueWhen( pSp, L, LoLB));
  196. xSp0 = SelectedValue(ValueWhen( pSp, x, LoLB));
  197. Delta = yRp0 - ySp0;

  198. function fib(ret)
  199. {
  200. retval = (Delta * ret);
  201. Fibval = IIf(ret < 1.0
  202. AND xSp0 < xRp0, yRp0 - retval, IIf(ret < 1.0
  203. AND xSp0 > xRp0, ySp0 + retval,IIf(ret > 1.0
  204. AND xSp0 < xRp0, yRp0 - retval, IIf(ret > 1.0
  205. AND xSp0 > xRp0, ySp0 + retval, Null))));
  206. return FibVal;
  207. }

  208. x0 = Min(xSp0,xRp0)-Back;
  209. x1 = (BarCount -1);
  210. //////////////////////////////////////////////////////////////////
  211. r236 = fib(0.236); r236I = LastValue (r236,1);
  212. r382 = fib(0.382); r382I = LastValue (r382,1);
  213. r050 = fib(0.50); r050I = LastValue (r050,1);
  214. r618 = fib(0.618); r618I = LastValue (r618,1);
  215. r786 = fib(0.786); r786I = LastValue (r786,1);
  216. e127 = fib(1.27); e127I = LastValue (e127,1);
  217. e162 = fib(1.62); e162I = LastValue (e162,1);
  218. e200 = fib(2.00); e200I = LastValue (e200,1);
  219. e262 = fib(2.62); e262I = LastValue (e262,1);
  220. e424 = fib(4.24); e424I = LastValue (e424,1);
  221. //////////////////////////////////////////////////////////////////
  222. p00 = IIf(xSp0 > xRp0,ySp0,yRp0); p00I = LastValue (p00,1);
  223. p100 = IIf(xSp0 < xRp0,ySp0,yRp0); p100I = LastValue (p100,1);
  224. color00 =IIf(xSp0 > xRp0,colorLime,colorRed);
  225. color100 =IIf(xSp0 < xRp0,colorLime,colorRed);
  226. //////////////////////////////////////////////////////////////////
  227. numbars = LastValue(Cum(Status("barvisible")));
  228. fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
  229. //////////////////////////////////////////////////////////////////
  230. if(fibs==1)
  231. {
  232. Plot(LineArray(xRp0-Fwd,yRp0,x1,yRp0,Back),"PR",32,8|styleNoRescale,Null, Null,Fwd);
  233. Plot(LineArray(xSp0-Fwd,ySp0,x1,ySp0,Back),"PS",27,8|styleNoRescale,Null, Null,Fwd);
  234. Plot(LineArray(x0-Fwd,r236,x1,r236,Back),"",45,style|styleNoRescale,Null, Null,Fwd);
  235. Plot(LineArray(x0-Fwd,r382,x1,r382,Back),"",44,style|styleNoRescale,Null, Null,Fwd);
  236. Plot(LineArray(x0-Fwd,r050,x1,r050,Back),"",41,style|styleNoRescale,Null, Null,Fwd);
  237. Plot(LineArray(x0-Fwd,r618,x1,r618,Back),"",43,style|styleNoRescale,Null, Null,Fwd);
  238. Plot(LineArray(x0-Fwd,r786,x1,r786,Back),"",42,style|styleNoRescale,Null, Null,Fwd);
  239. Plot(LineArray(x0-Fwd,e127,x1,e127,Back),"e127",47,style|styleNoRescale,Null, Null,Fwd);
  240. Plot(LineArray(x0-Fwd,e162,x1,e162,Back),"e162",47,style|styleNoRescale,Null, Null,Fwd);
  241. Plot(LineArray(x0-Fwd,e200,x1,e200,Back),"p200",47,style|styleNoRescale,Null, Null,Fwd);
  242. Plot(LineArray(x0-Fwd,e262,x1,e262,Back),"p262",47,style|styleNoRescale,Null, Null,Fwd);
  243. Plot(LineArray(x0-Fwd,e424,x1,e424,Back),"p424",25,style|styleNoRescale,Null, Null,Fwd);
  244. }
  245. //////////////////////////////////////////////////////////////////
  246. if(text==1)
  247. {
  248. PlotText(" 0% = " + WriteVal(p00,fraction), LastValue(BarIndex())-(numbars/hts), p00I + 0.05, color00);
  249. PlotText("23% = " + WriteVal(r236,fraction), LastValue(BarIndex())-(numbars/hts), r236I + 0.05, 45);
  250. PlotText("38% = " + WriteVal(r382,fraction), LastValue(BarIndex())-(numbars/hts), r382I + 0.05, 44);
  251. PlotText("50% = " + WriteVal(r050,fraction), LastValue(BarIndex())-(numbars/hts), r050I + 0.05, 41);
  252. PlotText("62% = " + WriteVal(r618,fraction), LastValue(BarIndex())-(numbars/hts), r618I + 0.05, 43);
  253. PlotText("78% = " + WriteVal(r786,fraction), LastValue(BarIndex())-(numbars/hts), r786I + 0.05, 42);
  254. PlotText("100% = " + WriteVal(p100,fraction), LastValue(BarIndex())-(numbars/hts),p100I + 0.05, color100);
  255. PlotText("127% = " + WriteVal(e127,fraction), LastValue(BarIndex())-(numbars/hts),e127I + 0.05, 47);
  256. PlotText("162% = " + WriteVal(e162,fraction), LastValue(BarIndex())-(numbars/hts),e162I + 0.05, 47);
  257. PlotText("200% = " + WriteVal(e200,fraction), LastValue(BarIndex())-(numbars/hts),e200I + 0.05, 47);
  258. PlotText("262% = " + WriteVal(e262,fraction), LastValue(BarIndex())-(numbars/hts),e262I + 0.05, 47);
  259. PlotText("424% = " + WriteVal(e424,fraction), LastValue(BarIndex())-(numbars/hts),e424I + 0.05, 25);
  260. }
  261. _SECTION_END();
  262. //////////////////////////////////////////////////////////////////
  263. if (tchoice==1 )
  264. {
  265. _N(Title = EncodeColor(colorBlack)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open: %g, High: %g, Low: %g, Close: %g {{VALUES}}",O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
  266. }
  267. //////////////////////////////////////////////////////////////////
  268. if (tchoice==2 )
  269. {
  270. Title = EncodeColor(colorBlack)+ Date() + " Tick = " + EncodeColor(5) + Interval()+
  271. EncodeColor(colorBlack) + " Open = " + EncodeColor(colorBlack) + O +
  272. EncodeColor(colorBlack) + " High = " + EncodeColor(5) + H +
  273. EncodeColor(colorBlack) + " Low = " + EncodeColor(colorRed) + L +
  274. EncodeColor(colorBlack) + " Close = " + EncodeColor(colorBlack) + C + "\n" +
  275. EncodeColor( colorBlack) +"_______________"+"\n"+
  276. EncodeColor( colorBlack) + "424% = " + EncodeColor(25)+ e424 + " " +"\n"+
  277. EncodeColor( colorBlack) + "262% = " + EncodeColor(47)+ e262 + " " +"\n"+
  278. EncodeColor( colorBlack) + "200% = " + EncodeColor(47)+ e200 + " " +"\n"+
  279. EncodeColor( colorBlack) + "162% = " + EncodeColor(47)+ e162 + " " +"\n"+
  280. EncodeColor( colorBlack) + "127% = " + EncodeColor(47)+ e127 + " " +"\n"+
  281. EncodeColor( colorYellow) + " Res = " + EncodeColor(32)+ p100 + " " +"\n"+
  282. EncodeColor( colorBlack) + " 78% = " + EncodeColor(42)+ r786 + " " +"\n"+
  283. EncodeColor( colorBlack) + " 62% = " + EncodeColor(43)+ r618 + " " +"\n"+
  284. EncodeColor( colorBlack) + " 50% = " + EncodeColor(41)+ r050 + " " +"\n"+
  285. EncodeColor( colorBlack) + " 38% = " + EncodeColor(44)+ r382 + " " +"\n"+
  286. EncodeColor( colorBlack) + " 23% = " + EncodeColor(45)+ r236+ " " +"\n"+
  287. EncodeColor( colorYellow) + " Sup = " + EncodeColor(34)+ p00 + " " ;
  288. }
  289. GraphXSpace=5;

  290. _SECTION_BEGIN("BACK COLR");
  291. SetChartBkGradientFill( ParamColor("BgTop", ColorRGB( 172,172,172 )),

  292. ParamColor("BgBottom", ColorRGB( 172,172,172 )),ParamColor("titleblock",ColorRGB( 172,172,172 )));
  293. _SECTION_END();
複製代碼



2.jpg
發表於 10-6-11 16:56 | 顯示全部樓層
謝謝分享好東西

黃金切割率很多人很愛用
發表於 10-6-11 19:49 | 顯示全部樓層
GOOD~謝啦
發表於 10-6-16 20:51 | 顯示全部樓層
好東西 ~~  謝謝分享  ~  
發表於 10-10-6 13:18 | 顯示全部樓層
如果能解釋一下最好
發表於 10-12-27 13:50 | 顯示全部樓層
好東西 ~~  謝謝分享  ~
發表於 11-3-27 03:58 | 顯示全部樓層
謝謝
謝謝分享  
追求自由是唯一的路,我已經把一半的資金放到程式交易了。
發表於 12-1-28 20:38 | 顯示全部樓層
看起來是個好東西
謝謝分享
發表於 12-2-22 13:43 | 顯示全部樓層
謝謝分享,會寫程式真好…
能夠加一些原本軟體沒有的功能
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-12-24 03:06

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |