I'm trying to backtest a strategy where my position size is depending on the ATR of the underlying security. But when I run the test, I recieve the amount of contracts specified in the "Strategy Properties" window. Is there a way to disable the settings from Strategy Properties so my position size is deterined from the values generated in my code?
In case the error lies within my code, you can find it here (I use MACD as a tester):
Code: Select all
////////////////////////////VARIABLES////////////////////////////
vars:
entryLong (true),
exitLong (true);
////////////////////////////MONEY MANAGEMENT////////////////////////////
Inputs:
InitialCapital(10000),
rskAmt (0.02),
atrLen(14);
vars:
risk (0),
numContracts (0);
// Define risk
risk = AvgTrueRange(atrLen)*bigpointvalue;
numContracts = (InitialCapital * rskAmt) / risk;
//Round down to the nearest whole number
value1 = Round(numContracts, 0);
if(value1 > numContracts)
then numContracts = value1 -1
else
numContracts = value1;
//If numcontracts are less then 1 then this will round it uo to one
numcontracts = maxlist(numContracts, 1);
////////////////////////////MACD////////////////////////////
inputs:
MACDFastLength( 12 ),
MACDSlowLength( 26 ),
MACDLength( 9 ) ;
variables:
var0( 0 ),
var1( 0 ),
var2( 0 ) ;
var0 = MACD( Close, MACDFastLength, MACDSlowLength ) ;
var1 = XAverage( var0, MACDLength ) ;
var2 = var0 - var1 ;
entryLong = var2 crosses over 0;
exitLong = var2 crosses under 0;
////////////////////////////LONG SIGNAL////////////////////////////
// Entry Signal Long
if marketposition = 0 and entryLong = true then
Buy ( "TestEntry" ) numContracts contract next bar at market ;
////////////////////////////EXIT////////////////////////////
if marketposition = 1 and exitLong = true then
Sell ( "TestExit" ) numContracts contract next bar at market ;