IOPEN function not returning values on new candle

 

I need help in figuring this out. My program is looking at the two previous candles, checking if conditions are met then reporting on the current candle. My issue is it is not reporting on current candle it is reporting on the candle after the current. 

I have a sleep function of five second to make sure the values are filled for the different pairs I am looking at. I am seeing when i do an iopen of current candle i am getting opening price of previous (Shift 1) candle. Is it that you cannot get opening price unless bar is closed? How do i get the right values when new bar opens

***

but i am getting the same error. one bar late

Documentation on MQL5: Common Functions / Sleep
Documentation on MQL5: Common Functions / Sleep
  • www.mql5.com
Sleep - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019.05.06)
              Messages Editor

  2. You posted in the MT5 General section instead of the MQL4 section, (bottom of the Root page)? Therefor, you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020.03.08)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020.07.05)
              How to call indicators in MQL5 - MQL5 Articles (12 March 2010

  3. For a new bar test, 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 programming forum.) Always use time.
              New candle - MQL4 programming forum #3 (2014.04.04)

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              Running EA once at the start of each bar - MQL4 programming forum (2011.05.06)

  4. Just because the current chart starts a new bar, doesn't mean the other symbol have. I recommend: Do not trade multiple currencies in one EA.

    1. You can't use any {MT4: predefined variables, MT5: predefined variables,}

    2. Must poll (not OnTick, unless you use specific indicators)
                The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles (18 February 2011

    3. and usually other problems, e.g. A problem with iBarShift - MQL4 programming forum - Page 2

    4. You must handle History {MT4:4066/4073 errors: Download history in MQL4 EA - MQL4 programming forum, MT5: Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5.}

    5. Code it to trade the chart pair only. Look at the others if you must. Don't assume that Time[i] == iTime(otherPair, TF, i) always use iBarShift.

    Then put it on other charts to trade the other pairs. Done.
 
triniatlarge:

I need help in figuring this out. My program is looking at the two previous candles, checking if conditions are met then reporting on the current candle. My issue is it is not reporting on current candle it is reporting on the candle after the current. 

I have a sleep function of five second to make sure the values are filled for the different pairs I am looking at. I am seeing when i do an iopen of current candle i am getting opening price of previous (Shift 1) candle. Is it that you cannot get opening price unless bar is closed? How do i get the right values when new bar opens

***

but i am getting the same error. one bar late

Please insert the code correctly: when editing a message, press the button     Codeand paste your code into the pop-up window
 

Thank you so much for your reply. I have been reading through all the links you gave me trying to understand this environment. I am new at this and I only found out of the community group to post questions. Quick question, i see i might have to use register handles in oninit using onchart event, is this in MQL5 only and that means i need to switch to mql5. Sorry again for the question I am new to the environment

William Roeder:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019.05.06)
              Messages Editor

  2. You posted in the MT5 General section instead of the MQL4 section, (bottom of the Root page)? Therefor, you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020.03.08)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020.07.05)
              How to call indicators in MQL5 - MQL5 Articles (12 March 2010

  3. For a new bar test, 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 programming forum.) Always use time.
              New candle - MQL4 programming forum #3 (2014.04.04)

    I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
              Running EA once at the start of each bar - MQL4 programming forum (2011.05.06)

  4. Just because the current chart starts a new bar, doesn't mean the other symbol have. I recommend: Do not trade multiple currencies in one EA.

    1. You can't use any {MT4: predefined variables, MT5: predefined variables,}

    2. Must poll (not OnTick, unless you use specific indicators)
                The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles (18 February 2011

    3. and usually other problems, e.g. A problem with iBarShift - MQL4 programming forum - Page 2

    4. You must handle History {MT4:4066/4073 errors: Download history in MQL4 EA - MQL4 programming forum, MT5: Timeseries and Indicators Access /  Data Access - Reference on algorithmic/automated trading language for MetaTrader 5.}

    5. Code it to trade the chart pair only. Look at the others if you must. Don't assume that Time[i] == iTime(otherPair, TF, i) always use iBarShift.

    Then put it on other charts to trade the other pairs. Done.
 
triniatlarge: , is this in MQL5 only and that means i need to switch to mql5. Sorry

You originally posted in a MQL5 section with MQL4 code (now deleted). Make up your mind what language you are using. Post your code in the correct forum; no mind readers here.

Reason: