Possible to auto save RTD every 5 min in Ami during market hours?

Steve

Active Member
#1
Hi All,

Is it possibley to auto save RT data every 5 or 10 minutes in Ami
during market hours, at times during power outages, when pc
goes on the blink, entire data of previous hours is lost, if it was
not saved manually

Is there a way to auto save?

Thanks.

Steve
 
Last edited:
#2
yes should be possible using Jscript, VBscript /VBA (excel) or i think can be done in a AFL itself . . .

the Application object exposes a sub SaveDatabase()

JScript:

AB = new ActiveXObject("Broker.Application");

VB/VBScript:

AB = CreateObject("Broker.Application")

AFL:

AB = CreateObject("Broker.Application");


Methods:

Sub SaveDatabase()
Easiest should be using Excel, try doing it . . . if u not getting it i can try it next week end . . .


:) Happy


EDIT: better way is download Josh's excel that backfills data into amibroker, he saves the AB database, modify it to get what you want



EDIT2: does AB have a configuration somewhere to auto save, maybe, but why i did not think of that, before jumping to coding solutions :D
 

Steve

Active Member
#3
Hi Happy,

Ami does save data on its own when you exit amibroker,
but if entire pc goes off cause of power breakdown then all previous data
of the day is lost.
I do use Josh1 utility to stream data from NOW>excel>Ami, and
this problem occurs, during power outages.
Amibroker data saved at Prefrence>Misc>auto save.
What I require is afl or some other means to auto save data every
five or ten minutes, for trading intraday.
 
#4
Try this if it works . . . but use it at your own risk, I have not tested it (no way of closing Amibroker without it saving on exit) so don't know if it will work when AB crashes on no power . . .

Code:
_SECTION_BEGIN("AUTO SAVE");
function GetSecondNum()
{
	Time = Now( 4 );
	Seconds = int( Time % 100 );
	Minutes = int( Time / 100 % 100 );
	Hours = int( Time / 10000 % 100 );
	SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
	return SecondNum;
}
 
RequestTimedRefresh( 1 );
SaveTime = Interval()  * 1 ;// to increase time Use * 2 or 5 or give the Time directly in number of Seconds
SecNumber = GetSecondNum();
Newperiod = SecNumber % SaveTime == 0;
SecsLeft = SecNumber - int( SecNumber / SaveTime ) * SaveTime;
SecsToGo = SaveTime - SecsLeft;
MinsLeft	= floor(SecsToGo/60); 
SecsLeft	= SecsToGo%60;
GfxSetBkColor( colorBlack) ;
GfxSetTextColor(colorGold);
GfxSelectFont("Comic Sans MS", 12, 400 );		// Font and Size
GfxDrawText("Save After: " + NumToStr( SecsToGo, 1.0, False) + " Secs" ,5,20, 1300, 360, 0); 
AB = CreateObject("Broker.Application"); //
if (SecsToGo==1) AB.SaveDatabase ;
_SECTION_END();
This code will give you a warning about threading model etc as we are creating application object inside an AFL

:) Happy
 
Last edited:

josh1

Well-Known Member
#6
Suppose you want to save every 5 minutes.
1. Type "Save Period" in cell A4 and "0:5:00" in cell B4 (without quotes)
2. Open Module1 to add a counter in RTNest or RTNow whichever you are using.
In the top section after Dim, where Public variables are declared, add this line-
Code:
    Public SP as date ' Variable SP stores Save Period
3. Find the Timer() subroutine and replace it with this-
Code:
Private Sub Timer()
    If TimerActive = True Then
    On Error Resume Next
        If TimeValue(Now()) >= Range("L4").Value Then
            MyBook.Sheets("Nest").Range("D4") = "Time is- " & Now() & "   Exchange closed"
        ElseIf TimeValue(Now()) <= Range("L3").Value Then
            MyBook.Sheets("Nest").Range("D4") = "Time is- " & Now() & "   Exchange not open yet"
        Else
        MyBook.Sheets("Nest").Range("D4") = Now()

' New Code for saving database at fixed interval
		If SP > Range("B4") Then
		    SP = #0:00:00#   ' This part of code may have to be changed
		    AB.SaveDatabase
		    Else
		    SP = SP + RP
		    End If

        MakeCSV          'Calls Subroutine for generating csv file
        If DBPath <> "" Then CallAmiBroker    'Calls AmiBroker for importing file
    End If
4. I have not tested this code. You will have to do some R&D
 
#7
Suppose you want to save every 5 minutes.
1. Type "Save Period" in cell A4 and "0:5:00" in cell B4 (without quotes)
2. Open Module1 to add a counter in RTNest or RTNow whichever you are using.
In the top section after Dim, where Public variables are declared, add this line-
Code:
    Public SP as date ' Variable SP stores Save Period
3. Find the Timer() subroutine and replace it with this-
Code:
Private Sub Timer()
    If TimerActive = True Then
    On Error Resume Next
        If TimeValue(Now()) >= Range("L4").Value Then
            MyBook.Sheets("Nest").Range("D4") = "Time is- " & Now() & "   Exchange closed"
        ElseIf TimeValue(Now()) <= Range("L3").Value Then
            MyBook.Sheets("Nest").Range("D4") = "Time is- " & Now() & "   Exchange not open yet"
        Else
        MyBook.Sheets("Nest").Range("D4") = Now()

' New Code for saving database at fixed interval
		If SP > Range("B4") Then
		    SP = #0:00:00#   ' This part of code may have to be changed
		    AB.SaveDatabase
		    Else
		    SP = SP + RP
		    End If

        MakeCSV          'Calls Subroutine for generating csv file
        If DBPath <> "" Then CallAmiBroker    'Calls AmiBroker for importing file
    End If
4. I have not tested this code. You will have to do some R&D
Thanks Josh


This should do the trick :thumb:

But i wonder why AB does not have this feature inbuilt, . . .


:) Happy
 

josh1

Well-Known Member
#8
:

But i wonder why AB does not have this feature inbuilt, . . .
:) Happy
Australia is a developed country. They do not know "Power failure" :lol::lol:.
 

Steve

Active Member
#9
Try this if it works . . . but use it at your own risk, I have not tested it (no way of closing Amibroker without it saving on exit) so don't know if it will work when AB crashes on no power . . .

Code:
_SECTION_BEGIN("AUTO SAVE");
function GetSecondNum()
{
	Time = Now( 4 );
	Seconds = int( Time % 100 );
	Minutes = int( Time / 100 % 100 );
	Hours = int( Time / 10000 % 100 );
	SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
	return SecondNum;
}
 
RequestTimedRefresh( 1 );
SaveTime = Interval()  * 1 ;// to increase time Use * 2 or 5 or give the Time directly in number of Seconds
SecNumber = GetSecondNum();
Newperiod = SecNumber % SaveTime == 0;
SecsLeft = SecNumber - int( SecNumber / SaveTime ) * SaveTime;
SecsToGo = SaveTime - SecsLeft;
MinsLeft	= floor(SecsToGo/60); 
SecsLeft	= SecsToGo%60;
GfxSetBkColor( colorBlack) ;
GfxSetTextColor(colorGold);
GfxSelectFont("Comic Sans MS", 12, 400 );		// Font and Size
GfxDrawText("Save After: " + NumToStr( SecsToGo, 1.0, False) + " Secs" ,5,20, 1300, 360, 0); 
AB = CreateObject("Broker.Application"); //
if (SecsToGo==1) AB.SaveDatabase ;
_SECTION_END();
This code will give you a warning about threading model etc as we are creating application object inside an AFL

:) Happy
Hi Happy

As you rightly mentioned the above code gives this error:
Ln:35, Col:19 : Warning 503. Using LOE/CreateObject/CreateStatic Object is
not multi-threading friendly. See users Guide "Efficient use of
multithreading" for more detail.

Anyway thanks for trying.

Steve
 

Steve

Active Member
#10
Suppose you want to save every 5 minutes.
1. Type "Save Period" in cell A4 and "0:5:00" in cell B4 (without quotes)
2. Open Module1 to add a counter in RTNest or RTNow whichever you are using.
In the top section after Dim, where Public variables are declared, add this line-
Code:
    Public SP as date ' Variable SP stores Save Period
3. Find the Timer() subroutine and replace it with this-
Code:
[COLOR="Yellow"]Private Sub Timer()[/COLOR]
    If TimerActive = True Then
    On Error Resume Next
        If TimeValue(Now()) >= Range("L4").Value Then
            MyBook.Sheets("Nest").Range("D4") = "Time is- " & Now() & "   Exchange closed"
        ElseIf TimeValue(Now()) <= Range("L3").Value Then
            MyBook.Sheets("Nest").Range("D4") = "Time is- " & Now() & "   Exchange not open yet"
        Else
        MyBook.Sheets("Nest").Range("D4") = Now()

' New Code for saving database at fixed interval
		If SP > Range("B4") Then
		    SP = [COLOR="yellow"]#12:00:00 AM#[/COLOR]   ' This part of code may have to be changed
		    AB.SaveDatabase
		    Else
		    SP = SP + RP
		    End If

        MakeCSV          'Calls Subroutine for generating csv file
        If DBPath <> "" Then CallAmiBroker    'Calls AmiBroker for importing file
    End If
4. I have not tested this code. You will have to do some R&D
Hi Josh1

Thanks for the above changes, getting error
compile error:
Expected End Sub

Not an excel expert so don't know how to work with this error,
its the Private Sub Timer () heading that is yellowed (Shown on top)
and SP = #12:00:00 AM# This code has changed on its own.

Thanks

Steve
 

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?