High[0] Low[0] Close[0] all return the open value of the bar... am I missing something here?

 

High[0] Low[0] Close[0] all return the open value of the bar... am I missing something here?

Doesn't make sense why if I do the following:


Print("Open = ", Open[0]);
Print("High = ", High[0]);
Print("Low = ", Low[0]);

Print("Close = ", Close[0]);


They all return the Open value for the bar. This is a demo account, fyi.


Thanks,

Brant

 

try on a daily chart

 
At start of new bar, Open, High, Low and Close will be the same value. You would need to wait for further last bar interpolation of price to see different values.
 
wackena:
At start of new bar, Open, High, Low and Close will be the same value. You would need to wait for further last bar interpolation of price to see different values.

ok, I'm new to MT4 here, but am an experience programmer who's working with TradeStation, Interactive Brokers, and other APIs. If I use a 15-minute period, is start() called for every 15-minute bar that is formed? or do I have to build them up? I have a 15-minute chart opened, and I'm using the iBullsPower function -the chart seems to indicate that the iBullsPower value is calculated for each 15-minute bar. I wanted to simulate this in the MQL code - if I do have to build up the 15-minute bars, how do I pass them into the iBullsPower function?
 
bhahn1800:

ok, I'm new to MT4 here, but am an experience programmer who's working with TradeStation, Interactive Brokers, and other APIs. If I use a 15-minute period, is start() called for every 15-minute bar that is formed? or do I have to build them up? I have a 15-minute chart opened, and I'm using the iBullsPower function -the chart seems to indicate that the iBullsPower value is calculated for each 15-minute bar. I wanted to simulate this in the MQL code - if I do have to build up the 15-minute bars, how do I pass them into the iBullsPower function?
int start()
  {

  }
This start() functions cycles on each incoming price tick received by Client Terminal and is not effected by Period choice.. Function calls within start() function can be looped to a selected period choice. If you use same M15 period selection in your technical indicator, like IBulls() within the EA, it should work the same as the iBulls Indicator attached to M15 chart. You use Comment() call within EA to display indicator values to chart, then attached indicator to chart and then compare values using the Data Window pane of the Client Terminal.
 
wackena:
This start() functions cycles on each incoming price tick received by Client Terminal and is not effected by Period choice.. Function calls within start() function can be looped to a selected period choice. If you use same M15 period selection in your technical indicator, like IBulls() within the EA, it should work the same as the iBulls Indicator attached to M15 chart. You use Comment() call within EA to display indicator values to chart, then attached indicator to chart and then compare values using the Data Window pane of the Client Terminal.


Thanks for the quick reply.


So what's the point of selecting the Period value in tester if start() just cycles the incoming price tick? Also, you mentioned "Function calls within start() function can be looped to a selected period choice" - is there a proper way to do this or just invoke a function inside start that keeps track of the timestamp?

 
wackena:
This start() functions cycles on each incoming price tick received by Client Terminal and is not effected by Period choice.. Function calls within start() function can be looped to a selected period choice. If you use same M15 period selection in your technical indicator, like IBulls() within the EA, it should work the same as the iBulls Indicator attached to M15 chart. You use Comment() call within EA to display indicator values to chart, then attached indicator to chart and then compare values using the Data Window pane of the Client Terminal.

ok, I thought I had figured it out (see code below) - the iBullsPower and iBearsPower are both returning the same value. What might I be doing wrong here?


bool newBar = false;

int start()
  {
 
   newBar();
   if (newBar == false) return;
  
   double bullsPwr = iBullsPower(Symbol(), PERIOD_M15, 13, PRICE_CLOSE, 0);
   double bearsPwr = iBearsPower(Symbol(), PERIOD_M15, 13, PRICE_CLOSE, 0);
  
   Print("BullsPwr = ", bullsPwr, "BearsPwr = ", bearsPwr);
  
   return(0);
  }

void newBar() {
   static datetime newTime = 0;
   newBar = false;
  
   if (newTime != Time[0]) {
      newTime = Time[0];
      newBar = true;
   }
}
 

I was referring to demo and live trading. In Strategy Tester using Every Tick modeling, start() function cycles on M1 price data. Tester period selection determines predefined variable values and values for technical indicators when period selection is "NULL" or "0".

Period loop within start() functionexample.

int start()
{
   double BarHigh = iHigh(Symbol(),Period M15,0); // loops and returns value on M15 period cycles.
}
 
wackena:

I was referring to demo and live trading. In Strategy Tester using Every Tick modeling, start() function cycles on M1 price data. Tester period selection determines predefined variable values and values for technical indicators when period selection is "NULL" or "0".

Period loop within start() functionexample.




so are you saying that the EA needs to handle thing differently when in demo/live trading versus Tester? I was under the assumption that the code would not have to change or accommodate the different trading modes.
 
Tester limitation: You can not get bar zero of other timeframes/pairs
 
bhahn1800:
so are you saying that the EA needs to handle thing differently when in demo/live trading versus Tester? I was under the assumption that the code would not have to change or accommodate the different trading modes.

See the answer to your separate question in https://www.mql5.com/en/forum/129856.

In general, code does not have to "change or accommodate the different trading modes". Your issue is about the difference between the variable timeframe of the chart versus the fixed timeframe (M15) of your indicator calculation, and would apply in forward-trading as well if e.g. you ran the code on an H1 chart.

Reason: