# Help on getting 25% of bar range

26

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

1401

```// 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

Moderator
10561

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

26

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```

26

deysmacro:

I think you don't need

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