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.
I looked everywhere but I wasn't able to locate such reference.
Rename
Could you clarify why this may be required?
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.
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
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.
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.
Thanks for clarifying. You're making what seems to me a solid point for exposing an IsStreaming property.
Thank you for considering adding a new property.
This should be flagged with #FeatureRequest so it can be voted on.
Voila! It is a Feature Request now. Vote if you want it!
QUOTE: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.
3- To speed up backtesting I disable calculating visual indicators which are only needed when I look at the strategy while streaming.
A new property, ExecutionMode is coming to Build 10, it's an enum with the following possible values: Strategy, Optimization, StreamingChart, StrategyMonitor.
QUOTE: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?
ExecutionMode is ... an enum with ... values: Strategy, Optimization, Chart, StrategyMonitor.
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.
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/
But, to answer the technical question:
https://makolyte.com/csharp-how-to-use-enum-flags-to-pass-multiple-options-as-a-single-parameter/
Thanks for that link. This is interesting and a great example. I bookmarked it.
Your Response
Post
Edit Post
Login is required