Trying to get Trades closed only at the beginning of each bar and from the indicator and not the OHLC.

 

I'm trying to get the EA to only close out specified trades at the very beginning of each new bar, but it closes out the trades anytime it hits the TP or SL levels. I want it to ONLY act on the indicator level and NOT by the OHLC and ONLY at the beginning of each new bar.

I have been using the following code to try and get it to only act at the start of each new bar, but it is not working in this EA for some reason:

Thanks for any and all assistance (< 8)

//---- go trading only for first ticks of new bar
   if(Volume[0]>1) return;
 
FourX:

I'm trying to get the EA to only close out specified trades at the very beginning of each new bar, but it closes out the trades anytime it hits the TP or SL levels. I want it to ONLY act on the indicator level and NOT by the OHLC and ONLY at the beginning of each new bar.

I have been using the following code to try and get it to only act at the start of each new bar, but it is not working in this EA for some reason:

ONLY act on the indicator level and NOT by the OHLC --> you can trigger your action by almost any condition you specify... use iCustom() to call indicator's value, if it's not embedded in your EA.

ONLY at the beginning of each new bar --> this has been answered many times, please search. keep in mind charts can have missing bars and EA or Indy can miss first tick of the bar.. HTH

 
 
cameofx:

ONLY at the beginning of each new bar --> this has been answered many times [...]

For example, https://www.mql5.com/en/forum/109887 and https://www.mql5.com/en/forum/125732. In short, don't use Volume[0] to check for the start of a new bar. It only works reliably in backtesting.
 
jjc:
For example, https://www.mql5.com/en/forum/109887 and https://www.mql5.com/en/forum/125732. In short, don't use Volume[0] to check for the start of a new bar. It only works reliably in backtesting.

Hi,

I'll check them thanks. Along with the search engine here not finding things that we know are in the DataBase; There is also the typical problem of getting swamped with results and no way to refine them to find what is needed. Its pretty bad when a web search is much more proficient than the sites own search engine! )< 8(

ONLY act on the indicator level and NOT by the OHLC --> you can trigger your action by almost any condition you specify... use iCustom() to call indicator's value, if it's not embedded in your EA.

I do have the indicator in the EA in several places. I'm not familiar with iCustom yet., but it appears that I'm about to. As I said, the EA keeps getting triggered by OHLC and not just by the indicator line as I want it to.

Thanks to all for your assistance ! (< 8)





 

I was apprehensive of utilizing the volume as an indicator of a new bar. Once more the ol 'Spidey Sense' is right. In my experience it's ALWAYS right! But lots of times I don't listen to it as it is not what I WANT to do as opposed Should do or NEED to do (which == 'Dharma') and override it usually to the detriment that I end up regretting.

Thanks to everyone for the info and examples of better, more reliable methods.

 
gordon:

https://www.mql5.com/en/forum/125561

Seems familiar...

Yes it is, It's from my query on this same issue.

I still haven't been able to get it to work properly utilizing either the Bar[] nor the Time[] arrays

 
cameofx:

ONLY act on the indicator level and NOT by the OHLC --> you can trigger your action by almost any condition you specify... use iCustom() to call indicator's value, if it's not embedded in your EA.

ONLY at the beginning of each new bar --> this has been answered many times, please search. keep in mind charts can have missing bars and EA or Indy can miss first tick of the bar.. HTH

Apparently so, but alas I haven't been able to get any of the techniques, approaches or methods to work reliably.

I can readily understand and appreciate missing ticks regularly, but entire bars when I am on a 1 hour chart ??

 
Viffer wrote >>
Bar 0 forms as new ticks come in. A new tick gererates a new close for bar 0 and may also produce new highs or lows and your indicators will re calculate accordingly. Your EA will react to the indicator as currently calculated but a second later your indicator will re calculate based on the next tick. It only becomes static (most indicators but not all) at the completion of the time frame. If you want static indicator values, you need to reference the previous bar, Bar 1. Set the shift on your indicator to 1 and it will ignore all revised calculations of the indicator until the next new time period starts.

I hope I've understood you correctly and hope that helps
V

Hi Viffer,

I haven't been able to get any other approaches to work reliably and I can see the wisdom of your approach, especially as I am using longer intervals. I'll try utilizing the closing of bar 1 instead of the opening of bar 0.

Thanks for the suggestion

Reason: