Click here to Login





                                                   Money Management Scripting

  0

0
Stefan Kroscen
2010-10-30 18:38:57


What do the values in GetBuySignals and GetSellSignals signify in the OnEndPeriod event? I had anticipated them being the symbols that pass the buy rules and sell rules
respectively. But both lists contain the same symbols for me, which wouldn't make sense (my test rules were: buy = CLOSE > 10;short = close < 10;).

The other thing that didn't make sense to me was that the number of values in the collection varied in some unknown way with the number of allowed positions. With
20 allowed positions, it generates 41 buy and 41 short signals. With 5 allowed positions, it generates 21 respectively.

Can you shed some light on where in the event order the buy and sell rules are turned into new positions? Before OnEndPeriod, or between OnEndPeriod and OnNewPosition?

I am trying to write a script that will keep the money fully invested at all times, assuming there are enough positions to fill the max allowed, regardless of position type.
For the most part, I will be either all long or all short. As a result, default behaviour results in only half of the money being invested at a time.

I was thinking that in OnEndPeriod, I could use the GetOpenPositions and the signals to calculate how many positions I want to have in the next period and of what types,
then set the UpdateCategorySettings appropriately. But that doesn't seem to work. Appreciate any advice you can give!




QuantShare
2010-11-01 06:36:39

  0

Best Answer
- Yes, they contain a list of symbols that pass the buy and sell rules. A change in our code has not been committed and that is why you are getting the same list. It is fixed now. Thank you for reporting this.

- To optimize the execution of trading systems, the number of symbols in the list (for a particular date) will not contain more than 2 * (Max number of symbols) + 1.

- "OnNewPosition" gets the signal. You can then use this event to modify it. After that the signal is converted into an order.
After all orders are procceeded, the OnEndPeriod is executed.

However, if you execute orders on today's bar, then the "OnNewPosition" will be called after "OnEndPeriod".

- I am not sure I understand exactly what you want to do with GetOpenPositions, but here is an example on how to be fully invested in either long or short positions: (You need to set the trading system type to Long/Short)

string index = "^GSPC";
double result = Data.ParseFormula("a = rsi(14) > 50;").GetTimeSeries(index, "a")[0];
bool isfullylong = (result == 1) ? true : false; // Long positions if RSI of index is higher than 50
MMPosition[] positions = Portfolio.GetOpenPositions();
if(positions.Length > 0)
{
if(positions[0].IsLong == isfullylong)
{
// Portfolio is already in the correct long or short mode
return;
}
}
Divers.Output("IsLong: " + isfullylong);

// Close positions
for(int i=0;i<positions.Length;i++)
{
positions[i].ClosePosition();
}

if(isfullylong)
{
Portfolio.UpdateCategorySettings("short", 0, 0, Orders.OpenMarketOrder());
Portfolio.UpdateCategorySettings("long", 100, 5, Orders.OpenMarketOrder());
}
else
{
Portfolio.UpdateCategorySettings("long", 0, 0, Orders.OpenMarketOrder());
Portfolio.UpdateCategorySettings("short", 100, 5, Orders.OpenMarketOrder());
}





Stefan Kroscen
2010-11-01 22:16:55

  0

Thanks! I haven't yet tried out your code, but your explanation of how it is supposed to work is very helpful!

I do have a follow-up question and feature request.

With the signals being limited, are the rankings applied before or after they are limited?

The request is, could you make the limit on the signals be parameter based so that it can be adjusted?

Appreciate the info and love the product!



QuantShare
2010-11-02 06:28:04

  0

Stocks with higher ranking are always kept in the list.
Yes we can make this limit parameter-based. We will add this feature in the next release.

Thanks for the suggestion.



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
Withdraw a Fixed Amount Every Month - Money Management
Correlation Filter Money Management Strategy
Investing in stocks using the Kelly criterion money management st...
Return per Bar Stop - Money Management Strategy
Averaging Down Money Management Strategy

How-to Lessons
How to calculate the average of a time series using the money man...
How to debug a trading system using the money management tool
How to dynamically change the number of positions in a portfolio?
How to generate buy/sell signals from a trading system
How to add custom position-based metrics to your trading system

Related Forum Threads
Example of Money Management
Advanced Money Management
Money management - C#
Hedging Money Management
Ability to edit multiple money management scripts at once

Blog Posts
Create a trading strategy using the money management tool - Part ...
Create a trading strategy using the money management tool - Part ...
Basic trading system implemented using the money management tool
Several money management strategies in a trading system
Money Management: Optimize a trading system









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.