Metatrader 5 coding questions / issues - page 11

 
dr.house7:
this is the Journal:

2013.10.18 15:35:42 2013.05.20 00:06:02 failed instant sell 3.00 EURUSD at 1.28444

2013.10.18 15:35:42 2013.05.20 00:06:01 failed instant sell 3.00 EURUSD at 1.28445

2013.10.18 15:35:42 2013.05.20 00:06:00 close sell

2013.10.18 15:35:42 2013.05.20 00:06:00 order performed buy 3.00 at 1.28483 [#3 buy 3.00 EURUSD at 1.28483]

2013.10.18 15:35:42 2013.05.20 00:06:00 deal performed [#3 buy 3.00 EURUSD at 1.28483]

2013.10.18 15:35:42 2013.05.20 00:06:00 deal #3 buy 3.00 EURUSD at 1.28483 done (based on order #3)

2013.10.18 15:35:42 2013.05.20 00:06:00 instant buy 3.00 EURUSD at 1.28483 (1.28444 / 1.28483 / 1.28444)

2013.10.18 15:35:42 2013.05.20 00:06:00 price corrected from 1.28444 to 1.28483, deviation: 10000 (instant buy 3.00 EURUSD at 1.28444)(1.28444 / 1.28483 / 1.28444)

2013.10.18 15:35:42 2013.05.20 00:05:59 order performed sell 3.00 at 1.28444 [#2 sell 3.00 EURUSD at 1.28444]

2013.10.18 15:35:42 2013.05.20 00:05:59 deal performed [#2 sell 3.00 EURUSD at 1.28444]

2013.10.18 15:35:42 2013.05.20 00:05:59 deal #2 sell 3.00 EURUSD at 1.28444 done (based on order #2)

2013.10.18 15:35:42 2013.05.20 00:05:59 instant sell 3.00 EURUSD at 1.28444 (1.28444 / 1.28472 / 1.28444)

Doc

I can not compile the EA (getting error "can not open mql4_Lib.mqh" include file). Can you post that file too?

 
mladen:
Doc I can not compile the EA (getting error "can not open mql4_Lib.mqh" include file). Can you post that file too?

here we go...but it's only for the time filter (scantrades is not used)

Files:
mql4_lib.mqh  55 kb
 
dr.house7:
here we go...but it's only for the time filter (scantrades is not used)

Doc

Try adding these lines :

OpenBuySignal = 0;

OpenSellSignal = 0;

CloseBuySignal = 0;

CloseSellSignal = 0;

[/PHP]

In front of this block :

[PHP] if((firstindicator[0]>secondindicator[0])&&(spread<=maxspread)&& timecond && getLastOrderType(_Symbol)!=1) OpenBuySignal = 1;

if((firstindicator[0]<secondindicator[0])&&(spread<=maxspread)&& timecond && getLastOrderType(_Symbol)!=0) OpenSellSignal = 1;

if(((firstindicator[0]<secondindicator[0])&&(spread<=maxspread))) CloseBuySignal = 1;

if(((firstindicator[0]>secondindicator[0])&&(spread<=maxspread))) CloseSellSignal = 1;

Those variables should be cleaned up on each tick (otherwise they could have a state from some time ago and they could cause an error)

 
mladen:
Doc

Try adding these lines :

OpenBuySignal = 0;

OpenSellSignal = 0;

CloseBuySignal = 0;

CloseSellSignal = 0;

[/PHP]

In front of this block :

[PHP] if((firstindicator[0]>secondindicator[0])&&(spread<=maxspread)&& timecond && getLastOrderType(_Symbol)!=1) OpenBuySignal = 1;

if((firstindicator[0]<secondindicator[0])&&(spread<=maxspread)&& timecond && getLastOrderType(_Symbol)!=0) OpenSellSignal = 1;

if(((firstindicator[0]<secondindicator[0])&&(spread<=maxspread))) CloseBuySignal = 1;

if(((firstindicator[0]>secondindicator[0])&&(spread<=maxspread))) CloseSellSignal = 1;

Those variables should be cleaned up on each tick (otherwise they could have a state from some time ago and they could cause an error)

OK

the first problem seems gone, but I got again this other one:

2013.10.18 16:17:22 2013.05.20 01:00:42 failed instant buy 3.01 EURUSD at 1.28342

 
dr.house7:
OK

the first problem seems gone, but I got again this other one:

2013.10.18 16:17:22 2013.05.20 01:00:42 failed instant buy 3.01 EURUSD at 1.28342

Doc

Try rounding (normalizing) the lot size. Something like this :

lots = NormalizeDouble(0.0001*LotsPct*AccountInfoDouble(ACCOUNT_BALANCE),0);

if (lot_min==0.01) lots = NormalizeDouble(0.0001*LotsPct*AccountInfoDouble(ACCOUNT_BALANCE),2);

if (lot_min==0.1) lots = NormalizeDouble(0.0001*LotsPct*AccountInfoDouble(ACCOUNT_BALANCE),1);

 
mladen:
Doc

Try rounding (normalizing) the lot size. Something like this :

lots = NormalizeDouble(0.0001*LotsPct*AccountInfoDouble(ACCOUNT_BALANCE),0);

if (lot_min==0.01) lots = NormalizeDouble(0.0001*LotsPct*AccountInfoDouble(ACCOUNT_BALANCE),2);

if (lot_min==0.1) lots = NormalizeDouble(0.0001*LotsPct*AccountInfoDouble(ACCOUNT_BALANCE),1);

Mladen,

thanks to you, everything looks good now!

just another thing...I saw the ea waiting 1 tick from close 1 deal to open a new one...do you know a trick to make ea able to close and open a new position (when this happen) in the same moment?

 

Doc,

As far as I know it can not be done

 
mladen:
Doc, As far as I know it can not be done

so bad

 

Mladen,

I got again a problem...as you can see here, the ea close the first deal of 1 lot with 3 lots. I don't have any martingale so how is it possible?

2013.10.18 18:17:43 2013.09.05 09:44:37 close sell

2013.10.18 18:17:43 2013.09.05 09:44:37 order performed buy 3.00 at 1.31770 [#3 buy 3.00 EURUSD at 1.31770]

2013.10.18 18:17:43 2013.09.05 09:44:37 deal performed [#3 buy 3.00 EURUSD at 1.31770]

2013.10.18 18:17:43 2013.09.05 09:44:37 deal #3 buy 3.00 EURUSD at 1.31770 done (based on order #3)

2013.10.18 18:17:43 2013.09.05 09:44:37 instant buy 3.00 EURUSD at 1.31770 (1.31763 / 1.31770 / 1.31763)

2013.10.18 18:17:43 2013.09.05 09:44:37 price corrected from 1.31902 to 1.31770, deviation: 10000 (instant buy 3.00 EURUSD at 1.31902)(1.31763 / 1.31770 / 1.31763)

2013.10.18 18:07:46 2013.09.05 04:43:59 order performed sell 1.00 at 1.31902 [#2 sell 1.00 EURUSD at 1.31902]

2013.10.18 18:07:46 2013.09.05 04:43:59 deal performed [#2 sell 1.00 EURUSD at 1.31902]

2013.10.18 18:07:46 2013.09.05 04:43:59 deal #2 sell 1.00 EURUSD at 1.31902 done (based on order #2)

2013.10.18 18:07:46 2013.09.05 04:43:59 instantsell 1.00 EURUSD at 1.31902 (1.31902 / 1.31907 / 1.31902)

 
dr.house7:
Mladen,

I got again a problem...as you can see here, the ea close the first deal of 1 lot with 3 lots. I don't have any martingale so how is it possible?

2013.10.18 18:17:43 2013.09.05 09:44:37 close sell

2013.10.18 18:17:43 2013.09.05 09:44:37 order performed buy 3.00 at 1.31770 [#3 buy 3.00 EURUSD at 1.31770]

2013.10.18 18:17:43 2013.09.05 09:44:37 deal performed [#3 buy 3.00 EURUSD at 1.31770]

2013.10.18 18:17:43 2013.09.05 09:44:37 deal #3 buy 3.00 EURUSD at 1.31770 done (based on order #3)

2013.10.18 18:17:43 2013.09.05 09:44:37 instant buy 3.00 EURUSD at 1.31770 (1.31763 / 1.31770 / 1.31763)

2013.10.18 18:17:43 2013.09.05 09:44:37 price corrected from 1.31902 to 1.31770, deviation: 10000 (instant buy 3.00 EURUSD at 1.31902)(1.31763 / 1.31770 / 1.31763)

2013.10.18 18:07:46 2013.09.05 04:43:59 order performed sell 1.00 at 1.31902 [#2 sell 1.00 EURUSD at 1.31902]

2013.10.18 18:07:46 2013.09.05 04:43:59 deal performed [#2 sell 1.00 EURUSD at 1.31902]

2013.10.18 18:07:46 2013.09.05 04:43:59 deal #2 sell 1.00 EURUSD at 1.31902 done (based on order #2)

2013.10.18 18:07:46 2013.09.05 04:43:59 instantsell 1.00 EURUSD at 1.31902 (1.31902 / 1.31907 / 1.31902)

Doc

From the code it should not be possible (since your code would open buy only if there is no open position for that symbol) but have to check more