Market Order EA Slippage

Moderator: moderators

User avatar
MarketSlayer
rank: <50 posts
rank: <50 posts
Posts: 23
Joined: Mon Aug 31, 2009 10:57 pm
Reputation: 0
Gender: Male
Contact:

Market Order EA Slippage

Postby MarketSlayer » Sat Nov 07, 2009 10:47 pm

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?
Attachments
EA Market Orders LONG.mq4
(5.16 KiB) Downloaded 23 times

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

glenngie
rank: <50 posts
rank: <50 posts
Posts: 38
Joined: Sat Oct 03, 2009 4:51 am
Reputation: 0
Gender: None specified

Postby glenngie » Sun Nov 08, 2009 12:30 am

What broker are you with? Re-quoting brokers can cause havoc with orders.

User avatar
bredin
rank: 1000+ posts
rank: 1000+ posts
Posts: 1032
Joined: Mon Feb 16, 2009 10:41 pm
Reputation: 0
Gender: None specified
Contact:

Postby bredin » Sun Nov 08, 2009 12:50 am

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.
Welcome to the era of "Guns and Maskies" Trading!
The previous message contains discretion. Viewer nudity is advised.
Insanity Industries Indicators Here
Insanity Industries on YouTube!

User avatar
MarketSlayer
rank: <50 posts
rank: <50 posts
Posts: 23
Joined: Mon Aug 31, 2009 10:57 pm
Reputation: 0
Gender: Male
Contact:

Postby MarketSlayer » Sun Nov 08, 2009 2:19 pm

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?

User avatar
newschool
rank: 150+ posts
rank: 150+ posts
Posts: 489
Joined: Fri Aug 21, 2009 2:26 am
Reputation: 0
Gender: Male

Postby newschool » Sun Nov 08, 2009 8:25 pm

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.

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

User avatar
MarketSlayer
rank: <50 posts
rank: <50 posts
Posts: 23
Joined: Mon Aug 31, 2009 10:57 pm
Reputation: 0
Gender: Male
Contact:

Postby MarketSlayer » Mon Nov 09, 2009 12:06 am

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
Last edited by MarketSlayer on Wed Nov 18, 2009 1:35 pm, edited 2 times in total.

User avatar
bredin
rank: 1000+ posts
rank: 1000+ posts
Posts: 1032
Joined: Mon Feb 16, 2009 10:41 pm
Reputation: 0
Gender: None specified
Contact:

Postby bredin » Mon Nov 09, 2009 1:29 am

"uninit reason 5" and "uninit reason 3"

these arent trade condition errors.

Cheers
G
Welcome to the era of "Guns and Maskies" Trading!
The previous message contains discretion. Viewer nudity is advised.
Insanity Industries Indicators Here
Insanity Industries on YouTube!

User avatar
newschool
rank: 150+ posts
rank: 150+ posts
Posts: 489
Joined: Fri Aug 21, 2009 2:26 am
Reputation: 0
Gender: Male

Postby newschool » Mon Nov 09, 2009 1:40 am

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.

User avatar
MarketSlayer
rank: <50 posts
rank: <50 posts
Posts: 23
Joined: Mon Aug 31, 2009 10:57 pm
Reputation: 0
Gender: Male
Contact:

Postby MarketSlayer » Mon Nov 09, 2009 3:37 am

This is with forex.com... It is a 4 digit price..
Should I change the slippage variable to 0.0003, or 0.0010 ??

User avatar
newschool
rank: 150+ posts
rank: 150+ posts
Posts: 489
Joined: Fri Aug 21, 2009 2:26 am
Reputation: 0
Gender: Male

Postby newschool » Tue Nov 10, 2009 10:23 pm

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.

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.


Return to “MetaTrader”