|
一根均线走天涯
均线斜率目测指标
原作者:frlin2003,鸣谢
均线斜率代码;
- //+------------------------------------------------------------------+
- //| Slope.mq4 |
- //| Copyright ?2011, MetaQuotes Software Corp. |
- //| http://www.metaquotes.net |
- //+------------------------------------------------------------------+
- #property copyright "Copyright ?2011, MetaQuotes Software Corp."
- #property link "http://www.metaquotes.net"
- #define SIGNAL_BAR 1
- #property indicator_separate_window
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //http://articles.mql4.com/374
- //+------------------------------------------------------------------+
- extern int Ma_period=60;
- extern int RangeValue=5;
- double Slopebuffer[];
- double Mabuffer[];
- double prevbuffer[];
- int init()
- {
- //---- indicators
- IndicatorBuffers(3);
- SetIndexBuffer(0,Slopebuffer);
- SetIndexStyle(0,1,EMPTY,2,DarkGreen);
-
- SetIndexBuffer(1,Mabuffer);
- SetIndexBuffer(2,prevbuffer);
-
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //| Custom indicator deinitialization function |
- //+------------------------------------------------------------------+
- int deinit()
- {
- //----
-
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //| Custom indicator iteration function |
- //+------------------------------------------------------------------+
- int start()
- {
- int counted_bars=IndicatorCounted();
- int limit;
-
- if(counted_bars > 0)
- counted_bars--;
- limit = Bars - counted_bars;
- static int PrevSignal = 0, PrevTime = 0;
-
- for(int i = 0; i < limit; i++)
- {
- Mabuffer[i]=iMA(NULL,0,Ma_period,0,MODE_SMA,PRICE_CLOSE,i);
- // Slopebuffer[i]=(Mabuffer[i]-Mabuffer[i+1])/0.0001;
- }
- for(i = 0; i < limit; i++)
- {
- Slopebuffer[i]=(Mabuffer[i]-Mabuffer[i+1])/0.0001;
- /*if(i>1 && count<=4)
- {
- if(Slopebuffer[i]*Slopebuffer[i-1]<=0 )
- {
- prevbuff[count-1]=i;
- if(MathAbs(prevbuff[count-1]-prevbuff[count])<=8)
- {
- prevbuff[count-1]=prevbuff[count];
- }
- else
- {
- count++;
- }
-
- }
- }*/
- }
- /*
- int count=0;
- /*
- for(i=0;i<limit;i++)
- {
- if(Slopebuffer[i]*Slopebuffer[i+1]<0 && count<=5 )
- {
-
- prevbuffer[count]=i+1;
-
-
- if(count >=1 && MathAbs(prevbuffer[count]-prevbuffer[count-1])<=RangeValue)
- {
- prevbuffer[count-1]=prevbuffer[count];
- count--;
- }
- count++;
- }
- }
-
- while(count<=4)
- {
-
- count++;
- }
-
-
- Print(" "+prevbuffer[0]+" "+prevbuffer[1]+" "+prevbuffer[2]+" "+prevbuffer[3]+" ");
-
-
- if(SIGNAL_BAR > 0 && Time[0] <= PrevTime)
- return(0);
- PrevTime = Time[0];*/
-
-
- //----
- //get previous 3 points,High,Low
-
- //---
- /* if(Slopebuffer[SIGNAL_BAR]*Slopebuffer[SIGNAL_BAR+1]<=0 &&PrevSignal!=1)
- {
- PrevSignal=1;
- //judge up or down
- if(Slopebuffer[1]>=0 && Slopebuffer[2]<0)
- {
- //check previous 3 point
-
- Alert(Symbol()+","+Period()+",up");
- }
- if(Slopebuffer[1]<=0 && Slopebuffer[2]>0)
- {
- Alert(Symbol()+","+Period()+",down");
- }
- }
- if(Slopebuffer[SIGNAL_BAR]*Slopebuffer[SIGNAL_BAR+1]>0 &&PrevSignal!=0)
- {
- PrevSignal=0;
- }
- */
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
复制代码
|
|