HELP! Code Not working right

NewBie Here…
So I’m trying to write a code that closes all open trades when it reaches a net profit. The problem is that the code is closing on a negative. Please, what am I doing wrong…

#include <Trade\Trade.mqh>

CTrade trade;

input int TakeProfit =100;
void OnTick()
{
//Get Ask Price

// Get The Balance
double Balance = AccountInfoDouble(ACCOUNT_BALANCE);

double profit = AccountInfoDouble(ACCOUNT_PROFIT);

//Get the Equity
double Equity = AccountInfoDouble(ACCOUNT_EQUITY); 

if(MathAbs(profit)>TakeProfit)

CloseAllPosition();

}
//±-----------------------------------------------------------------+

void CloseAllPosition()
{
for(int i=PositionsTotal()-1; i>=0; i–)
{

 int ticket= PositionGetTicket(i);
 
 //Get Position Direction
 int PositionDirection=PositionGetInteger(POSITION_TYPE);
 
 //if it is a buy position 
 if(PositionDirection==POSITION_TYPE_BUY)
 trade.PositionClose(ticket);
 
 if(PositionDirection==POSITION_TYPE_SELL)
 trade.PositionClose(ticket);
  
 }

}

// if(MathAbs(profit)>TakeProfit)
if (profit > TakeProfit)
1 Like

Thanks!! that fixed it…

Thanks @mql5com for your correct answer