zoop Posted November 25, 2011 Report 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
mutant Posted November 30, 2011 Report 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
zoop Posted November 30, 2011 Author Report 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
iwjw Posted November 30, 2011 Report 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now