//KurlFX 2009/1/29 //+------------------------------------------------------------------+ //| *** MTFPI-sub3 *** SL-line by stochastic cross | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 OrangeRed extern int K_Period = 5; extern int D_Period = 3; extern int Slowing = 3; double BS[];//StopLoss;Buy double SS[];//StopLoss;Sell double Sto[];//stochastic;main double Sig[];//stochastic;signal double BG[];//sign;Buy/No double SG[];//sign;Sell/No double Bx[];//price;at stochas up cross double Sx[];//price;at stochas dn cross //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(8); SetIndexBuffer(4, Bx); SetIndexBuffer(5, Sx); SetIndexBuffer(2, BG); SetIndexBuffer(3, SG); SetIndexBuffer(0, BS); SetIndexBuffer(1, SS); SetIndexBuffer(6, Sto); SetIndexBuffer(7, Sig); SetIndexLabel(0,"BuySL"); SetIndexLabel(1,"SellSL"); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bar=IndicatorCounted(); int limit=Bars-counted_bar; int pos=0; if(counted_bar==0) limit-=K_Period+D_Period+Slowing; for(int i=limit-1; i>=0; i--) { Sto[i]=iStochastic(NULL,0,K_Period,D_Period,Slowing,MODE_SMA,0,MODE_MAIN,i); Sig[i]=iStochastic(NULL,0,K_Period,D_Period,Slowing,MODE_SMA,0,MODE_SIGNAL,i); } if (counted_bar ==0){limit-= 50;BS[limit]=EMPTY_VALUE;SS[limit]=EMPTY_VALUE;} for(i = limit-1;i>=0;i--) { BS[i]=BS[i+1];SS[i]=SS[i+1]; if (Sto[i+1]<=Sig[i+1] && Sto[i]>Sig[i])pos=1; if (Sto[i+1]>=Sig[i+1] && Sto[i] 0) { for(int j=2; j<=50; j++) { if (Sto[i+j+1]<=Sig[i+j+1] && Sto[i+j]>Sig[i+j]){Bx[i] = MathMin(Low[i+j+1],Low[i+j]);break;} } } else Bx[i] = Bx[i+1]; if (pos < 0) { for(j=2; j<=50; j++) { if (Sto[i+j+1]>=Sig[i+j+1] && Sto[i+j]Bx[i]) bx=1; else{if (Close[i+1]>=Bx[i+1] && Close[i]Sx[i]) sx=1; else{if (Close[i+1]>=Sx[i+1] && Close[i]