指标是LW%R
- //+------------------------------------------------------------------+
- //| LW%R.mq4 |
- //| Copyright ?2005, MetaQuotes Software Corp. |
- //| http://www.metaquotes.net |
- //+------------------------------------------------------------------+
- #property copyright "Copyright ?2005, MetaQuotes Software Corp."
- #property link "http://www.metaquotes.net"
- #property indicator_separate_window
- #property indicator_buffers 2
- #property indicator_color1 Silver
- #property indicator_color2 Yellow
- //---- input parameters
- extern int NPeriod=9;
- extern int KPeriod=3;
- extern int SKPeriod=3;
- extern int SDPeriod=3;
- double ind_buffer1[];
- double ind_buffer2[];
- double ind_buffer3[];
- double ind_buffer4[];
- double ind_buffer5[];
- double HighesBuffer[];
- double LowesBuffer[];
- int draw_begin1=0;
- int draw_begin2=0;
- //+------------------------------------------------------------------+
- //| expert initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- string short_name;
- //---- 2 additional buffers are used for counting.
- IndicatorBuffers(7);
- SetIndexBuffer(0, ind_buffer3);
- SetIndexBuffer(1, ind_buffer4);
- SetIndexBuffer(2, ind_buffer1);
- SetIndexBuffer(3, ind_buffer2);
- SetIndexBuffer(4, HighesBuffer);
- SetIndexBuffer(5, LowesBuffer);
- SetIndexBuffer(6, ind_buffer5);
- //---- indicator lines
- SetIndexStyle(0,DRAW_LINE);
- SetIndexBuffer(0, ind_buffer3);
- SetIndexStyle(1,DRAW_LINE);
- SetIndexBuffer(1, ind_buffer4);
- //---- name for DataWindow and indicator subwindow label
- IndicatorShortName("LW%R("+NPeriod+","+KPeriod+","+SKPeriod+","+SDPeriod+")");
- SetIndexLabel(0,"K");
- SetIndexLabel(1,"D");
- //----
- draw_begin1=NPeriod+SKPeriod;
- draw_begin2=draw_begin1+KPeriod;
- SetIndexDrawBegin(0,draw_begin1);
- SetIndexDrawBegin(1,draw_begin2);
- return(0);
- }
- //+------------------------------------------------------------------+
- //| expert deinitialization function |
- //+------------------------------------------------------------------+
- int start()
- {
- int i,k;
- int counted_bars=IndicatorCounted();
- double price;
- //----
- if(Bars<=draw_begin2) return(0);
- //---- initial zero
- if(counted_bars<1)
- {
- for(i=1;i<=draw_begin1;i++) ind_buffer1[Bars-i]=0;
- for(i=1;i<=draw_begin2;i++) ind_buffer2[Bars-i]=0;
- }
- //---- minimums counting
- i=Bars-NPeriod;
- if(counted_bars>NPeriod) i=Bars-counted_bars-1;
- while(i>=0)
- {
- double min=1000000;
- k=i+NPeriod-1;
- while(k>=i)
- {
- price=Low[k];
- if(min>price) min=price;
- k--;
- }
- LowesBuffer[i]=min;
- i--;
- }
- //---- maximums counting
- i=Bars-NPeriod;
- if(counted_bars>NPeriod) i=Bars-counted_bars-1;
- while(i>=0)
- {
- double max=-1000000;
- k=i+NPeriod-1;
- while(k>=i)
- {
- price=High[k];
- if(max<price) max=price;
- k--;
- }
- HighesBuffer[i]=max;
- i--;
- }
- //---- %K line
- i=Bars-draw_begin1;
- if(counted_bars>draw_begin1) i=Bars-counted_bars-1;
- while(i>=0)
- {
- double sumlow=0.0;
- double sumhigh=0.0;
- for(k=(i+SKPeriod-1);k>=i;k--)
- {
- sumlow+=Close[k]-LowesBuffer[k];
- sumhigh+=HighesBuffer[k]-LowesBuffer[k];
- }
- if(sumhigh==0.0) ind_buffer1[i]=100.0;
- else ind_buffer1[i]=sumlow/sumhigh*100;
- i--;
- }
- //---- last counted bar will be recounted
- if(counted_bars>0) counted_bars--;
- int limit=Bars-counted_bars;
- //---- signal line is simple movimg average
- for(i=0; i<limit; i++)
- ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,KPeriod,0,MODE_SMA,i);
- for(i=0; i<limit; i++)
- {ind_buffer5[i]=iMAOnArray(ind_buffer2,Bars,SKPeriod,0,MODE_SMA,i);
- ind_buffer3[i]=100-ind_buffer5[i];
- }
- for(i=0; i<limit; i++)
- ind_buffer4[i]=100-iMAOnArray(ind_buffer5,Bars,SDPeriod,0,MODE_SMA,i);
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
复制代码 |