#cs ........Intro
;// // //
;// // File: DelRT.au3 //
;// // Author: Josh1 //
;// // Purpose: Remove all quotations between //
;// // two given Date //
;// // Language: Autoitscript //
;// // ENJOY :-) //
;// // //
; // ////////////////////////////////////////////////////////////////////
#ce
Global $DataDir, $DayDeleteFrom, $DayDeleteUpto
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiDateTimePicker.au3>
#include "DTC.au3"
#include <Date.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#Region ### START Koda GUI section ### Form=
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
;$Scrip = "NIFTY"
$Form1 = GUICreate("Select Days to delete", 460, 322, 202, 120)
GUISetFont(10, 400, 0, "MS Sans Serif")
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
$Label1 = GUICtrlCreateLabel("From Date", 40, 20, 67, 20)
$Date1 = GUICtrlCreateDate(_NowCalcDate(), 128, 12, 233, 24)
$Label2 = GUICtrlCreateLabel("To Date", 40, 52, 53, 20)
$Date2 = GUICtrlCreateDate(_NowCalcDate(), 128, 52, 233, 24)
$Label3 = GUICtrlCreateLabel("Database Path", 24, 92, 94, 24)
$Input1 = GUICtrlCreateInput(IniRead(@WorkingDir & "\DelRT.ini", "AB", "Datadir", "C:\AmiBroker\"), 128, 92, 297, 24)
$Label4 = GUICtrlCreateLabel("Delete data for", 24, 122, 94, 24)
$Input2 = GUICtrlCreateInput(IniRead(@WorkingDir & "\DelRT.ini", "AB", "Scrip", "NIFTY"), 128, 122, 297, 24)
$Button1 = GUICtrlCreateButton("OK", 168, 162, 105, 25)
$Edit1 = GUICtrlCreateEdit("",128,192,300,120)
GUICtrlSetOnEvent($Date1, "Date1Change")
GUICtrlSetOnEvent($Date2, "Date2Change")
GUICtrlSetOnEvent($Input1, "Input1Change")
GUICtrlSetOnEvent($Input2, "Input2Change")
GUICtrlSetOnEvent($Button1, "DeleteTics")
$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
$style = "yyyy/MM/dd"
GUICtrlSendMsg($Date1, $DTM_SETFORMAT_, 0, $style)
GUICtrlSendMsg($Date2, $DTM_SETFORMAT_, 0, $style)
GUISetState(@SW_SHOW,$Form1)
#EndRegion ### END Koda GUI section ###
While 1
Sleep (100)
WEnd
Func Date1Change()
If GUICtrlRead($Date1) <= GUICtrlRead($Date2) Then
; MsgBox(64,"",$DayDeleteFrom & " - " & GUICtrlRead($Date1))
Else
MsgBox(64,"","From Date cannot be greater than To Date")
GUICtrlSetData($Date1,_NowCalc())
EndIf
EndFunc
Func Date2Change()
If GUICtrlRead($Date2) < GUICtrlRead($Date1) Then
MsgBox(64,"","To date cannot be before From Date")
GUICtrlSetData($Date2,_NowCalc())
ElseIf GUICtrlRead($Date2) > _NowCalc() Then
MsgBox(64,"","To date cannot be future Date")
GUICtrlSetData($Date2,_NowCalc())
EndIf
EndFunc
Func Input1Change()
$DataDir = GUICtrlRead($Input1)
EndFunc
Func Input2Change()
$Scrip = GUICtrlRead($Input2)
EndFunc
Func CLOSEButton()
Exit
EndFunc ;==>CLOSEButton
Func DeleteTics()
$DayDeleteFrom = (_Date_Time_Convert(GUICtrlRead($Date1), "yyyy/MM/dd", "yyyyMMdd")) & "000001"
$DayDeleteUpto = (_Date_Time_Convert(GUICtrlRead($Date2), "yyyy/MM/dd", "yyyyMMdd")) & "235959"
$DataDir = GUICtrlRead($Input1)
$Scrip = GUICtrlRead($Input2)
IniWrite(@WorkingDir & "\DelRT.ini", "AB", "Datadir", $DataDir)
IniWrite(@WorkingDir & "\DelRT.ini", "AB", "Scrip", $Scrip)
$oAB = ObjCreate("Broker.Application")
$oAB.Visible = 1
; $oAB.LoadDatabase($DataDir)
$oStocks = $oAB.Stocks
$Qty = $oStocks.Count
$i = 0
$j = 0
$k = 0
For $i = 0 To ($Qty-1)
$Stock = $oStocks($i)
$k = 0
$ScripName = $Stock.Ticker
$QQ = $Stock.Quotations.Count
$Quotes = $Stock.Quotations
if $ScripName = $Scrip Then
_GUICtrlEdit_AppendText($Edit1,"Total Quotes - "&$ScripName&" -"& $QQ & @CRLF)
$ts = TimerInit()
For $j = ($QQ-1) to 0 Step -1
$Quote = $Quotes($j)
$tmpDateNum = $Quote.Date
if (($tmpDateNum >= $DayDeleteFrom) and ($tmpDateNum <= $DayDeleteUpto)) Then
$k+=1
$Quotes.Remove($j)
ElseIf ($tmpDateNum < $DayDeleteFrom) Then
ExitLoop
EndIf
Next
$oAB.RefreshAll
$td = TimerDiff($ts)
_GUICtrlEdit_AppendText($Edit1,"Total" & $k &"- Quotations removed in -" & int($td) & " miliSecs")
EndIf
Next
EndFunc