#CommentFlag //
SendMode Input // Recommended for new scripts
SetWorkingDir %A_ScriptDir% // Ensures a consistent starting directory.
SetTitleMatchMode, 2 // A window's title can contain the text anywhere
//!F1:: ; Press Alt F1 to execute
// TODO - ini to variable + split up stuff
// TODO - ABBackFIll error handling - Put Time + append as log
// TODO - DataTable - Get only todays data
// TODO - VWAP - HS needs extra columns for volume - Just select correct columns
// TODO - Index Backfill - Space in name
// TODO - DataTable - Search columns for Trading symbol, remove TradingSymbolColIndex
// TODO - Datatable - Loop Scrips
// TODO - VWAP - Better logic to check if vwap data has been fetched
// TODO - VWAP loop scrips
// ------------------------- Settings -----------------------------
scripAlias = NIFTY_F1
mode = DT // DT or VWAP
nowWindowTitle = NOW 1.13
backfillExePath = %A_ScriptDir%\ABBackFill
backfillExe = ABBackFill\ABBackFill.exe
// ---------- VWAP -----------
param1 = NFO // Exchg-Seg
param2 = FUTIDX // Series
param3 = NIFTY // Symbol
param4 = 1 // Expiry Date - Set by Position
param5 = XX // Opt Type
param6 = // Strike Price
VWAPSleepTime = 5000 // Wait Time in ms
vwapWindowTitle = Hourly Statistics
VWAPBackfillFileName = ABBackFill\VWAP.txt
// ------- DataTable ---------
TradingSymbol = NIFTY15AUGFUT
TradingSymbolColIndex = 2 // Position of Trading Symbol Column in Market Watch
dtWindowTitle = DataTable
DTBackfillFileName = ABBackFill\DataTable.txt
// ----------------------------------------------------------------
IfWinExist, NOW 1.13
{
global mode
if( mode = "DT" ){
dtBackFill()
}
else{
vwapBackFill()
}
}
return
// -------------------------------- DT -----------------------------------------------------
// NestPlus DataTable Backfill
dtBackFill()
{
global backfillExe, backfillExePath, dtWindowTitle
openDataTable()
writeDTData()
Run, %backfillExe%, %backfillExePath%, hide // Do backfill by calling exe
WinClose, %dtWindowTitle%,, 0 // Close DT - waits 500ms
}
openDataTable()
{
global nowWindowTitle, dtWindowTitle, TradingSymbolColIndex, TradingSymbol
ControlGet, RowCount, List, Count, SysListView323, %nowWindowTitle% // No of rows in MarketWatch
ControlSend, SysListView323, {Home}, %nowWindowTitle% // Start from top and search for scrip
Loop, %RowCount%{ // Select row with our scrip
ControlGet, symbol, List, Selected Col%TradingSymbolColIndex%, SysListView323, %nowWindowTitle%
// Take Trading Symbol from column Number in %TradingSymbolColIndex%
if( symbol = TradingSymbol ){ // and compare it with %TradingSymbol%
break
}
ControlSend, SysListView323, {Down}, %nowWindowTitle% // Move Down to next row if not found yet
}
if ( symbol != TradingSymbol ) {
MsgBox, %TradingSymbol% Not Found
ExitApp
}
ControlSend, SysListView323, {Shift}D, %nowWindowTitle% // At this point row should be selected. Open Data Table with shift-d
WinWait %dtWindowTitle%,, 30 // Wait for Data Table to open
WinMinimize %dtWindowTitle%
}
// columns expected order - TradingSymbol Time O H L C V
writeDTData()
{
global dtWindowTitle, DTBackfillFileName, VWAPBackfillFileName, scripAlias
ControlGet, data, List, , SysListView321, %dtWindowTitle% // Copy Data
IfExist, %VWAPBackfillFileName% // Clear Out VWAP data
{
file := FileOpen(VWAPBackfillFileName, "w" )
if IsObject(file){
file.Write(" ")
file.Close()
}
}
IfExist, %DTBackfillFileName%
{
file := FileOpen(DTBackfillFileName, "w" ) // := does not need %% for var
if !IsObject(file){
MsgBox "Can't open DT backfill file for writing"
ExitApp
}
AliasText := "name=" . scripAlias . "`n"
file.Write(AliasText) // Append AB Scrip Name
file.Write(data) // Add Data
file.Close()
}
else{
MsgBox "DT backfill file Not Found"
ExitApp
}
}
// ------------------------------- VWAP ----------------------------------------------------
// Open Hourly Stats
vwapBackFill()
{
global backfillExe, backfillExePath, vwapWindowTitle
openVwap()
writeVwapData() // Write csv
Run, %backfillExe%, %backfillExePath%, hide // Do backfill by calling exe
WinClose, %vwapWindowTitle%,, 0 // Close HS - waits 500ms
}
openVwap(){
global nowWindowTitle, vwapWindowTitle, param1,param2,param3,param4,param5,param6
WinMenuSelectItem, %nowWindowTitle%,, Market, Hourly Statistics // Open HS using NOW Menu
WinWait, %vwapWindowTitle%,,10 // Wait for HS to open
WinMinimize %vwapWindowTitle%
Control, ChooseString , %param1%, ComboBox1, %vwapWindowTitle% // Set Params - Exchg-Seg
Control, ChooseString , %param2%, ComboBox2, %vwapWindowTitle% // Series
Control, ChooseString , %param3%, ComboBox3, %vwapWindowTitle% // Symbol
Control, Choose , %param4%, ComboBox4, %vwapWindowTitle% // Expiry Date - Set by Position
Control, ChooseString , %param5%, ComboBox5, %vwapWindowTitle% // Opt Type
Control, ChooseString , %param6%, ComboBox6, %vwapWindowTitle% // Strike Price
ControlSetText, Edit1, 1, %vwapWindowTitle% // Set Interval as 1
ControlSend, Edit1, {Enter}, %vwapWindowTitle% // Request Data
}
// Columns Expected Order - Start time, O, H, L, C, V
writeVwapData(){
global vwapWindowTitle, VWAPBackfillFileName, DTBackfillFileName, scripAlias, VWAPSleepTime
// Wait till all data is available
// Just hope that sleep time is enough to fetch all data
// When slow, NOW seems to fetch them in batches without necessarily a clear order. sort messes it up more
// Better option - Can sort and try to verify that each minute from current time till 09:15 has been fetched
Sleep, %VWAPSleepTime%
ControlGet, vwapStats, List, , SysListView321, %vwapWindowTitle% // Copy Data into vwapStats
IfExist, %DTBackfillFileName% // Clear Out DT data
{
file := FileOpen(DTBackfillFileName, "w" )
if IsObject(file){
file.Write(" ")
file.Close()
}
}
IfExist, %VWAPBackfillFileName%
{
file := FileOpen(VWAPBackfillFileName, "w" ) // := does not need %% for var
if !IsObject(file){
MsgBox "Can't open VWAP file for writing"
ExitApp
}
AliasText := "name=" . scripAlias . "`n"
file.Write(AliasText) // Append AB Scrip Name
file.Write(vwapStats) // Add Data
file.Close()
}
else{
MsgBox "VWAP backfill file Not Found"
ExitApp
}
}