Hi All,
I originally posted this as a new thread, but it was moved into another programming thread (I have no objections to its move BTW) and now seems to have got lost due to the amount of posters in that thread.
Perhaps someone here can help me?
I have nearly finished my first EA after nearly 7 days of trial and error and cutting and pasting and hours of research....
Can someone please tell me how to issue an exit or stop function to an EA?
I want the EA to delete all current and pending trades and exit after reaching 10,000 in equity. Below is that portion of the code so far:
PHP Code:
bool StopTrade;
int total = OrdersTotal(), cnt = 0, ExitAtEquity=10000;
for (cnt = total ; cnt >=0 ; cnt-- )
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (AccountEquity ()== ExitAtEquity)//(TimeCurrent()- OrderOpenTime() >= ActiveMinutes*60 )
{if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
if(OrderType()>OP_SELL)
OrderDelete(OrderTicket());
StopTrade=true;}
}
if (dclose==dopen && OrdersTotal() < ConcurrentTrades && StopTrade != true)
As you can see, the EA looks at the Equity and then sets the bool value of the StopTrade variable to true. The EA then acknowledges the command and does not process anything under the StopTrade != true for one cycle, but then the bool value of the StopTrade gets reset I guess and trades continue.
Firstly, is there anyway for me to get this to do what I need it to do in the manner in which I am doing it?
Secondly, is there a function that I can use to simply tell the EA to quit?
All assistance is greatly appreciated.
NB.
Quote:
|
cutzpr - How Many Currently open Buy, and Sell Orders from EA
|
I think part of my code can help you with what you need.