Requests & Ideas - page 58

 

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"

#include

//+------------------------------------------------------------------+

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;

//+------------------------------------------------------------------+

int init()

{

//----

start();

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

//----

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 )

{

GetOrder ( "buy" ) ; return(0);

}

}

//

//

//

// no opened orders yet, open the first order

//

//

else GetOrder ( "buy" );

//----

return(0);

}

//====================================== Send Order ===========================================

int GetOrder(string cmd)

{

double stoploss =0;

double takeprofit =0;

int Ticket=0;

int lastError=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")

{

if(TP == 0 ) takeprofit = 0;

else takeprofit = MarketInfo(Symbol(),MODE_BID) - TP * Point*pipMultiplier;

if(SL == 0 ) stoploss = 0;

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);

if (Ticket < 0)

{

lastError = GetLastError();

Print("OrderSend failed with error #", lastError, " ", ErrorDescription(lastError));

}

}

return (Ticket);

}

Thank you so much for your kindness and Helping Sir'.

Best regards,

Paulinge

 

paapi

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

paapi:
Hi Mladen..,

Just for curiosity sake.., i changed the code as u'd suggested

Line 244 goes like this :

PHP Code:

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 :

PHP Code:

if (alertsOnBreakOut)

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.
 

Hi Mladen..,

Just for curiosity sake.., i changed the code as u'd suggested

Line 244 goes like this :

PHP Code:

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 :

PHP Code:

if (alertsOnBreakOut)

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

 
mladen:
paapi 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

Hi Mladen..,

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

if (alertsOnBreakOut && trendp[whichBar] != trendp[whichBar+1])

to

if (alertsOnBreakOut)

regards,

paapi

 

paapi

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

paapi:
Hi Mladen..,

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

if (alertsOnBreakOut && trendp[whichBar] != trendp[whichBar+1])

to

if (alertsOnBreakOut)

regards,

paapi
 

Hi Mladen..,

thanks a lot for solving this issue.., yes.., it was my fault.., the "alerts on current" was set to true.

 

Hi Mladen..,

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.

regards,

paapi

 

Hi Mladen..,

I am speechless.., thanks a lot for this new indi from you.

 

paapi

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)

___________________________________

Now the continuance : the separate window version. Depending on the parameters you have 3 sub-versions :
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
In the examples I kept the donchian channel 2 on the main chart in order to show how it compares to this version
Files:
dc_-_1.gif  25 kb
dc_-_2.gif  27 kb
dc_-_3.gif  27 kb
 

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

paapi:
Hi Mladen.., I am speechless.., thanks a lot for this new indi from you.