In search of close all by percentage loss

 

Hello

I have been trying to find a close all ea the uses a percentage eg if the account equity is 15% lower than the account balance close all positions.

any help would be great

cheers

kiwi

 

pseudocode:

....

// flag management

equity = AccountEquity( );

balance = AccountBalance();

if( loss is above 15%)

GlobalVariableSet("full_house_close",1);

if(OrdersTotal()==0) // or you can put flag full_house_close to 0/1 directly in "terminal->tools->Global Variables"

GlobalVariableSet("full_house_close",0);

....

//positions closing

bool full_house_close = GlobalVariableGet("full_house_close");

if(full_house_close)

{

....

}


/*

it is necessary to keep the flag to close persistent because, after closing some positions the difference between balance and equity goes below 15% and remaining orders will not be shut.

*/