Jump to content

⤴️-Paid Ad- Check advertising disclaimer here. Add your banner here.🔥

Recommended Posts

Posted (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 by zoop
Posted

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);

}

Posted

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

Posted

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())

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

⤴️-Paid Ad- Check advertising disclaimer here. Add your banner here.🔥

×
×
  • Create New...