COCO研究院

 找回密碼
 註冊
搜索
查看: 4079|回復: 1

NMA SWING SYSTEM (參考看看)

[複製鏈接]
發表於 10-6-18 14:54 | 顯示全部樓層 |閱讀模式
本帖最後由 alexwang7777 於 10-6-18 03:36 PM 編輯
  1. _SECTION_BEGIN("graph");
  2. SetChartOptions(0,chartShowArrows|chartShowDates);
  3. gxs=Param("GRAPH spaceing",10,5,50,5);
  4. GraphXSpace = gxs;
  5. strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
  6. _SECTION_END();
  7. _SECTION_BEGIN("NMA ");
  8. k = Optimize("K",Param("K",1.75,1,5,0.25),1,5,0.25);
  9. Per= Optimize("atr",Param("atr",10,3,30,1),3,30,1);
  10. j=(O+H+L+C)/4;
  11. nm= (H-L);
  12. rfsctor = WMA(nm, PER);
  13. revers = K * rfsctor;
  14. Trend = 1;
  15. NW[0] = 0;
  16. for(i = 1; i < BarCount; i++)
  17. {
  18. if(Trend[i-1] == 1)
  19. {
  20. if(j[i] < NW[i-1])
  21. {
  22. Trend[i] = -1;
  23. NW[i] = j[i] + Revers[i];
  24. }
  25. else
  26. {
  27. Trend[i] = 1;
  28. if((j[i] - Revers[i]) > NW[i-1])
  29. {
  30. NW[i] = j[i] - Revers[i];
  31. }
  32. else
  33. {
  34. NW[i] = NW[i-1];
  35. }
  36. }
  37. }
  38. if(Trend[i-1] == -1)
  39. {
  40. if(j[i] > NW[i-1])
  41. {
  42. Trend[i] = 1;
  43. NW[i] = j[i] - Revers[i];
  44. }
  45. else
  46. {
  47. Trend[i] = -1;
  48. if((j[i] + Revers[i]) < NW[i-1])
  49. {
  50. NW[i] = j[i] + Revers[i];
  51. }
  52. else
  53. {
  54. NW[i] = NW[i-1];
  55. }
  56. }
  57. }
  58. }

  59. Plot(NW, "", IIf(Trend == 1, 6, 4), 4);

  60. //---------------trading -------------

  61. Buy=Cover=Cross(j,nw);
  62. Sell=Short=Cross(nw,j);
  63. Buy=ExRem(Buy,Sell);
  64. Sell=ExRem(Sell,Buy);
  65. Short=ExRem(Short,Cover);
  66. Cover=ExRem(Cover,Short);
  67. PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorSkyblue, 0,Low,-15);
  68. PlotShapes(IIf(Sell, shapeHollowDownArrow, shapeNone),colorLightYellow, 0,High,-15);
  69. PlotShapes(IIf(Cover, shapeHollowCircle, shapeNone),colorTan, 0,Close,0);
  70. PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorGold, 0,High,-25);
  71. //-----------end--------------
  72. Long=Flip(Buy,Sell OR Cover);
  73. Shrt=Flip(Sell,Buy OR Cover);
  74. NOTrade= NOT (Long OR shrt);
  75. Edc=(
  76. WriteIf (Buy AND Ref(shrt,-1), " GO LONG / Reverse Signal at "+C+" ","")+
  77. WriteIf (Buy AND Ref(NOTrade,-1), " GO LONG at "+C+" ","")+
  78. WriteIf (Sell AND Ref(NOTrade,-1), " GO Short at "+C+" ","")+
  79. WriteIf (Sell AND Ref(Long,-1), " EXIT LONG / Reverse Signal at "+C+" ",""));
  80. _SECTION_END();
  81. grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
  82. Plot(grid_day,"",colorDarkGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
  83. ///--------------------------------------------------------------------------------------------------

  84. UpCandle = ParamColor("Up Color", colorBrightGreen );
  85. DownCandle = ParamColor("Down Color", colorDarkRed );
  86. Consolidation = ParamColor("Consolidation", colorBlack );
  87. BG2a=HHV(LLV(L,4)+ATR(4),8);
  88. BR2a=LLV(HHV(H,4)-ATR(4),8);
  89. Candlecolor = IIf(Close>BG2a ,UpCandle,IIf(Close < BR2a,DownCandle,Consolidation));
  90. SetBarFillColor( IIf(O <C, colorSeaGreen,colorOrange) );
  91. Plot( Close, "Price", CandleColor, styleCandle );
  92. TimeFrameSet( 2*Interval() );
  93. BG2=HHV(LLV(L,4)+ATR(4),8);
  94. BR2=LLV(HHV(H,4)-ATR(4),8);
  95. C1=C;
  96. TimeFrameRestore();
  97. M5 = TimeFrameExpand(BG2,2*Interval() );
  98. MM5=TimeFrameExpand( BR2,2*Interval() );
  99. cM5=TimeFrameExpand( C1, 2*Interval() );
  100. TimeFrameSet( 4*Interval() );
  101. BG2=HHV(LLV(L,4)+ATR(4),8);
  102. BR2=LLV(HHV(H,4)-ATR(4),8);
  103. C1=C;
  104. TimeFrameRestore();
  105. M15 = TimeFrameExpand(BG2,4*Interval() );
  106. MM15=TimeFrameExpand(BR2,4*Interval() );
  107. cM15=TimeFrameExpand( C1,4*Interval() );
  108. TimeFrameSet( 6*Interval() );
  109. BG2=HHV(LLV(L,4)+ATR(4),8);
  110. BR2=LLV(HHV(H,4)-ATR(4),8);
  111. C1=C;
  112. TimeFrameRestore();
  113. M30 = TimeFrameExpand(BG2,6*Interval() );
  114. MM30=TimeFrameExpand(BR2,6*Interval() );
  115. cM30=TimeFrameExpand( C1,6*Interval() );
  116. TimeFrameSet( 8*Interval() );
  117. BG2=HHV(LLV(L,4)+ATR(4),8);
  118. BR2=LLV(HHV(H,4)-ATR(4),8);
  119. C1=C;
  120. TimeFrameRestore();
  121. H1 = TimeFrameExpand(BG2 ,8*Interval() );
  122. HH1=TimeFrameExpand( BR2,8*Interval() );
  123. Ch1=TimeFrameExpand( C1,8*Interval() );
  124. TimeFrameSet( 16*Interval() );
  125. BG2=HHV(LLV(L,4)+ATR(4),8);
  126. BR2=LLV(HHV(H,4)-ATR(4),8);
  127. C1=C;
  128. TimeFrameRestore();
  129. H4 = TimeFrameExpand( BG2,16*Interval() );
  130. HH4=TimeFrameExpand( BR2,16*Interval() );
  131. cH4 = TimeFrameExpand( C1,16*Interval() );
  132. Com=("\n "+Name()+ " - Trend in ")+"\n "+
  133. EncodeColor(colorLightGrey)+(""+Interval(2)+":")+
  134. WriteIf(Close>BG2a,EncodeColor(colorLime)+" UP",WriteIf(Close<BR2a,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  135. EncodeColor(colorLightGrey)+(" "+2*Interval()/60+"m:")+
  136. WriteIf(Cm5>M5,EncodeColor(colorLime)+" UP",WriteIf(Cm5<MM5,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  137. EncodeColor(colorLightGrey)+(" "+4*Interval()/60+"m:")+
  138. WriteIf(Cm15>M15,EncodeColor(colorLime)+" UP",WriteIf(Cm15<MM15,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  139. EncodeColor(colorLightGrey)+(" "+6*Interval()/60+"m:")+
  140. WriteIf(Cm30>M30,EncodeColor(colorLime)+" UP",WriteIf(Cm30<MM30,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  141. EncodeColor(colorLightGrey)+(" "+8*Interval()/60+"m:")+
  142. WriteIf(CH1>H1,EncodeColor(colorLime)+" UP",WriteIf(CH1<HH1,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  143. EncodeColor(colorLightGrey)+(" "+16*Interval()/60+"m: ")+
  144. WriteIf(Ch4>H4,EncodeColor(colorLime)+" UP",WriteIf(Ch4<HH4,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
  145. //---------------------------------------------------------------------------------------
  146. Vr=ParamList("Index",List = "^NSEI,^NSEBANK,NIFTY_F1,RELIANCE.NS,SBIN.NS,EURUSD,XAUUSD,GOLD",0);
  147. SetForeign(Vr);
  148. HaC =(O+H+L+C)/4;
  149. HaO = AMA( Ref( HaC, -1 ), 0.5 );
  150. HaH = Max( H, Max( HaC, HaO) );
  151. HaL = Min( L, Min( HaC, HaO) );
  152. HBG=HHV(LLV(HaL,4)+ATR(4),8);
  153. HBR=LLV(HHV(HaH ,4)-ATR(4),8);
  154. co = IIf(Hac>HBG ,colorAqua,IIf(Hac < HBR,colorCustom12,colorGrey50));
  155. Plot(4, "", Co,styleArea+styleOwnScale | styleNoLabel, -1, 100);
  156. //PlotOHLC(HaO,HaH,HaL,HaC, "", Co,styleCandle|styleOwnScale );
  157. //=====================================================================================
  158. TimeFrameSet( 2*Interval() );
  159. BG2H=HHV(LLV(HaL,4)+ATR(4),8);
  160. BR2H=LLV(HHV(HaH,4)-ATR(4),8);
  161. C1H=HaC;
  162. TimeFrameRestore();
  163. M5H = TimeFrameExpand(BG2H,2*Interval() );
  164. MM5H=TimeFrameExpand( BR2H,2*Interval() );
  165. cM5H=TimeFrameExpand( C1H, 2*Interval() );
  166. TimeFrameSet( 4*Interval() );
  167. BG2H=HHV(LLV(HaL,4)+ATR(4),8);
  168. BR2H=LLV(HHV(HaH,4)-ATR(4),8);
  169. C1H=HaC;
  170. TimeFrameRestore();
  171. M15H = TimeFrameExpand(BG2H,4*Interval() );
  172. MM15H=TimeFrameExpand(BR2H,4*Interval() );
  173. cM15H=TimeFrameExpand( C1H,4*Interval() );
  174. TimeFrameSet( 6*Interval() );
  175. BG2H=HHV(LLV(HaL,4)+ATR(4),8);
  176. BR2H=LLV(HHV(HaH,4)-ATR(4),8);
  177. C1H=HaC;
  178. TimeFrameRestore();
  179. M30H = TimeFrameExpand(BG2H,6*Interval() );
  180. MM30H=TimeFrameExpand(BR2H,6*Interval() );
  181. cM30H=TimeFrameExpand( C1H,6*Interval() );
  182. TimeFrameSet( 8*Interval() );
  183. BG2H=HHV(LLV(HaL,4)+ATR(4),8);
  184. BR2H=LLV(HHV(HaH,4)-ATR(4),8);
  185. C1H=HaC;
  186. TimeFrameRestore();
  187. H1H = TimeFrameExpand(BG2H ,8*Interval() );
  188. HH1H=TimeFrameExpand( BR2H,8*Interval() );
  189. Ch1H=TimeFrameExpand( C1H,8*Interval() );
  190. TimeFrameSet( 16*Interval() );
  191. BG2H=HHV(LLV(HaL,4)+ATR(4),8);
  192. BR2H=LLV(HHV(HaH,4)-ATR(4),8);
  193. C1H=HaC;
  194. TimeFrameRestore();
  195. H4H = TimeFrameExpand( BG2H,16*Interval() );
  196. HH4H=TimeFrameExpand( BR2H,16*Interval() );
  197. cH4H = TimeFrameExpand( C1H,16*Interval() );
  198. RestorePriceArrays();
  199. Comm2=("\n "+VR+ " - Phase in ")+"\n "+
  200. EncodeColor(colorLightYellow)+(""+Interval(2)+":")+
  201. WriteIf(Hac>HBG,EncodeColor(colorLime)+" UP",WriteIf(Hac < HBR,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  202. EncodeColor(colorLightYellow)+(" "+2*Interval()/60+"m:")+
  203. WriteIf(cM5H>M5H,EncodeColor(colorLime)+" UP",WriteIf(cM5H<MM5H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  204. EncodeColor(colorLightYellow)+(" "+4*Interval()/60+"m:")+
  205. WriteIf(cM15H>M15H,EncodeColor(colorLime)+" UP",WriteIf(cM15H<MM15H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  206. EncodeColor(colorLightYellow)+(" "+6*Interval()/60+"m:")+
  207. WriteIf(cM30H>M30H,EncodeColor(colorLime)+" UP",WriteIf(cM30H<MM30H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  208. EncodeColor(colorLightYellow)+(" "+8*Interval()/60+"m:")+
  209. WriteIf(Ch1H>H1H,EncodeColor(colorLime)+" UP",WriteIf(Ch1H<HH1H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~"))+
  210. EncodeColor(colorLightYellow)+(" "+16*Interval()/60+"m: ")+
  211. WriteIf(cH4H>H4H,EncodeColor(colorLime)+" UP",WriteIf(cH4H<HH4H,EncodeColor(colorRed)+" DN",EncodeColor(colorGrey50)+" ~~" ));
  212. //============

  213. BuyPrice=ValueWhen(Buy,C);
  214. SellPrice=ValueWhen(Sell,C);
  215. ShortPrice=ValueWhen(Short,C);
  216. CoverPrice=ValueWhen(Cover,C);
  217. //=====Title================================================================================================
  218. _SECTION_BEGIN("Title");
  219. if( Status("action") == actionIndicator )
  220. (
  221. Title = EncodeColor(colorWhite)+ "NMA I.T v-3("+k+" - "+per+")" + " - " + Name() + "-" + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
  222. " - " + Date() +" - "+ strWeekday +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
  223. "Cl-"+C+" "+ "Vol= "+ WriteVal(V)+
  224. EncodeColor(colorTan)+ Com+
  225. EncodeColor(colorYellow)+ Comm2);
  226. _SECTION_END();

  227. _SECTION_BEGIN("Background text");
  228. C11=ParamColor("up panel",colorDarkOliveGreen );
  229. C12=ParamColor("dn panel",colorDarkGrey );
  230. C13=Param("fonts",20,10,30,1 );
  231. C14=Param("left-right",2.1,1.0,5.0,0.1 );
  232. C15=Param("up-down",12,1,20,1 );
  233. Miny = Status("axisminy");
  234. Maxy = Status("axismaxy");
  235. lvb = Status("lastvisiblebar");
  236. fvb = Status("firstvisiblebar");
  237. pxwidth = Status("pxwidth");
  238. pxheight = Status("pxheight");
  239. GfxSetBkMode( 0 );
  240. GfxSetOverlayMode(1);
  241. GfxGradientRect(0,0,pxwidth, pxheight, C11, C12 );
  242. GfxSelectFont("Tahoma", Status("pxheight")/C13 );
  243. GfxSetTextAlign( 6 );
  244. GfxTextOut( Name(), Status("pxwidth")/C14, Status("pxheight")/C15 );
  245. GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
  246. GfxTextOut( "NMA", Status("pxwidth")/C14, Status("pxheight")/C15*2.5 );
  247. GfxSelectFont("Tahoma", Status("pxheight")/C13*0.5 );
  248. GfxTextOut( " Karthik Marar", Status("pxwidth")/C14, Status("pxheight")/C15*4 );
  249. GfxSelectFont("MS Sans Serif", 10, 500, False, False, 0);
  250. GfxTextOut(""+Vr+"---cas67", Status("pxwidth")/1.08, Status("pxheight")/C15*10.8 );
  251. GfxSelectFont("Ariel",9, 700, False, False, 0);
  252. GfxSetTextColor(colorYellow);
  253. GfxTextOut(""+edc+"", Status("pxwidth")/1.15, Status("pxheight")/C15*0.3 );
  254. //axisarea = 56; // may need adjustment if you are using non-default font for axis
複製代碼



1.jpg
 樓主| 發表於 10-6-18 16:00 | 顯示全部樓層
^^必須在改良一下
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

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

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

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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