Simplest way to write this code?

Questions about MultiCharts and user contributed studies.
nlaporte
Posts: 21
Joined: 16 Feb 2011
Location: Switzerland
Has thanked: 1 time
Been thanked: 1 time

Simplest way to write this code?

Postby nlaporte » 16 Feb 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

=========================================================

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;

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: Simplest way to write this code?

Postby Dave Masalov » 16 Feb 2011

Dear Nicolas,

You may want to set the following variables as inputs for your study:

Portfolio_total(20000), // total portfolio aum
Portfolio_size(0.05);


Return to “MultiCharts”