Requests & Ideas - page 59

 

Hi Mladen.

There was an alert showing EUR/CHF at 15:14:53 Donchian Channel Price broke lower band and there was an alert showing gbp/jpy broke the upper band when neither had happened actually .., this is an issue with the chart window indicator.., can you please look what might be the cause and post the one which has got the option of alert on every break of the band by a candle.., i mean if 1, 2, 3, 4, 5...... candles keep on breaking it., i would like to be alerted.

regards,

paapi.

 
mladen:
paapi

I think that with the price drawn as it is in this separate window version, it will be much clearer how does it monitor the chosen price and bands and how does it check for breakouts

regards

Mladen

Hi Mr Mladen

is it possible, when you have time, to do the same with your cfb channel.

Thx

 

paapi

Please read the post (the beginning of this post : https://www.mql5.com/en/forum/179807/page39 ) where I explained what can (could) happen and what to do

regards

Mladen

paapi:
Hi Mladen.

There was an alert showing EUR/CHF at 15:14:53 Donchian Channel Price broke lower band and there was an alert showing gbp/jpy broke the upper band when neither had happened actually .., this is an issue with the chart window indicator.., can you please look what might be the cause and post the one which has got the option of alert on every break of the band by a candle.., i mean if 1, 2, 3, 4, 5...... candles keep on breaking it., i would like to be alerted.

regards,

paapi.
 

Hi Mladen..,

Sorry to be dragging this out and checking your patience (i know u've got a lot of this ), but the truth is i'd read the post u'd made and only after that i made the last post. I am not using MTF, but as i was reading your new post.., i got an alert, for eur/chf, gbp/chf, and gbp/jpy to have broken the lower band, but only gbp/jpy was correct, the other two were not, the gbp/chf had broken the middle band and eur/chf was just above the lower band .

PS: With great trepidation, i'm writing this, I would be more than happy to have a new one where it alerts on all breaking of the bands unlike the earlier ones where it only alerted on first instance and ignored the rest or the 2nd version where it alerted on the 2nd instance provided the price came down/up the band and again pierced.

regards,

paapi

 

paapi

I am testing it over and over and it works correctly (even the version with the change proposed to alert on every bar that breaks the upper or lower band) There is no alert on middle line brake (break out alerts check only the upper and lower bands, they completely ignore the middle line)

Here is a "history" of alerts with the change in code I sent you on a 1 minute EURUSD chart (no mtf, current bar) and as you can see there were no alerts when the price retraced into the channel nor the alert was repeated - it alerted at the exact moment (which is seen from the exact time of the alert in the list of alerts) when the price broke the band
regards

Mladen

paapi:
Hi Mladen..,

Sorry to be dragging this out and checking your patience (i know u've got a lot of this ), but the truth is i'd read the post u'd made and only after that i made the last post. I am not using MTF, but as i was reading your new post.., i got an alert, for eur/chf, gbp/chf, and gbp/jpy to have broken the lower band, but only gbp/jpy was correct, the other two were not, the gbp/chf had broken the middle band and eur/chf was just above the lower band .

PS: With great trepidation, i'm writing this, I would be more than happy to have a new one where it alerts on all breaking of the bands unlike the earlier ones where it only alerted on first instance and ignored the rest or the 2nd version where it alerted on the 2nd instance provided the price came down/up the band and again pierced.

regards,

paapi
Files:
dc_-_correct.jpg  200 kb
 

Hi Mladen..,

That is great.., send me the changed version (by you to alert on every break).., maybe it is my mistake in coding i don't know.., but whatever comes from your hands will be a perfect one.

regards,

paapi.

 

This is the version I tested

regards

Mladen

paapi:
Hi Mladen..,

That is great.., send me the changed version (by you to alert on every break).., maybe it is my mistake in coding i don't know.., but whatever comes from your hands will be a perfect one.

regards,

paapi.
Files:
 

Hi Mladen..,

Thanks a lot.., i would have never attempted changing it if i'd known that it would give u so much headache..., but the one sent by you works perfectly. I had changed the code in the original donchian, which missed one line of code, which is present in the 2nd version, and i think that was the problem.., sorry.., but you cannot expect us humans to be a God like you

regards,

Paapi

 

paapi,

Only now I understood what happened : the change I told you must be plied to version 2.0 (it will not work with previous version since the previous version did not take care a state when it retraced into the channel - that is the extra line that take care of that)

Glad that it is solved

________________________

Paulinge

In your code ( good place would be at before this line in the start procedure : if(OrdersTotal() > 0 ) or any line before orders opening) ad a call to this procedure :
//----------------------------------------------------------------------------------------

//

//----------------------------------------------------------------------------------------

//

//

// close orders

// example usage : closeOrders(OP_BUY,PERIOD_H1); will close buys that are opened at a previous or older 1 hour bar

// example usage : closeOrders(OP_SELL,PERIOD_H4); will close sells that are opened at a previous or older 4 hour bar

//

//

//

void closeOrders(int orderType, int timeFrameToCheck)

{

for(int i=OrdersTotal()-1; i>=0; i--)

{

if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)==false) break;

if(OrderMagicNumber() != MagicNumber) continue;

if(OrderType() != orderType) continue;

if(OrderSymbol() != Symbol()) continue;

//

//

//

// check if order has to be closed at all

// it is checking the target time frame (use PERIOD_H1 in timeFrameToCheck

// if you want to close an order after 1 hour bar has expired)

//

//

//

int y = iBarShift(Symbol(),timeFrameToCheck,OrderOpenTime()); // target time frame bar of the order open time

int c = iBarShift(Symbol(),timeFrameToCheck,Time[0]); // target time frame bar of the current bar

if (y<=c) continue; // if the bar is lees (opened after - in some errors case)

// or the bar is the same, no need to close this opened order

//

//

//

//

//

RefreshRates();

switch(orderType)

{

case OP_BUY : OrderClose(OrderTicket(),OrderLots(),Bid,0,CLR_NONE); break;

case OP_SELL : OrderClose(OrderTicket(),OrderLots(),Ask,0,CLR_NONE); break;

}

}

}
Added some comments as of what and why is it doing (and some example usage). Testing if time is for example nn:59 minutes is risky and has many pitfalls :
- if you do not receive ticks in that minute, for example - and that can happen more often than we think), it will not close the order

- if you compare the time to broker last sent tick time (TimeCurrent()), you might end up in an error, and it will not work in back-test

- if you compare time to your local time (TimeLocal()) if the time on your PC is not OK, you are going to end up in error, and it will not work in back-test either

- if for some reason time checking is missed (you turned off your PC) you might end up with an opened order that you do not want

That is the reason why this procedure checks if the target time frame bar number of the order open time is greater than the current bar number (it should work even in back-testing, but please check it out) and if the current bar number is less than order open time bar number, then the order should be closed

Try it out and if some more explanation is needed please let me know

regards

Mladen

 

Hi Mladen,

Thank you so much Sir for your help.

I will try it first and hopefully not get a mistake.

Best regards,

Paulinge

mladen:
paapi,

Only now I understood what happened : the change I told you must be plied to version 2.0 (it will not work with previous version since the previous version did not take care a state when it retraced into the channel - that is the extra line that take care of that)

Glad that it is solved

________________________

Paulinge

In your code ( good place would be at before this line in the start procedure : if(OrdersTotal() > 0 ) or any line before orders opening) ad a call to this procedure :
//----------------------------------------------------------------------------------------

//

//----------------------------------------------------------------------------------------

//

//

// close orders

// example usage : closeOrders(OP_BUY,PERIOD_H1); will close buys that are opened at a previous or older 1 hour bar

// example usage : closeOrders(OP_SELL,PERIOD_H4); will close sells that are opened at a previous or older 4 hour bar

//

//

//

void closeOrders(int orderType, int timeFrameToCheck)

{

for(int i=OrdersTotal()-1; i>=0; i--)

{

if(OrderSelect(i,SELECT_BY_POS, MODE_TRADES)==false) break;

if(OrderMagicNumber() != MagicNumber) continue;

if(OrderType() != orderType) continue;

if(OrderSymbol() != Symbol()) continue;

//

//

//

// check if order has to be closed at all

// it is checking the target time frame (use PERIOD_H1 in timeFrameToCheck

// if you want to close an order after 1 hour bar has expired)

//

//

//

int y = iBarShift(Symbol(),timeFrameToCheck,OrderOpenTime()); // target time frame bar of the order open time

int c = iBarShift(Symbol(),timeFrameToCheck,Time[0]); // target time frame bar of the current bar

if (y<=c) continue; // if the bar is lees (opened after - in some errors case)

// or the bar is the same, no need to close this opened order

//

//

//

//

//

RefreshRates();

switch(orderType)

{

case OP_BUY : OrderClose(OrderTicket(),OrderLots(),Bid,0,CLR_NONE); break;

case OP_SELL : OrderClose(OrderTicket(),OrderLots(),Ask,0,CLR_NONE); break;

}

}

}
Added some comments as of what and why is it doing (and some example usage). Testing if time is for example nn:59 minutes is risky and has many pitfalls :
- if you do not receive ticks in that minute, for example - and that can happen more often than we think), it will not close the order

- if you compare the time to broker last sent tick time (TimeCurrent()), you might end up in an error, and it will not work in back-test

- if you compare time to your local time (TimeLocal()) if the time on your PC is not OK, you are going to end up in error, and it will not work in back-test either

- if for some reason time checking is missed (you turned off your PC) you might end up with an opened order that you do not want

That is the reason why this procedure checks if the target time frame bar number of the order open time is greater than the current bar number (it should work even in back-testing, but please check it out) and if the current bar number is less than order open time bar number, then the order should be closed

Try it out and if some more explanation is needed please let me know

regards

Mladen
Reason: