Facing problem about current bar Open, High & Low

 

Hello,

I'm trying to write a PinBar detector function for the current bar (index 0).

The Pinbar_Bar() function will detect the pin bar based on the following assumption:

h1= Height of the total bar (difference between current high and low)

uc= Distance between open price and current high. 

The condition h1>20*PP means that it will check the pinbar if the total height of the bar is greater than 20 pips (this part works) 

If  h1/uc > 2 (which means uc if half of the total bar (at least) it will trigger the pinbar.

 

The problem is both uc and h1 is the same value (say 0.0038) and the ratio is always 1 (open price is = lowest). I tried both with High[] and iHigh() type of functions, result is the same.

Is there a problem in strategy tester (visual mode) to test index 0? If yes is there a way to overcome this issue?

 

My code is as below:

bool Pinbar_Buy()
{
   //double h1=High[0]-Low[0];
   //double uc=High[0]-Open[0];
   
   double h1=iHigh(_Symbol,0,0)-iLow(_Symbol,0,0);
   double uc=iHigh(_Symbol,0,0)-iOpen(_Symbol,0,0);
   
   if( (h1/uc)<2 && h1>20*PP) { Alert(" h1=",h1,"  uc=",uc," h1/uc=",h1/uc); return(True); }
  
   return(False);
}
 
Have you googled ("pinbar mt4")? There are tons of code for that.
 

Yes, I have one as well but they detect after the bar closes. I would like to do something that works on the current bar. By the way I don't have any issue on the pin bar method itself but the commands High, Low, Open does not seem working on index 0 during visual tests.

 

Alert does not work in the Start.-Tester - could that be the problem?

Use either Comment() or Print()..

 
aed71:  The problem is both uc and h1 is the same value
Of course they're the same value on the first tick of a new bar.
You can't test for a pin bar on the forming bar.
 
gooly:

Alert does not work in the Start.-Tester - could that be the problem?

Use either Comment() or Print()..

It's not about Alert(), it works fine in tester. Thanks.
 
WHRoeder:
aed71:  The problem is both uc and h1 is the same value
Of course they're the same value on the first tick of a new bar.
You can't test for a pin bar on the forming bar.

It's not related with the first tick of the new bar. To avoid this I've put 20 pips distance condition.

The problem is during 1 Hour bar, the Ask/Bid line moves up and down but the uc and h1 values are never changes? 

Why the high[0] does not change in the current bar?  (it goes up like 35 pips and you can clearly see that it's moving up in the tester)

 

Any other idea why High[0], Low[0] does not change during the strategy tester?

Does it get the highest and lowest values in advance by looking to H1 data? If so we could not test any strategy working on the index 0.

 
If Close[0] ranges between High[0] and Low[0] both aren't changed of course!
 
aed71: Any other idea why High[0], Low[0] does not change during the strategy tester?

Always has except if you don't return from OnTick.

All you posted is your simple function. Post all the relevant code, where do you call it?

Reason: