Click here to Login





                                                   Money Management Script variables and more

  0

0
Russ
2010-11-08 21:45:15


I would like to write a script that will only buy individual stocks when a secondary symbol (in this case ^DJI) meets an entirely different set of criteria than the buy and sell criteria used to purchase/sell individual stocks.

For example, here is how I envision the code working:

int dowbuy;

if (10 day sma of the close of ^DJI > 20 day sma of the close of ^DJI)
{
dowbuy = 1;
}


if (10 day sma of the close of ^DJI < 20 day sma of the close of ^DJI)
{
dowbuy = 0;
}



// Individual Stock buy criteria

if (dowbuy == 1)
{
if (close of individual stock == Highest.Value(last 100 periods)
{
BuyPosition
}
}


if (dowbuy == 0)
{
Sell Position
}

if (close of individual stock < 20 day sma of the close of the individual stock)
{
Sell Position
}




I apologize for this being a very rough set of code, I've only used Fidelity's Wealth Lab Pro in the past and am much more familiar with the structure of that program. Any help would be greatly appreciated.
I appear to be having a difficult time understanding how to declare a variable and have it's value stay the same for multiple periods.







QuantShare
2010-11-09 04:01:00

  0

Best Answer
- You can use the QuantShare vector-based language to create such strategy.
Example:

djiRule = Ticker("^DJI",close,LastData);
rule1 = sma(djiRule, 10) > sma(djiRule, 20);
rule2 = (close == hhv(100));
buy = rule1 AND rule2;

- Using the money management script to check for a specific value:

MMParser parser = Data.ParseFormula("a = sma(10) > sma(20);");
TimeSeries dji = parser.GetTimeSeries("^DJI", "a");
int dowbuy = (int)dji[0];

- To persist a variable value across multiple periods, use the "Variables" class:
Variables.SetVariable("variable name", 10);
int result = (int)Variables.GetVariable("variable name");



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
Averaging Down Money Management Strategy
Correlation Filter Money Management Strategy
Investing in stocks using the Kelly criterion money management st...
Money Management System to Split Order Into Smaller Pieces
Money management to Reject Trading Positions Based on their Past ...

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 run a screen or a watchlist from a script
How to get stocks for a particular index using the global script
How to execute a script at regular intervals

Related Forum Threads
Money Management script and exit options in the wizard
How do I use variables in Money Management Scripts?
Get the Previous N bar Date/DateTime in Money Management script
Can a Money Management script access a custom function?
Advance Money Management Script debug.

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









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.