- [HELP] Creating EA for Breakout with Custom Trade Execution Time
- MetaTrader 5: September 9th - Red-Letter Day!
- Why is this not producing any results on strategy tester?
- 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
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);
}
- 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
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); }
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.
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
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));
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use