Jump to content

REQ: If close one the close all


zoop

Recommended Posts

how would i add this code to my hedge EA?

 

i have the close all code working closeallpostions ();

 

i need to add if any order is closed either by stoploss or take profit then closeallpostions(); is activated

 

how would i do this with a simple few line if possible?

 

 

thanks Zoop

Edited by zoop
Link to comment
Share on other sites

extern double My_Money_Profit_Target=300; //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()

{

if (AccountProfit()>= My_Money_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,Pink);

break;

 

//Close opened short positions

case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Pink);

 

}

 

if(result == false)

{

Sleep(3000);

}

}

Print ("Account Profit Reached. All Open Trades Have Been Closed");

return(0);

}

 

Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),

"\nMy Account Profit Target: ",My_Money_Profit_Target);

 

return(0);

}

Link to comment
Share on other sites

thanks Mutant, but its not the profit target im after, but its to do with losing a hedge trade

 

we start buying and selling in basket style, when we reach a price point we close

 

but what i need is , if any single open order is closed for any reason before we reach our price point, we close the whole basket

 

Zoop

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...