ekeko price chart.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:12k
源码类别:

金融证券系统

开发平台:

Others

  1. //------------------------------------------------------------------------------
  2. //
  3. //  Formula Name:    ekeko price chart
  4. //  Author/Uploader: RAFAEL GOMEZ 
  5. //  E-mail:          
  6. //  Date/Time Added: 2006-03-17 01:00:42
  7. //  Origin:          Peru
  8. //  Keywords:        
  9. //  Level:           semi-advanced
  10. //  Flags:           system
  11. //  Formula URL:     http://www.amibroker.com/library/formula.php?id=598
  12. //  Details URL:     http://www.amibroker.com/library/detail.php?id=598
  13. //
  14. //------------------------------------------------------------------------------
  15. //
  16. //  price chart with trade calls for aroon + sar signs
  17. //
  18. //------------------------------------------------------------------------------
  19. ScriptVersion = " explorativo del Main al 12 de set 2005";
  20. //////////////////// PRECIO //////////////////////////////////////////////
  21. Plot(C,"",colorBlack,styleCandle|styleNoLabel);
  22. Filter = Close > 10;
  23. AddColumn(Close,"Close");
  24. PositionSize = 100;
  25. /////////////////////// MEDIAS MOVILES///////////////////
  26. slope = Param("slope",2,2,100,1);
  27. Color20= IIf(LinRegSlope(MA(C,20),slope)<0,colorRed,colorBrightGreen);
  28. event1= LinRegSlope(MA(C,20),slope)<0;
  29. Plot( MA( C,  20), "",Color20 , styleLine);
  30. //Plot( event1, "", colorRose, styleArea|styleOwnScale);
  31. Color50= IIf(LinRegSlope(MA(C,50),slope)<0,colorRed,colorBlue); 
  32. Plot( MA( C, 50), "",Color50  , styleLine);
  33. Color100= IIf(LinRegSlope(MA(C,100),slope)<0,colorRed,colorYellow);
  34. Plot( MA( C,  100), "",Color100 , styleLine);
  35. Color150= IIf(LinRegSlope(MA(C,150),slope)<0,colorRed,10); 
  36. Plot( MA( C, 150), "",Color150  , styleLine);
  37. event1=Cross(MA(C,20),MA(C,50));
  38. PlotShapes( IIf(event1 ,shapeDigit1,0) ,5, 0, L,-30);
  39. event2=Cross(MA(C,50),MA(C,100));
  40. PlotShapes( IIf(event2 ,shapeDigit2,0) ,6, 0, L,-30);
  41. event3=Cross(MA(C,100),MA(C,150));
  42. PlotShapes( IIf(event3 ,shapeDigit3,0) ,7, 0, L,-30);
  43. event4=Cross(MA(C,50),MA(C,20));
  44. PlotShapes( IIf(event4 ,shapeDigit4,0) ,5, 0, H,30);
  45. event5=Cross(MA(C,100),MA(C,50));
  46. PlotShapes( IIf(event5 ,shapeDigit5,0) ,6, 0, H,30);
  47. event6=Cross(MA(C,150),MA(C,100));
  48. PlotShapes( IIf(event6 ,shapeDigit6,0) ,7, 0, H,30);
  49. event7=Cross(MA(C,5),MA(C,20));
  50. PlotShapes( IIf(event7 ,shapeDigit7,0) ,9, 0, L,-30);
  51. //////////////////////////////////MACD///////////////////////////////////
  52. MACDRequired=1; 
  53. FAST = Param("FAST",12,0,100,1);
  54. SLOW = Param("SLOW",26,0,100,1);
  55. SIG  = Param("SIG",9,0,100,1);
  56. MACDLine   = MACD(FAST,SLOW);
  57. MACDSignal = Signal(FAST,SLOW,SIG);
  58. MACDHisto  = MACDLine - MACDSignal;
  59. MIN10=   Param("X MACD10", 5,1,30,step=0.1);
  60. MIN60=   Param("X MACD60",10,1,30,step=0.1);
  61. MACDBACKBARS=Param("Lookback MACD",1,1,30,step=1);
  62. MinDir=      Param("DirChange",0.6,-5,5,step=0.01);
  63. NOEXCESS=    Param("Remove Excess Signals",1,0,1,step=1);
  64. if(Interval() <= 600 ) MACDRequired=MIN10;  // 10 minute +/-5 extreme
  65. if(Interval() >= 3600) MACDRequired=MIN60;  // 60 minute +/- 10
  66. /////////////////// HISTOGRAMA ////////////////////////////////
  67. MACDHisto  = MACDLine - MACDSignal;
  68. HistDivUp = Cross(LinRegSlope(MACDHisto,3),0);
  69. HistDivDn = Cross(0,LinRegSlope(MACDHisto,3));
  70. HBuy  = HistDivUp ;
  71. HSell = HistDivDn ;
  72. PlotShapes( IIf(HBuy ,3,0) ,colorBlue, 0,Graph0,-22 );
  73. PlotShapes( IIf(HSell,4,0) ,colorYellow, 0,Graph0,-22);
  74. //////////////////////       AROON       //////////////////////////////////
  75. Period = Param("Aroon Period",14,1,100,1);
  76. LLVBarsSince = LLVBars(L, Period) + 1;
  77. HHVBarsSince = HHVBars(H, Period) + 1;
  78. AD = 100 * (Period - LLVBarsSince) / (Period - 1);
  79. AU   = 100 * (Period - HHVBarsSince) / (Period - 1);
  80. AO  = AU - AD;
  81. MINAROONOSC= Param("AO  ",45,0,100,step=0.1);
  82. MINAROONSIG= Param("AV ",99.9,0,100,step=0.1);
  83. MINAROONOSC= Optimize("Aroon Osc  ",MINAROONOSC,0,100,step=1);
  84. MINAROONSIG= Optimize("Aroon Value",MINAROONSIG,0,100,step=1);
  85. event1 =Cross(MINAROONSIG,AD) AND AO <= -MINAROONOSC;
  86. event2=Cross(MINAROONSIG,AU)   AND AO >=  MINAROONOSC;
  87. // Include MACD / Signal Cross
  88. AroonMACD=MACD() >= Signal();
  89. event3=Cross(MINAROONSIG,AU)   AND AO >=  MINAROONOSC AND AroonMACD > 0;
  90. event4 =Cross(MINAROONSIG,AD) AND AO <= -MINAROONOSC ;
  91. //if(AroonBuy[BarCount-1]) PlotShapes( ( AroonBuy OR AroonSell )+5 ,IIf( AroonBuy, colorPaleGreen, colorPink ), 0 );
  92. event5=Cross(AO,0);
  93. event6= Cross(0,AO); 
  94. event7=Cross(AO,-50);
  95. event8= Cross(0,AO);
  96. event9= Cross(AU,AD); 
  97. event10=Cross(AD,AU);
  98. //Plot(AU  ,"AU" ,colorBrightGreen,styleLine); 
  99. //Plot(AD,"AD" ,colorRed  ,styleLine); 
  100. //Plot(AO ,"Osc",colorBlack,styleLine+styleOwnScale); 
  101. AroonBuy= event9;
  102. AroonSell=event10;
  103. PlotShapes( IIf(AroonBuy ,5,0) ,colorBlue, 0,L);
  104. PlotShapes( IIf(AroonSell,6,0) ,colorYellow, 0,H);
  105. ////////////////////////////////   DMI //////////////////////////////////
  106. MACDLine   = MACD(FAST,SLOW);
  107. range=Param("R ADX ",14,1,50,step=1);
  108. //Prefs(49);
  109. MINADX=      Param("X ADX ",30,1,50,step=0.1);
  110. ADXBACKBARS= Param("LB ADX",3,1,30,step=1);
  111. // Find the direction of ADX
  112. ADXTipDirA  = LinRegSlope(ADX(range),2);  // Short term direction change
  113. ADXTipDir   = LinRegSlope(ADXTipDirA*4,3);    // Short term direction change
  114. ADXFastDir = LinRegSlope(ADX(range),3);  // Medium
  115. ADXSlowDir = LinRegSlope(ADX(range),6);  // Longer
  116. // Direction *CHANGE* of ADX at the 'extremes'
  117. ADXSlopeUp = Cross(ADXTipDir,0) AND ADX(range)<20;
  118. ADXSlopeDn = Cross(0,ADXTipDir) AND ADX(range)>MINADX;
  119. ADXHistory = ADX(range);
  120. ADXBuy1 =  ADXFastDir >0 AND ADX(range)> 20 AND ( PDI(range)>MDI(range)) AND MACDLine > 0;//TrendUp
  121. ADXSell2 =  ADXFastDir >0 AND ADX(range)> 20 AND ( MDI(range)>PDI(range)) AND MACDLine < 0; //TrendDown
  122. ADXBuy3=  ADXSlowDir >0; //AND ADX(range)< 20 AND ( PDI(range)>MDI(range));//WarnUp
  123. ADXSell4=  ADXSlowDir >0; //AND ADX(range)< 20 AND ( MDI(range)>PDI(range));//WarnDn  
  124. ADXBuy5=ADX(range)>MDI(range) AND MDI(range)>30;//MDIX
  125. ADXSell6=ADX(range)>PDI(range) AND PDI(range)>30;//PDIX
  126. ADXBuy7  = BarsSince(ADXTipDir<MinDIR)<BarsSince(ADXBuy1)+ADXBACKBARS AND ADX(range)>MINADX;
  127. ADXSell8 = BarsSince(ADXTipDir<MinDIR)<BarsSince(ADXSell6)+ADXBACKBARS AND ADX(range)>MINADX;
  128. ADXBuy9  = BarsSince(MACDLine < -MACDRequired)<MACDBACKBARS ;  // AND HistDivUp;
  129. ADXSell10 = BarsSince(MACDLine >  MACDRequired)<MACDBACKBARS;  //  AND HistDivDn;
  130. ADXBuy11  = ADXBuy5 AND ADXSlopeDn;
  131. ADXSell12 = ADXSell6 AND ADXSlopeDn;
  132. ADXBuy13  = ADXBuy5 AND ADXTipDir<0 AND Peak(ADXHistory,0.5,1)>ADX(range); //AND ADXSlopeDn;
  133. ADXSell14 = ADXSell6 AND ADXTipDir<0 AND Peak(ADXHistory,0.5,1)>ADX(range); //AND ADXSlopeDn;
  134. ADXBuy15  = ADXBuy5 AND ADXTipDir<0 AND ADXHistory[BarCount-10]<ADX(range); //AND ADXSlopeDn;
  135. ADXSell16 = ADXSell6 AND ADXTipDir<0 AND ADXHistory[BarCount-10]<ADX(range); //AND ADXSlopeDn;
  136. ADXBuy17  = ADXBuy5 AND ADXSlopeDn;
  137. ADXBuy18=Cross(PDI(range),MDI(range));
  138. ADXSell19=Cross(MDI(range),PDI(range));
  139. ADXBuy=ADXBuy18;
  140. ADXSell=ADXSell19;
  141. // Remove excess Buy/Sell Signals from ADX Based Signals
  142. if(NOEXCESS) ADXBuy  = ExRemSpan( ADXBuy, 5);
  143. if(NOEXCESS) ADXSell = ExRemSpan( ADXSell, 5); 
  144. PlotShapes( IIf(ADXBuy ,5,0) ,colorBlack, 0);
  145. PlotShapes( IIf(ADXSell,6,0) ,colorWhite, 0);
  146. //////////////////////  BOLLINGER BANDS ///////////////////////
  147. TopBand = BBandTop(Close, 20, 2);
  148. LowBand = BBandBot(Close, 20, 2);
  149. dirup= (BarsSince(Low<LowBand)<5);
  150. dirdn= (BarsSince(High>TopBand)<5);
  151. BBBuy=0;
  152. BBSell=0;
  153. ///////////////////// ORDEN DE COMPRA ////////////////////////////////////
  154. //Buy = AroonBuy;
  155. //Sell = AroonSell;
  156. // Remove excess Buy/Sell Signals
  157. //Short = Sell;
  158. //Cover = Buy;
  159. //if(NOEXCESS) Buy  = ExRemSpan( Buy, 1 );
  160. //if(NOEXCESS) Sell = ExRemSpan( Sell, 1 ); 
  161. //PlotShapes( IIf(Buy ,1,0) ,colorBlue, 0,Graph0,-18 );
  162. //PlotShapes( IIf(Sell,2,0) ,colorYellow, 0,Graph0,-18 );
  163. //////////////////REGRESION LINEAL ///////////////////////////////////
  164. LookBack=Param("Lookback (RegressionChannel)",72,1,300);
  165. NH = LastValue(HHVBars(High,LookBack));   // lookback period  - can be set by the user if necessary
  166. NL = LastValue(LLVBars(Low ,LookBack));   // lookback period  - can be set by the user if necessary
  167. N=0;
  168. if(NL>NH) { N=NL; } else { N=NH; }
  169.  
  170. Start = 1;
  171. X = Cum(Start);    // Set up the x cordinate array of the Linear Regression Line
  172. Y = Close;         // Set the y co-ordinate of the Linear Regression line    
  173. /* Calculate the slope (bconst) and the y intercept (aconst) of the line */
  174. SUMX    = LastValue(Sum(X,N));
  175. SUMY    = LastValue(Sum(Y,N));
  176. SUMXY   = LastValue(Sum(X*Y,N));
  177. SUMXSqd = LastValue(Sum(X*X,N));
  178. SUMSqdX = LastValue(SUMX * SUMX);
  179. bconst  = (N * SUMXY - SUMX * SUMY)/(N * SUMXSqd - SUMSqdX);
  180. aconst  = (SUMY - bconst * (SUMX))/N;
  181. /* Force the x value to be very negative so the graph does not apear before the
  182. lookback period */
  183. Domain =  IIf ( X > LastValue(X) - N, 1 , -1e10);   
  184. Xvar = X * Domain;
  185. /* Linear Regression Line */
  186. Yvar = aconst + bconst * Xvar;
  187. Plot(Yvar + LastValue(HHV(High - Yvar,N)),"Upper Channel",colorWhite,styleLine|styleNoLabel);
  188. Plot(Yvar,"Middle Channel",colorWhite,styleLine|styleNoLabel);
  189. Plot(Yvar - LastValue(HHV(Yvar - Low ,N)),"Lower Channel",colorWhite,styleLine|styleNoLabel);
  190. /////////////////   SAR ////////////////////////////////////////////////
  191. IAF = 0.02;       // acceleration factor
  192. MaxAF = 0.2;     // max acceleration
  193. psar = Close; // initialize
  194. long = 1;        // assume long for initial conditions
  195. af = IAF;         // init acelleration factor
  196. ep = Low[ 0 ];   // init extreme point
  197. hp = High [ 0 ];
  198. lp = Low [ 0 ];
  199. for( i = 2; i < BarCount; i++ )
  200. {
  201. if ( long )
  202. {
  203. psar [ i ] = psar [ i-1 ] + af * ( hp - psar [ i-1 ] );
  204. }
  205. else
  206. {
  207. psar [ i ] = psar [ i-1 ] + af * ( lp - psar [ i-1 ] );
  208. }
  209. reverse =  0;
  210. //check for reversal
  211. if ( long )
  212. {
  213. if ( Low [ i ] < psar [ i ]  )
  214. {
  215. long = 0; reverse = 1; // reverse position to Short
  216. psar [ i ] =  hp;       // SAR is High point in prev trade
  217. lp = Low [ i ];
  218. af = IAF;
  219. }
  220. }
  221. else
  222. {
  223. if ( High [ i ] > psar [ i ]  )
  224. {
  225. long = 1; reverse = 1;        //reverse position to long
  226. psar [ i ] =  lp;
  227. hp = High [ i ];
  228. af = IAF;
  229. }
  230. }
  231. if ( reverse == 0 )
  232. {
  233. if ( long )
  234. {
  235. if ( High [ i ] > hp ) 
  236. {
  237. hp = High [ i ]; 
  238. af = af + IAF; 
  239. if( af > MaxAF ) af = MaxAF; 
  240. }
  241.              
  242. if( Low[ i - 1 ] < psar[ i ] ) psar[ i ] = Low[ i - 1 ];
  243. if( Low[ i - 2 ] < psar[ i ] ) psar[ i ] = Low[ i - 2 ];
  244. }
  245.        else
  246. {
  247. if ( Low [ i ] < lp )  
  248. lp = Low [ i ]; 
  249. af = af + IAF; 
  250. if( af > MaxAF ) af = MaxAF; 
  251. }
  252. if( High[ i - 1 ] > psar[ i ] ) psar[ i ] = High[ i - 1 ];
  253. if( High[ i - 2 ] > psar[ i ] ) psar[ i ] = High[ i - 2 ];
  254. }
  255. }
  256. }
  257. Plot( psar, "SAR", colorSkyblue, styleDots | styleNoLine | styleThick );
  258. ///////////// COMENTARIOS DE INTERPRETACION ///////////////////
  259. if( SelectedValue(ADXBuy1) OR SelectedValue(ADXSell2))
  260.  if( SelectedValue(ADXBuy1)) { printf("We're in a uptrend."); };
  261.  if( SelectedValue(ADXSell2)) { printf("We're in a downtrend."); };
  262. }
  263. else
  264. {
  265.  printf("Falling ADX - watch for MACD Histogram Divergence");
  266.  if(SelectedValue(HistDivUp)) printf("(currently UP)");
  267.  if(SelectedValue(HistDivDn)) printf("(currently DOWN)");
  268. }
  269. if( SelectedValue(ADXFastDir)>0 )
  270. {
  271.  if(SelectedValue(ADXBuy5)) printf("Wait for retest of low, and then ADX turn down");
  272.  if(SelectedValue(ADXSell6)) printf("Wait for retest of high, and then ADX turn down");
  273. }
  274. WriteIf( BBBuy   ,"Bollinger Buy Signal  (usually good until 20EMA)","");
  275. WriteIf( BBSell  ,"Bollinger Sell Signal (usually good until 20EMA)","");
  276. WriteIf( ADXBuy3 ,"Watch out - could be a beginning uptrend.","");
  277. WriteIf( ADXSell4 ,"Watch out - could be a beginning downtrend.","");
  278. WriteIf( ADXBuy1 AND MACDLine <  1 AND HistDivDn, "*WARNING* Trend could fail to begin !","");
  279. WriteIf( ADXSell2 AND MACDLine > -1 AND HistDivUp, "*WARNING* Trend could fail to begin !","");
  280. WriteIf( ADX(range) < 20 , "Trading range, weak direction - watch for Histogram Divergences","");
  281. WriteIf( True ," ------- DEBUG -------","");
  282. WriteIf( HistDivUp  ,"Histogram divergence up  ","Hup wait");
  283. WriteIf( HistDivDn  ,"Histogram divergence down","Hdn wait");
  284. WriteIf( ADXSlopeUp  ,"ADX Up ","Aup wait");
  285. WriteIf( ADXSlopeDn  ,"ADX Dn ","Adn wait");
  286. WriteIf( MDI(range)>30  ,"MDI","DMI wait");
  287. WriteIf( PDI(range)>30  ,"PDI","DMI wait");
  288. WriteIf( ADXBuy5 ,"MDI-X","DMI wait");
  289. WriteIf( ADXSell6 ,"PDI-X","DMI wait");