Buys three contracts only

Questions about MultiCharts and user contributed studies.
WHO
Posts: 5
Joined: 06 Jul 2011

Buys three contracts only

Postby WHO » 24 Apr 2012

I have what seems to be 2 problems here.No matter what capital i enter ,it buys only 3 contracts.The other problem is to remove init capital from script and be able to use MC init capital

inputs:Price(C),
FastLength(12),
SlowLength(26),
InitCapital(5000) ,
CapitalDivisor_HCL(c);
variables: var0( 0 ), var1( 0 ), var2( 0 ) ;
Value1 = (InitCapital + netprofit)/CapitalDivisor_HCL;

var0 = XAverage( Price , FastLength );
var1 = XAverage( Price ,SlowLength );
Value1 = SessionStartDay(1,3);

condition1 = CurrentBar > 2 and var0 crosses above var1 ;

//If Date <> Date[1] thenEntryDate(1) = Date or
//if EntryDate(1) = Date then

//Condition1 = false;

if EntryDate(1) < Date then

if condition1 then


Begin
Buy ("MA")value1 shares this Bar at close ;

End;


If var0 crosses under var1 then
Sell ("MAX") this Bar at Close;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Buys three contracts only

Postby TJ » 24 Apr 2012

I have what seems to be 2 problems here.No matter what capital i enter ,it buys only 3 contracts.The other problem is to remove init capital from script and be able to use MC init capital

inputs:Price(C),
FastLength(12),
SlowLength(26),
InitCapital(5000) ,
CapitalDivisor_HCL(c);
variables: var0( 0 ), var1( 0 ), var2( 0 ) ;
Value1 = (InitCapital + netprofit)/CapitalDivisor_HCL;

var0 = XAverage( Price , FastLength );
var1 = XAverage( Price ,SlowLength );
Value1 = SessionStartDay(1,3);

condition1 = CurrentBar > 2 and var0 crosses above var1 ;

//If Date <> Date[1] thenEntryDate(1) = Date or
//if EntryDate(1) = Date then

//Condition1 = false;

if EntryDate(1) < Date then

if condition1 then


Begin
Buy ("MA")value1 shares this Bar at close ;

End;


If var0 crosses under var1 then
Sell ("MAX") this Bar at Close;
Don't have answers off the bat, but I do have a few suggestions:

1. Use code tag when posting codes, it makes reading easier.

2. do not use generic variable names. ie. value1, condition1, var1, etc.,

Custom variable names are free, they do not cost money!
eg. use MA1 instead of var1, so that you know it is a moving average.
Using a specific name for a specific variable can help you debug your code faster, and lose less hair.

3. add comments to the code, so that you can follow the logic and trace the operation as the strategy steps through its pace.

Good luck.

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Buys three contracts only

Postby SP » 25 Apr 2012

You always buy ( Value1 = SessionStartDay(1,3); ) contracts.
As TJ suggested dont use value1...in codes, at least change the line
Value1 = SessionStartDay(1,3);
to Value2 = SessionStartDay(1,3);

If you use Interactive, you could use GetRTAccountEquity("YourAccount") for the init capital, but only in realtime, not for historical values.


Return to “MultiCharts”