Click here to Login

                                                   example of advanced money management tool Stop Order


Christopher Rass
2016-03-06 22:55:19


I can't seem to figure out how to use the advanced money management tool for back-testing.

What I want to do is set up a sell order that will trigger if the price drops by 10%:

I thought I could do it with a function that looked like this:
Functions.SellPosition("XIV", Orders.StopOrder(0.10) );

It always sells all my shares of XIV every bar. It seems like the stop order doesn't do anything.

I've also tried a lot of other permutations, and it always sells everything.

Does anyone have an example of what this line should look like to function correctly in the Advanced Money Management back-testing tool?


2016-03-07 05:57:19


Advanced money management tool requires some C# knowledge.
Why don't you use a simple stop loss.

Christopher Rass
2016-03-09 15:30:22


Do people tend to not use the Advanced Money Management tool? I have solid c# and general coding experience so felt that it would be more powerful and easier to understand for me. I don't think the coding is the problem, I can't find any documentation or examples of how to use the stopOrder function correctly.

2016-03-10 03:48:18


If your system can be implemented in QS language and doesn't require advanced stuff then it is better not to use the money management tool since the former can be backtested faster.

In your example, you are using a stop order with a stop price of 0.1$. Note that there "StopOrder" function has several signatures, it is better to also specify for how many bars the stop should be valid and the order lag.
Orders.StopOrder(15, 0, 5)

If after 5 bars the stop is not executed then it is transformed into a market order.

To use a stop loss (in percentage) then you should specify that when you enter the order. Example:

MMPositionSettings s = Orders.CreateOrderSettings();
Functions.AddLongPosition("XIV", 10, Orders.OpenMarketOrder(), s);

You also need to enable stop loss by checking "Stop loss" in the bottom panel after you click on the "Strategy" tab (In the "Create a trading system" form).

Christopher Rass
2016-03-10 21:59:37


Thanks for the help. I tried out your recommendations. I turned on the "stop loss" in the strategy tab, I tried out your exact code with adding the stop loss to the "addLongPosition" function. But nothing seemed to work.

I'm trying to do something that seems like it should be fairly simple. On the end of a period, I want to use that information to decide how tight to set a "sellPosition". So If my signals are saying that we're in a high-risk environment, I want to tighten that stop loss and sell my position if the value drops even a few percent. But then other times I want to loosen that sellPositin and only sell if it loses a fairly large % value.

So I would think that I could set up something like:
Functions.SellPosition("XIV", xivPos2.NbShares , Orders.StopOrder(currentShareValue*0.9,0,2) );

meaning that I would like to create a sell position that will trigger if the value of the shares drops below 90% of it's current value within the next two bars.

I've tried various permutations of this and it always just sells all my shares in the next bar.

Can you see what I'm doing wrong, ore what I'm not understanding about this process?

2016-03-11 02:53:19


Your formula is correct. Maybe your positions are sold because the "sell" rule in your QS language based strategy formula.
First try commenting Functions.SellPosition and see if the position is sold or not. If it is then you know the problem otherwise, everything should work. If after two days the stop limit is not hit then the position is sold with a market order. Check the "Details" tab in the simulation report to track every day orders.

Finally, you have many money management scripts on the sharing server that you can download, debug and learn from.

2016-03-11 09:29:12


@ Christopher:

what about the following (just assuming that you determine high risk through Momentum):

a) in the strategy (this decides on the signal date whether it is high risk or not - and this is not changed during the lifetime of the trade)

highRiskEnvironment = Mom(14) < 0;
stopPercent = Iff(highRiskEnvironment, 10, 20);
SetSimStop(_StopLoss, _Percent, stopPercent, 0);

OR (not AND !!!) b) in the OnEndPeriod of your MM script (this adjusts StopLoss level each bar)

MMPosition[] allOpenPositions = Portfolio.GetOpenPositions();
for (int i = 0; i < allOpenPositions.Length; i ++)
MMPosition thisPosition = allOpenPositions[i];
thisPosition.StopSettings.StopLossOption = 1;
double stopPercent = 20;
double highRiskEnvironment = Data.ParseFormula("a = Mom(14) < 0;").GetTimeSeries(thisPosition.Symbol, "a")[0];
if (highRiskEnvironment == 1) stopPercent = 10;
thisPosition.StopSettings.StopLoss = stopPercent;

May the profits be with you!

Christopher Rass
2016-03-11 23:42:02


Thank you both! With your advice I was able to figure it out. I think the key piece of info I didn't understand was that after the time runs out the sell order is executed as a market order. I had expected the sell order to cancel if the time ran out. So because I had my order time set as 2 bars, I sold out of my position every 2 days no matter what.

I resolved it by making the lag much longer and canceling the sell orders if I wanted to change the stop-loss percent.

2016-03-12 05:18:27


It is the buy order that is canceled after the lag period, the sell order is not. As you said, it would be executed as a market order.

No more messages


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"


Trading Items
Money Management System to Split Order Into Smaller Pieces
Long strategy created with the money management tool
Return per Bar Stop - Money Management Strategy
Money management to Reject Trading Positions Based on their Past ...
Correlation Filter 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 use a custom drawing tool
How to set order type of a trading system programmatically
How to optimize the stop limit of a trading system

Related Forum Threads
Advanced Money Management
Place a profit stop through Money management strategy
Example of Money Management
Change exit type in Advanced Money Management
Money Management script and exit options in the wizard

Blog Posts
Create a trading strategy using the money management tool - Part ...
Basic trading system implemented using the money management tool
Create a trading strategy using the money management tool - Part ...
Several money management strategies in a trading system
Example of advanced rule

Create an account
Affiliate Program
Contact Us
Trading Forum
How-to Lessons
About Us
Terms of Use

Copyright 2021
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
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.