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.
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();
s.AddStopLoss(10);
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).
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?
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.
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.
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.