Code: Select all
variables:
DeltaShares (0),
SharesFor100k (0);
once ClearPrintLog;
if date > date[1] then begin
print(ELDateToString(date), " ", SymbolName, " details:");
print("SharesFor100k = ", SharesFor100k);
SharesFor100k = ceiling(100000 / close);
DeltaShares = SharesFor100k - CurrentShares;
if DeltaShares > CurrentShares * 0.01 then begin
print("++ ", DeltaShares);
buy("LE") DeltaShares shares next bar at market;
end else if -DeltaShares > CurrentShares * 0.01 then begin
print("-- ", -DeltaShares);
sell absvalue(DeltaShares) shares total next bar at market;
end;
end;
Unfortunately, the resulting trades w/ AAPL look like this:
It can be seen that the code is not working: instead of scaling the number of shares back to stay close to a $100k investment, the code fails to sell properly.
This is a topic that has been discussed on this forum several times and I feel stupid about asking again. I am trying to use an 'untied exit', according to this post:
viewtopic.php?f=1&t=48438&hilit=sell+partial+position
There are also other posts, which seem to suggest different approaches:
* viewtopic.php?f=1&t=48200&hilit=sell+partial+position
* viewtopic.php?f=1&t=7827&hilit=sell+partial+position
What am I missing?
Thanks a lot for your help,
best regards, Felix