Code: Select all
variables:
DeltaShares (0),
SharesFor100k (0);
[SameExitFromOneEntryOnce = false]
once ClearPrintLog;
if date > date[1] then begin
print(ELDateToString(date), " ", SymbolName, ": ",
CurrentShares:4:0, " x ", close:6:2, " = ",
(CurrentShares * close):9:2);
SharesFor100k = ceiling(100000 / close);
DeltaShares = SharesFor100k - CurrentShares;
if DeltaShares > CurrentShares * 0.01 then begin
print("++ ", DeltaShares:0:0);
buy DeltaShares shares next bar at market;
end else if -DeltaShares > CurrentShares * 0.01 then begin
print("-- ", -DeltaShares:0:0);
sell absvalue(DeltaShares) shares total next bar at market;
end;
end;
(1) Allow multiple orders in the same direction as the currently held position
Without this setting, MultiCharts will be unable to scale into positions properly. See this screenshot:
(2) [SameExitFromOneEntryOnce = false]
Without this setting, MultiCharts will not allow more than one exit per entry. Scaling out of positions will fail.
(3) sell xxx shares total
Without the keyword total, the specified # of shares will be applied to each entry, which is not what we want.
The strategy will print log output like this, to help follow its operation. The ++ and -- lines indicate buy or sell orders:
- 01/04/2005 AAPL: 0 x 4.23 = 0.00
++ 23641
01/05/2005 AAPL: 23641 x 4.31 = 101892.71
-- 439
01/06/2005 AAPL: 23202 x 4.27 = 99072.54
01/07/2005 AAPL: 23202 x 4.33 = 100464.66
01/10/2005 AAPL: 23202 x 4.61 = 106961.22
-- 1510
01/11/2005 AAPL: 21692 x 4.55 = 98698.60
++ 287
01/12/2005 AAPL: 21979 x 4.21 = 92531.59
Cheers, Felix