Help on getting 25% of bar range

 

Hello my trading logic requires to check if the close of the bar is equal to 25% of the bar's range. Can somebody check if I am doing it right? below is a snippet of my code

 

// For long trade

if(iClose(NULL,0,0) >= (0.25 * ( iHigh(NULL,0,0) - iLow(NULL,0,0) ) + iLow(NULL, 0, 0)) // OpenBuyOrder

if(iClose(NULL,0,0) <= (0.25 * ( iHigh(NULL,0,0) - iLow(NULL,0,0) ) - iLow(NULL, 0, 0)) // OpenSellOrder

 

Although this is  working okay I just want to get some advice if there's a better way of doing it :)

TIA 

 
// For long trade

if(iClose(NULL,0,0) >= (0.25 * ( iHigh(NULL,0,0) - iLow(NULL,0,0) ) + iLow(NULL, 0, 0)) // OpenBuyOrder

if(iClose(NULL,0,0) <= (0.25 * ( iHigh(NULL,0,0) - iLow(NULL,0,0) ) - iLow(NULL, 0, 0)) // OpenSellOrder

I think you don't need

 

You are working with open bars, you do realise that?

if(iClose(NULL,0,0) <= (0.25 * ( iHigh(NULL,0,0) - iLow(NULL,0,0) ) - iLow(NULL, 0, 0)) // OpenSellOrder

 

 I don't think that this works as it will certainly return a negative value

Also, as I am not sure exactly what you are trying to do, you may get both a buy and sell order from the same bar 

 
GumRai:

You are working with open bars, you do realise that?

 

 I don't think that this works as it will certainly return a negative value

Also, as I am not sure exactly what you are trying to do, you may get both a buy and sell order from the same bar 


Hi @Gumrai basically my signal for a trade is to buy if the close of the previous bullish bar is 25% of the it's range and sell if its a bearish bar. Having said that the code snippet should have been.

 

if(iClose(NULL,0,1) >= (0.25 * ( iHigh(NULL,0,1) - iLow(NULL,0,1) ) + iLow(NULL, 0, 1)) // OpenBuyOrder

if(iClose(NULL,0,1) <= (0.25 * ( iHigh(NULL,0,1) - iLow(NULL,0,1) ) - iLow(NULL, 0, 1)) // OpenSellOrder

 

 


 

 
deysmacro:

I think you don't need



that's what I figured will give that a try thanks @deysmacro
 
traderbino:

that's what I figured will give that a try thanks @deysmacro

Just remember. It is either >= and < or <= and >

Any combination is OK but never both <= and >= because if both are true, something wrong could happen real fast. I learned that the hard way.