Simplest way to write this code?
Posted: Feb 16 2011
Hello,
The code works, i.e. long with a cross and closing after nn-days but I am wondering if it is the cleanest way to write it?
(I just started working w MC).
Thank you,
Best
Nicolas
=========================================================
The code works, i.e. long with a cross and closing after nn-days but I am wondering if it is the cleanest way to write it?
(I just started working w MC).
Thank you,
Best
Nicolas
=========================================================
Code: Select all
inputs: Price( Close ), Length( 9 );
Variables:
Portfolio_total(20000), // total portfolio aum
Portfolio_size(0.05), // total size of each open position (expressed in %)
Position_shares(0); // number of shares/contracts to buy
condition1 = (CurrentBar > 1) AND (close[1]<= AverageFC( Close[1], Length )) AND (Close > AverageFC( Close, Length )) AND (marketposition = 0);
if condition1 then begin
Position_shares = round((Portfolio_total*Portfolio_size)/Price,0);
Buy ("Buy") Position_shares shares next bar at market ;
end
else begin
if marketposition = 1 and barssinceentry = 10 then
sell ("Sell") Position_shares shares next bar at market;
end;