Expert Advisor doesn`t trade !!!!

 

I`ve just created a new EA , but I have a problem with this one, just like the past one, as well. Can you help me figure out why the EA doesn`t trade!!

Thanks 

#property copyright "Stanislav Ivanov"
#property link      ""
#property version   "1.00"
#property strict
//--- input parameters
input double   takeprofit=0.1;
input double   stoploss = 0.1;
input double   LotSize = 0.01 ;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
double point = Point;

double MyHigh = iHighest ( NULL,0,MODE_HIGH, 30 , 30);
double MyLow = iLowest (NULL,0,MODE_LOW,30,30);



double priceA = MarketInfo ( NULL , MODE_ASK );
double priceB = MarketInfo ( NULL , MODE_BID);
int total = OrdersTotal ();
int ticket ;



//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
if (MyHigh<0) Print ( "Error :",GetLastError() );
if ( MyLow <0) Print ( " Error :",GetLastError()) ;
if ( Digits ==3  || Digits == 5) point*=10 ;


 
 
 
if ( total < 1)
{
if ( UpBreakthrough() == true)  
{
 ticket = OrderSend ( Symbol() , OP_BUY , LotSize , Ask , 5, priceA-(stoploss * point), priceA+(takeprofit*point) ,NULL , 0 ,0,Green);
if ( ticket <0) {
 Print (" Error sending Buy order :", GetLastError());
 }
}
return;
}

if ( DownBreakthrough() == true)
{
 ticket = OrderSend ( Symbol() , OP_SELL, LotSize , Bid , 5, priceB+(stoploss*point) , priceB-(takeprofit*point),NULL , 0,0,Red);

 if (ticket<0) { Print ( " Error sendig Sell order number :",GetLastError());}
 
 return; 
}
}

bool UpBreakthrough () // Declaring the Breakthrough signal for the upper side of the price range 
  {
  if (priceA > MyHigh) 
  {
  return true;
  }
  else return false;
  }
  
  bool DownBreakthrough () // Deaclaring the Breakthrough signal for the down side of the price range 
  {
  if ( priceB < MyLow)
  {
  return true;
  }
  else return false;
  }
Files:
 

With such a small amount of code, please post it using the SRC button. I have done it for you this time.

First thing that I see wrong with your code is that there is no initialisation function.

Second is that iHighest and iLowest return an index, but you are calculating with them as if they are prices.

Third PriceA and PriceB and total are assigned values globally, so they will not change from tick to tick. 

 
Ok thanks for the answer but can u tell me how can i make my ea calculate the highest price for the last 30 bars
 
  int index_highest=iHighest(Symbol(),0,MODE_HIGH,30,1);
  double price_highest=High[index_highest];
  

That will find the highest index and value of the last 30 closed bars

Unless I need the index for other calculations, I would normally combine the 2 lines as

  double price_highest=High[iHighest(Symbol(),0,MODE_HIGH,30,1)];

 and do away with an unnecessary variable

 
double MyHigh = iHighest ( NULL,0,MODE_HIGH, 30 , 30);
double MyLow = iLowest (NULL,0,MODE_LOW,30,30);
double priceA = MarketInfo ( NULL , MODE_ASK );
double priceB = MarketInfo ( NULL , MODE_BID);
int total = OrdersTotal ();
None of these variables change; assign them in OnTick.
 
Thanks 
 
//+------------------------------------------------------------------+
//|                                                  StanScalper.mq4 |
//|                                                 Stanislav Ivanov |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Stanislav Ivanov"
#property link      ""
#property version   "1.00"
#property strict
//--- input parameters
input double   takeprofit=0.1;
input double   stoploss = 0.1;
input double   LotSize = 0.01 ;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
double point = Point;



int OnInit ()
{
return (INIT_SUCCEEDED);
}



//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  double priceA = MarketInfo ( Symbol() , MODE_ASK );
double priceB = MarketInfo ( Symbol() , MODE_BID);
int total = OrdersTotal ();
int ticket ;

  int MyHigh = iHighest ( Symbol(),0,MODE_HIGH, 30 ,1);
int MyLow = iLowest (Symbol(),0,MODE_LOW,30,1);
double price_highest=High[MyHigh];
double price_lowest=Low[MyLow];

if (price_highest<0) Print ( "Error :",GetLastError() );
if ( price_lowest<0) Print ( " Error :",GetLastError()) ;
if ( Digits ==3  || Digits == 5) point*=10 ;

bool UpBreakthrough = false;
bool DownBreakthrough = false;

  if ( price_highest<priceA) 
  {
  UpBreakthrough = true;
  }
  return;
  if ( priceB < price_lowest)
  {
  DownBreakthrough = true;
  }
  return ;
  
  
  
if ( total < 1)
{
if ( UpBreakthrough == true)  
{
 ticket = OrderSend ( Symbol() , OP_BUY , LotSize , Ask , 5, priceA-(stoploss * point), priceA+(takeprofit*point) ,NULL , 0 ,0,Green);
if ( ticket <0) {
 Print (" Error sending Buy order :", GetLastError());
 }
}
return;
}

if ( DownBreakthrough == true)
{
 ticket = OrderSend ( Symbol() , OP_SELL, LotSize , Bid , 5, priceB+(stoploss*point) , priceB-(takeprofit*point),NULL , 0,0,Red);

 if (ticket<0) { Print ( " Error sendig Sell order number :",GetLastError());}
 
 return; 
}
}





   
  
  
  
  
//+------------------------------------------------------------------+
 
Okay i feel stupid I did what u told me was the problem but it still doesn t trade, what i did wrong, Oh and btw i know its not the right section but can u tell me a book that can help me learn, because ,as u can guess, i am a new into this.
 
Stan4o1 but it still doesn t trade, what i did wrong,
How can it trade when you return before doing anything?
  if ( price_highest<priceA) 
  {
  UpBreakthrough = true;
  }
  return;                     
  if ( priceB < price_lowest) 
  {                           
  DownBreakthrough = true;    
  }                           
  return ;                    
  :                           
 
Ok so i must remove the return operators where u showed? Or there are other return operators i must remove 
 
In the first comment you wrote "I created a new EA" and now you ask where to remove return operators in your own code ? Nobody besides you knows the own code better than anyone else.
Reason: