Opening orders on current bar

  • Thread starter Thread starter sm17h
  • Start date Start date
  • Watchers Watchers 3

sm17h

Trader
Jun 19, 2024
9
0
6
36
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 ?
 
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.
 
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
 
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

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 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
 
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

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.
 
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 ??
 
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.
 
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.
 
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.