Edit script compares pairs of charts

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
Posts: 2058
Joined: 21 Jul 2007
Has thanked: 186 times
Been thanked: 410 times

Edit script compares pairs of charts

Postby bowlesj3 » 29 Mar 2010

The edit script compares pairs of charts to see if they match up properly. I wrote this to be sure the spikes I keep getting on MC 6.0 startup were limited only to the end of a backfill.

Both options are finished and tested on my setup.

Option #1: You run it offline buy turning the scripts on. It edits all data where charts overlap.
Option #2: You can run it automatically at a selected time you set (likely at days end).

For option #2 you can either hard code the time to run it or submit the time with a GV. Option #2 runs faster because it only processes the current days data. There is a parameter that forces the files to be written out one minute earlier than the edit itself runs. The edit is smart enough to bypass data that is incomplete between the charts being compared.

The attached zip file contains the two scripts, a sample input parameter file and a sample report using my workspace, symbol and charts.

Special Install Notes:
Before you can run these scripts you must install GV 2.2 and the ELcollections. See this thread.

I also hard code my GVs in this directory (An old TS4.0 habit).
"C:\Program Files\TS Support\MultiCharts\GlobalVariable.dll"

Setting up and running this is very easy. However, I only trade one symbol and have it on several charts. These scripts are set up for one symbol only and thus pick it up automatically for me. If you have two symbols on a chart and want to edit one of these symbols across charts you need to learn the code and tweak it (you are on your own here).

Step #1: While in offline mode, Apply the “A_Z_ChartEdit_Write” to all charts that you want to report on and simply turn it on. It will immediately write out the txt data to your C:\ root directory. An example would be ChartEdit_ES_60M.txt, which is the 60 minute bars. You can do any minute bar size and any second bar size. If you apply this script to any other bar type it aborts on you.

Step #2: Create a txt file with the parameters. It directs the matching script to compare and edit pairs of charts you applied the “A_Z_ChartEdit_Write” to. This txt must also be in the C:\ root directory. There is one pair of charts to edit per each line in the script. The big-Chart has to be the first chart on a line followed by the small-chart. Here are the lines in the first parameter file I set up for initial testing. As noted above I included my parameter file in the zip file below.


You parameter list must have “0,M,0,M” as your last record always or the “A_Z_ChartEdit_Match” script will abort. Also the small file size must divide evenly into the large file size. This is why I do not have a 15,M,10M compare because 10 minute bars do not divide evenly into 15 minute bars. If you submit a parameter that breaks this rule it aborts the script.

Report details go into C:\ChartEdit_ES_Result.txt. Of course if your symbol was IBM it would be C:\ChartEdit_IBM_Result.txt

FileAppend was used instead of print because if the script aborts you do not loose your report up to that point. Not only that. I learned from this exercise that you can write to the same txt file using FileAppend from different scripts at the same time.
My parameters file in the zip file is called “ChartEdit_ES_Params.txt”. If your symbol was IBM you would change the ES to IBM to match your output .txt files.

Now apply the “A_Z_ChartEdit_Match” to your 1 minute bar chart and (for option #1 off-line runs which has RunTimeIn=0) turn it off then on each time you want to run the matching edit. Currently I have it set up to give a popup alert each time it runs regardless of good or bad results.

Tips for verifying the report is reporting an error correctly.

1/ You get a popup at the end of the match run regardless of results.

2/ According to Bruce in thread
the second bars not matching the minute bars is okay so do not get too upset if there are mismatches here. I am getting 517 mismatches between the 1 minute bars and the 10 second bars (disappointing). I got no errors between the other charts. So I guess I am okay. What does seem strange is that the minute bars are reporting lows below the second bars. Interactive Brokers does not have seconds bars so I can not verify against a TWS chart. I plan on digging into this more over time. I may set up edits for the amount that the charts are misaligned. I may set up a way of finding them very easily visually (meaning the charts would be marked at the locations where they mismatch). This last sentence naturally leads directly to the next topic #3.

3/ If you get an error and want to verify it
A/ first find the big-chart location and zoom in on the exact bar being reported.
B/ Next place a vertical line right over that bar to mark that spot clearly.
C/ Now set snap mode on & zoom in on the small-chart where the mismatch is being reported.
D/ Place a line along the bars that are contained within the big-chart bars (inclusive on both ends).
E/ Now figure out if the highest bars within the small-chart match the high of the Big-Chart.
F/ Do the same for the low.

4/ I found it handy to set the Write script alerts to show for 60 seconds.
5/ I set the match script alert to stay on the screen until I click on it.

Notes on the Option #2 run:
** You could hard code the time to run it before applying the script.
** You can submit a GV with the RunTimeIn to be picked up by all scripts.
** With the GV it defaults to write the files 1 minute before the edit run.
** If the write script last record is BarStatus=2 then EOF is 9999999.
** However, the edit run forces an EOF record out with FileAppend (date=8888888).
** If EOF 8888888 was used then the last bars match is bypassed.
** It process only one day of data at a time which makes it run faster.
** I have run it for many days now and it runs fine (very fast).

Special notes on using the GV for option #2.
I wanted a GV so I could quickly change the start time for repeat tests. I would change the GV value and recompile the scripts and every application of these scripts to all the charts would be restarted because of the recompile. If you change the GV mid day you have to restart scripts since the GV is picked up at the currentbar=1 test so it worked out very well for testing and was much easier than having to change the time in the individual parameters on all those charts (way way easier). However for users who do not need to test the scripts it is probably easier to set your time for the end of the day in the scripts as the default then apply them to the charts. If you study how the RunTimeIn parameter is used you will see that both the write script and the match script should have the same RunTimeIn settings. The Write script automatically adjusts its RunTimeIn to be 1 minute before the match run so all the files are certain to be out there when the match script runs.

I am not sure how useful this will be but it was an interesting exercise.
A/ I now know for the first time that that all my charts above the seconds bars and below the daily bars line up properly.
B/ It is good to study for learning the Elcollections commands required to read in records with both numbers and strings.
C/ Some day I will adapt this for daily bars which I am sure do not match.

Regarding daily bars, weekly bars and tick charts; knowing the logic, it should be possible for this program to process these charts and properly compare them. However I have not tested them yet and have decided to look at these eventually (in a few weeks probably I will get around to it).

Late Additions:
1/ I added an output result history file that will collect your summary result totals with each successive run. The file name is "ChartEdit_ES_ResultHistory.txt". There is now a sample of this report in the zip file. On the far left of this report on each line is the date and time that the run took place.

2/ I also added a png picture of the 1-minute bars and 10-second bars together showing one of the edit results. I copied the edit report line out of "ChartEdit_ES_Result.txt" that reports this error into this png file at the very bottom. I used the tips mentioned above for verifying the edit report to mark the PNG file so you can see the edit report is reporting correctly.
(79.62 KiB) Downloaded 145 times

Return to “User Contributed Studies and Indicator Library”