IsStreaming in trading mode
Author: kazuna
Creation Date: 6/1/2009 9:57 PM
profile picture

kazuna

#1
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.

profile picture

Cone

#2
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.
profile picture

kazuna

#3
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.
profile picture

Eugene

#4
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.
profile picture

kazuna

#5
Cool. This is exactly I wanted. Thanks!
profile picture

kazuna

#6
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?

profile picture

Eugene

#7
Sad but true. Thanks for the heads-up.
profile picture

kazuna

#8
May I create a support ticket to track this issue?
profile picture

Cone

#9
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.
profile picture

kazuna

#10
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.
profile picture

Cone

#11
This should work -
CODE:
Please log in to see this code.
profile picture

kazuna

#12
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.
profile picture

kazuna

#13
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?
profile picture

Cone

#14
Right click and "execute now".
profile picture

kazuna

#15
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?
profile picture

kazuna

#16
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.
profile picture

kazuna

#17
Apparently PricePane and VolumePane are not working as explained in the quick reference.
May I create a support ticket for it?
profile picture

Eugene

#18
Please do.
profile picture

Eugene

#19
P.S. It's enough to link to this thread.
profile picture

Eugene

#20
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.
profile picture

kazuna

#21
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?
profile picture

Eugene

#22
Frankly, they seem to produce the same results in my short weekend test.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).