Hello everyone,
I hope someone can help me. I want to open my trades manually, but I want my exit strategy to run fully automated via the StrategyMonitor. However, when setting it up, I always get the message that a Buy condition is missing.
What condition do I need to enter in the Building Block so that only the exit strategy runs automatically without requiring a Buy condition?
Thanks a lot for your help!
I hope someone can help me. I want to open my trades manually, but I want my exit strategy to run fully automated via the StrategyMonitor. However, when setting it up, I always get the message that a Buy condition is missing.
What condition do I need to enter in the Building Block so that only the exit strategy runs automatically without requiring a Buy condition?
Thanks a lot for your help!
Rename
Without creating a hypothetical position to sell, you can create an exit signal by assigning non-zero Quantity to the exit Transaction object. In this example, you just assign 1 share and allow PortfolioSync to sync to the position with the "Always set Exit Order Quantity to full Position Quantity" enabled.
CODE:
public override void Execute(BarHistory bars, int idx) { // just create an exit signal if (idx == bars.Count - 1) { Transaction t = PlaceTrade(bars, TransactionType.Sell, OrderType.Market); t.Quantity = 1; } }
Thank you very much. But can I also create this in the Building Block? I don’t know how to add my condition to the code because I have no experience with programming at all. 😬
No. One way or another you need to use a C#-coded strategy for this one. You can start with blocks, Open as C# Code Strategy, and then a good amount of manipulation is required.
If you post the C# code here from your blocks, we could whip that up for you quickly.
Note - For the blocks, you'll need to include an entry signal too (to be ignored later).
If you post the C# code here from your blocks, we could whip that up for you quickly.
Note - For the blocks, you'll need to include an entry signal too (to be ignored later).
Actually, you can do it yourself like this -
1. Instead of a "Sell" signal, put all your conditions on a "Short" signal block.
2. Click on "Multiple Positions"
3. Then Open as C# Code
4. For a Short at Market signal, the Execute block of code will look something like this -
Now, you only have to edit the last statement like this:
Save this as your "Exit Strategy" (any name will do).
1. Instead of a "Sell" signal, put all your conditions on a "Short" signal block.
2. Click on "Multiple Positions"
3. Then Open as C# Code
4. For a Short at Market signal, the Execute block of code will look something like this -
CODE:
public override void Execute(BarHistory bars, int idx) { int index = idx; bool condition0; condition0 = false; { if (indicator[index] < 30.00) { condition0 = true; } } if (condition0) { Backtester.CancelationCode = 1; _transaction = PlaceTrade(bars, TransactionType.Short, OrderType.Market, 0, 0, "Short At Market (1)"); } }
Now, you only have to edit the last statement like this:
CODE:
//WAS: _transaction = PlaceTrade(bars, TransactionType.Short, OrderType.Market, 0, 0, "Short At Market (1)"); //CHANGE TO: _transaction = PlaceTrade(bars, TransactionType.Sell, OrderType.Market, 0, 0, "Exit"); _transaction.Quantity = 1;
Save this as your "Exit Strategy" (any name will do).
Very cool. Thank you very much. I understand it now. I have one last question. I know that Wealth Lab needs a constant connection to my broker, but does the Strategy Monitor always have to be open in the background?
Of course, whenever you want to trade.
Your Response
Post
Edit Post
Login is required