I want to use 2 positions in a simulation study, where I use position 1 (say symbol SPY) to take long positions using a rule I define and for position 2(say symbol MSFT) I want to take short positions using a different rule. I don't know how to do this. I have done it where the long and short rules use the same symbol, but can't figure out how to do this for two symbols as I described. Please advise
Thank you. I did not explain my problem clearly. What I want to do is when, say, I buy SPY using a buy rule ( close>sma100), sell it when sma<100, and at this time (upon selling SPY), enter a short or a long of a different smybol, say MSFT until the SPY buy rule is satisfied again when MSFT trade is exited. In other words, I want to be able to enter a trade using a different symbol exactly when I exit SPY, and exit this trade exactly when I enter a new trade with SPY. This will be the strategy for the simulation over a period of time to test.I should add that as it moves from one trade (say after it exitrs SPY and enters MSFT), it should invest the entire avaiable equity in the MSFT trade, and so on. So all the avaiable equity is in one trade or the other ( SPY or MSFT) depending on which rule is in effect
This only enters a MSFT short at the beginning of the defined peroid which it holds through the entire period. There must be a conditional rule that is incorrect/missing. This problem occurs regardless of beginnind date I select or the symbols I select, it always enters and holds the short symbol.
Also I would like to make the following as varables:
For entering Long: sma(a)*(1+b); for exitnig Long sma(c)*(1+d)
For entering Short sma(e)*(1+f); for exiting short sma(g)*(1+h)
so a,b,c,d,e,f,g,h would be varables in the optimization.
Thanks alot for your help.
yes, I would like several stocks and the ability to have all longs as well as longs and shorts;ie, say I start with one or two longs and upon exiting these two, I would enter two new longs or one long and one short etc.
-
- Create a simple trading system with the appropriate buy, sell, short and cover rules.
Example of buy rule: sma(a)*(1+b), then in the optimize grid, set the "a" and "b" variables start, end and step values.
- Select a Long/Short system type. The simulator will assign 50% equity to long positions and 50% equity to short positions
- Depending on how you want to change this percentage. Create a money management script that simply call the function (Portfolio.UpdateCategorySettings)
my problem is I don't know how to create separate buy/sell rules for each equity in the same strategy. Say I want to buy/sell SPY using sma of SPY>100 to buy and sma of spy<100 to sell. In the same strategy I want to buy MSTFT when MSFT sma>150 and sell when MSFT sma<150. I don'nt know how to tie sma values to specific symbols for buy, sell, short and cover rules. Please show me how to do this. Thanks for you help
If you specify close > sma(100) as a buy rule then the simulator will execute that rule for each symbol and enter the symbols (if there are free positions) where the buy rule condition is true.
I used the script you suggested, it works except in one aspect. It enters a long ( ILF) using the rule ILF close >SMA(200)*1.035 and exits this position when ILF close<sma(200)*1.035. It enters and exits shorts in SPY in opposite direction to ILF which is what I want. The aspect that I want to change is to exit the long ILF when its close is less than sma(200)*0.965 ( not < sma(200)*1.035). The short in SPY should occur when the ILF long is exited( close<sma(200)*0.965) and covered when the ILF long is entered( ILF close>sma(200)*1.35). Please show me how to modify the OnEndPeriod code, shown below, to accomplish this.
Thank you. I made the change you suggested, but to my surprise, the output remains absolutely unchanged. The sames exact trades, etc.? I'm guessing that the new rule is not getting invoked in the "IF" statements!
Using the above MM script I would like to get an output that tabulates the bar by bar return; i.e.; the rate of change of equity per bar, in a format that can be exported/copied to an excel file. Please show me how to do this. Thanks.
Thanks. I added the extra lines. What I get is the normal info under "Trades' tab, plus an extra column for ROC/bar (see attached picture). What I am looking for is the actual daily (bar by bar) ROC or the actual equity value for every day from which I would calculate the ROC for every day.I know this data is there since the system plots the equity curve based on daily vales . I also noticed under the D.W.M.Y tab, there is a "Daily Return" plot, I just need this data in a tabular form. I'm including the entire script below. Thanks again for you patience in helping me.
string symbolLong = "spy";
string symbolShort = "SPY";
string rule1 = "a = close > sma(200)*1.035;";
string rule2 = "a = close < sma(200)*0.965;";
TimeSeries buy = Data.ParseFormula(rule1).GetTimeSeries(symbolLong, "a");
TimeSeries sell = Data.ParseFormula(rule2).GetTimeSeries(symbolLong, "a");
Thanks, it works. However; once I run the Simulator with different inputs, like changing dates(simulation period), the output window returns the same starting date as I ran the first time. Even when I change the symbols, and use entirely different dates with the new symbol, the output window starts with dates that I did not specify in the strategy. The end dates appear to be always correct. This is not a problem with the strategy report itself, the dates and the simulation are correct in the simulation report. The problem is in the output window. I'm reproducing the entire script for you to test yourself.
string symbolLong = "SPY";
string symbolShort = "SPY";
string rule1 = "a = close > sma(200)*1.035;";
string rule2 = "a = close < sma(200)*0.965;";
TimeSeries buy = Data.ParseFormula(rule1).GetTimeSeries(symbolLong, "a");
TimeSeries sell = Data.ParseFormula(rule2).GetTimeSeries(symbolLong, "a");
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.