Opening orders on current bar

sm17h

Trader
Jun 19, 2024
9
0
6
35
Hello, I have created an expert advisor that receives buy and sell signals from a custom indicator through iCustom, when it receives the signals to open orders on the current bar (shift = 0) the orders do not open but when working with the bar previous(shift=1) works fine. Could someone help me ?
 

Amy4

Trader
Mar 15, 2023
57
9
19
29
Hello, I have created an expert advisor that receives buy and sell signals from a custom indicator through iCustom, when it receives the signals to open orders on the current bar (shift = 0) the orders do not open but when working with the bar previous(shift=1) works fine. Could someone help me ?
The issue might be due to the current bar (shift = 0) not being fully formed. Using shift = 1 works because the previous bar is complete. Adjust your logic to handle this timing.
 

sm17h

Trader
Jun 19, 2024
9
0
6
35
The issue might be due to the current bar (shift = 0) not being fully formed. Using shift = 1 works because the previous bar is complete. Adjust your logic to handle this timing.
Thanks for your answer, i understand, the problem is when i use shift = 1, the order opens far from the signal given by the custom indicador ( opens on the next bar ) and i need that the orders opens as close as possible
 

sm17h

Trader
Jun 19, 2024
9
0
6
35
From custom indicador the EA gets number 1 for buy and 2 for sell. Thanks for your help
 

Attachments

  • fxDragon2v1.7.5.1.mq4
    20.3 KB · Views: 1

sm17h

Trader
Jun 19, 2024
9
0
6
35
Perhaps the indicator never fills the value for bar #0? Could you please attach the indicator here as well?
Well, i have printed indicador output and apparently it fills the value for bar 0, i thought that maybe it could be an indicator problem but i am not sure, also when i use the strategy tester it works. I send You the custom indicator. Thanks
 

Attachments

  • Range_Filter_5m.mq4
    5 KB · Views: 1

Enivid

Administrator
Staff member
Nov 30, 2008
19,201
1,499
144
Odesa
www.earnforex.com
I think there is an error in this indicator's code:
MQL4:
        if (MdUp[i] > MdUp[i - 1]) {
            currentDirection = 1;
        } else if (MdUp[i] < MdUp[i - 1]) {
Both [i - 1] should actually be [i + 1]. This also results in the array out of range error for the indicator. So, I'm not even sure how you got it working...
 

sm17h

Trader
Jun 19, 2024
9
0
6
35
I think there is an error in this indicator's code:
MQL4:
        if (MdUp[i] > MdUp[i - 1]) {
            currentDirection = 1;
        } else if (MdUp[i] < MdUp[i - 1]) {
Both [i - 1] should actually be [i + 1]. This also results in the array out of range error for the indicator. So, I'm not even sure how you got it working...
I will check that part of the code and i will run a test. Thanks for your help
 

sm17h

Trader
Jun 19, 2024
9
0
6
35
I will check that part of the code and i will run a test. Thanks for your help
I think there is an error in this indicator's code:
MQL4:
        if (MdUp[i] > MdUp[i - 1]) {
            currentDirection = 1;
        } else if (MdUp[i] < MdUp[i - 1]) {
Both [i - 1] should actually be [i + 1]. This also results in the array out of range error for the indicator. So, I'm not even sure how you got it working...
I checked the code and i relized that the file uploaded it is an old version, the actual one is this
 

Attachments

  • Range_Filter_5m.mq4
    6.2 KB · Views: 2

Enivid

Administrator
Staff member
Nov 30, 2008
19,201
1,499
144
Odesa
www.earnforex.com
Your indicator is using Close price of the current bar to produce signals:
MQL4:
double cprice = iMA(NULL,0,1,0,MODE_EMA,appliedPrice,i);
For the bar #0, this is almost always very close to the previous Close price. Since you then use some conditions that compare the current close to the previous values of the indicator, they never get fulfilled at the bar's open time. This isn't a big problem per se, but your EA checks the indicator values only once per bar (right when it opens), which means that if it uses the bar #0's values, it will always (or almost always) get nothing useful.
 

sm17h

Trader
Jun 19, 2024
9
0
6
35
Your indicator is using Close price of the current bar to produce signals:
MQL4:
double cprice = iMA(NULL,0,1,0,MODE_EMA,appliedPrice,i);
For the bar #0, this is almost always very close to the previous Close price. Since you then use some conditions that compare the current close to the previous values of the indicator, they never get fulfilled at the bar's open time. This isn't a big problem per se, but your EA checks the indicator values only once per bar (right when it opens), which means that if it uses the bar #0's values, it will always (or almost always) get nothing useful.
Thanks for your help. How can i solve the problem ??
 

sm17h

Trader
Jun 19, 2024
9
0
6
35
If I do that, wouldn't the buy and sell orders be produced with a delay? I was trying to opens orders as close as posible for the signals given by the custom indicator
Use indicator values at the bar #1 to enter trades.
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,201
1,499
144
Odesa
www.earnforex.com
If I do that, wouldn't the buy and sell orders be produced with a delay? I was trying to opens orders as close as posible for the signals given by the custom indicator
Yes, they will - same as there is delay in how the indicator works.
Another thing you could do is to re-check the bar #0 continuously not only when it just opened. However, you'd be getting false signals there as the bar #0's value is always recalculated.
 

sm17h

Trader
Jun 19, 2024
9
0
6
35
Yes, they will - same as there is delay in how the indicator works.
Another thing you could do is to re-check the bar #0 continuously not only when it just opened. However, you'd be getting false signals there as the bar #0's value is always recalculated.
Ok, thanks for your help.