kazuna8
 ( 32.02% )
- ago
Is there a way to get all Strategy logs written to a log file?

My strategy runs fine most of the time, but occasionally it fails to generate a signal like today, and I didn't notice it until later after closing WL8.

I would like all Strategy logs written to a log file to make it easier to find out what would have gone wrong. I'm just guessing if IQFeed was not updating the daily data for some reason.
0
397
Solved
22 Replies

Reply

Bookmark

Sort
- ago
#1
I would take a look at AddLogItem and AddLogItemOrders, which are member methods for IHost. I think the latter is for writing a broker extension, but there's no reason you couldn't call it from a strategy.

I use the first one for error reporting within my own local.components.dll code libraries. I've never used it in a strategy (I use WriteToDebugLog for that), but I don't see why you couldn't. The error logs can be copied to the clipboard.
0
kazuna8
 ( 32.02% )
- ago
#2
Thank you for your suggestion.

I'm rather looking for something like "SCLog.txt" that we used to have in the WL6 days.

Also, I was wondering if there is a way to have the Strategy Log written to a log file, or an API to access the Log programatically when the strategy code gets run.
0
Cone8
 ( 6.07% )
- ago
#3
If you need one of us to say it, there's no "SCLog" (that only sounds familiar to me, but I can't even find a reference to it on the WL6 forum), but it's pretty easy to create a logger and add it to a strategy. Any AI tool will do it for you. You don' t need an another API for that.
0
kazuna8
 ( 32.02% )
- ago
#4
This is the Strategy Log when I ran my strategy.
I want to save these lines in a log file to troubleshoot an issue by comparing another log file I'm writing from my strategy code.

CODE:
2025/05/22 01:32:00: Status = LoadingData 2025/05/22 01:32:00: Start Polling Thread 2025/05/22 01:32:00: Populating Data 2025/05/22 01:32:00: Calling GetHistories Pass 1 2025/05/22 01:32:00: GetHistories returned with 12 symbols 2025/05/22 01:32:00: Calling GetHistories Pass 2 2025/05/22 01:32:00: GetHistories returned with 12 symbols 2025/05/22 01:32:00: TQQQ   3843 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: RVX.XO 4792 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: VXD.XO 5081 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: VXN.XO 6051 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: QQQ   6592 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: IWM   6285 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: TNA   4161 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: DIA   6878 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: VIX.XO 8916 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: UDOW   3843 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: UPRO   4002 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: SPY   7396 bars to 2025/05/21 | IQFeed 2025/05/22 01:32:00: NextRun set to 2025/05/22 13:35 2025/05/22 01:32:00: Status = Idle 2025/05/22 01:32:06: Running Now 2025/05/22 01:32:06: Status = Processing 2025/05/22 01:32:06: Pass 1 - Requesting updates for 12 symbols... 2025/05/22 01:32:08: Pass 1 - UpdateHistories returned 0 symbols 2025/05/22 01:32:10: Ran Strategy on TQQQ,RVX.XO,VXD.XO,VXN.XO,QQQ,IWM,TNA,DIA,VIX.XO,UDOW,UPRO,SPY: 0 Signals, Run Time=2sec 2025/05/22 01:32:10: NextRun set to 2025/05/23 13:35 2025/05/22 01:32:10: Status = Completed 2025/05/22 01:32:10: Processed all Symbols
0
Cone8
 ( 6.07% )
- ago
#5
That's the Strategy Monitor log. I change the title to reflect it and add it as a feature request. Then it's up to Glitch.
0
- ago
#6
The tool you are looking for is called "log4net". I included a link below, which I like for its simplicity, but it's very old. https://www.codeproject.com/Articles/140911/log-net-Tutorial

What you should do instead is Google "log4net C#" and follow those newer links instead.

Personally, I think you are trying to kill a sparrow with a sledge hammer using a tool like log4net in this capacity. But we are both professional computer guys and we know what we want, so we should say this is a difference of opinion (and leave it there). Happy computing.
0
Glitch8
 ( 9.82% )
- ago
#7
kazuna, I'll add the option to save the SM logs to files in the next build.
1
Best Answer
kazuna8
 ( 32.02% )
- ago
#8
Glitch, that's very helpful.

My strategy in SM appears not to be getting run these days for some unknown reason.
I have my own logging in my strategy code, but so far no clue as the strategy appears not even getting a run.
0
Cone8
 ( 6.07% )
- ago
#9
Re: no clue as the strategy appears not even getting a run.

Usual culprits:
1. Wrong Market selected at the bottom of the S. Monitor configuration.
2. Delayed data
3. Local clock not synchronized properly to the local time zone.
0
kazuna8
 ( 32.02% )
- ago
#10
Cone, thank you for your suggestion.

I haven't changed anything on my side, but it started suddenly.
That's why I need the SM log.

The only thing I changed recently was to update WL8, but there is no culprit in the change list, so I suspect it is something to do with IQFeed.

If I test my strategy well enough after the market closes, I cannot duplicate the problem.
0
Cone8
 ( 6.07% )
- ago
#11
But the log is available. It's just not saved to disk.
0
kazuna8
 ( 32.02% )
- ago
#12
Yes, the log is available, but only while WL8 is running.
Once WL8 restarts or crashes, the log is all gone.
The log greatly helps at that time and later times to examine what was going on or infer what would have gone wrong.
0
Cone8
 ( 6.07% )
- ago
#13
What's causing restarts and crashes? A crash should be a very rare event.
0
kazuna8
 ( 32.02% )
- ago
#14
Forgot about crashes. I have never seen WL8 crashing. I just used it to explain the fact that the log is gone when WL8 is closed.

I semi-automate WL8, and it opens and closes WL8 automatically to schedule the strategy runs. I usually monitor it when WL8 running but occasionally I'm away from the screen for a short meeting, kids poking me etc, and it happened in the last few days.

Regardless, I would like an option to have the SM log saved to the disk.
1
kazuna8
 ( 32.02% )
- ago
#15
I updated my WL8 to Build 123 and found the "Save Log to File" option to enable.
Once I enable the option, I see the SMLogs folder with a dated log text file created in it.
However, soon I noticed a few issues.

The log is saved, but only from one instance of the strategy running in SM. I have three instances of the same strategy in SM. The log from the last instance of the strategy seems to be overwriting the log file.

The log file appears to be named like this:
<Strategy Folder>Ì<Strategy Name>_<DataSet>;<Data Provider>_<Scale>_<Date>.txt

What's "Ì" between <Strategy Folder> and <Strategy Name>?
It should be "|" not "Ì"?

My suggestion would be changing the log file to be named to include the number registered in SM, like this:
<Strategy Folder>|<Strategy Name>_<DataSet>;<Data Provider>_<Scale>_<Date>_#1.txt
<Strategy Folder>|<Strategy Name>_<DataSet>;<Data Provider>_<Scale>_<Date>_#2.txt
<Strategy Folder>|<Strategy Name>_<DataSet>;<Data Provider>_<Scale>_<Date>_#3.txt
0
Glitch8
 ( 9.82% )
- ago
#16
Good idea, I’ll make that change for Build 124.
0
Glitch8
 ( 9.82% )
- ago
#17
It's in place for Build 124.
0
kazuna8
 ( 32.02% )
- ago
#18
Awesome.

Do you append the log to the log file?
I want the log to be kept across restarts of WL8.
0
kazuna8
 ( 32.02% )
- ago
#19
One more thing I just noticed.

The log isn't saved to the log file unless you focus on the strategy from the strategy list on SM.
I would like the log to be saved as the strategy gets run and generates the log.
0
kazuna8
 ( 32.02% )
- ago
#20
I have just tested Build 124 and confirmed that the log file is named to include the number registered in SM. Looks great!

However, those two issues I pointed out later remain.

1. The log isn't saved to the log file unless you focus on the strategy from the strategy list on SM. I would like the log to be saved as the strategy gets run and generates the log without requiring the log window to refresh the logs.

2. Restarting WL8 and opening the SM will overwrite the log file. I would like SM to append the log to the log file.
0
Glitch8
 ( 9.82% )
- ago
#21
I’ll definitely work on those improvements for the next Build.
1
kazuna8
 ( 32.02% )
- ago
#22
Tested on Build 126, and everything works as expected, or even exceeds expectations. Awesome!

I especially like this message:
QUOTE:
--Log file read, new entries begin below--


Thank you very much!
1

Reply

Bookmark

Sort