Cant get positionclosepatial to work once

 

i am a beginner to coding mql5 language. i was able to get the positionclosepartial to work but it keep running on the same position each time a new position opens.

please can anyone help me fix this problem?

//+------------------------------------------------------------------+
//|                                                 ONTIMER BOOM.mq5 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+

#include<Trade/trade.mqh>
CTrade trade;


input double LotSize = 1.0; //Lotsize
input int TakeProfitInPips = 20000; //Take Profit Pips
//input int StopLossInPips = 2000000; //Take Profit Pips

int OnInit()
  {
//--- create timer
   EventSetTimer(5);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 
  }
  
  void BuyOrder()
  {
      double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
      double TakeProfit = Ask + TakeProfitInPips*_Point;
      if(PositionsTotal()>=0){
      trade.Buy(LotSize,_Symbol,Ask,0,TakeProfit,NULL);
      
      }
      
   ChangePositionSize(Ask);
   
        
  }
  
  
  
  void ChangePositionSize(double Ask)
  {
   for(int i=PositionsTotal()-1; i>=0; i--)
   {
      string symbol=PositionGetSymbol(i);
      
     if (_Symbol==symbol)
     {
      ulong PositionTicket=PositionGetInteger(POSITION_TICKET);
      
      long PositionDirection=PositionGetInteger( POSITION_TYPE ); 
      
      if(PositionDirection==POSITION_TYPE_BUY) { 
         
         trade.PositionClosePartial(PositionTicket,0.20);
      }
      
    }
      
   }
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
      BuyOrder();   
  }
//+------------------------------------------------------------------+



Reason: