Can I use IsStreaming to determine whether or not the script is running in trading mode or backtest mode?
I have a script which closes position as soon as the market opens. I plan placing an order at the night before the market opens but I still want the script to close the position just in case if I forget to place an order.
The code looks like this:
CODE:
Please log in to see this code.
Size:
Color:
You can use IsStreaming to determine if the Strategy Window is streaming or not. That's all. Strategies always run in theoretical mode in Version 5.
You shouldn't forget to place the order after executing an EOD Strategy. If you have Alerts after you've updated your data and run the Strategy, place the orders immediately. You don't have to wait.
Size:
Color:
Actually I wanted to know if I can use IsStreaming to determine whether the script is executing in Strategy Monitor or backtesting in Strategy Window. As far as I tested, this is true as long as Streaming button is turned off in Strategy Window.
Size:
Color:
If you're looking for a way to tell if your Strategy is running in a strategy window vs. Strategy Monitor, then take a look at the QuickRef example for Cosmetic Chart, the PricePane Property.
Size:
Color:
Cool. This is exactly I wanted. Thanks!
Size:
Color:
I tried PricePane property but it is always non-null regardless if the script is running in Strategy Window or Strategy Monitor. Am I missing something?
Size:
Color:
Sad but true. Thanks for the heads-up.
Size:
Color:
May I create a support ticket to track this issue?
Size:
Color:
Sure, but we're checking first if it is an issue at all. There could be a good reason for PricePane to return a value now.
Size:
Color:
Is there any way for the script to know whether it is running in Strategy Window or Strategy Monitor other than looking at PricePane?
I need a solution for my script to differentiate these two windows.
Size:
Color:
This should work -
CODE:
Please log in to see this code.
Size:
Color:
So it means that ChartStyle object exists (not null) but not initialized (or allocated?) therefore casting will raise an exception? Or will DrawLabel raise an exception because PricePane is invalid object (not null)?
Supposed the above assumption is correct, how about this one?
CODE:
Please log in to see this code.
Size:
Color:
I wish I could test my code but Strategy Monitor doesn't run the script when market is closed.
Any way to test the code on Strategy Monitor while market is closed?
Size:
Color:
Right click and "execute now".
Size:
Color:
The "run now" has been giving me an error saying "Error(7): Thread was being aborted.".
I changed the symbol and now it works.
However, neither your code nor mine doesn't work well.
Your code ends up with no exception and my code ends up with an exception whether or not running in Strategy Monitor.
Any idea?
Size:
Color:
Just figured that I had to use 5 Minutes scale not 1 Minute.
Somehow using 1 Minute scale on Strategy Monitor didn't work but apparently it kept updating the data.
Anyway I wrote the code below and it works fine.
This works fine only with ChartStyle but neither PricePane nor VolumePane.
Because PricePane and VolumePane are always non null value even on Strategy Monitor.
CODE:
Please log in to see this code.
Size:
Color:
Apparently PricePane and VolumePane are not working as explained in the quick reference.
May I create a support ticket for it?
Size:
Color:
Please do.
Size:
Color:
P.S. It's enough to link to this thread.
Size:
Color:
Update:
According to the developers, this breaking change was purposeful and required, so the QuickRef examples will be reviewed.
Meanwhile, yet another workaround to detect if a strategy is being run in SM and it's the
PricePane.IsPricePane property:
CODE:
Please log in to see this code.
Size:
Color:
Thanks for the update.
Which one would you recommend whether looking at "ChartStyle == null" or "PricePane.IsPricePane" to determine if a script is running in SM?
Size:
Color:
Frankly, they seem to produce the same results in my short weekend test.
Size:
Color: