Partial close orders

 
if(PositionsTotal()>0){
for(int i=PositionsTotal()-1; i>=0; i--){
string symbol=PositionGetSymbol(i);
if(_Symbol==symbol)
{
ulong Ticket = PositionGetInteger(POSITION_TICKET);
double sl = PositionGetDouble(POSITION_SL);
double tp = PositionGetDouble(POSITION_TP);
double price = PositionGetDouble(POSITION_PRICE_OPEN);
double volume = Position

//buy
if(tp>sl){
if( trade.ResultVolume()==0.02){
if(price+0.5*(tp-price)<=Ask){
bool res=trade.PositionClosePartial(Ticket,0.01,1);
}}}



//sell
if(tp<sl){
if(double trade.RequestVolume==0.02){
if(price-0.5*(price-tp)>=Bid){
bool res=trade.PositionClosePartial(Ticket,0.01,1);
}}
}
}}}

Code is meant to close 50% of trades at 50% profit level, however it closes everything instead. Is it possible to filter out closing by volume amount. 
Aka, if(volume=0.02) then close partial 

 
micobez:

Code is meant to close 50% of trades at 50% profit level, however it closes everything instead. Is it possible to filter out closing by volume amount. 
Aka, if(volume=0.02) then close partial 

I am working for same code, Haven't you solved it.. I have one code that closes everything. Irrespective of trade symbols.
 
if(_Symbol==symbol)
{
ulong Ticket = PositionGetInteger(POSITION_TICKET);
double sl = PositionGetDouble(POSITION_SL);
double tp = PositionGetDouble(POSITION_TP);
double price = PositionGetDouble(POSITION_PRICE_OPEN);
double volume = Position

//buy
if(tp>sl){
if( trade.ResultVolume()==0.02){

What is “trade” and how does it know what position you have currently selected?

Reason: