
01-04-2007, 02:41 PM
|
|
Senior Member
|
|
Join Date: Dec 2006
Posts: 109
|
|
|
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.
|
|