compiles but won't work
extern double My_Money_Profit_Target=60; //The amount of money profit at which you want to close ALL open trades. int Slippage=5; int i; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int Profit_Target=(AccountBalance()*0.001); if (Hour()>23 || Hour()<22 && AccountProfit()>=Profit_Target) { for(i=OrdersTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); int type = OrderType(); bool result = false; switch(type) { //Close opened long positions case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Blue); break; } if(result == false) { Sleep(1000); } } Print ("Account Profit Reached. All Open Trades Have Been Closed"); Comment("Risk has been removed..all trades closed!"); PlaySound("money.wav"); return(0); } Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(), " My Account Profit Target: ", My_Money_Profit_Target); return(0); }
syntax might be correct.... but what do you expect it would do? Maybe it better to make a plan for your EA and then code it.
Russell
1. I didn't find how you use the variable My_Money_Profit_Target
2.Why do you close Buy orders only?
I want it to close the orders once the profit target is reached-which I want to be 1% of the balance. I don't want to keep changing an external input. Also, I only buy......not sell. Please help.......
Can anyone help me with this? It compiles but does not work.....maybe I have something in the wrong place or wrong syntax? Thank you in advance......
extern double My_Money_Profit_Target=60; //The amount of money profit at which you want to close ALL open trades.
int Slippage=5;
int i;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int Profit_Target=(AccountBalance()*0.001);
if (Hour()>23 || Hour()<22 && AccountProfit()>=Profit_Target)
{
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Blue);
break;
}
if(result == false)
{
Sleep(1000);
}
}
Print ("Account Profit Reached. All Open Trades Have Been Closed");
Comment("Risk has been removed..all trades closed!");
PlaySound("money.wav");
return(0);
}
Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
" My Account Profit Target: ", My_Money_Profit_Target);
return(0);
}