Thanks, I'm just at that level of knowledge. There's the same problem with the script in the example. It's inconvenient when you turn on the script and it goes in at the end of the trend.
How do I tell the script to trigger only if there are less than 4 bars after the crossing of two bars?
Thanks, I'm just at that level of knowledge. There's the same problem with the script in the example. It's inconvenient when you turn on the script and it goes in at the end of the trend.
How do I tell the script to trigger only if there are less than 4 bars after the crossing of two bars?
The script does not understand words. It's in your hands - run the script no later than 4 bars after 2 MAs have been crossed.
People, I've already asked here how to make an order open only when a new candle appears. I am using a D1 timeframe.
I have decided to place pending orders at certain levels (buystop_lvl and sellstop_lvl), based on analysis of previous candlesticks.
I wanted to place them at the beginning of the day and delete them when a new candlestick comes. It doesn't matter if the pending orders were activated or not, if they were activated, then market orders should also be closed. At most 2 orders, buystop and sellstop.
Here is what I wrote:
1. First I check whether the market orders or pending orders are active, and if they are, I delete/close them.
int total=OrdersTotal();
if (total!=0 && NewBar()==true){
for (int i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,10);
if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,10);
if(OrderType()==OP_BUYSTOP) OrderDelete(OrderTicket());
if(OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket());
}
}
2. Then I place pending orders by calculated levels:
As a result, when a new candle opens, the orders are placed and immediately deleted. The orders are placed and immediately deleted.
When I commented out the code from point (1) I couldn't get it to open orders in the tester, but the orders didn't open, i.e. the orders didn't become market ones.
Shit, I still don't understand how to do it. I need the code to delete and close orders only on the next candlestick. But there will also be others to open on it. This means the program will again get into the deletion. I need some flag, but my brain is already sweating to understand how to do it :)
And in general, you throw out NewBar, look at the time of the last order opening and compare it with Time[0]. If it's higher, it's your case, you can delete everything.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Please advise how to buy a trading robot ?
Hello,
Please have this question about the EA:
I have an order opening by swinging, for example, if MA_1 > MA_2 then we buy. But when I exit the trade this rule is triggered again.
How can I tell the EA to open a position only if the price has moved no more than 4 bars away from MA_2?
Thank you!
If something is wrong or wrong place, do not kick me. This is my first post on this huge forum.
Hello,
Please have this question about the EA:
I have an order opening by swinging, for example, if MA_1 > MA_2 then we buy. But when I exit the trade this rule is triggered again.
How can I tell the EA to open a position only if the price has moved no more than 4 bars away from MA_2?
Thank you!
If something is wrong or wrong place, do not kick me. This is my first post on this huge forum.
Thanks, I'm just at that level of knowledge. There's the same problem with the script in the example. It's inconvenient when you turn on the script and it goes in at the end of the trend.
How do I tell the script to trigger only if there are less than 4 bars after the crossing of two bars?
Thanks, I'm just at that level of knowledge. There's the same problem with the script in the example. It's inconvenient when you turn on the script and it goes in at the end of the trend.
How do I tell the script to trigger only if there are less than 4 bars after the crossing of two bars?
People, I've already asked here how to make an order open only when a new candle appears. I am using a D1 timeframe.
I have decided to place pending orders at certain levels (buystop_lvl and sellstop_lvl), based on analysis of previous candlesticks.
I wanted to place them at the beginning of the day and delete them when a new candlestick comes. It doesn't matter if the pending orders were activated or not, if they were activated, then market orders should also be closed. At most 2 orders, buystop and sellstop.
Here is what I wrote:
1. First I check whether the market orders or pending orders are active, and if they are, I delete/close them.
2. Then I place pending orders by calculated levels:
3. If I have a Sell or Sell Sell order, I will open a new bar on it:
As a result, when a new candle opens, the orders are placed and immediately deleted. The orders are placed and immediately deleted.
When I commented out the code from point (1) I couldn't get it to open orders in the tester, but the orders didn't open, i.e. the orders didn't become market ones.
Can you tell me what might be the problem?
This NewBar() function cannot be used twice in a row
Something like this is better:
bool newBar = NewBar();
// and further in the text, replacing NewBar() with newBar