Why won't this open any trades?

 
int start()
  {
  double lots=NormalizeDouble(MathAbs((AccountEquity()/10000)),2),lot;
  int hour=TimeHour(TimeCurrent()),minute=TimeMinute(TimeCurrent());
 
  if (hour==7 && minute==5)
  {
  double high=High[1],low=Low[1];
  }

  if ((Bid>=high+150*Point && high!=0) && OrdersTotal()==0)
  {
  int send=OrderSend(Symbol(),OP_BUY,lots,Ask,20,Bid-520*Point,high+300*Point);
  }
  if ((Ask<=low-150*Point && low!=0) && OrdersTotal()==0)
  {
  int send1=OrderSend(Symbol(),OP_SELL,lots,Bid,20,Ask+520*Point,low-300*Point);
  }
   return(0);
  }
It is meant for USDJPY M5. No trades,no errors,nothing happens in the strategy tester.
 
If you put ANY error reporting (never mind error handling) into your code, you will get the clues you need to solve your problem.
- Just one example - what does your program do if "lots" gets calculated (due to a small account balance) to be smaller than minlots at the broker?

Other than that, try adding some print statements in your code so that you know
- a) whether conditional statements are being executed and
- b) the contents of variables at key points (eg parameters immediately prior to OrderSend)

And what does the Journal say?

CB
 
Same Old Bloody Error, Error 130, Invalid Stops? Here is the simple sample code to fix that Error 130 bug.

Open the order without Stop Loss and Take Profit first. Then select the last order and modify with SL and TP.

OrderSend(Symbol(),OP_SELL,Lots,Bid,5,0,0,"Reverse",255,0,CLR_NONE);
OrderSelect(SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_SELL && OrderSymbol()== Symbol()&& OrderComment()== "Reverse")
{
OrderModify(OrderTicket(),5,OrderOpenPrice()+(200*Point),OrderOpenPrice()-(500*Point),0,CLR_NONE);
}
 
@Eurotrader:

- You don't know what the original poster's problem is; you're guessing; I'm trying to help farhang understand how to help himself in a self-sufficient manner with this and also with future problems

- Even if 130 is indeed the issue AND the cause is that Instant Execution is disabled in favour of Market Execution on the MT4 server (ie. stops need set to 0 in send and subsequently modified), the user needs to CONSIDER his options - he may wish to change brokers rather than to have orders (even temporarily) naked in the market

- The code you have posted is dangerous is used as-is; just one post above I've commented on the need for error handling; if ever there was a need for error handling, don't you think it should be included in the piece of code which you supplied? Your "solution" would, each time the OrderModify failed, leave the original poster with a naked position.

CB
 
Its because your high and low variables goes out of scope after the if(hours == 7 && minute == 5). You have to declare them outside of the brackets.

Try something like this:

int start()
{

  double lots=NormalizeDouble(MathAbs((AccountEquity()/10000)),2),lot;
  int hour=TimeHour(TimeCurrent()),minute=TimeMinute(TimeCurrent());
 
  double high, low = 0;
   
  if (hour==7 && minute==5)
  {
      high = High[1];
      low = Low[1];
  }

  if ((Bid>=high+150*Point && high!=0) && OrdersTotal()==0)
  {
      int send=OrderSend(Symbol(),OP_BUY,lots,Ask,20,Bid-520*Point,high+300*Point);
  }
  
  if ((Ask<=low-150*Point && low!=0) && OrdersTotal()==0)
  {
      Alert("aaa");
      int send1=OrderSend(Symbol(),OP_SELL,lots,Bid,20,Ask+520*Point,low-300*Point);
  }
  
  return(0);
}
 
Thank you CB for the tips. I Understand what you are talking about completely. I do think ahead about what might happen and how my EA is supposed to handle errors and I do use print every now and then to trace errors but as you might have guessed this is a part of sth bigger and it all boils down to this simple few lines of code. the problem isn't that I get any errors in the journal, in fact quite the contrary the matter is that I don't, which indicates that the conditions in the if statement are never met. But the fact of the matter is that THEY ARE MET IN REALITY! Maybe you can see the problem!

And Ziggy, your answer shows me that you don't have the slightest idea what this EA is trying to do which is my fault because I assumed everyone would get it. the problem with what you suggest is that the variables high and low are going to assume the value of 0 after the time is no longer 7:5 which is very dumb because that's when the trades are meant to be done.
 
farhang:
the problem isn't that I get any errors in the journal, in fact quite the contrary the matter is that I don't, which indicates that the conditions in the if statement are never met. But the fact of the matter is that THEY ARE MET IN REALITY! Maybe you can see the problem!

To satisfy yourself about the conditional statement, then use Print directly before the conditional to output the variables evaluated in it. And use Print at the start of the code block triggered by the conditional to check if that code block gets executed.

Having no errors in the journal doesn't tell you that you don't have errors. Neither does having no errors in the experts log. But the latter (and your code) tells me that you aren't REPORTING those errors in the first place. And therefore you are making life difficult for yourself.

Having been an assembler programmer in the early 80s, then latterly working as a commercial heli-pilot, when I first started writing MQL, I had not written much code in about 25 years. What I'm trying to say is that I would not call myself an expert in any way. However, by frequent use of the Print statement, I have never had a bug in my code that left me stumped for longer than it took me to look at the logs.

Trust me and do likewise.

CB

 
farhang wrote >>
It is meant for USDJPY M5. No trades,no errors,nothing happens in the strategy tester.

Because you are getting the time from the server, you will only be able to test this one minute every day, when the server is on 7:05. If you use the time from the price bar, you'll be able to test anytime you want. Try this:

int start() {

int hour, minute, send, send1;
double lots, high, low;

lots=NormalizeDouble(MathAbs((AccountEquity()/10000)),2);
hour=TimeHour(Time[0]); minute=TimeMinute(Time[0]);
if (hour==7 && minute==5) {
high=High[1]; low=Low[1];
}
if ((Bid>=high+150*Point && high!=0) && OrdersTotal()==0)
send=OrderSend(Symbol(),OP_BUY,lots,Ask,20,Bid-520*Point,high+300*Point);
if ((Ask<=low-150*Point && low!=0) && OrdersTotal()==0)
send1=OrderSend(Symbol(),OP_SELL,lots,Bid,20,Ask+520*Point,low-300*Point);
return(0);
}

Not sure if it was your intention to look for trades only one minute a day, this will look for trades for five minutes until the 7:10 bar opens. If you want to look for trades for only one minute, put this on a M1 chart and set "hour" and "minute" to get their values from iHigh/iHighest and iLow/iLowest, like so:

high=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,5,1)); low=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,5,1));

 
You are right I do not have the slightest idea of what you are trying to achieve with that EA and I am not very interested either. You asked for help why it did not open orders and the answers I gave you is why. If you have something else in your mind that you do not tell us then that is your problem.