Python / Sierra Chart modules - futures io
futures io futures trading

Python / Sierra Chart modules

Discussion in Sierra Chart

Updated by asterix
    1. trending_up 1,110 views
    2. thumb_up 8 thanks given
    3. group 4 followers
    1. forum 3 replies
    2. attach_file 0 attachments

Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

Search this Thread

Python / Sierra Chart modules

(login for full post details)
  #1 (permalink)
Gold Coast
Experience: Advanced
Platform: Sierra Chart
Trading: Futures and Forex
Posts: 21 since Aug 2010
Thanks: 11 given, 40 received

Here's a little module that will convert all text files in a directory to scid files in the same or another directory. If the constant KEEP_UPDATING is True it will then check the text files every REFRESH seconds and if they've changed it will update the scid files.

Set FILES_IN and FILES_OUT. In windows the format is "C:\\mydir\\mysubdir\\"

Also set Timezone if you wish to change the times in Sierra's scid files (Sierra saves them in the UTC time zone).

Save the code in a file named something like and run it using python
Tested with Python 3.7 on Linux & Windows. Have fun:

Convert's Text files to SCID files for SierraChart
It will create a new scid file for every text file it finds
  format is assumed to be D T O H L C V T with comma separated variables
It will continue to update the scid file every REFRESH seconds
  generally refresh would be set to 1/2 the time period for the text file updates

import os
import struct
from time import sleep
from datetime import datetime as dt, timedelta as tdelta
import subprocess

# these are linux format, windows might need to use double backslashes \\
FILES_IN = "/home/john/Python/Trading/textfiles/"
FILES_OUT = "/home/john/zRamdisk/SierraData/"
TIMEZONE = 0  # scid saved as UTC, use this if the text file is another time zone
KEEP_UPDATING = True  # set to False to convert and stop; True for live updating
REFRESH = 0.25  # refresh every 1/4 second for 1/2 second updating text files
TEXT_FILE_SUFFIX = ".txt"  # usually .txt or .csv

sizeHeader = 0x38
sizeRecord = 0x28
file_header = (b'SCID8\x00\x00\x00\x28\x00\x00\x00\x01\x00\x00\x00\x00\x00' +
               b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +
               b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +

def excel_date(datetime, offset=TIMEZONE):
    """convert date&time with offset in hours to excel format for scid"""
    delta = datetime - dt(1899, 12, 30) + tdelta(hours=offset)
    return delta.days + delta.seconds / 86400

def python_date(exceldt, offset=TIMEZONE):
    """convert date&time with offset in hours to python format"""
    excel_as_delta = tdelta(days=exceldt//1) + tdelta(seconds=exceldt%1*86400)
    return dt(1899, 12, 30) + excel_as_delta + tdelta(hours=offset)

def write_struct(record, f):
    if len(record) == 8 and record[0][0].isnumeric():
        out = [excel_date(dt.strptime(f'{record[0]} {record[1]}', '%Y-%m-%d %H:%M:%S.%f'))]
        out.extend([float(s) for s in record[2:]])
        # note that SC packs dt, O, H, L, C, T, V not V, T so swap them
        wt = struct.pack('d4f4I', out[0], out[1], out[2], out[3], out[4], int(out[6]), int(out[5]), 0, 0)

def create_base(f):
    record = None
    with open(FILES_OUT + f[: -3] +'scid', "wb") as scidfile:
        with open(FILES_IN + f, "r") as txtfile:
            for line in txtfile:
                record = line.split(',')
                write_struct(record, scidfile)
    return f'{record[0]} {record[1]}'  # will update when date+time changes

def update_if_changed(files):
    for f in files:
        with open(FILES_IN + f, "r") as txtfile:
            record = txtfile.readlines()[-1].split(',')
            last_dt = f'{record[0]} {record[1]}'
            if files[f] == last_dt:
            files[f] = last_dt
            with open(FILES_OUT + f[: -3] +'scid', "ab") as scidfile:
                write_struct(record, scidfile)

if __name__ == '__main__':
    files = sorted(k for k in os.listdir(path=FILES_IN) if k[-4:] == TEXT_FILE_SUFFIX)
    files = {k: '' for k in files}
    for f in files:
        files[f] = create_base(f)
    print('finished base')
        # now test each input file each REFRESH interval & update if datetime changed
        while True:

Reply With Quote
The following 8 users say Thank You to kiwi for this post:

Can you help answer these questions
from other members on futures io?
DataLoader- incorrect cumulative values for other symbols
FYI plot bug & workaround: changing color or width is delayed 1 bar
EasyLanguage Programming
Chart text fixed and move with time
Scan by comparing SMAs within 5 mins
Volume Chart Trend Lines
(login for full post details)
  #2 (permalink)
Posts: 2 since Mar 2012
Thanks: 1 given, 0 received

hello Kiwi
I saw your code on sierracharts forums (and then here) (the one which reads scid file into pd df) but it keeps crashing for me, and as I am relatively new to programming I could not yet figure out why. May be you have a newer version , you could share?
I am also running sierra charts on linux.

Reply With Quote
(login for full post details)
  #3 (permalink)
Salt lake city utah
Posts: 16 since Dec 2014
Thanks: 4 given, 12 received

same here. keeps crashing

Reply With Quote
(login for full post details)
  #4 (permalink)
Posts: 2 since Mar 2012
Thanks: 1 given, 0 received

I figured out a "workaround", probably not as fast as the SCID file. I used a study which is writing the bar+study data to txt file. I can read that into a dataframe and work with that. It takes ~0.01 sec to update and return a dataframe at each update. That is sufficient for now.

Reply With Quote

futures io Trading Community Platforms and Indicators Sierra Chart > Python / Sierra Chart modules

February 25, 2020

Upcoming Webinars and Events

Introducing Edge Pools: Prop Pricing Model w/Edge Clear

Jul 9

Every journal equals ten meals for the hungry


Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432,
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts