Topic: Add TakeProfit in Percent in Portfolio?
Hi,
i like to mod my Portfolio Ea with a special function. I want to Close all trades if % profit reached.
I tried this out with a input amount and it is working. But how i have to change this when i want to say if 5% profit reached close all trades?
THE INPUT:
input bool useTakeProfitBasket = true; // USE TAKEPROFIT BASKET
input double TakeProfitBasket = 100;
ON ON TICK I ADD THIS:
void OnTick()
{
if(useTakeProfitBasket && (Open_Orders_Profit()>=TakeProfitBasket))
{
CloseAllPositions();
Print("Take Profit Basket Reached. All Trades CLOSED!");
printf("Take Profit Basket Reached. All Trades CLOSED!");
Alert("Take Profit Basket Reached. All Trades CLOSED!");
Comment("Take Profit Basket Reached. All Trades CLOSED!");
}
and i have this function added to get Profit of open orders.
double Open_Orders_Profit()
{
double openordersprofit = 0;
RefreshRates();
int Total=OrdersTotal();
if(Total>0)
{
for(int i=Total-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==TRUE)
{
const int magicNumber = OrderMagicNumber();
if(OrderSymbol()==Symbol() && (1000 * Base_Magic_Number <= magicNumber && magicNumber < (1000 * Base_Magic_Number + 100)))
{
openordersprofit +=OrderProfit()+OrderSwap()+OrderCommission();
}
}
}
}
return(openordersprofit);
}
Can someone help me out to change this to have it in percent?