I need help on My Stochastic based EA

 

Hi ! Can someone help my EA, i need it to open a position when the K and D lines are crossing above 20 and then close that same position when it crosses down 81, that is for the bullish positions. I also need it to open another position when the stochastic crosses down 80 and then close the position when the stochastic crosses above 21. 

i tried to do it mylsef but it doesn't work well. 

I add the code.

if someone can help that will be nice...

Sorry for my english, i'm french...and that's not a good excuse ! 


Thank you

#include<Trade\Trade.mqh>

//Create an Instance of CTrade
CTrade trade;
void OnTick()
  {
 
 
  //We create a string for the signal
  string signal="";
  
  //We calculate the Ask Price
  double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
  
  //We calculate the bid Price
  double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
  
  //We create an array for the K-line and D-Line
  double Karray[];
  double Darray[];
  
  //Sort the array from the ccurrent candle downwards
  ArraySetAsSeries(Karray,true);
  ArraySetAsSeries(Darray,true);
  
  //Defined EA, Current Candle, 3 candles, Save the result
  int StochasticDefinition=iStochastic(_Symbol,_Period,14,2,1,MODE_SMA,STO_LOWHIGH);
  
  //We fill the array with price data
  CopyBuffer(StochasticDefinition,0,0,4,Karray);
  CopyBuffer(StochasticDefinition,1,0,4,Darray);
  
  //We calculate the value for the current candle
  double Kvalue0=Karray[0];
  double Dvalue0=Darray[0];
  
  //We calculate the value for the last candle
  double Kvalue1=Karray[1];
  double Dvalue1=Darray[1];
  
  //Buy Signal 
  
  //If Both value are above 20
  if(Kvalue0>20&&Dvalue0>20)
  //if the K value has crossed the D value from above
  if((Kvalue0<Dvalue0)&&(Kvalue1>Dvalue1))
  {
  signal="buy";
  }
  
  //Sell Signal 
  
  //If Both Values are below 81
  if(Kvalue0>81&&Dvalue0>81)
  
  //If the K value Has crossed the D value From below
  if((Kvalue0<Dvalue0)&&(Kvalue1>Dvalue1))
  {
  signal="sell";
  }
  
  //Sell 3 Microlot
  if(signal == "sell"&&PositionsTotal()<1)
  trade.Sell(0.03,NULL,Bid,0,(Bid-100*_Point),NULL);
  
  //Buy 3 Microlot
  if (signal =="buy"&& PositionsTotal()<1)
  trade.Buy(0.03,NULL,Ask,0,(Ask+100*_Point),NULL);
  
  //Create a chart output 
  Comment("The current signal is: ",signal);
  
  
  }