- ago
Would you please tell me how programmatically to know whether I am running my strategy in 'Backtest' window or under SM/Streaming chart?

I looked everywhere but I wasn't able to locate such reference.

6
1,365
Solved
12 Replies

Reply

Bookmark

Sort
- ago
#1
Could you clarify why this may be required?
0
- ago
#2
Here are three example scenarios where I need to know the context in which the strategy runs:
1- Dropping a strategy to run in a streaming chart: In the charts preferences, “Data/Trading” is a global setting it affects other strategy start dates which could be meant for different time frames. To avoid this I set a date in the code to control StartIndex.
CODE:
DateTime StartDate = new DateTime(2021, 4, 1, 9, 35, 0); StartIndex = bars.IndexOf(StartDate, true);


But when I backtest the same strategy I have to comment the code each time.
If I know I was running in backtest mode I could do something like this

CODE:
   If(!backtest) { DateTime StartDate = new DateTime(2021, 4, 1, 9, 35, 0); StartIndex = bars.IndexOf(StartDate, true); } Else { StartIndex = 1; }


2- I’d like to automate trades with keyboard simulation: If I know the strategy is running in backtest then I don’t invoke the simulator.

3- To speed up backtesting I disable calculating visual indicators which are only needed when I look at the strategy while streaming.

I currently use a strategy parameter I set for different context, but since my strategy is compiled I have to reset the parameter each run. I forget to do this sometime and causes me to re-run.

0
- ago
#3
Thanks for clarifying. You're making what seems to me a solid point for exposing an IsStreaming property.
0
- ago
#4
Thank you for considering adding a new property.
0
Glitch8
 ( 10.62% )
- ago
#5
This should be flagged with #FeatureRequest so it can be voted on.
0
Cone8
 ( 4.98% )
- ago
#6
Voila! It is a Feature Request now. Vote if you want it!
1
- ago
#7
QUOTE:
3- To speed up backtesting I disable calculating visual indicators which are only needed when I look at the strategy while streaming.
What about a property to say if a Chart window is open whether or not it's streaming. I display many fundamentals on the Chart window, which I don't need to calculate if there isn't a Chart window.
0
- ago
#8
Linked feature request:

https://www.wealth-lab.com/Discussion/Name-of-Current-DataSet-6153
0
Glitch8
 ( 10.62% )
- ago
#9
A new property, ExecutionMode is coming to Build 10, it's an enum with the following possible values: Strategy, Optimization, StreamingChart, StrategyMonitor.
3
Best Answer
- ago
#10
QUOTE:
ExecutionMode is ... an enum with ... values: Strategy, Optimization, Chart, StrategyMonitor.
Using an enum implies these are mutually exclusive states. I'm trying to decide if that's really true. Couldn't you have a Chart open and be performing an Optimization at the same time? If so, what would be the ExecutionMode of such a combination situation?

The way we do it in hardware is to have a status register such that each bit setting is independent (I.e. orthogonal) to the others. For example:

Strategy=1, Optimization=2, Chart=4, StrategyMonitor=8 forms a 4-bit status register. Then you can AND mask the status register for the "combination testing" you want (which is commonly done in device drivers). Now these states don't have to be mutually exclusive for testing.

I'm not sure how C# does bitwise testing (and masking). I haven't done that.
0
Glitch8
 ( 10.62% )
- ago
#11
They are mutually exclusive ST. When optimizing, there is no chart context, for example.

But, to answer the technical question:

https://makolyte.com/csharp-how-to-use-enum-flags-to-pass-multiple-options-as-a-single-parameter/
1
- ago
#12
Thanks for that link. This is interesting and a great example. I bookmarked it.
0

Reply

Bookmark

Sort