Join useThinkScript to post your question to a community of 21,000+ developers and traders.
def marketOpen = if agg >= AggregationPeriod.DAY then 1 else if SecondsTillTime(adjEndTime) >= 300 and SecondsFromTime(adjStartTime) >= -300 then 1 else 0;
If anyone is interested, I adjusted the thinkScript strategy and the Powershell script to include volume. I have a screenshot but don't know how to include that in posts to the forum.
It looks like you have an extra space.
C:\Users\jud\Documents\Get-SOHLCP.ps1 C:\Users\jud\Documents\StrategyReports_ESXCME_72720.csv
That was it, that seemed to just open the excel file though. Does it save the data somewhere?
name="SOHLCP|"+GetSymbol()+"|"+open[-1]+"|"+high[-1]+"|"+low[-1]+"|"+close[-1]+"|"+close);
name="SOHLCP|"+GetSymbol()+"|"+open[-1]+"|"+high[-1]+"|"+low[-1]+"|"+close[-1]+"|"+close+"|"+macdValue[-1]+"|"+macdAvg[-1]);
JonR,
I also adapted the script to include volume; however, in order for most trading platforms to import this data the numerical values have to be in a numerical format not in a text format as this script generates. You can tell the format by seeing that the numbers are enclosed in quotation marks. Also the date/time field needs to be separated into a date field and a time field separately, not date & time combined. Possibly my previous post didn't clarify that. Have you tried to import your data into a trading platform yet?
Script for exporting volume.
https://mega.nz/file/4tckTQSB#voXExrndNk_PvDMC8880XjioVl946FVAu_i_uRZ4HZ0
#
# kg_EveryTickSOHLCP
#
# Strategy to capture every bar OHLC and P, the previous close.
# Useful for exporting data from TOS into a CSV file for further processing.
#
# Author: Kory Gill, @korygill
#
declare upper;
declare once_per_bar;
input startTime = 820; #hint startTime: start time in EST 24-hour time
input endTime = 1600; #hint endTime: end time in EST 24-hour time
def adjStartTime = startTime;# - 1;
def adjEndTime = endTime;# - 1;
def agg = GetAggregationPeriod();
# we use a 1 bar offset to get orders to line up, so adjust for that here
def marketOpen = 1;#if agg >= AggregationPeriod.DAY then 1 else if SecondsTillTime(adjEndTime) >= 60 and SecondsFromTime(adjStartTime) >= -60 then 1 else 0;
# get indicator values
#def macdValue = MACD().Value;
#def macdAvg = MACD().Avg;
# if you want macdValue and macdAvg, replace the name= line in the forula with
# name="SOHLCP|"+GetSymbol()+"|"+open[-1]+"|"+high[-1]+"|"+low[-1]+"|"+close[-1]+"|"+close+"|"+volume[-1]+"|"+macdValue+"|"+macdAvg);
# but you also need to keep the PowerShell script in sync to parse the line properly
AddOrder(OrderType.BUY_TO_OPEN,
marketOpen,
low,
1,
Color.White,
Color.White,
name="SOHLCP|"+GetSymbol()+"|"+open[-1]+"|"+high[-1]+"|"+low[-1]+"|"+close[-1]+"|"+close+"|"+volume[-1]);
AddOrder(OrderType.SELL_TO_CLOSE, marketOpen, high, 1, Color.White, Color.White, name="SellClose");
#
# Get-SOHLCP.ps1
#
# Script to convert a TOS ThinkOrSwim kg_EveryTickSOHLCP strategy report csv file to an object and/or proper csv data file.
#
# Author: Kory Gill, @korygill
# Version: 20200304.2300
#
# Examples
# $x = gci 'StrategyReport*' | Select -ExpandProperty FullName | D:\Source\Repos\technical-analysis-dev\dev\Get-SOHLCP.ps1 -InformationAction Continue -ExportAsObject
# $x = gci 'D:\Database\MarketData\TOS-StrategyReport-Files-SOHLCP\feb-3to7\StrategyReport*' | Select -ExpandProperty FullName | D:\Source\Repos\technical-analysis-dev\dev\Get-SOHLCP.ps1 -InformationAction Continue
# $x = gci 'D:\Database\MarketData\TOS-StrategyReport-Files-SOHLCP\feb2020\StrategyReport*' | Select -ExpandProperty FullName | D:\Source\Repos\technical-analysis-dev\dev\Get-SOHLCP.ps1 -InformationAction Continue
# $x = gci 'D:\Database\MarketData\TOS-StrategyReport-Files-SOHLCP\UseThinkScriptDemo\StrategyReport*' | Select -ExpandProperty FullName | D:\Source\Repos\technical-analysis-dev\dev\Get-SOHLCP.ps1 -InformationAction Continue
#
# Get the symbol back:
# $m = 'SOHLCP-(~ES.XCME)(1.21.20 5.00 AM - 1.27.20 1.14 PM).csv' | Select-String -Pattern '\((.*?)\)' -AllMatches; $m.Matches[0].Groups[1].Value -replace '~', '/'
#
# $f = gci D:\temp\TOS-StrategyReport-Files-SOHLCP\sohlcp*.csv | Select -ExpandProperty FullName; $f | % {$m = $_ | Select-String -Pattern '\((.*?)\)' -AllMatches; $s = $m.Matches[0].Groups[1].Value -replace '~', '';$sym = ($s -split '\.' | Select -First 1); $file = $_; D:\Source\Repos\technical-analysis-dev\dev\Get-AllOrbTrades-SOHLCP.ps1 -FileName $file -SymbolName $sym}
# gci *glArray.csv | % {$csv = Import-Csv -Path $_; $csv | ? {[DateTime]::Parse($_.Datetime).Month -eq 1} | Export-Csv -NoTypeInformation -Path All_glArray_Data.csv -Append}
# get all January (month 1)
# gci D:\Database\MarketData\TOS-StrategyReport-Files-SOHLCP\feb-3to7\*glArray.csv | Select -ExpandProperty FullName | % {$csv = Import-Csv -Path $_; $csv | ? {[DateTime]::Parse($_.Datetime).Month -eq 1} | Export-Csv -NoTypeInformation -Path D:\Database\MarketData\TOS-StrategyReport-Files-SOHLCP\feb-3to7\All_glArray_Data.csv -Append}
#
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string[]]
$File,
[switch]
$ExportAsObject
)
Begin {
function Convert-CurrencyStringToDecimal ([string]$input)
{
((($input -replace '\$') -replace '[)]') -replace '\(', '-') -replace '[^-0-9.]'
}
$global:sohlcpAllData = New-Object System.Collections.Generic.List[PSCustomObject]
}
Process {
foreach ($f in $File)
{
if (-not (Test-Path $f))
{
throw "Cannot open file '$f'."
}
Write-Information "Processing file: '$f'."
# read csv file
$content = Get-Content -Path $f
# generate filename
$csvSymbol = ($content[1] -split 'Symbol: ')[1] -replace '/', '~' -replace ':', '.'
$csvWorkTime = ($content[2] -split 'Work Time: ')[1] -replace '/', '.' -replace ':', '.'
$outFile = 'SOHLCP-(' + $csvSymbol +')('+ $csvWorkTime + ')'
# find the lines that contain price information
$csvdata = $content | ? {$_ -match ";.*;"} | ConvertFrom-Csv -Delimiter ';'
# filter just the lines with (OHLC on them and make into CSV structure
$data = $csvData | ? {$_ -match "\(SOHLCP"}
$sohlcpFileData = New-Object System.Collections.Generic.List[PSCustomObject]
foreach ($item in $data)
{
# capture the OHLC data
$null = $item.Strategy -match "\(SOHLCP\|(.*)\)"
$v = $Matches[1] -split '\|'
$symbol = $v[0]
$open = $v[1] | Convert-CurrencyStringToDecimal
$high = $v[2] | Convert-CurrencyStringToDecimal
$low = $v[3] | Convert-CurrencyStringToDecimal
$close = $v[4] | Convert-CurrencyStringToDecimal
$prevClose = $v[5] | Convert-CurrencyStringToDecimal
$volume = $v[6] | Convert-CurrencyStringToDecimal
#
# Depending on how you gather data in your TOS script determines how you extract the values all separated by the | vertical bar symbol.
#
<#
$sohlcpData = [PSCustomObject]@{
'Symbol' = $symbol
'DateTime' = ([datetime]::Parse($item.'Date/Time'))
'Open' = [decimal]$open
'High' = [decimal]$high
'Low' = [decimal]$low
'Close' = [decimal]$close
'PrevClose' = [decimal]$prevClose
'Volume' = [decimal]$volume
'macdValue' = [decimal]$macdValue
'macdAvg' = [decimal]$macdAvg
}
#>
$sohlcpData = [PSCustomObject]@{
'Symbol' = $symbol
'DateTime' = ([datetime]::Parse($item.'Date/Time'))
'Open' = [decimal]$open
'High' = [decimal]$high
'Low' = [decimal]$low
'Close' = [decimal]$close
'PrevClose' = [decimal]$prevClose
'Volume' = [decimal]$volume
}
# add to our $sohlcpData array
$null = $sohlcpFileData.Add($sohlcpData)
$null = $sohlcpAllData.Add($sohlcpData)
}
# save to file
$sohlcpFileData | Export-Csv -Path (Join-Path (Split-Path -Path $f -Parent) ($outFile + '.csv')) -Force -NoTypeInformation -Encoding ASCII
}
}
End {
if ($ExportAsObject)
{
# helpful message to show caller our output variable
Write-Information "Out Data $($sohlcpAllData.Count) items (exported as `$sohlcpAllData)"
}
else
{
# don't show any extraneous output, and just return the data to the pipeline
return $sohlcpAllData
}
}
UVXY,"10/28/2020 8:28:00 AM","21.2","21.23","21.18","21.23","21.2" |
UVXY,"10/28/2020 8:30:00 AM","21.23","21.27","21.16","21.16","21.23" |
UVXY,"10/28/2020 8:30:00 AM","21.16","21.23","21.15","21.2","21.16" |
UVXY,"10/28/2020 8:30:00 AM","21.2","21.24","21.16","21.17","21.2" |
UVXY,"10/28/2020 8:30:00 AM","21.17","21.3","21.16","21.289","21.17" |
UVXY,"10/28/2020 8:31:00 AM","21.2899","21.38","21.2737","21.35","21.289" |
UVXY,"10/28/2020 8:31:00 AM","21.35","21.38","21.31","21.35","21.35" |
UVXY,"10/28/2020 8:31:00 AM","21.3482","21.35","21.275","21.3","21.35" |
UVXY,"10/28/2020 8:31:00 AM","21.3","21.31","21.2601","21.3","21.3" |
UVXY,"10/28/2020 8:32:00 AM","21.29","21.3","21.22","21.23","21.3" |
UVXY,"10/28/2020 8:32:00 AM","21.2399","21.34","21.2304","21.34","21.23" |
UVXY,"10/28/2020 8:32:00 AM","21.34","21.35","21.28","21.28","21.34" |
UVXY,"10/28/2020 8:32:00 AM","21.28","21.32","21.26","21.32","21.28" |
UVXY,"10/28/2020 8:32:00 AM","21.32","21.39","21.32","21.39","21.32" |
@krazyKarl are you using a 1m chart or a tick chart? the script should have a line for every bar on the chart.
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.