You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello Masters ......, Could you help me to made EA for open buy or open sell on a time...
I moved your post to here.
Read this thread from the first post and you will find few EAs.
Open only one buy and one sell per day!
Hi Guys,
I have a little problem with my EA. It's based on price movement and during one day it opens more than one position. I want to limit this but I didn't understand how can I do.
What I want to do is something like this:
If during the current day you have already opened a buy position, don't open any other BUY positions. But if you find a sell signal, open a sell signal. In this case, if after this you find another sell signal don't open other sell positions.
I don't know how to write this and what's the right position. Can you help me?
Thanks a lot!!!
Regards,
Mauro
EDIT:
On another topic I have found this code but I don't know where and how attach it:
{
if(TimeToStr(OrderOpenTime(),TIME_DATE ) != TimeToStr(CurTime(),TIME_DATE ))
{
//open new order
}
}In this topic there's nothing about what I'm looking for... this topic is about buy and sell at the same time....But what I'm talking about is that if I have already open a Buy order my EA during the day has no open new buy order. The same thing if it has already opened a sell order.
But if it opens a buy order, during the day it can open only a sell order...following the rules written above.
Example:
The time is: today
The EA opens a Buy order.
The position reach the TakeProfit or the StopLoss, so it is closed.
Now, the EA can see another buy signal but seen that it has already open a BUY ORDER in the previous time, it doesn't open this order.
Now the EA see a SELL signal, and seen that it hasn't opened a SELL ORDER yet, it opens a SELL position.
The position reach the TakeProfit or the StopLoss, so it is closed.
Now, the EA can see another sell signal but seen that it has already open a SELL ORDER in the previous time, it doesn't open this order.
This is what I'm looking for....
In this case you need those 2 threads:
https://www.mql5.com/en/forum/176322
https://www.mql5.com/en/forum/173026
Ok, thanks for your reply NewDigital. Now, I think that my code is this:
{
ticket=OrderSend(....
DayOfLastTrade=(TimeDayOfYear(TimeCurrent());
}
[/CODE]
So, can you check if I have added this code in the right way on my code?Here it is
[CODE]if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
if (TimeDayOfYear(TimeCurrent())!=DayOfLastTrade)
{
Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "MaxPower Buy Order", MagicNumber, 0, DodgerBlue);
DayOfLastTrade=(TimeDayOfYear(TimeCurrent());
}
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}The code above is only for buy position, so in this way it should open only a buy position. If I do the same thing for the code about SELL, it should open only a sell position, right?
Thanks for your help.
Mauro
MMM...the Metaeditor says that there's an error...
It means that this one
and
[CODE]}is unbalanced.
Check in the code.
Sorry, I am not a coder so I can not help much.
Hi newdigital...yes, I know for the pharentesis....but I've checked all the code and the pharentesis are balanced...
mmm....I don't understand where is the problem....However, I'll continue to check...I hope to find a solution!
Thanks for all...
Mauro
For example this one:
Debugging MT4 is a pain in the a** but if you're patient you can figure out the problem.
The first thing I'd say is where ever MT4 tells you the problem is...it's not! The next thing I'd do is start cutting out HUGE chunks of code in the complicated IF statement that's most likely causing the problems.
For example if I have...
if(){
//second if
if(){
//third if
if(){
}
}
}
I'd chop out if's 2 & 3 and just leave if 1. Try to compile it. If it compiles you've narrowed it down. Then paste back 2 & 3 then chop out 3. Test again. Keep doing this for a few minutes and you'll eventually find the problem.
Good luck.
LUx