Meng Yin Teoh:
Use MODE_HISTORY instead of MODE_TRADES and check the date of each closed order.
OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)
Thank you for your comments.
I wonder what's wrong with the code above.
I want to use "OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)", honestly I don't know how to use it.
DowaJuseyo: I'm trying to limit the number of times per day.
-
Play videoPlease edit your post.
For large amounts of code, attach it TimeMinute(Time[0]) != TimeMinute(Time[1]))
This will always be true on charts smaller than H1 and never be true on larger.if(Volume[0]>3) return(0);
Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 forum.) Always use time. New candle - MQL4 forum
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.extern double StopLoss = 10; ticketM=OrderModify(OrderTicket(),OrderOpenPrice(),Ask-StopLoss*Point*10,Ask+TakeProfit*Point*10,0,Blue);
Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles- Your stops are 10 points (one pip) from the market on a 5 digit broker but 10 pips on a 4. You are not
adjusting
SL, TP, and slippage; for 4/5 digit brokers
and for JPY pairs.
double pip = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
int pipsToPoints = int(pip / _Point);
int pipDigits = (int)MathLog10(pipsToPoints);
int slippage = 3 * pipsToPoints; - Your stops must be at least MODE_STOPLEVEL points. Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
- For a buy order, your stops must be relative to the Bid, not the Ask.
- I want to use "OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)", honestly I don't know how to use it.What do you mean you "don't know how?" You have a OrderSelect loop already in your code. Didn't you write it?
- "Limit the number of times per day" is ambiguous. Limit what? Currently you just try to open once per bar. Do you want to limit open orders (OrderSelect loop and count them,) or closed (OrderSelect loop through history?)
whroeder1:
-
Please edit your post.
For large amounts of code, attach it - This will always be true on charts smaller than H1 and never be true on larger.
- Bars is unreliable (a refresh/reconnect can change number of bars on chart,)
volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The
== operand. - MQL4 forum.) Always use time. New candle - MQL4
forum
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times. - Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
- Your stops are 10 points (one pip) from the market on a 5 digit broker but 10 pips on a 4. You are not
adjusting
SL, TP, and slippage; for 4/5 digit brokers
and for JPY pairs.
double pip = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
int pipsToPoints = int(pip / _Point);
int pipDigits = (int)MathLog10(pipsToPoints);
int slippage = 3 * pipsToPoints; - Your stops must be at least MODE_STOPLEVEL points. Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
- For a buy order, your stops must be relative to the Bid, not the Ask.
- What do you mean you "don't know how?" You have a OrderSelect loop already in your code. Didn't you write it?
- "Limit the number of times per day" is ambiguous. Limit what? Currently you just try to open once per bar. Do you want to limit open orders (OrderSelect loop and count them,) or closed (OrderSelect loop through history?)
Thank you for your comments.
Some comments are understandable and others don't.
I am not an English user.
I am bad at English.
The above contents are translated (on the Internet).
What I'd like to ask you is why I can't limit the number of entries per day in the code above.
DowaJuseyo: why I can't limit the number of entries per day in the code above.
| Because you haven't written any code to does that. |
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
Hellow
I'm trying to limit the number of times per day.
For example, once or twice a day, three times.
So I wrote the code below.
Every candle goes into it. What's wrong with it?
if you know how to limit the number of entries per day, let me know please.
(using OrdersTotal() function)
================================================
extern int MagicNo = 1234;
extern double Lots = 1.0;
extern double TakeProfit = 10;
extern double StopLoss = 10;
int start()
{
int DayEntry;
if (TimeDay(Time[0])!= TimeDay(Time[1])
&&
TimeMinute(Time[0]) != TimeMinute(Time[1]))
{DayEntry = 0;}
if(Volume[0]>3) return(0);
int i, ticket, total;
bool ticketM;
total=OrdersTotal();
if(total<1)
{
if( DayEntry < 2
&&
Close[1] - Open[1] > 1*Point*10)
{
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,10,0,0, "MA",MagicNo,0,Blue);
if ( ticket >0) {DayEntry = DayEntry + 1;}
return(0);
}
if( DayEntry < 2
&&
Open[1] - Close[1] > 1*Point*10)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,10,0,0,"MA",MagicNo,0,Red);
if ( ticket >0) {DayEntry = DayEntry + 1;}
return(0);
}
return(0);
}
for(i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
{
if(OrderMagicNumber()== MagicNo && OrderSymbol()==Symbol())
{
if(OrderType() == OP_BUY)
{
if(OrderStopLoss()==0 && OrderTakeProfit() ==0)
{
ticketM=OrderModify(OrderTicket(),OrderOpenPrice(),Ask-StopLoss*Point*10,Ask+TakeProfit*Point*10,0,Blue);
return(0);
}
}
if(OrderType() == OP_SELL)
{
if(OrderStopLoss()==0 && OrderTakeProfit() ==0)
{
ticketM=OrderModify(OrderTicket(),OrderOpenPrice(),Bid+StopLoss*Point*10,Bid-TakeProfit*Point*10,0,Red);
return(0);
}
}
}
}
}
return(0);
}