Page 1 of 1

Market Order EA Slippage

Posted: Sat Nov 07, 2009 10:47 pm
by MarketSlayer
I wrote an EA that simply blasts in 3 orders at the market. It sets a 15 pip stop and order 1 has a Take Profit of 10, Order 2 has Take Profit of 20 and order 3 has Take Profit of 30 for example.
Many times when I apply the EA to a chart it won't fill, I think it is slippage etc. Any ideas how to loop through an error condition until all three orders are placed?

Posted: Sun Nov 08, 2009 12:30 am
by glenngie
What broker are you with? Re-quoting brokers can cause havoc with orders.

Posted: Sun Nov 08, 2009 12:50 am
by bredin
Error control 101:

1. Whats the journal tab telling you the error is?

2. look up that error at docs.mql4.com

3. find a workaround

personally Id use a different magic number for each trade and process accordingly.


Cheers
G.

Posted: Sun Nov 08, 2009 2:19 pm
by MarketSlayer
I did check both logs and saw Reason 3 and Reason 5....
Here is what I tried with a similar script:
//--------------------------------------------------------------------7 --
if (ticket_1 >0 && ticket_2 >0 && ticket_3 >0 ) // Got it!:)
{
Alert ("Opened All 3 orders ");
break; // Exit cycle
}
//--------------------------------------------------------------------8 --
int Error=GetLastError(); // Failed :(
switch(Error) // Overcomable errors
{
case 135:Alert("The price has changed. Retrying..");
RefreshRates(); // Update data
continue; // At the next iteration
case 136:Alert("No prices. Waiting for a new tick..");
while(RefreshRates()==false) // Up to a new tick
Sleep(1); // Cycle delay
continue; // At the next iteration
case 146:Alert("Trading subsystem is busy. Retrying..");
Sleep(500); // Simple solution
RefreshRates(); // Update data
continue; // At the next iteration
}
switch(Error) // Critical errors
{
case 2 : Alert("Common error.");
break; // Exit 'switch'
case 5 : Alert("Outdated version of the client terminal.");
break; // Exit 'switch'
case 64: Alert("The account is blocked.");
break; // Exit 'switch'
case 133:Alert("Trading forbidden");
break; // Exit 'switch'
default: Alert("Occurred error ",Error);// Other alternatives
}
break; // Exit cycle
}
How do you suggest I use the Magic Number?

Posted: Sun Nov 08, 2009 8:25 pm
by newschool
To the OP, go in the journal and tell me what exact error code.

If you think its slippage, change it to 10 pips that will tell you if this is problem or somethingelse.

Posted: Mon Nov 09, 2009 12:06 am
by MarketSlayer
The EA Log shows two errors. I would load the EA on the chart....then when I wanted it to run, I would change the property "Trade Live" by selecting the check box, then hit ok... So the two errors I am seeing are:
"uninit reason 5" and "uninit reason 3"

When it worked it shows this...
05:17:21 EA Market Orders Short GBPUSDFXF,M15: loaded successfully
05:17:26 EA Market Orders Short GBPUSDFXF,M15: initialized
05:17:26 EA Market Orders Short GBPUSDFXF,M15: SHORT EA STARTING
05:17:26 EA Market Orders Short GBPUSDFXF,M15: 1 FUNCTION - f_Place_Orders - STARTING
05:17:29 EA Market Orders Short GBPUSDFXF,M15: open #8824069 sell 0.03 GBPUSDFXF at 1.6522 sl: 1.6537 tp: 1.6502 ok
05:17:31 EA Market Orders Short GBPUSDFXF,M15: open #8824071 sell 0.03 GBPUSDFXF at 1.6522 sl: 1.6537 tp: 1.6482 ok
05:17:32 EA Market Orders Short GBPUSDFXF,M15: open #8824073 sell 0.03 GBPUSDFXF at 1.6522 sl: 1.6537 tp: 1.6422 ok

When it doesn't work it shows this:
05:20:00 EA Market Orders Short GBPUSDFXF,M15: initialized
05:20:00 EA Market Orders Short GBPUSDFXF,M15: SHORT EA STARTING
05:20:00 EA Market Orders Short GBPUSDFXF,M15: 4 FUNCTION - f_Check_if_TP1_filled - STARTING
05:20:00 EA Market Orders Short GBPUSDFXF,M15: 4 FUNCTION - TP1 SHORT IS HIT
05:20:00 EA Market Orders Short GBPUSDFXF,M15: 4 FUNCTION - f_Check_if_TP1_filled - ENDING
05:20:00 EA Market Orders Short GBPUSDFXF,M15: SHORT EA STARTING
05:20:00 EA Market Orders Short GBPUSDFXF,M15: 4 FUNCTION - f_Check_if_TP1_filled - STARTING
05:20:00 EA Market Orders Short GBPUSDFXF,M15: 4 FUNCTION - TP1 SHORT IS HIT
05:20:00 EA Market Orders Short GBPUSDFXF,M15: 4 FUNCTION - f_Check_if_TP1_filled - ENDING

Posted: Mon Nov 09, 2009 1:29 am
by bredin
"uninit reason 5" and "uninit reason 3"

these arent trade condition errors.

Cheers
G

Posted: Mon Nov 09, 2009 1:40 am
by newschool
Are you testing with a 5 digits broker?

Because I checked your code and you only use "3" as slippage, that can be 3 pips or 0.3 pips.

Posted: Mon Nov 09, 2009 3:37 am
by MarketSlayer
This is with forex.com... It is a 4 digit price..
Should I change the slippage variable to 0.0003, or 0.0010 ??

Posted: Tue Nov 10, 2009 10:23 pm
by newschool
I checked and it seems good... the only thing I can see is that you "clog" the buy function.

Eitherways, I think you are wasting your time trying to code an EA, while you can a perfect blueprint here : http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/

Just enter some basic triggers then modify the rest directly on the code on your PC, since it generate MQ4 files you can download.