- ago
Hello,

I have two strategies with different logic working on daily data. Both strategies use

CODE:
PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose);


to enter.

On the Positions tab of both strategies I could see that they entered on Friday's close:


The problem is that Strategy 1 has "1 Signal" tab, but Strategy 2 doesn't have the tab. Can you please tell me why that could happen?

I'd also appreciate a link to Strategy monitor manual, as any attempt to use it will not give any signal for the Strategy 1, although all settings a set the same.

Thank you!
0
227
Solved
11 Replies

Reply

Bookmark

Sort
Cone8
 ( 3.70% )
- ago
#1
QUOTE:
Can you please tell me why that could happen?
We could tell you for sure if we had the strategy, but blindly guessing, it's because the strategy uses peeking code and doesn't process the last bar, which means you'll never get Signals.


QUOTE:
The problem is that Strategy 1 has "1 Signal" tab, but Strategy 2 doesn't have the tab.
Context is missing. Do you mean it has "1 Signal" "today" after Friday's close, so that's what you see "today"? Or it *had* "1 Signal" on Thursday, but the other did not? To get the entry on Friday's close, the strategy needs to signal on Thursday.

Also, if you enable "Use Live Positions", the Strategy Monitor can give you a different result than a normal Strategy Window - because it's ignore backtest positions and "using Live Positions".

Link to Manual:
Open the Strategy Monitor, Strike F1.
or,
Strike F1, search for Strategy Monitor
1
- ago
#2
Thank you for the answer, Cone!

Let's consider the strategy uses the peeking code, but how that could be that I see the trade in Backtest -> Positions, but don't see it as a Signal, although the date of the trade is 07.06.2024

I believe I don't understand the logic behind Positions/Signals. For example, I created a new strategy with a very primitive logic:

CODE:
   if (bars.DateTimes[bar].Date == new DateTime(2024,06,07))       PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose);


It does generate Signal, but I can't see any open trade under Backtest->Positions. Is it normal?


QUOTE:
Context is missing. Do you mean it has "1 Signal" "today" after Friday's close, so that's what you see "today"? Or it *had* "1 Signal" on Thursday, but the other did not? To get the entry on Friday's close, the strategy needs to signal on Thursday.


I use PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose). According to the Friday's EOD prices (after Friday's close) the PlaceTrade should be activated. And today (on Monday) I can see 1 Signal coming from Strategy 1, and I have Backtest->Positions row as of Friday. I also have Backtest->Positions row as of Friday for Strategy 2, but don't have 1 Signal from the Strategy 2.

So I expect that Backtest->Positions and Signal alert to be correlated. They are not, so I'm missing some important logic behind.

Thank you!
0
Cone8
 ( 3.70% )
- ago
#3
It's normal to have "NSF Positions", which are positions created but rejected by the Backtester due to "Not Sufficient Funds".
0
- ago
#4
I only open one position at a time, and I double checked, it's not because of NSF
0
- ago
#5
I added logging:
CODE:
            if (NeedToEnterLong(bars, bar))             {                PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose);                WriteToDebugLog(bars.DateTimes[bar].Date);             }


The output for both strategies is:

CODE:
06.02.2024 0:00:00 12.03.2024 0:00:00 02.05.2024 0:00:00 06.06.2024 0:00:00


So the PlaceTrades executes on Thursday, and the trade is done on Friday's close.

Actually I would expect, that both strategies do not show any Signals today (on Monday)
0
Cone8
 ( 3.70% )
- ago
#6
The way a program functions can differ from you expect for a myriad reasons. We can't help with only a snippet (with a reference to unknown custom function) and without knowing all the other conditions and preferences. You're expecting too much guessing from our part. I like to see the target before I start throwing darts.
4
- ago
#7
Fair enough!

For this I need to simplify two strategies, as the behaviour of tabs "Backtest Result -> Positions" and "Signal" differs.

So here is a simple strategy that enters EOD on Friday.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript4 {    public class MyTestStrategy : UserStrategyBase    {       public MyTestStrategy()       {                                                                                     }       public override void Initialize(BarHistory bars)       {       }       private bool NeedToEnterLong(BarHistory bars, int bar)       {          return true;       }              public override void Execute(BarHistory bars, int bar)       {          if (HasOpenPosition(bars, PositionType.Long) && bars.DateTimes[bar].Date == new DateTime(2024, 06, 05))          {             ClosePosition(LastPosition, OrderType.MarketClose);          }          if (!HasOpenPosition(bars, PositionType.Long))          {             if (NeedToEnterLong(bars, bar))             {                PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose);                WriteToDebugLog(bars.DateTimes[bar].Date);             }          }       }    } }


This strategy opens a Position, but doesn't show a Signal. Is that as expected?





If so, I will simplify the second strategy that (having the similar rules) has a position on 07.06.24 and also shows a Signal.
0
- ago
#8
Keep your code as simple as possible--but not too simple--for illustration on the forum. I would write it this way.
CODE:
      public override void Execute(BarHistory bars, int idx)       {          if (HasOpenPosition(bars, PositionType.Long))          {             //sell conditions below             if (bars.DateTimes[idx].Date == new DateTime(2024, 06, 05))                ClosePosition(LastPosition, OrderType.MarketClose);          }          else          {             //buy conditions below             if (true)             {                PlaceTrade(bars, TransactionType.Buy, OrderType.MarketClose);                WriteToDebugLog(bars.DateTimes[idx].Date);             }          }       }
The Signal occurs on the off-the-Chart bar (not shown), not the current bar. So you won't expect a trade to occur (or a Position created) until the following day. This is normal behavior for WL on an Order.Market execution trade. I see you're using a Order.MarketClose execution instead. I can't speak for that behavior, but there are situations when that order type may behave weird.
1
Cone8
 ( 3.70% )
- ago
#9
QUOTE:
This strategy opens a Position, but doesn't show a Signal. Is that as expected?
Let me say it a different way than in Post #8.

Signals are for trades in the future based on the data from the last bar on the chart.

Positions are hypothetical trades that the backtest has already entered.
1
Best Answer
- ago
#10
QUOTE:
Let me say it a different way than in Post #8.

Are you saying the way Post #7 does it creates a Position without creating a Signal first? Is that even possible?
0
Cone8
 ( 3.70% )
- ago
#11
No, it's a concise clarification.
0

Reply

Bookmark

Sort