Please how do I get a close trade close in pips

 

Please I am building an ea that uses martingale, I want to know a loss trade loss in pips whether the trade is closed before hitting SL or it close hitting SL all I want is to get the loss in pips which the next trade TP will be that loss trade pips. So even if next trade loss or any amount of trade loss the next trade will add that loss trade in pips as TP let say first trade you loss 20 pips the next trade TP is 20 pips which if this second trade loss let say it loss 20 pips so the next trade TP will be 40 pips and if this next trade loss let say it close 10 pips the next trade TP will be 50 pips and so on so if a trade win which the loss trade pips win the martingale will reset. So whether the trade close hitting SL or close without hitting SL once the trade close in negative that means close in (-) that means close in a loss in pips. I have tried to do it but can't figure it out, I have used OrderHistoryTotal function still can't figure it out

This is the code 

#property copyright "Andrew Young"
// External variables
extern double LotSize = 0.1;
extern double StopLoss = 50;
extern double TakeProfit = 100;
extern int Slippage = 5;
extern int MagicNumber = 123;
extern int FastMAPeriod = 10;
extern int SlowMAPeriod = 20;
// Global variables
int BuyTicket;
int SellTicket;
double UsePoint;
int UseSlippage;
// Init function
int init()
{
UsePoint = PipPoint(Symbol());
UseSlippage = GetSlippage(Symbol(),Slippage);
}
// Start function
int start()
{
// Moving averages
double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);
double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);

// Buy order
if(FastMA > SlowMA && BuyTicket == 0)
{
OrderSelect(SellTicket,SELECT_BY_TICKET);
// Close order
if(OrderCloseTime() == 0 && SellTicket > 0)
{
double CloseLots = OrderLots();
double ClosePrice = Ask;
bool Closed = OrderClose(SellTicket,CloseLots,ClosePrice,UseSlippage,Red);
}
double OpenPrice = Ask;
// Calculate stop loss and take profit
if(StopLoss > 0) double BuyStopLoss = OpenPrice - (StopLoss * UsePoint);
if(TakeProfit > 0) double BuyTakeProfit = OpenPrice + (TakeProfit * UsePoint);
// Open buy order
BuyTicket = OrderSend(Symbol(),OP_BUY,LotSize,OpenPrice,UseSlippage,
BuyStopLoss,BuyTakeProfit,"Buy Order",MagicNumber,0,Green);
SellTicket = 0;
}
// Sell Order
if(FastMA < SlowMA && SellTicket == 0)
{
OrderSelect(BuyTicket,SELECT_BY_TICKET);
if(OrderCloseTime() == 0 && BuyTicket > 0)
{
CloseLots = OrderLots();
ClosePrice = Bid;
Closed = OrderClose(BuyTicket,CloseLots,ClosePrice,UseSlippage,Red);
}
OpenPrice = Bid;
if(StopLoss > 0) double SellStopLoss = OpenPrice + (StopLoss * UsePoint);
if(TakeProfit > 0) double SellTakeProfit = OpenPrice - (TakeProfit * UsePoint);
SellTicket = OrderSend(Symbol(),OP_SELL,LotSize,OpenPrice,UseSlippage,
SellStopLoss,SellTakeProfit,"Sell Order",MagicNumber,0,Red);
BuyTicket = 0;
}
return(0);
}
// Pip Point Function
double PipPoint(string Currency)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2 || CalcDigits == 3) double CalcPoint = 0.01;
else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
return(CalcPoint);
}
// Get Slippage Function
int GetSlippage(string Currency, int SlippagePips)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2 || CalcDigits == 4) double CalcSlippage = SlippagePips;
else if(CalcDigits == 3 || CalcDigits == 5) CalcSlippage = SlippagePips * 10;
return(CalcSlippage);
}

Please help me guys

 
Paul peter: Please I am building an ea that uses martingale, I

Hedging, grid trading, same as Martingale.
          Martingale, Hedging and Grid : MHG - General - MQL5 programming forum (2016)

Martingale, guaranteed to blow your account eventually. If it's not profitable without, it is definitely not profitable with.
          Martingale vs. Non Martingale (Simplified RoR vs Profit and the Illusions) - MQL5 programming forum (2015)

Why it won't work:
          Calculate Loss from Lot Pips - MQL5 programming forum (2017)
          THIS Trading Strategy is a LIE... I took 100,000 TRADES with the Martingale Strategy - YouTube (2020)