Saturday, 22 September 2018

Remove data between the dates for Amibroker (AFL)

Many times there is bad data uploaded into the database due to various reasons and then there is no other solution but to create a new database.
Understanding the common difficulty faced by amibroker users all across , this is a one stop solution wherein you can delete a particular date’s or range of date’s data from a particular amibroker database. All you have to do is supply name of database and range date and time (in case of intraday data) and run the jscript file from the “command prompt”. This script works for both EOD and intraday data. Its not my script and I am just the medium.

==================================================================

// Downloaded From www.WiseStockTrader.com
/* Its a jscript and hence should be run from the command prompt. Change parameters  ** before executing the script. Also take backup of your data for safety reasons.
** AmiBroker/Win32 scripting Example
**
** File:                Remove all quotations between dates .js
** Version:             0.1 beta
** Purpose:             Remove all quotations between dates for all symbols !
** Language:            JScript (Windows Scripting Host)
**
**
** CHANGE variable DataDir
** CHANGE variable DeleteFrom and DeleteTo 
**
** ENJOY :-)
*/

// where database is stored
fs = new ActiveXObject("Scripting.FileSystemObject");

DataDir = "c:\\Program Files\\AmiBroker\\Data"

var oAB = new ActiveXObject("Broker.Application");
var fso = new ActiveXObject("Scripting.FileSystemObject");
file    = fso.OpenTextFile( "_remowe_xdays.log", 2, true );

oAB.LoadDatabase( DataDir );

var oStocks = oAB.Stocks;
var Qty = oStocks.Count;
var MiliSecInDay = 24 * 60 * 60 *1000;

var DeleteFrom = new Date("august 1, 2009 00:00:00");
var DeleteTo = new Date("august 15, 2009 00:00:00");

//add a day to the date
DeleteTo.setDate(DeleteTo.getDate() + 1);

// make date with time 00:00:00        
var DayDeleteFrom = new Date((Math.floor(DeleteFrom / MiliSecInDay)) * MiliSecInDay);
var DayDeleteFromNum = (Math.floor(DeleteFrom / MiliSecInDay)) * MiliSecInDay;

var DayDeleteTo = new Date((Math.floor(DeleteTo / MiliSecInDay)) * MiliSecInDay);
var DayDeleteToNum = (Math.floor(DeleteTo / MiliSecInDay)) * MiliSecInDay;

file.WriteLine( "Starting delete quotes from date:" + DeleteFrom);
file.WriteLine( "" );

for( i = 0; i < Qty; i++ )
{
        oStock = oStocks( i );
        file.Write( i + ". " + oStock.Ticker + "=" );

        for (j=oStock.Quotations.Count-1;j>=0;j--)
        {
                //file.Write( "j=" + j + "," );
                //tmpDate = new Date( oStock.Quotations( j ).Date );
                tmpDateNum = oStock.Quotations( j ).Date ;
                if (tmpDateNum >= DayDeleteFromNum) 
                {
   if (tmpDateNum <= DayDeleteToNum) 
   {
                        //file.WriteLine( "Delete data=" + tmpDateNum);
                        oStock.Quotations.Remove(j);
   }
                }
                else 
                {
                        //file.WriteLine( "Last data no to delete=" +tmpDateNum);
                        break;
                } 
        }
        file.WriteLine( "OK" );
}
oAB.SaveDatabase( );

file.Close();
WScript.Echo("Cleanup ended :-)" );


================================================================

For you who dont know how to use this, it’s a javascript. Copy and paste the code to notepad. Notice DataDir = “c:\\Program Files\\AmiBroker\\Data”. Change it according to your own amibroker database folder.
var DeleteFrom = new Date(“august 1, 2009 00:00:00”);
var DeleteTo = new Date(“august 15, 2009 00:00:00”);
Change it according to which date you wanna delete. In my case, I only need to delete 1 date, so i fill both with same date. It will be deleted without deleting the symbol. Only particular data and date. Period.
Save the notepad with .js extension, such as Datedelete.js etc.
How to use it? Double click that file to run it, and wait. It will take some time depend on how many data in that range. If the process is finished, there will be a small window notification said “Cleanup ended :-)”. Enjoy.

Monday, 10 September 2018

Saturday, 1 September 2018

Understanding Diversification in Stock Trading to Avoid Losses


Understanding Diversification in Stock Trading to Avoid Losses

 

Smart Money Indicator AFL





Here Is The Amibroker Code For  Smart Money Indicator.




_SECTION_BEGIN(" Smart Money Indicator");
SetBarsRequired(sbrAll,sbrAll);
BV = IIf( (H==L), 0, V*(C-L)/(H-L) );
SV = IIf( (H==L), 0, V*(H-C)/(H-L) );
PlotOHLC(SV,SV,0,0,"SellVolume",colorRed,styleCandle|styleNoTitle|styleNoLabel );
PlotOHLC(SV,BV+SV,SV,BV+SV,"BuyVolume",colorBrightGreen ,styleCandle|styleNoTitle|styleNoLabel );
Va = MA(V,30);
PlotOHLC( Va, Va, 0, 0, "", ColorBlend( colorWhite , GetChartBkColor(), 0.4 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
Plot(Va,"Average Volume",colorRose,styleNoLine|styleNoLabel );
VI = V/Va;
Title = "SellVolume : "+WriteVal(SV,5.0)+EncodeColor(colorTeal)+
 "\n"+" "+"BuyVolume : "+WriteVal(BV,5.0)+" "+
"\n"+"VolumeIndex : "+WriteVal(VI,1.2)+" "+ "\n"
+EncodeColor(colorPink)+
"BuyVolume : "+WriteVal(100*BV/(BV+SV),2.0)+"%"+" "+
"\n"+"SellVolume : " +WriteVal(100*SV/(BV+SV),2.0)+"%";
GfxSetOverlayMode(1);

_SECTION_END();