zoop Posted November 25, 2011 Report Share Posted November 25, 2011 (edited) 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 November 25, 2011 by zoop Quote Link to comment Share on other sites More sharing options...
mutant Posted November 30, 2011 Report Share Posted November 30, 2011 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); } zoop 1 Quote Link to comment Share on other sites More sharing options...
zoop Posted November 30, 2011 Author Report Share Posted November 30, 2011 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 Quote Link to comment Share on other sites More sharing options...
iwjw Posted November 30, 2011 Report Share Posted November 30, 2011 You can get the info from the orderhistory OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY); Think you only have to check the latest order if(OrderClosePrice()==OrderStopLoss() || OrderClosePrice()==OrderTakeProfit()) ...do whatever is needed (CloseAll()) zoop 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.