Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I have some code I use for position sizing in Easy Language. The idea is the position size of your order increases as your equity increases in your account. It works perfectly in backtesting, but there's a strange issue when I use the code live in my simulated account. The code allows a minimum contract amount of 1 and maximum of 50. We have a "stop loss" set at $10. As you can see in the code below, it will take my risk percentage (0.01) multiplied by starting equity ($2000) divided by my stop loss to get a contract size (vCon) of 2. This works in backtesting, but my live trading consistently tries to fill 50 contracts (the max amount) and gets rejected. It is getting rejected because I made my sim account equity set to $2000. Any ideas why this is failing to work only in live trading?
var: msg(""),
retVal(false),
debug(true),
vCon(0),
vTotalEquity(0),
vDollarsToRisk(0);
If ( iRiskPercent > .99 OR iRiskPercent < .01 ) Then
Begin
vCon = -1;
Print("Invalid risk percentage input. Please enter a percent value from .01 to .99.");
End;
If ( iStop$ < 0 ) Then
Begin
vCon = -1;
Print("Invalid stop in dollars. Please enter a value greater than zero.");
End;
That is because the code is only basing its decisions on the Net Profit and Equity of the strategy (not your actual account). So, if you run this strategy for 5 years, and it has a ton of profit built up, the strategy will think it should trade 50 contracts next trade.
What you want, for live trading, is to access your actual account equity, and base decisions off of that.
You should probably create a separate version of the strategy to do this.
Look at TS Help for the "Get" reserved words, like GetRTAccountEquity
Sorry to bother you. So I updated the code to use GetRTAccountEquity. My live account that I am using for this has $3,000 equity. I took a trade this morning on MCL, which should allow me to purchase 3 contracts with this code. However, it is still only purchasing the minimum (1 contract). Any thoughts? Here is the updated code (appreciate your help!):
var:
msg(""),
retVal(false),
debug(true),
vCon(0),
vTotalEquity(0),
vDollarsToRisk(0);
If ( iRiskPercent > .99 OR iRiskPercent < .01 ) Then
Begin
vCon = -1;
Print("Invalid risk percentage input. Please enter a percent value from .01 to .99.");
End;
If ( iStop$ < 0 ) Then
Begin
vCon = -1;
Print("Invalid stop in dollars. Please enter a value greater than zero.");
End;