# Public and for release, CBEC v3.2.06 Build 4255+ [14th November, 2025] # # Copyright(c) Ivyware Pty Ltd 2025 (all rights reserved) # MELBOURNE, VICTORIA, AUSTRALIA, 3000 # # This file is provided as-is by Ivyware Pty Ltd. No claims are made # as to fitness for any particular purpose. No warranties of any kind # are expressed or implied. The recipient agrees to determine # applicability of information provided. # # Ivyware hereby grants the right to freely use the information # supplied in this file for the creation of Python Advisor scripts # supporting the Chartboard Application, and to make copies of this # file in any form for internal or external distribution as long as # this notice remains attached. # # No waranty or suitability for purpose is implied. # # Simple Python Advisor script that generates "Simple Moving Averages" # for the Chart over which its run # NOTES: Download latest version from # https://www.ivyware.com.au/PythonScripts/Sample[SMA-EMA].pya # : Download latest version of the Chartboard Extension Classes # (PythonCBEC.pyw) upon which this script is based from # https://www.ivyware.com.au/PythonScripts/PythonCBEC.pyw # : Script can be run over any OHLCvs type chart stack, necessary # charts, indicators and overlays that are absent will be auto # generated, calculated and displayed whilst this script is # active. Such will be cleaned up upon completion, or new script # activation, returning OHLCvs chart stack to its original state. # Refer [Ribbon Bar >> Advisors Tab >> {Cancel}] button # : OHLCvs chart scripts can be run over chart stacks generated and # activated through the Scanning results window. # : Simply drag this script from either "Windows File Explorer" or # "Python Scripts Explorer" and drop over any OHLCvs type chart stack. # It then runs automatically and becomes the default [Ribbon Bar # >> Advisors Tab >> {Run Local}] script. # : Based upon Chartboard Extension Classes (CBEC) shipped with # Chartboard product # : Requirement is for phython 3.8 to be installed. # : Can be enhanced as circumstances dictate. However, it should be # be renamed given each successive Chartboard update over-writes this # file. # ***: Script under development and subject to change without notice*** # import sys sys.path.insert(0, 'C:\\Program Files\\Chartboard\\PythonScripts') # CBEC folder from PythonCBEC import * import ctypes # An included library with Python install. from datetime import datetime from PYCB import PYCB_return from PYCB import PYCB_error # # Environment variables # NOTES: List of current environment variables suitable for debugging import os print ( 'Python environment') for param in os.environ.keys(): print ( "%20s %s" % (param,os.environ[param]) ) # # STEP 1 - Establish Root from which all other objects are descendants # NOTES: Effectively the Chartboard application itself. This script # is coded to run on CViewOHLCvs type views only. # : The parent window 'CView' refers to collection of tabbed views # in the centre of the application, 'this' refers to current # Chartboard view with focus from which script has been activated. oCRoot = CRoot(); if oCRoot.CWndType('CView','this') != 'CStackOHLCvs': raise PYCB_error ( "Script only supports CStackOHLCvs views, not " + oCRoot.CWndType('CView','this') ) # # STEP 2 - Establish CView # NOTES: CView is the parent of all the tabbed views. Effectively # the View tab under which this python script is running and # identified by the 'this' tag # : CViews can be of many types (CViewOHLCvs, CViewPFigure, CScanOHLCvs etc) # : Confirm 'CViewOHLCvs' type view, script only supports such oCView = oCRoot.CViewFactory('this'); if not oCView.IsCViewOHLCvs(): raise PYCB_error ( "Script only supports CViewOHLCvs type CView's, not " + oCView.sType ) # # STEP 3 - Establish the CViewOHLCvs object # NOTES: Must be a OHLCvs type View tab for this script to work. Fails for # all other view types. Script may only access single Chart tab. # : Chart Period Units controlled by the current Ribbon Bar >> Chart Group # >> Chart Period Units tab selection. Alternatively this value may be # over-ridden via PUnits_Year, Quarter, Month, Week or Day definition # from PythonCBEC.pyw # : Calculations are performed and values persist concurrently for all # Period Units. Hence, state for alternative periods can be compared. oCViewOHLCvs = oCRoot.CViewFactory('this'); if not oCViewOHLCvs.IsCViewOHLCvs(): raise PYCB_error ( "Script only supports OHLCvs views, not " + oCViewOHLCvs.sCViewType ) # # STEP 4 - Access the CStackOHLCvs object within oCViewOHLCvs # NOTES: The CViewOHLCvs tab can add synthetic charts and overlays as # required via the Prerequisites method called within this script. # : Chart reference order is respected. # : Some of the Prerequisites are for demonstration and cosmetic # purposes only. Firstly the chart stack is defined as a list of # prerequisites. # : Stack type MUST identify as 'CStackOHLCvs' oCStackOHLCvs = oCViewOHLCvs.CStackFactory() if not oCStackOHLCvs.IsOHLCvs(): raise PYCB_error ( "Script only supports OHLCvs stacks, not " + oCStackOHLCvs.sStackType ) print ( 'CStackOHLCvs Period Units:' + oCStackOHLCvs.sPUnits) print ( 'CStackOHLCvs Stock Code:' + oCStackOHLCvs.StockCode()) print ( oCStackOHLCvs ) print ( 'CStackOHLCvs Operative Time=' + str(oCStackOHLCvs.DATE()) ) print ( 'CStackOHLCvs Period Units=' + str(oCStackOHLCvs.nPUnits) ) # # STEP 5 - Configuration of Charts and Overlays within stack # NOTES: Chart decorations that may or may not be referenced by Advisor logic # : Secondly the Prerequisite overlays are defined for each chart. # : Prerequisites method ensures Chart and Overlay existence within # the stack. If absent they are created, calculated and displayed. # Then discarded upon script displacement or cancellation. Refer # RibbonBar >> Advisors tab >> {Cancel} button for further details. oCStackOHLCvs.Prerequisites('MSA') if oCStackOHLCvs.ChartExists('MSA'): oChartMSA = oCStackOHLCvs.ChartFactory('MSA') # # Testing DSeriesMSA oDSeriesMSA = oChartMSA.DSeriesFactory('MSA') ################################################# # OHLCvs Chart test # NOTES: Logically OHLCvs chart needs to exist within the chart stack # : Otherwise create temporary instance of chart for life of # Advisor. All necessary calculations are auto preformed # and displayed. Auto deleted when script is de-activated oCStackOHLCvs.Prerequisites('OHLCvs') print('Step1') if oCStackOHLCvs.ChartExists('OHLCvs'): oChartOHLCvs = oCStackOHLCvs.ChartFactory('OHLCvs') print('Step2') # # Testing DSeriesOHLCvs oDSeriesOHLCvs = oChartOHLCvs.DSeriesFactory('OHLCvs') print('Step3') # # Generate and configure 'Visuals' for SMA # NOTES: Utilises existing configuration if SMA already exists oDSeriesSMA030d = oChartOHLCvs.DSeriesSMAnnnFactory(32,5) oDSeriesSMA030w = oChartOHLCvs.DSeriesSMAnnnFactory(30,4) # # Generate and configure 'Visuals' for EMA # NOTES: Utilises existing configuration if EMA already exists oDSeriesEMA015d = oChartOHLCvs.DSeriesEMAnnnFactory(15,5) oDSeriesEMA040w = oChartOHLCvs.DSeriesEMAnnnFactory(40,4)