• Sign up >>

Requests & Ideas - page 60

Mladen Rakic
163288
Mladen Rakic  

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

Paulinge
106
Paulinge  

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
Paulinge
106
Paulinge  

" Need your HELP "

Hi Mr.mladen,

When I was compiled that source, why there is ERROR like this : " ) ' - wrong parameter count....

this is for code 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;

closeOrders();

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

}

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

//

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

//

//

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

}

}

}

Thank you so much for your kindness Sir' and helping me.

Please forgive if I'm disturbing you.

Best regards,

Paulinge

William Snyder
9493
William Snyder  
Paulinge:
Hi Mr.mladen,

When I was compiled that source, why there is ERROR like this : " ) ' - wrong parameter count....

this is for code 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;

closeOrders();

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

}

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

//

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

//

//

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

}

}

}

Thank you so much for your kindness Sir' and helping me.

Please forgive if I'm disturbing you.

Best regards,

Paulinge

Paulinge you were very close from what i can see you needed to add

closeOrders(OP_BUY,PERIOD_H1);

closeOrders(OP_SELL,PERIOD_H1);

right after the start routine, not 100% sure but think you can make the timeperiods an external parameter, which would make it easier to test other timeframes.

Files:
test.mq4 5 kb
paapi
32
paapi  

Hi Mladen..,

I think it is entirely out of the context of this thread, but it is just a question that has been sitting in the corner of my mind for a long time since i read it somewhere and since there were conflicting views, i was a little confused., but i think now you are the only right person that i can ask this, even though it sounds silly (the question that is), i think i should ask it to put an end to the speculation for my part though.

Is it possible for the MT4 broker to know what indicators i'm using while trading, the settings i'm using, etc., (not that i've found a holy grail, ha ha). Though it sounds a little on the edge of paranoia, there was a code developed by some guy to mask the winning EA or indicator u r using from the broker.

regards,

Paapi

Paulinge
106
Paulinge  

" The Sample of Simple learning EA "

Hi Mr. tools,

Thank you so much Sir'.... thank's for you have done !!!!

And now the Sample of EA was running well.....

You and Mr. mladen was a GREAT and a MASTER.....

Thank's GOD this forum have the both of you..... Very very nice and SMART people.. a Place to everybody can ask and discuss clearly.....

Thank you so much to both of you for helping and kindness.

Best regards,

Paulinge

mrtools:
Paulinge you were very close from what i can see you needed to add

closeOrders(OP_BUY,PERIOD_H1);

closeOrders(OP_SELL,PERIOD_H1);

right after the start routine, not 100% sure but think you can make the timeperiods an external parameter, which would make it easier to test other timeframes.
Mladen Rakic
163288
Mladen Rakic  

Flytox

Posted it here : https://www.mql5.com/en/forum/179686/page3

regards

Mladen

Flytox:
Hi Mr Mladen

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

Thx
Flytox
256
Flytox  

You rock Mr Mladen.

Thx again.

paapi
32
paapi  

Hi Mladen..,

I've got one more request. Can you please create an indicator that draws vertical lines on the chart depending on the GMT shift i want for each new day..., like if i want GMT+2, the indicator should draw vertical line at the start of new day for GMT+2 and this GMT shift should be changeable to whatever periods i want.

regards,

paapi

Paulinge
106
Paulinge  

" Need Your HELP "

Hi Mr.mladen,

Can you helping me to change code this indicator as to be visible in Chart, NOT in separate windows.

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

Best regards,

Paulinge