COCO研究院

 找回密碼
 註冊
搜索
查看: 4577|回復: 2

Advanced Support Resistamce Buy@sell for Amibroker

[複製鏈接]
發表於 10-6-11 16:27 | 顯示全部樓層 |閱讀模式
  1. _SECTION_BEGIN("advancesuppresibuysell");
  2. ///////////////////////////////////////////////////////////////////////////////////////////
  3. SetChartOptions(0,chartShowArrows|chartShowDates);
  4. _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} ,{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
  5. Plot(C, "", IIf(O>=C, colorOrange, colorGreen),styleCandle);

  6. SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
  7. _N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open:%g, Close:%g ,{{VALUES}}",O,C ));

  8. /////////////////////////////////////////////////////////////////////////////////////////////

  9. Plot(EMA(C,13),"",colorYellow);
  10. /////////////////////////////////////////////////////////////

  11. per1=Param ("per1", 0.325,0.1,50,0.10);

  12. per=per1;
  13. x = Cum(1);
  14. s1=L;
  15. s11=H;
  16. pS = TroughBars( s1, per, 1 ) == 0;
  17. endt= SelectedValue(ValueWhen( pS, x, 1 ));
  18. startt=SelectedValue(ValueWhen( pS, x, 2 ));
  19. dtS =endt-startt;
  20. endS = SelectedValue(ValueWhen( pS, s1, 1 ) );
  21. startS = SelectedValue( ValueWhen( pS, s1, 1 ));
  22. aS = (endS-startS)/dtS;
  23. bS = endS;
  24. trendlineS = aS * ( x -endt ) + bS;
  25. g3= IIf(x>startt-10,trendlineS,-1e10);
  26. Plot(g3,"",colorRed,styleDashed);

  27. pR = PeakBars( s11, per, 1 ) == 0;
  28. endt1= SelectedValue(ValueWhen( pR, x, 1 ));
  29. startt1=SelectedValue(ValueWhen( pR, x, 2 ));
  30. dtR =endt1-startt1;
  31. endR = SelectedValue(ValueWhen( pR, s11, 1 ) );
  32. startR = SelectedValue( ValueWhen( pR, s11, 1 ));
  33. aR = (endR-startR)/dtR;
  34. bR = endR;
  35. trendlineR = aR * ( x -endt1 ) + bR;
  36. g4= IIf(x>startT1-10,trendlineR,-1e10);
  37. Plot(g4,"",colorGreen,styleDashed);
  38. //////////////////////////////////////////////////////////////////////////////////////////////////
  39. perc=per1;
  40. x=BarIndex();xx=SelectedValue(x);
  41. t1=SelectedValue(ValueWhen(PeakBars(C,perc)==0,x)) ;
  42. H1=SelectedValue(ValueWhen(PeakBars(C,perc)==0,C)) ;
  43. t11=SelectedValue(ValueWhen(TroughBars(C,perc)==0, x));
  44. H11=SelectedValue(ValueWhen(TroughBars(C,perc)==0, C));
  45. g=t1>t11;
  46. shape=IIf(g,shapeDownArrow*(x==t1),shapeUpArrow*(x ==t11));
  47. Color=IIf(g,colorRed,colorGreen);
  48. PlotShapes(shape,color);
  49. /////////////////////////////////////////////////////////////////////////////////////////////////

  50. per=per1;

  51. x = Cum(1);
  52. s1=C;
  53. s11=C;
  54. pS = TroughBars( s1, per, 1 ) == 0;
  55. endt= SelectedValue(ValueWhen( pS, x, 1 ));
  56. startt=SelectedValue(ValueWhen( pS, x, 2 ));
  57. dtS =endt-startt;
  58. endS = SelectedValue(ValueWhen( pS, s1, 1 ) );
  59. startS = SelectedValue( ValueWhen( pS, s1, 2 ));
  60. aS = (endS-startS)/dtS;
  61. bS = endS;
  62. trendlineS = aS * ( x -endt ) + bS;
  63. g3= IIf(x>startt-10,trendlineS,-1e10);
  64. Plot(g3,"",colorRed,styleThick);

  65. pR = PeakBars( s11, per, 1 ) == 0;
  66. endt1= SelectedValue(ValueWhen( pR, x, 1 ));
  67. startt1=SelectedValue(ValueWhen( pR, x, 2 ));
  68. dtR =endt1-startt1;
  69. endR = SelectedValue(ValueWhen( pR, s11, 1 ) );
  70. startR = SelectedValue( ValueWhen( pR, s11, 2 ));
  71. aR = (endR-startR)/dtR;
  72. bR = endR;
  73. trendlineR = aR * ( x -endt1 ) + bR;
  74. g4= IIf(x>startT1-10,trendlineR,-1e10);
  75. Plot(g4,"",colorGreen,styleThick);
  76. //////////////////////////////////////////////////////////////////////////////

  77. //z_ZigZagValid
  78. // ******** CHARTING
  79. per=Param ("per1", 0.325,0.1,50,0.10);

  80. PercentChange = per;
  81. mystartbar = SelectedValue(BarIndex()); // FOR GRAPHING

  82. mystartbardate = LastValue(ValueWhen(mystartbar == BarIndex(), DateNum(),1));

  83. InitialValue = LastValue(ValueWhen(mystartbardate == DateNum(), C , 1 ) ) ;
  84. Temp1 = IIf(BarIndex() >= mystartbar, InitialValue, Null) ;
  85. Plot(Temp1, " ", colorBlack,styleLine);
  86. Plot((1+(LastValue(PercentChange)/100))*(Temp1), " ", colorGreen, styleLine) ;
  87. Plot((1-(LastValue(PercentChange)/100))*(Temp1), " ", colorRed, styleLine) ;

  88. ZZ = Zig(C,LastValue(PercentChange)) ;
  89. PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, Null),1);
  90. PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, Null),1);

  91. PlotShapes( shapeCircle*PivotLow, colorGreen,0, L, -20) ;
  92. PlotShapes( shapeCircle*PivotHigh,colorRed,0,H, 20) ;

  93. Buy_Valid = IIf(C>(1+(LastValue(PercentChange)/100))*(ValueWhen(PivotLow, C,
  94. 1))
  95. AND ROC(ZZ,1) > 0,1,0);
  96. Sell_Valid = IIf(C<(1-(LastValue(PercentChange)/100))*(ValueWhen(PivotHigh, C,
  97. 1))
  98. AND ROC(ZZ,1) < 0,1,0);

  99. Buy_Valid = ExRem(Buy_Valid,Sell_Valid);
  100. Sell_Valid = ExRem(Sell_Valid,Buy_Valid);

  101. PlotShapes( shapeUpArrow*Buy_Valid, colorGreen,0, L, -20);
  102. PlotShapes( shapeDownArrow*Sell_Valid, colorRed,0,H, -20) ;

  103. BarColors =
  104. IIf(BarsSince(Buy_Valid) < BarsSince(Sell_Valid)
  105. AND BarsSince(Buy_Valid)!=0, colorGreen,
  106. IIf(BarsSince(Sell_Valid) < BarsSince(Buy_Valid)
  107. AND BarsSince(Sell_Valid)!=0, colorRed, colorBlue));

  108. Plot(C, " ", BarColors, styleCandle ) ;
  109. Plot(ZZ," ", colorLightGrey,styleLine|styleThick);
  110. Plot(ZZ," ", BarColors,styleDots|styleNoLine);

  111. Title = Name() + " " + Date() + WriteIf(PivotLow, " Up Pivot
  112. ","")+WriteIf(PivotHigh," Down Pivot ","")+ WriteIf(Buy_Valid, " Buy Point ",
  113. "") + WriteIf(Sell_Valid, " Sell Point ", "") ;

  114. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  115. x = Cum(1);
  116. s1=C;
  117. s11=C;
  118. pS = TroughBars( s1, per, 1 ) == 0;
  119. endt= SelectedValue(ValueWhen( pS, x, 1 ));
  120. startt=SelectedValue(ValueWhen( pS, x, 2 ));
  121. dtS =endt-startt;
  122. endS = SelectedValue(ValueWhen( pS, s1, 1 ) );
  123. startS = SelectedValue( ValueWhen( pS, s1, 2 ));
  124. aS = (endS-startS)/dtS;
  125. bS = endS;
  126. trendlineS = aS * ( x -endt ) + bS;
  127. g3= IIf(x>startt-10,trendlineS,-1e10);
  128. Plot(g3,"",colorRed,styleThick);

  129. pR = PeakBars( s11, per, 1 ) == 0;
  130. endt1= SelectedValue(ValueWhen( pR, x, 1 ));
  131. startt1=SelectedValue(ValueWhen( pR, x, 2 ));
  132. dtR =endt1-startt1;
  133. endR = SelectedValue(ValueWhen( pR, s11, 1 ) );
  134. startR = SelectedValue( ValueWhen( pR, s11, 2 ));
  135. aR = (endR-startR)/dtR;
  136. bR = endR;
  137. trendlineR = aR * ( x -endt1 ) + bR;
  138. g4= IIf(x>startT1-10,trendlineR,-1e10);
  139. Plot(g4,"",colorGreen,styleThick);
  140. _SECTION_END();

  141. _SECTION_BEGIN("Triangle search");
  142. /* 20 day __Triangle Search
  143. This is a scan for triangles using highest high and lowest low over a chosen
  144. period, then next high over a chosen period after these HHV and LLV. Then the
  145. order of the highs and lows are to be in alternate order. This will pick up
  146. ascending, descending and eqaul triangles. Variable d1 is the number of days to
  147. search for the last highest high, and d2 is the gap after this HH to start
  148. searching for the next HH after the first. Similarly for the lowest lows
  149. The variables w? represent the highs, and z? are the lows.
  150. Graham Kavanagh*/

  151. Filter=Close>1;
  152. d1=20;
  153. d2=4;

  154. z1=HHV(High,d1);
  155. za1=HHVBars(High,d1);
  156. zb1=za1-d2;
  157. z2=HHV(High,zb1);
  158. za2=HHVBars(High,zb1);
  159. w1=LLV(Low,d1);
  160. wa1=LLVBars(Low,d1);
  161. wb1=wa1-d2;
  162. w2=LLV(Low,wb1);
  163. wa2=LLVBars(Low,wb1);

  164. aa1=LastValue(High);
  165. aa2=LastValue(Low);




  166. Buy= ((z1>=z2 AND w2>w1) OR(z1>z2 AND w2>=w1)) AND za1>za2 AND wa1>wa2 AND
  167. ((za1>wa1 AND wa1>za2 AND za2>wa2) OR (wa1>za1 AND za1>wa2 AND wa2>za2)) AND
  168. aa1<z2 AND aa2>w2 AND Ref(Volume,-za1) > MA(Volume,d2) AND
  169. Ref(MA(Close,d1),-za1) > Ref(MA(Close,d1),-2*za1) AND MA(Close,d1) >
  170. Ref(MA(Close,d1),-2*za1);

  171. //PlotShapes(z1*shapeDownArrow,colorRed, 0, High, Offset =-40);
  172. //PlotShapes(z1*shapeDigit1,colorRed, 0, High, Offset =55);
  173. //PlotShapes(z2*shapeDownArrow,colorRed, 0, High, Offset =-10);
  174. //PlotShapes(z2*shapeDigit2,colorRed, 0, High, Offset =25);

  175. //PlotShapes(w1*shapeUpArrow,colorBrightGreen, 0, Low, Offset =0);
  176. //PlotShapes(w1*shapeDigit1,colorBrightGreen, 0, Low, Offset =-15);
  177. //PlotShapes(w2*shapeUpArrow,colorGreen, 0, Low, Offset =-35);
  178. //PlotShapes(w2*shapeDigit2,colorGreen, 0, Low, Offset =-50);



  179. NumColumns = 8;

  180. Column0 = z1;
  181. Column1 = z2;
  182. Column2 = w1;
  183. Column3 = w2;
  184. Column4 = za1;
  185. Column5 = za2;
  186. Column6 = wa1;
  187. Column7 = wa2;
  188. _SECTION_END();
複製代碼
2.jpg
發表於 10-6-11 20:01 | 顯示全部樓層
來挖寶~謝謝分享喔
發表於 10-6-16 20:56 | 顯示全部樓層
謝謝分享  學習程式  好用的例子 ~
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

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

GMT+8, 24-11-22 16:46

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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