Forex



Go Back   Forex Trading > Discussion Areas > Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 01-04-2007, 02:41 PM
Senior Member
 
Join Date: Dec 2006
Posts: 109
dwmcqueen is on a distinguished road
Questions on simple EA

This is just an EA I created for testing. This EA just is supposed to open a trade and close it every few minutes. However, the close always fails with a 129 error (bad price). Any ideas?


Quote:
extern double TakeProfit = 50;
extern double Lots = 0.1;
extern double TrailingStop = 30;

datetime LastDateSnap;
bool OpenCloseFlag;
int ticket;

//Open is true, close is false
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
LastDateSnap = CurTime();
OpenCloseFlag = false;
Print("Starting at", LastDateSnap);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
Print("Starting");
// If one minute from LastDateSnap - open trade
if (CurTime() - LastDateSnap > 5)
{
if (OpenCloseFlag == true)
{
OrderClose(ticket,Lots,Bid,3,Violet);
OpenCloseFlag = false;
Print("Switching to false");
}
else
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid -TakeProfit*Point,"TestingEA",0,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());

OpenCloseFlag = true;
Print("Switching to true");
}
LastDateSnap = CurTime();
}

return(0);
}
// the end.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 01-04-2007, 02:55 PM
jlpi's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 336
jlpi is an unknown quantity at this point
I had a look at it quickly and I think that the mistake is that you try to close a sell order at the Bid price. Replace Bid by Ask in the close order and see if that works.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MT3 Questions Nicholishen Metatrader 3 11 11-15-2008 11:54 PM
MT4 (Basic) Questions stepwise Metatrader 4 6 09-22-2008 03:22 AM
2 questions on codergurus course hayseed Setup Questions 3 12-07-2006 11:56 PM
Beginner questions. Thanks Locutus General Discussion 2 10-11-2006 08:26 PM


All times are GMT. The time now is 10:54 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.