Line 244 goes like this :
if (alertsOnBreakOut && trendp[whichBar] != trendp[whichBar+1])[/PHP]
[PHP] if (alertsOnBreakOut)
As of zero binding : it would need to be recoded completely (there is no way to do that without recoding). Will see what can be done to keep it as simple as possible (coding wise)
thanks a lot for this.., what line of code sud be changed to make it alert on every break.., just to learn the nuances of coding and is it possible to bind the donchian in a separate window to a value say 0 like an MACD?
thanks for everything.., now cannot wait to see what would come out of ur arsenal when it is made into a separate window 0 bound donchian..,
Just for curiosity sake.., i changed the code as u'd suggested
if (alertsOnBreakOut && trendp[whichBar] != trendp[whichBar+1])
If you want the alert on every bar that is breaking the channel up or down, change it to :
That should do it
but on gbp/usd today i was getting conflicting signals.., actually the price was breaking the upper band to the upside and i was getting alert correct, but as soon as the price came down the upper band., i was getting signal that the price broke the lower band.., can you please explain why this is happening. For others., when there was no break at all., it was signalling as the price broke the lower band or upper band.., what might be the mistake i made. What should be done to make it alert on closed bar.., i mean when the price breaks the donchian it is enough to get an alert on closed bar.., how????
Need Your HELP for this SAMPLE Learn EA....
Hi Mr. mladen,
Sorry If I'm disturbing you Sir'.
I need your HELP to adding code for trade can be CLOSE in the end of Hour ....
Sample : Open Trade 01:00 ------> Close 01.59
This is coding for that EA Sir'.
#property copyright "Test"
#property link "http://www.test.com"
extern int Secend = 3600;
//extern int Secend = 300;
extern double Lot = 1;
extern double SL = 10;
extern double TP = 5;
extern double Slippage_Open = 1;
extern double Slippage_Close = 1;
extern string Comments = "example";
extern int MagicNumber = 123456;
//| expert deinitialization function |
//| expert start function |
int Last_openorder_time = Secend+1 ;
int Last_historyorder_time = Secend+10;
if(OrdersTotal() > 0 )
OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES);
Last_openorder_time = TimeCurrent() - OrderOpenTime();
if( Last_openorder_time > Secend )
GetOrder ( "buy" ) ; return(0);
else if( OrdersHistoryTotal() > 0 )
OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);
Last_historyorder_time = TimeCurrent() - OrderOpenTime();
if( Last_historyorder_time > Secend )
// no opened orders yet, open the first order
else GetOrder ( "buy" );
//====================================== Send Order ===========================================
int GetOrder(string cmd)
double stoploss =0;
double takeprofit =0;
// pip multiplier needed for 5 digit brokers to convert point into pips
int pipMultiplier = 1;
if (Digits==3 || Digits==5) pipMultiplier=10;
if(cmd == "buy")
if(TP == 0 ) takeprofit = 0;
else takeprofit = MarketInfo(Symbol(),MODE_ASK) + TP * Point*pipMultiplier;
if(SL == 0 ) stoploss = 0;
else stoploss = MarketInfo(Symbol(),MODE_ASK) - SL * Point*pipMultiplier;
Print("Buy Order Sent With: Symbol=", Symbol(), " Lot=", Lot, " Price=", MarketInfo(Symbol(),MODE_ASK));
Ticket = OrderSend(Symbol(), OP_BUY, Lot, MarketInfo(Symbol(),MODE_ASK), Slippage_Open, stoploss, takeprofit, Comments, MagicNumber, 0, Blue);
if (Ticket < 0)
lastError = GetLastError(); // save last error because GetLastError() clears the error number and than you do not
// know what the error code was when calling ErrorDescription() function
Print("OrderSend failed with error #", lastError, " ", ErrorDescription(lastError));
else if(cmd == "sell")
else takeprofit = MarketInfo(Symbol(),MODE_BID) - TP * Point*pipMultiplier;
else stoploss = MarketInfo(Symbol(),MODE_BID) + SL * Point*pipMultiplier;
Print("Sell Order Sent With: Symbol=", Symbol(), " Lot=", Lot, " Price=", MarketInfo(Symbol(),MODE_BID));
Ticket = OrderSend(Symbol(), OP_SELL, Lot, MarketInfo(Symbol(),MODE_BID), Slippage_Open, stoploss, takeprofit, Comments, MagicNumber, 0, Blue);
lastError = GetLastError();
Thank you so much for your kindness and Helping Sir'.
Was it alerting only that it broke the level or was it possibly alert that the direction has changed too (since there are 2 kinds of alert - break out and direction change)? If it was the direction change, you can turn it of by setting the alertsOnDirectionChangeto false
No.., the alert on direction change is set to false only.., the problem is .., let me explain with the example of gbp/usd.., the price broke the upper band.., i got a signal the "the price broke the upper band", but as soon as the price came down the upper band.., the message is "the price broke the lower band". i got an alert in eur/chf which said the price broke the lower band, but there was no break that had happened. .., i might have made a mistake, but i don't know. What should be done to opt for an alert just 1 min before the bar close or on bar close;).., coz it is alerting as soon as the price breaks and not waiting for the candle close.
i'd changed this line
Regardless of the change of the code, if you set the alertsOnCurrent to false it will alert only on a first closed bar and then it will not repeat alerts - that should avoid the problem of changing alerts. if alertsOnCurrent is set to true, then it alerts on opened (current) bar and than it can give multiple alerts
As of eurchf alert : if you have multiple charts and indicator is attached to more than 1 chart, it will alert regardless of the active chart (alerts are not limited to the active chart - that is why the symbol is attached to alert message - to identify which symbol is alerting) so that alert was coming from eurchf chart not gbpusd
thanks a lot for solving this issue.., yes.., it was my fault.., the "alerts on current" was set to true.
Sorry to be bothering you so much with this issue., but treat it as a request to make a donchian with an alert on closed bar when it penetrates the upper/lower channel and everytime it is penetrated.., not only the first time because i think it is easier if you can check the code.., i switched to 1 min timeframe of gbp/usd.., to test with "alerts on current" set to false and "alert on direction change" set to false.., i think the alert function is unable to decide which is which band.., coz the price broke the middle band and i got the message., the price broke the upper band.
Which price broke the channel bands? By default (selectable by PriceToUseForBreakOut parameter) it is the close (not high or low) and in that case close is compared to bands. Also, in cases when you are switching time frame, in a moment when you switch to some time frame you can get an alert and then when data actually gets downloaded it turns out that the alert does not exist neither on a current nor on previous bar. It simply is the thing that metatrader does : while it waits for data to be downloaded it sends to an indicator variables that are actually wrong (the current time for example, and some other).
That is the only reason that comes to mind : indicator does recognize which is the bar it has to alert on and there is nothing that needs to be changed regarding that.
Also check if you are maybe using a mtf. In case when using mtf, then the target time frame data is used, not the current chart data (it works correctly even in the mtf mode since it strictly checks the target time frame, without unnecessary repeating the signal on a current time frame and that is how mtf should work)
the one that simply transfers what you had in previous version from main chart to separate window and adds the price you are monitoring to it (the blue line) like this (ZeroBind parameter set to false) :the one that zero binds the middle value and shows upper and lower bands values as values in points (so it is showing a real width of the channel - ZeroBind parameter set to true, Normalize parameter set to false) - like this :and the one that is normalized to -1 +1 range ZeroBind parameter set to true, Normalize parameter set to true) - like this