Click here to Login





                                                   Incorrect position metrics using MMExitPosition within MM script

  0

0
Dave Walton
2013-07-23 05:13:03


I'm getting very different values in OnClosePosition than I get when I look at the trade information after the simulation is done. The values are off by quite a bit and it is wreaking havoc on calculations. It becomes obvious when I simply add a trade metric to show the profit from within OnClosePosition; it is very different than the default Profit metric in the table of trades.

Here is the code for reference.

MMExitPosition pos = Functions.GetPositionDetails();
Functions.AddTradeMetric("pos.Profit", pos.Profit);

The value for the metric above is very different from the Profit metric, sometimes not even close. Please advise what is going on.



Dave Walton
2013-07-23 17:22:54

  0

Upon further investigation, it appears that the values in OnClosePosition are the values at the time the exit signal is received, but not necessarily the time when the position is actually closed (depending on simulation settings). So the difference seems to be that my system sell setting is to sell on the close tomorrow. So the profit shown in OnClosePosition is not correct because the position is not sold until tomorrow.

So I believe I need to add the trade metrics in OnEndPeriod using:
Portfolio.GetClosedPositions(Divers.CurrentDate);

Will this always give me the final profit per position?



QuantShare
2013-07-23 19:18:32

  0

Best Answer
Your understanding is correct.
You can use the "GetClosedPositions" function to retrieve positions and calculate the profit for each trade.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Exit Position based on Profitability
System Metrics v2.0
Risk Metrics
Trading System Template: Position Sizing Techniques
Volatility-based Position Sizing Method with Adjustable Parameter...

How-to Lessons
How to get stocks for a particular index using the global script
How to add custom position-based metrics to your trading system
How to calculate the average of a time series using the money man...
How to draw an horizontal segment line using QS language
How to plot a stock using different periods in the same chart

Related Forum Threads
Set Position Size by Ticker Within Main Strategy
How do I reduce a position size from within the Money Management
Can I update the sector and industry information in the stock dat...
Portfolio custom backtest metrics
Script to remove Symbols from an Index

Blog Posts
Charting & Scripts - Manage stock charts using the global script
Create custom metrics for the statistical data analysis tool
How to Create Custom Metrics for Your Trading Positions
5 position sizing techniques you can use in your trading system
Basic trading system implemented using the money management tool









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.