Download MetaTrader 5
To add comments, please log in or register
Do you keep a blog? Place a link to MQL5.community there and make money!
Blackburn
26
Blackburn 2014.11.06 23:54 

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 

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.11.07 00:43  
// 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

Keith Watford
Moderator
7875
Keith Watford 2014.11.07 00:48  

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 

Blackburn
26
Blackburn 2014.11.07 02:41  
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

 

 


 

Blackburn
26
Blackburn 2014.11.07 02:43  
deysmacro:

I think you don't need



that's what I figured will give that a try thanks @deysmacro
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.11.07 03:06  
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.

/
To add comments, please log in or register