Hi,
This is for backtesting only.
The blocks below work fine for sells where the limit is reached. What I want to do is if the sell doesn't happen by the 4th day after the buy, then sell at the closing price on the 4th day. The way this is laid out, the sells are using the open, instead of the close.
I just realized that even if it hits the limit, on the 4th day, it still shows the sell as being at the open for the day.
I've been playing with Trading Days in Trade, 1 Bar in Future, but not successfully.
Can this be done?
Thanks!
This is for backtesting only.
The blocks below work fine for sells where the limit is reached. What I want to do is if the sell doesn't happen by the 4th day after the buy, then sell at the closing price on the 4th day. The way this is laid out, the sells are using the open, instead of the close.
I just realized that even if it hits the limit, on the 4th day, it still shows the sell as being at the open for the day.
I've been playing with Trading Days in Trade, 1 Bar in Future, but not successfully.
Can this be done?
Thanks!
Rename
You can do it using the Power Pack Blocks:
- Sell Next Bar at Market Close
- Bars since Entry/Exit Condition
- Sell Next Bar at Market Close
- Bars since Entry/Exit Condition
Thanks, Glitch. It works fine if I do Single Position:
But if I try Multiple Positions, it doesn't seem to be able to keep them apart. Stock bought on different days should exit on different days, not bunched together like this:
Am I missing something?
But if I try Multiple Positions, it doesn't seem to be able to keep them apart. Stock bought on different days should exit on different days, not bunched together like this:
Am I missing something?
The rule is based on the "last Entry" not the entry of each position.
Try using "Trading Days in Trade" instead.
Try using "Trading Days in Trade" instead.
Yes. I tried that, but it doesn't compile. Nothing in the Log Viewer. Is there some undocumented method to see why it won't compile?
Click the Open as C# Coded Strategy button, Compile.
We'll have to check that too.
... and it compiles fine for me. There must be something else in the Strategy that's broken... ah, multiple positions....
We'll have to check that too.
... and it compiles fine for me. There must be something else in the Strategy that's broken... ah, multiple positions....
It looks like that Power Pack Block was not coded to play nice with the multiple position setting. I'll fix it ASAP.
Glitch, but the whole point of this was not to use the LastOpenPosition. Make sure to fix it on a per-Position basis.
Here's what I got when I compiled:
@steinh,
I'm not certain yet if it will be possible to fix rule in blocks for multiple positions, but you can do it by rearranging the C# code like this:
Find this section (you have to be precise):
And rearrange it like this (you can just copy and paste this to replace the section above)
I'm not certain yet if it will be possible to fix rule in blocks for multiple positions, but you can do it by rearranging the C# code like this:
Find this section (you have to be precise):
CODE:
condition0 = false; { tdays = bars.TradingDaysBetweenDates(bars.DateTimes[foundPosition0.EntryBar].AddMinutes(-bars.Scale.Interval), bars.DateTimes[index]); if (tdays >= 3) { condition0 = true; } } if (condition0) { foreach(Position foundPosition0 in OpenPositions) { if (foundPosition0.PositionTag == 0) { Backtester.CancelationCode = 1; ClosePosition(foundPosition0, OrderType.Market, 0, "Sell At Market (1)"); } } }
And rearrange it like this (you can just copy and paste this to replace the section above)
CODE:
foreach(Position foundPosition0 in OpenPositions) { condition0 = false; { tdays = bars.TradingDaysBetweenDates(bars.DateTimes[foundPosition0.EntryBar].AddMinutes(-bars.Scale.Interval), bars.DateTimes[index]); if (tdays >= 3) { condition0 = true; } } if (condition0) { if (foundPosition0.PositionTag == 0) { Backtester.CancelationCode = 1; ClosePosition(foundPosition0, OrderType.Market, 0, "Sell At Market (1)"); } } }
Thanks, Cone, but it sells at the open. The new code produces the same results as "Sell after 4 bars".
I tried using "OrderType.MarketClose", but it errors with
87: 'OrderType' does not contain a definition for 'MarketCLose'
I need it to sell at the closing price, as I'm trying to simulate doing a MOC for whichever stocks haven't already sold on the final day (4th day after entering the trade).
I tried using "OrderType.MarketClose", but it errors with
87: 'OrderType' does not contain a definition for 'MarketCLose'
I need it to sell at the closing price, as I'm trying to simulate doing a MOC for whichever stocks haven't already sold on the final day (4th day after entering the trade).
In C# code, case matters. You put "MarketCLose" with a capital "L" that should be lowercase: OrderType.MarketClose
D'oh! Fat-finger coding.
That fixed it. Thanks!
That fixed it. Thanks!
Your Response
Post
Edit Post
Login is required