Download MetaTrader 5
To add comments, please log in or register
Why to sell products in MetaTrader AppStore? Find that out from the article!
Stan4o1
118
Stan4o1 2015.11.23 09:27 

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:
Keith Watford
Moderator
7990
Keith Watford 2015.11.23 11:03  

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. 

Stan4o1
118
Stan4o1 2015.11.23 11:23  
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
Keith Watford
Moderator
7990
Keith Watford 2015.11.23 11:37  
  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

whroeder1
13644
whroeder1 2015.11.23 11:49  
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.
Stan4o1
118
Stan4o1 2015.11.23 12:25  
Thanks 
Stan4o1
118
Stan4o1 2015.11.23 12:56  
//+------------------------------------------------------------------+
//|                                                  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; 
}
}





   
  
  
  
  
//+------------------------------------------------------------------+
Stan4o1
118
Stan4o1 2015.11.23 12:59  
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.
whroeder1
13644
whroeder1 2015.11.23 13:56  
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 ;                    
  :                           
Stan4o1
118
Stan4o1 2015.11.23 16:03  
Ok so i must remove the return operators where u showed? Or there are other return operators i must remove 
Ali Akcaagac
169
Ali Akcaagac 2015.11.23 18:41  
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.
/ /12
To add comments, please log in or register