COCO研究院

 找回密碼
 註冊
搜索
查看: 5544|回復: 10

[範例程式碼] KBrain System V1.1

[複製鏈接]
發表於 11-5-10 11:06 | 顯示全部樓層 |閱讀模式
本帖最後由 COCO巡按 於 11-12-14 05:21 PM 編輯

  1. //KBrain System Coded by Karthikmarar. Blog. www.stocktechnician.blogspot.com email. karthikmarar@yahoo.com
  2. //System based on the BrainTrend system in Metatrader
  3. // The Turquiose colored Dot indicates start of a Up Trend
  4. // The Magenta DOt indicates end of an Up move and beginning of a downmove
  5. // The system is a Stop and reverse system
  6. //Revision Index - V.1.1 resolves the scan issues
  7. _SECTION_BEGIN("KBrain");
  8. //========================Initiation========================
  9. bts=ParamToggle("BrainTrend1 signal","No|Yes" ,1);
  10. btst=ParamToggle("BrainTrend1 stop","No|Yes" ,1);
  11. btsl=ParamToggle("BrainTrend1 stop line","No|Yes" ,1);
  12. period=Param("Period",14,6,20,1);
  13. x1=53;
  14. x2=47;
  15. d=2.3;
  16. f=7;
  17. s=1.5;
  18. range=ATR(f);
  19. Range1 = ATR(f)/d;
  20. Range2 = (ATR(f)*s)/4;
  21. range3=ATR(10);
  22. R = ((HHV(H,period) - C) /(HHV (H,period) -LLV (L,period))) *-100;
  23. EMA1= EMA(R,Period);
  24. EMA2= EMA(EMA1,5);
  25. Difference= EMA1 - EMA2;
  26. ZeroLagEMA= EMA1 + Difference;
  27. value2=abs(ZeroLagEMA);


  28. function PercentR( periods )
  29. {
  30. return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) );
  31. }


  32. for( i = 1; i < Period-1; i++ )
  33. {


  34. tm                =        1;
  35. bstop        =        1;
  36. sstop        =        1;
  37. p                =        1;
  38. }

  39. for( i = period+10; i < BarCount; i++ )
  40. {
  41. C[0]=0;
  42. Value2[0]=0;
  43. p[0]=0;
  44. Plot1[0]=0;
  45. Plot2[0]=0;
  46. Val1=0;
  47. Val2=0;
  48. temp[0]=0;
  49. Value3[0]=0;
  50. tm[0]=0;
  51. p1=0;
  52. bt1[0]=0;
  53. bt2[0]=0;
  54. r[0]=0;
  55. bt1a[0]=0;
  56. bt2a[0]=0;
  57. istop[0]=Val1[0];
  58. stop=Val1[0];
  59. bstop[0]=0;
  60. sstop=0;
  61. //==================================Indicators============================
  62. {
  63. if (value2 < x2 AND abs(Close-Close[i-2]) > range1)
  64. p = 1 ;
  65. else
  66. {
  67. if (value2 > x1 AND abs(Close-Close[i-2]) > Range1)
  68. p = 2 ;

  69. else

  70. p=0;
  71. }
  72. }

  73. if ((value2 < x2 AND p == 1) OR (value2 < x2 AND p == 0))

  74. {
  75. if (abs(Close-Close[i-2]) > Range1)
  76. {
  77. Plot1=H;
  78. Plot2=L;
  79. }
  80. else
  81. {
  82. Plot1=Plot1[i-1];
  83. Plot2=Plot2[i-1];
  84. }
  85. }
  86. else
  87. {
  88. if ((value2 > x1 AND p == 2) OR (value2 > x1 AND p == 0))

  89. {
  90. Plot1=L;
  91. Plot2=H;
  92. }
  93. else
  94. {
  95. Plot1=Plot1[i-1];
  96. Plot2=Plot2[i-1];
  97. }
  98. }
  99. //==================KBrain Signal ====================================
  100. {
  101. if (value2 < x2 AND (abs(Close-Close[i-2]) > Range1))
  102. {
  103. if (p == 1 OR p == 0)
  104. Value3=L-range3;
  105. val1=Value3;
  106. p=1;
  107. temp=1;
  108. }
  109. else
  110. {
  111. temp=temp[i-1];
  112. }
  113. {
  114. if (value2 > x1 AND (abs(Close-Close[i-2]) > Range1))
  115. {
  116. if (p == 2 OR p == 0)
  117. Value3=H+range3;
  118. val2=Value3;
  119. p=2;
  120. temp=2;;
  121. }

  122. }
  123. }
  124. {

  125. if (temp==1 AND Plot1>0 AND tm != 1)
  126. tm= 1;

  127. if (temp==2 AND Plot2>0 AND tm != 2)
  128. tm=2;

  129. }
  130. //===============================stop========================================
  131. {
  132. if (value2 < x2 AND (abs(Close-Close[i-2]) > Range1)AND p !=2)

  133. {
  134. value3=L-range3;
  135. va1=Value3;
  136. p1=2;
  137. r=Va1;
  138. bstop=Va1;
  139. bt2=bt2[i-1];
  140. }

  141. if (value2 > x1 AND (abs(Close-Close[i-2]) > Range1)AND p !=1)

  142. {
  143. Value3=H+range3;
  144. va2=Value3;
  145. p1=1;

  146. r=Va2;
  147. sstop=Value3;
  148. bt1=bt1[i-1];
  149. }

  150. }



  151. if (val1 == 0 AND val2 == 0 AND p == 0 )
  152. {
  153. bstop=bstop[i-1];
  154. sstop=sstop[i-1];
  155. }


  156. if (bstop<bstop[i-1] AND tm==1 AND tm[i-1]==1) bstop=bstop[i-1];
  157. if (sstop>sstop[i-1] AND tm==2 AND tm[i-1]==2) sstop=sstop[i-1];

  158. }
  159. //=============================SYSTEM======================================
  160. Mycolor=IIf(p==1,colorLime,IIf(p==2,colorRed,colorBlue));
  161. PlotOHLC( Open, High, Low, Close, "", Mycolor, styleCandle| styleThick );
  162. PlotShapes( shapeCircle* (bts AND tm==1 AND Ref(tm,-1)==2),colorTurquoise, 0, bstop, 0 );
  163. PlotShapes( shapeCircle* (bts AND tm==2 AND Ref(tm,-1)==1), colorCustom12, 0, sstop, 0 );
  164. PlotShapes( IIf(btst AND p==1,shapeSmallCircle,Null), colorTurquoise,0,bstop,0);
  165. Plot(IIf(btsl AND tm==1,bstop,Null),"",colorPaleBlue,1);
  166. PlotShapes( IIf(btst AND p==2,shapeSmallCircle,Null), colorCustom12,0,sstop,0);
  167. Plot(IIf(btsl AND tm==2,sstop,Null),"",colorLightYellow,1);
  168. Buy=Cover=(bts AND tm==1 AND Ref(tm,-1)==2);
  169. Sell=Short=(bts AND tm==2 AND Ref(tm,-1)==1);
  170. SellPrice=ValueWhen(Sell,C,1);
  171. BuyPrice=ValueWhen(Buy,C,1);
  172. Long=Flip(Buy,Sell);
  173. Shrt=Flip(Sell,Buy );
  174. _SECTION_END();
  175. //=================TITLE================================================================================================
  176. _SECTION_BEGIN("Title");
  177. if( Status("action") == actionIndicator )
  178. (
  179. Title = EncodeColor(colorWhite)+ "KBrain V 1.1. " + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
  180. " - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
  181. "Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
  182. EncodeColor(colorLime)+
  183. WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
  184. WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
  185. WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
  186. WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
  187. WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
  188. WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
  189. WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
  190. WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));

  191. _SECTION_END();
  192. BuyPrice=ValueWhen(Buy,C);
  193. SellPrice=ValueWhen(Sell,C);
  194. Filter=(Buy OR Sell );;
  195. AddColumn(IIf(Buy,BuyPrice,Null)," Buy ", 6.2,1,colorGreen);
  196. AddColumn(IIf(Sell,SellPrice,Null)," sell ",6.2,1,colorOrange);
複製代碼
發表於 11-5-10 11:21 | 顯示全部樓層
之前網路上抓過V1.0,
現在有v1.1了!
發表於 11-5-10 13:07 | 顯示全部樓層
 樓主| 發表於 11-5-10 14:18 | 顯示全部樓層
不好意思,我是新手兼穷人。重新贴过:

  1. //KBrain System Coded by Karthikmarar. Blog. www.stocktechnician.blogspot.com email. karthikmarar@yahoo.com
  2. //System based on the BrainTrend system in Metatrader
  3. // The Turquiose colored Dot indicates start of a Up Trend
  4. // The Magenta DOt indicates end of an Up move and beginning of a downmove
  5. // The system is a Stop and reverse system
  6. //Revision Index - V.1.1 resolves the scan issues
  7. _SECTION_BEGIN("KBrain");
  8. //========================Initiation========================
  9. bts=ParamToggle("BrainTrend1 signal","No|Yes" ,1);
  10. btst=ParamToggle("BrainTrend1 stop","No|Yes" ,1);
  11. btsl=ParamToggle("BrainTrend1 stop line","No|Yes" ,1);
  12. period=Param("Period",14,6,20,1);
  13. x1=53;
  14. x2=47;
  15. d=2.3;
  16. f=7;
  17. s=1.5;
  18. range=ATR(f);
  19. Range1 = ATR(f)/d;
  20. Range2 = (ATR(f)*s)/4;
  21. range3=ATR(10);
  22. R = ((HHV(H,period) - C) /(HHV (H,period) -LLV (L,period))) *-100;
  23. EMA1= EMA(R,Period);
  24. EMA2= EMA(EMA1,5);
  25. Difference= EMA1 - EMA2;
  26. ZeroLagEMA= EMA1 + Difference;
  27. value2=abs(ZeroLagEMA);

  28. function PercentR( periods )
  29. {
  30. return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods ) );
  31. }

  32. for( i = 1; i < Period-1; i++ )
  33. {

  34. tm  = 1;
  35. bstop = 1;
  36. sstop = 1;
  37. p  = 1;
  38. }
  39. for( i = period+10; i < BarCount; i++ )
  40. {
  41. C[0]=0;
  42. Value2[0]=0;
  43. p[0]=0;
  44. Plot1[0]=0;
  45. Plot2[0]=0;
  46. Val1=0;
  47. Val2=0;
  48. temp[0]=0;
  49. Value3[0]=0;
  50. tm[0]=0;
  51. p1[i]=0;
  52. bt1[0]=0;
  53. bt2[0]=0;
  54. r[0]=0;
  55. bt1a[0]=0;
  56. bt2a[0]=0;
  57. istop[0]=Val1[0];
  58. stop[i]=Val1[0];
  59. bstop[0]=0;
  60. sstop[i]=0;
  61. //==================================Indicators============================
  62. {
  63. if (value2[i] < x2 AND abs(Close[i]-Close[i-2]) > range1[i])
  64. p[i] = 1 ;
  65. else
  66. {
  67. if (value2[i] > x1 AND abs(Close[i]-Close[i-2]) > Range1[i])
  68. p[i] = 2 ;
  69. else
  70. p[i]=0;
  71. }
  72. }
  73. if ((value2[i] < x2 AND p[i] == 1) OR (value2[i] < x2 AND p[i] == 0))
  74. {
  75. if (abs(Close[i]-Close[i-2]) > Range1[i])
  76. {
  77. Plot1[i]=H[i];
  78. Plot2[i]=L[i];
  79. }
  80. else
  81. {
  82. Plot1[i]=Plot1[i-1];
  83. Plot2[i]=Plot2[i-1];
  84. }
  85. }
  86. else
  87. {
  88. if ((value2[i] > x1 AND p[i] == 2) OR (value2[i] > x1 AND p[i] == 0))
  89. {
  90. Plot1[i]=L[i];
  91. Plot2[i]=H[i];
  92. }
  93. else
  94. {
  95. Plot1[i]=Plot1[i-1];
  96. Plot2[i]=Plot2[i-1];
  97. }
  98. }
  99. //==================KBrain Signal ====================================
  100. {
  101. if (value2[i] < x2 AND (abs(Close[i]-Close[i-2]) > Range1[i]))
  102. {
  103. if (p[i] == 1 OR p[i] == 0)
  104. Value3[i]=L[i]-range3[i];
  105. val1[i]=Value3[i];
  106. p[i]=1;
  107. temp[i]=1;
  108. }
  109. else
  110. {
  111. temp[i]=temp[i-1];
  112. }
  113. {
  114. if (value2[i] > x1 AND (abs(Close[i]-Close[i-2]) > Range1[i]))
  115. {
  116. if (p[i] == 2 OR p[i] == 0)
  117. Value3[i]=H[i]+range3[i];
  118. val2[i]=Value3[i];
  119. p[i]=2;
  120. temp[i]=2;;
  121. }
  122. }
  123. }
  124. {
  125. if (temp[i]==1 AND Plot1[i]>0 AND tm[i] != 1)
  126. tm[i]= 1;
  127. if (temp[i]==2 AND Plot2[i]>0 AND tm[i] != 2)
  128. tm[i]=2;
  129. }
  130. //===============================stop========================================
  131. {
  132. if (value2[i] < x2 AND (abs(Close[i]-Close[i-2]) > Range1[i])AND p[i] !=2)
  133. {
  134. value3[i]=L[i]-range3[i];
  135. va1[i]=Value3[i];
  136. p1[i]=2;
  137. r[i]=Va1[i];
  138. bstop[i]=Va1[i];
  139. bt2[i]=bt2[i-1];
  140. }
  141. if (value2[i] > x1 AND (abs(Close[i]-Close[i-2]) > Range1[i])AND p[i] !=1)
  142. {
  143. Value3[i]=H[i]+range3[i];
  144. va2[i]=Value3[i];
  145. p1[i]=1;
  146. r[i]=Va2[i];
  147. sstop[i]=Value3[i];
  148. bt1[i]=bt1[i-1];
  149. }
  150. }

  151. if (val1[i] == 0 AND val2[i] == 0 AND p[i] == 0 )
  152. {
  153. bstop[i]=bstop[i-1];
  154. sstop[i]=sstop[i-1];
  155. }

  156. if (bstop[i]<bstop[i-1] AND tm[i]==1 AND tm[i-1]==1) bstop[i]=bstop[i-1];
  157. if (sstop[i]>sstop[i-1] AND tm[i]==2 AND tm[i-1]==2) sstop[i]=sstop[i-1];
  158. }
  159. //=============================SYSTEM======================================
  160. Mycolor=IIf(p==1,colorLime,IIf(p==2,colorRed,colorBlue));
  161. PlotOHLC( Open, High, Low, Close, "", Mycolor, styleCandle| styleThick );
  162. PlotShapes( shapeCircle* (bts AND tm==1 AND Ref(tm,-1)==2),colorTurquoise, 0, bstop, 0 );
  163. PlotShapes( shapeCircle* (bts AND tm==2 AND Ref(tm,-1)==1), colorCustom12, 0, sstop, 0 );
  164. PlotShapes( IIf(btst AND p==1,shapeSmallCircle,Null), colorTurquoise,0,bstop,0);
  165. Plot(IIf(btsl AND tm==1,bstop,Null),"",colorPaleBlue,1);
  166. PlotShapes( IIf(btst AND p==2,shapeSmallCircle,Null), colorCustom12,0,sstop,0);
  167. Plot(IIf(btsl AND tm==2,sstop,Null),"",colorLightYellow,1);
  168. Buy=Cover=(bts AND tm==1 AND Ref(tm,-1)==2);
  169. Sell=Short=(bts AND tm==2 AND Ref(tm,-1)==1);
  170. SellPrice=ValueWhen(Sell,C,1);
  171. BuyPrice=ValueWhen(Buy,C,1);
  172. Long=Flip(Buy,Sell);
  173. Shrt=Flip(Sell,Buy );
  174. _SECTION_END();
  175. //=================TITLE================================================================================================
  176. _SECTION_BEGIN("Title");
  177. if( Status("action") == actionIndicator )
  178. (
  179. Title = EncodeColor(colorWhite)+ "KBrain V 1.1. " + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
  180. " - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
  181. "Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
  182. EncodeColor(colorLime)+
  183. WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
  184. WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
  185. WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
  186. WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
  187. WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
  188. WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
  189. WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
  190. WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
  191. _SECTION_END();
  192. BuyPrice=ValueWhen(Buy,C);
  193. SellPrice=ValueWhen(Sell,C);
  194. Filter=(Buy OR Sell );;
  195. AddColumn(IIf(Buy,BuyPrice,Null)," Buy ", 6.2,1,colorGreen);
  196. AddColumn(IIf(Sell,SellPrice,Null)," sell ",6.2,1,colorOrange);

複製代碼
發表於 11-5-10 14:28 | 顯示全部樓層
你轉貼別人的東西未註明,不是你原創的還收10塊?
ironheart 發表於 11-5-10 01:07 PM


好嚴厲喔 ! 小朋友會被嚇出尿尿來 !!
發表於 11-5-10 14:42 | 顯示全部樓層
不好意思,我是新手兼穷人。重新贴过:
powerway 發表於 11-5-10 02:18 PM

多多回文就有錢了啊。
發表於 11-11-28 09:40 | 顯示全部樓層
這個勢什麼
發表於 11-12-14 15:49 | 顯示全部樓層
多多回文就有錢了啊。
發表於 12-12-21 23:20 | 顯示全部樓層
說多回文就有錢,那我來賺錢
發表於 12-12-27 03:32 | 顯示全部樓層
哈哈, 很好笑的板大
發表於 13-1-7 16:37 | 顯示全部樓層

哈哈, 很好笑的板大
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

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

GMT+8, 24-11-23 06:32

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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