With the trailing stop script below I would like to adapt the position size to the TradeStopLimit, however if I define Lots inside the function TrailingStop it is ignored and set to 1, also I do not have access to TradeStopLimit in the run even if it has been set in TrailingStop, it will output 0.
Could you please tell me how I could some this issue please?

int TrailingStop()
{
if(TradeIsLong and TradeProfit > 0)
TradeStopLimit = max(TradeStopLimit, priceLow() - 3 * ATR(20));

if(TradeIsShort and TradeProfit > 0)
TradeStopLimit = min(TradeStopLimit, priceHigh() + 3 * ATR(20));

return 0;
}

static TRADE* MyTrade = NULL;

function run()
{
set(TICKS);

BarPeriod = 1440;
LookBack = 61;
StartDate = 2017;
EndDate = 2018;

Slippage = 0;
Spread = 0;

if(!TradeIsOpen)
{
if(random() < 0)
MyTrade = enterShort(TrailingStop);
else
MyTrade = enterLong(TrailingStop);
}

if (TradeIsOpen)
{
ThisTrade = MyTrade;

printf("nStop = %.5f", TradeStopLimit);
}

set(LOGFILE);
}