//+------------------------------------------------------------------+
//|                                            rijfie stockastic.mq4 |
//|                                      Donald Rijfkogel versie 001 |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Donald Rijfkogel versie 001"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
// ben bij les 5

double pips;
extern double highlevel = 90;
extern double lowlevel = 10;
extern double stoploss = 200;
extern double takeprofit = 100;
extern double magicnumber = 123456;
extern double lot = 0.01;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
    double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE);      
   if(ticksize ==0.0001||ticksize ==0.001)
   pips = ticksize * 10;
   else pips = ticksize;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
 int BuyCnt = 0;
  int SellCnt = 0;
  int BuyStopCnt = 0;
  int SellStopCnt = 0;
  int BuyLimitCnt = 0;
  int SellLimitCnt = 0;
  
  int cnt = OrdersTotal();
  for (int i=0; i < cnt; i++) 
  {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    if (OrderSymbol() != Symbol()) continue;
    if (OrderMagicNumber() != magicnumber) continue;
    
   
    
    int type = OrderType();
    if (type == OP_BUY) BuyCnt++;
    if (type == OP_SELL) SellCnt++;
    if (type == OP_BUYSTOP) BuyStopCnt++;
    if (type == OP_SELLSTOP) SellStopCnt++;
    if (type == OP_BUYLIMIT) BuyLimitCnt++;
    if (type == OP_SELLLIMIT) SellLimitCnt++;
   }
   double Stochastic = iStochastic(NULL,240,5,3,3,MODE_SMA,0,MODE_MAIN,1);
   double CurrentMa = iMA(NULL,0,50,8,MODE_SMMA,PRICE_MEDIAN,1);
  double StockasticCurrent = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);
  double StockasticPrevious = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,2);
  if (StockasticPrevious < lowlevel)
  if (StockasticCurrent>StockasticPrevious) 
   if(BuyCnt==0)
    OrderSend(Symbol(),OP_BUY,lot,Ask,3,Ask-(stoploss*pips),Ask+(takeprofit*pips),"",magicnumber,0,Green); 
 if(StockasticCurrent<StockasticPrevious)
 if(StockasticPrevious>highlevel)
   if (SellCnt==0)
      OrderSend(Symbol(),OP_SELL,lot,Bid,3,Bid+(stoploss*pips),Bid-(takeprofit*pips),"",magicnumber,0,Green);
   
  }
//+------------------------------------------------------------------+
