Help

 

Can anyone help me to say what is wrong with this EA.

//+------------------------------------------------------------------+
//|                                          1M Stochastic Cross.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double LotSize = 2.0;
extern double StopLossPips = 10;
extern double TakeProfitPips = 10;

double sl, tp;
double kline[3], dline[3];
bool crossedup, crosseddown;
int longtkt, shorttkt, cnt, t;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
      crossedup = false;
      crosseddown = false;
      t = 0;
      longtkt = -1;
      shorttkt = -1;
      cnt = 0;
      if((Point == 0.001) || (Point == 0.00001))
      {
         sl = 10*StopLossPips;
         tp = 10*TakeProfitPips;
      }
      else
      {
         sl = StopLossPips;
         tp = TakeProfitPips;
      }
      
  return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   if(PositionOpen()) return(0);
   crossedup = false;
   crosseddown = false;

   for(int i = 0;i < 3;i++)
   {
      kline[i] = iStochastic(NULL, Period(), 13, 4, 6, MODE_LWMA, 0, MODE_MAIN, i);
      dline[i] = iStochastic(NULL, Period(), 13, 4, 6, MODE_LWMA, 0, MODE_SIGNAL, i);
   }
   if ((kline[1] < dline[1]) && (kline[2] > dline[2])) crosseddown = true;
   else if ((kline[1] > dline[1]) && (kline[2] < dline[2])) crossedup = true;
   else return(0);
   if (crossedup && (kline[1] < 20.0)) GoLong();
   if (crosseddown && (kline[1] > 80.0)) GoShort();
    
   return(0);
  }
//+------------------------------------------------------------------+
int GoLong()
{
   longtkt = -1;
   cnt = 0;
   while((longtkt < 0) && (cnt < 20))
   {
      longtkt = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 2, Ask-sl*Point,Ask+tp*Point, NULL, 55558, 0, Green);
      cnt++;
   }
   return(longtkt);
}

int GoShort()
{
   shorttkt = -1;
   cnt = 0;
   while((shorttkt < 0) && (cnt < 20))
   {
      shorttkt = OrderSend(Symbol(), OP_SELL, LotSize, Bid, 2, Bid+sl*Point, Bid-tp*Point, NULL, 55559, 0, Blue);
      cnt++;
   }
   return(shorttkt);
}



bool PositionOpen()
{
   t = OrdersTotal();
   for(int z = 0;z < t;z++)
   {
      OrderSelect(z, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol()) return(true);
   }
   return(false);

}


I change the parameter for stochastic after that it dont start. This EA starts buy trades and suddenly it start an sell trade. I want an EA to trade after that the stochastic gives signal when it cross its signalline.


Lars

MetaQuotes — the developer of trading platforms for brokers, banks, exchanges and hedge funds
MetaQuotes — the developer of trading platforms for brokers, banks, exchanges and hedge funds
  • www.metaquotes.net
MetaTrader 5 trading platform is a free Forex and stock trading tool
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button


 
      kline[i] = iStochastic(NULL, Period(), 13, 4, 6, MODE_LWMA, 0, MODE_MAIN, i);

Perhaps you should read the manual. iStochastic - Technical Indicators - MQL4 Reference

mode
[in] Indicator line index. It can be any of the Indicators line identifiers enumeration value (0 - MODE_MAIN, 1 - MODE_SIGNAL).

   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.