How obtain the sum of last row of losses

 

I want to adjust the Take profit to recover all losses row for a given Currency Pair.

Assume The results for GBPUSD closed trades are : -20 , 14 , 30 , -34 , 32 , -12 , -13 ,-34

The expert need to sum the last loses row Only in this case Sum=(-12)+(-13)+(-34)=-59 $

Then Calculated_Take_Profit = abs(Sum)/(PIP_Price_Value X lots Size) (divide by PIP value to compare it with Default_Take_Profit)

Default_Take_Profit= 50 ( user input as pips)

IF (  Calculated_Take_Profit <= Default_Take_Profit) Take_Profit=Default_Take_Profit

Else Take_Profit=Calculated_Take_Profit

if last closed Trade was positive For example : -20 , 14 , 30 , -34 , 32 , -12 , -13 ,-34 , 5

Then :  Take_Profit=Default_Take_Profit

I need the help to find the Sum variable Then Create Take Profit variable for MT4 

Note :

I want to update MACD sample Expert with this change and test it 

Thank you  

Reason: