ONCE partialclose = 1
ONCE PerCent = pc //0.2 = 20% positions to close
ONCE PerCent2 = pc2 //0.2 = 20% positions to close
ONCE PerCentGain = pcg //.0025 = 0.25% gain
ONCE PerCentGain2 = pcg2 //.005 = 0.5% gain
ONCE MinLotSize = 0.5 //0.5 lots minimum
ExitQuantity = abs(CountOfPosition) * PerCent
LeftQty = max(MinLotSize,abs(CountOfPosition) - ExitQuantity)
CloseQuantity = abs(CountOfPosition) - LeftQty
ExitQuantity2 = abs(CountOfPosition) * PerCent2
LeftQty2 = max(MinLotSize,abs(CountOfPosition) - ExitQuantity2)
CloseQuantity2 = abs(CountOfPosition) - LeftQty2
IF Not OnMarket THEN
Flag = 1
Flag2 = 1
ENDIF
IF partialclose AND LongOnMarket and close >= (PositionPrice * (1 + PerCentGain)) AND Flag THEN
SELL CloseQuantity Contracts AT Market
Flag = 0
endif
IF partialclose AND shortOnMarket and close <= (PositionPrice * (1 - PerCentGain2)) AND Flag2 THEN
exitshort CloseQuantity2 Contracts AT Market
Flag2 = 0
endif