i cant find my mistake,can someone help me ?.?.?.?.?.?.?.?.?.?.?.?.?

 
Hello,

i am programming my own ea but the ea isnt trading but if i look at the charts, there are bars with my conditions !!!
the ordersend code is correct and working.

conditions for long trade:

the difference between the open and close price must be at least 3 pips
the differenze between the last 2 bars must be under 1 pip
the last bar close price must be higher than the open price
William's percent range must be under 40
Stochastic must be under 25
rsi must be under 51

conditions for short trade:

the difference between the open and close price must be at least 3 pips
the differenze between the last 2 bars must be under 1 pip
the last bar open price must be higher than the close price
William's percent range must be over 60
Stochastic must be over 75
rsi must be over 49
extern double mnumber = 100;
extern double TakeProfit = 250;
extern double StopLoss = 100;
extern double Lots = 0.1;
extern double bardifferenz = 0.00011;
extern double minimalecodifferenz = 0.00030;

int start()
  {
  
   double close1, close2, open1, open2, d1, d2, dges, stoch1, stoch2, rsi1, rsi2, wpr1, wpr2;
   int ticket, total, cnt, start, tradeok, status1, status2;

   stoch1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,2);
   stoch2 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);
   rsi1 = iRSI(NULL,0,14,PRICE_CLOSE,2);
   rsi2 = iRSI(NULL,0,14,PRICE_CLOSE,1);
   wpr1 = iWPR(NULL,0,25,2);
   wpr2 = iWPR(NULL,0,25,1);

   open1 = Open[2];
   open2 = Open[1];
   close1 = Close[2];   
   close2 = Close[1];
   
   start = 1;

 // allows only 1 trade per chart

 total=OrdersTotal();
   
      for(cnt=0;cnt<=total;cnt++)
     {
      if(start==1)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderMagicNumber()==mnumber)
      {
       tradeok = 0;
       start=0;
      }
      else
      {
       tradeok = 1;
      }
      }
      }
 
 if(tradeok==1)
 {
  if((close1 - open1)>0)
  {
   status1 = 0; // 0 = empty
  }
  else
  {
   status1 = 1;
  }
  if((close2 - open2)>0)
  {
   status2 = 0;
  }
  else
  {
   status2 = 1;
  }
  
  if(status1 == 0)
  {
   d1=(close1-open1);
  }
  else
  {
   d1=(open1-close1);
  }
  if(status2 == 0)
  {
   d1=(close2-open2);
  }
  else
  {
   d1=(open2-close2);
  }
  
  if(d1!=d2)
  {
  if(d1>d2)
  {
   dges=(d1-d2);
  }
  else
  {
   dges=(d2-d1);
  }
  }
  
  if((dges<=bardifferenz) && (d1>minimalecodifferenz) && (d2>minimalecodifferenz) && (status2==0) && (status1==1) && ((stoch1<25) || (stoch2<25)) && ((rsi1<51) || (rsi2<51)) && ((wpr1<40) || (wpr2<40)))
  {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"firstea",mnumber,0,Green);
         return(0); 
  }
  
  if((dges<=bardifferenz) && (d1>minimalecodifferenz) && (d2>minimalecodifferenz) && (status2==1) && (status1==0) && ((stoch1>75) || (stoch2>75)) && ((rsi1>49) || (rsi2>49)) && ((wpr1>60) || (wpr2>60)))
  {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"firstea",mnumber,0,Red);
         return(0); 
  }
  
 }

   return(0);
  }
// the end.

Mo1k
 
Mo1k wrote >>
Hello,

i am programming my own ea but the ea isnt trading but if i look at the charts, there are bars with my conditions !!!
the ordersend code is correct and working.

conditions for long trade:

the difference between the open and close price must be at least 3 pips
the differenze between the last 2 bars must be under 1 pip
the last bar close price must be higher than the open price
William's percent range must be under 40
Stochastic must be under 25
rsi must be under 51

conditions for short trade:

the difference between the open and close price must be at least 3 pips
the differenze between the last 2 bars must be under 1 pip
the last bar open price must be higher than the close price
William's percent range must be over 60
Stochastic must be over 75
rsi must be over 49

Mo1k


i was not looking to all your code, only i noticed your Wiliams.
If you put Wiliams Percent Range (WPR) on your chart you will see the negative values..0 to -100
So ... WPR>60 never will become true and WPR<40 always true :-)
 
ok thx this was 1 mistake ... but it is still not working =(
in a backtest of 1 year my ea made 0 trades...
 
The d2 variable is declared as a double data type, but has not be assigned a value. So conditional expressions like this will always have false return.
(d2>minimalecodifferenz)
 

Sometimes it is easier to break the thing up into functions.....looking at som many interleaved if's and's or's can be painful.

#define  NO_RESULT   -10

extern double mnumber               = 100;
extern double TakeProfit            = 25;
extern double StopLoss              = 10;
extern double Lots                  = 0.1;
extern double bardifferenz          = 1.1;
extern double minimalecodifferenz   = 3;

int 
   D_Factor = 1;
   
double   
   Slippage = 3;


//+------------------------------------------------------------------+
//| Expert Initialisation                                            |
//+------------------------------------------------------------------+

int init() 
{
double
   Pip = Point;
   if (Digits == 3|| Digits == 5){D_Factor = 10; Pip = Point * 10;}
   TakeProfit           *= Pip;
   StopLoss             *= Pip;
   bardifferenz         *= Pip;
   minimalecodifferenz  *= Pip;
   Slippage             *= Pip;
}
//+------------------------------------------------------------------+
//| Expert Start                                                     |
//+------------------------------------------------------------------+

int start()
{
   if(!Can_Trade())return(0);                                     //there is an open trade so do nothing
   if(!Open_Close_Diff())return(0);// difference between Open and Close is less than 3 pips>>Do nothing
   if(!Bar_Pip_Difference())return(0);                            //difference between bars is more than 1 pip
   int Buy_or_Sell = WPR_Check() + Stoch_Check() + RSI_Check();   //if all return buy(0) sum = 0......if all return sell(1) sum = 3....if any return fail sum = less than 0(-10 per fail)
   
   if(Buy_or_Sell == 0){                                          //buy signal
      double Temp_SL = NormalizeDouble(Ask - StopLoss,Digits);    //claculate stops and normalise
      double Temp_TP = NormalizeDouble(Ask + TakeProfit,Digits);
      int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"firstea",mnumber,0,Green);//enter order without stop to be ECN compatible
      if (ticket > 0)bool mod = OrderModify(ticket,OrderOpenPrice(),Temp_SL,Temp_TP,0,CLR_NONE);//if order is successfull enter the stops
      if(!mod)Alert("Error entering SL or TP");                                                 //the ordermodify had a problem >> alter the user
   }

   if(Buy_or_Sell == 3){                                          //sell signal
      Temp_SL = NormalizeDouble(Bid + StopLoss,Digits);   //claculate stops and normalise
      Temp_TP = NormalizeDouble(Bid - TakeProfit,Digits);
      ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"firstea",mnumber,0,Green);//enter order without stop to be ECN compatible
      if (ticket > 0)mod = OrderModify(ticket,OrderOpenPrice(),Temp_SL,Temp_TP,0,CLR_NONE);//if order is successfull enter the stops
      if(!mod)Alert("Error entering SL or TP");                                                 //the ordermodify had a problem >> alter the user
   }
   return(0);
  }
//-----------------------------------------------------------------
bool Can_Trade()           //returns false if we have an open trade
{
   for(int cnt=0;cnt<OrdersTotal();cnt++){
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderMagicNumber()==mnumber)return(false);
   }
   return(true);           //no open trade so return true
}
//-----------------------------------------------------------------
bool Open_Close_Diff()
{
   if (MathAbs(Open[1] - Close[1]) > minimalecodifferenz)return(false);
   if (MathAbs(Open[2] - Close[2]) > minimalecodifferenz)return(false);
   return(true);
}
//----------------------------------------------------------------
bool Bar_Pip_Difference()
{
double   
   Bar_1 = MathAbs(Open[1] - Close[1]),   //size of bar 1
   Bar_2 = MathAbs(Open[2] - Close[2]);   //size of bar 2
   
   if (MathAbs(Bar_1 - Bar_2) < bardifferenz) return(true); //difference between 2 bars is less than 1 pip
   return(false);
}
//----------------------------------------------------------------
int WPR_Check()
{
double
   wpr1 = iWPR(NULL,0,25,2),
   wpr2 = iWPR(NULL,0,25,1);
   
   if (wpr1 < 40 || wpr2 < 40)return(OP_BUY);
   if (wpr1 > 60 || wpr2 > 60)return(OP_SELL);
   return(NO_RESULT);
}
//-----------------------------------------------------------------
int Stoch_Check()
{
double
   stoch1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,2),
   stoch2 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);
   
   if (stoch1 < 25 || stoch1 < 25)return(OP_BUY);
   if (stoch1 > 75 || stoch2 > 75)return(OP_SELL);
   return(NO_RESULT);
}
//-----------------------------------------------------------------
int RSI_Check()
{
double   
   rsi1 = iRSI(NULL,0,14,PRICE_CLOSE,2),
   rsi2 = iRSI(NULL,0,14,PRICE_CLOSE,1);
   
   if (rsi1 <= 50 || rsi2 <= 50)return(OP_BUY);
   if (rsi1 >= 50 || rsi2 >= 50)return(OP_SELL);
   return(NO_RESULT);
}
//-----------------------------------------------------------------
Reason: