How to disable Google Doodles using an AdBlock filter

Assuming you have the AdBlock add-on installed, you can use it as shown below to filter out Google Doodles. The doodles are almost always a distraction; my poor mind is already burdened with enough things.

Also, FYI : I use AdBlock Edge, a version of the AdBlock plug-in which block Google’s ads, too (I read somewhere that the original AdBlock developer accepted donations by Google in exchange for allowing some of their ads through!). Here’s a link to it : https://addons.mozilla.org/en-US/firefox/addon/adblock-edge/.

  1. Go to Tools –> Add Ons


  2. Click on AdBlock Edge’s “Options”. Click on “Filter Preferences”


  3. Go to the  “Custom Filters” tab and click “Add filter group”

  4. Add a new group. I called mine “Google’s idiotic distracting doodles”, as you can see above
  5. Use the “Add filter” button to type in the following URLs one at a time:

  6. Note that I added the Google Hong Kong domain (www.google.com.hk/) because I get redirected to that when I use www.google.com. You have to figure out the URL appropriate to you. For example, in India, I would expect that the filters above would have to be changed to www.google.co.in/logo/*

That’s it!

Oh, and by the way, I highly recommend installing the DuckDuckGo Plus add-on, which is helping me slowly get rid of the Google search habit and move to DDG. Why, you ask? Privacy is one reason : Google tracks you, DDG doesn’t : http://donttrack.us/

A regular expression to match prime numbers!

  • The “Command Line Session” section below shows a session in perl -d where I explored this regular expression that matches a prime number of characters, but NOT a non-prime number of characters!
  • Let’s call this the “primes regex”
  • ^(?!(..+)\1+$)
  • I found the original regex in this hacker news post “Regex Golf” : https://news.ycombinator.com/item?id=6942086
  • The key concepts in play are:
    • Grouping
      • The (..+) in the primes regex is a group of two or more characters
    • Backreferences : “Backreferences match the same text as previously matched by a capturing group”
      • The \1 is the backreference that refers to the group of characters matched above
      • Let’s say the group (..+) matched n characters
      • \1+ means that the group is repeated at least once, and maybe more. Let’s say it is repeated m times.
      • Thus, in combination, the regex (..+)\1+ would match a multiple of n characters, such as 2n, 3n, 4n, etc;…
      • …and n could be 2, 3, 4,… in length. Backtracking would try various values for n until one matched!
      • Thus, in combination, (..+)\1+ matches any number of characters that is a multiple of two numbers n x m
    • Negative Lookahead, explained well here http://www.regular-expressions.info/lookaround.html
      • Lookaround actually matches characters, but then gives up the match, returning only the result: match or no match
      • Negative Lookahead checks that something is NOT ahead of the current position
      • Thus, the negative lookahead above basically says that the number of characters should not be “any number x such that it is a multiple of two numbers n x m”, i.e., this number resists factorization into a multiple of two other numbers, which, of course, is the definition of a prime number! :-)
  • Later, I realized that by using the !~ (doesn’t match) operator, the negative lookahead can be avoided, i.e., we just check that the number is not a non-prime (see Command-Line Session below)
    • (The Regex Golf site only asserts matches, i.e., it’s using =~. That’s why the negation using negative lookahead was needed)

Command-Line Session

  • Annotations by me marked “VJ: ” in green colour
VJ : Here's a prime number of characters first
 DB<7> print "x" x 31
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 DB<56> print "Matches!" if (("x" x 31) =~ /^(?!(..+)\1+$)/)
Matches!
 DB<57> print "Matches!" if (("x" x 18) =~ /^(?!(..+)\1+$)/)

VJ : No need of negative lookahead if you use !~
 DB<63> print "Matches!" if (("x" x 31) !~ /^(..+)\1+$/)
Matches!
 DB<64> print "Matches!" if (("x" x 18) !~ /^(..+)\1+$/)

Range Bars in NinjaTrader 7

Back in March 2012, I had to do a LOT of work to backtest some trading systems that used Range Bars with NinjaTrader 7. These are the personal notes I made during that period. These may be relevant to you if you are working with Range Bars in NinjaTrader or R.

 Overall TODOs

  • TODO : write script to convert each GBPJPY file to.period(“seconds”), then write that file out in NT7-friendly format.
  • TODO : import all these files into NT7, check once more
  • NT7 export!
  • Read the 250R file in R
  • Try getIntradayWindow() to correlate with the seconds-level tick data. Fix it to work with NT7
    • bar.Count is getting reset after the Session is crossed! Screw it. Not fixing it…95% of data is as expected, and I checked it VERY carefully, so ignoring this little thing. <– Fixed!
  • Finally, analyze setting a Stop on Winners based on the max reversal and/or Re-entry and/or Doubling Down!

Notes about getting Range Bars working with NT7

  • Data import : use the local timezone, not UTC, so that NT7 reads the timestamps as-is.
  • Very frustrating experience with Ninjatrader 7 : it refused to do charting on the imported data until I did right-click on the chart, selected “Data Series”, and in the “Data” section, set the “Session Template” to “Default 24/7″! Grr! Not obvious at all!! Till then, it was presumably using the “<Use instrument settings>” template, and $GBPJPY was set to “Forex”, which ends trading at 5:00 PM as per Ninja’s Tools –> Session Manager. Grr again!! Very frustrating.

Range Bars, Range Alt Bars

  • The built-in NT7 range bars do phantom / dummy bars to produce picture-perfect Range Bars. Amibroker does the same. But that is NOT what Iwant. I want real prices. Thus, only if price action is smooth (tick by tick, say) do we see perfect 250R range bars. Otherwise, the Close price might be > 250R.
    • Luckily, the code is available for inspection + modification! @see @BarsTypes.cs. And someone wrote up “Range Alt Bars” to fix this problem. I needed to tweak that, too, to get real prices + no phantom bars.
  • COLOURS [10076] trunk/ami/systems/ > svn commit -m “This is a NinjaTrader custom Bar Type to draw Range Bars that I fixed and tested to not draw phantom / dummy bars in case there is a sudden move; i.e., all prices seen are real” ‘@RangeAltBarsTypeV7.cs
  • To effect changes to a custom Bar Type / other .cs file after changing the code, one needs to compile any indicator. Tools –> Edit Ninjascript –> Indicator. Select any indicator, make a minor change and then undo, press F5. All the .cs files will be re-compiled.
  • The difference between Range Bars, and my RangeAltBars:
    • Default Range Bars : pretty 250R phantom bars with fake (computed) Close
    • Range Alt Bars : no phantom bars; no fake Close
  • Note : the timestamp on range bars in NT is the time the bar ends.
    • This is what quantmod’s to.minutes(), to.period() do, too : “It is important to note that all dates will be aligned to the end of each period by default”
    • Thus, my getIntradayWindow() in system31_intraday_analysis1.R should work as-is.
  • Also, note that the way @RangeAltBarsTypeV7.cs works right now, the Close of the current bar, which breaches 250R, is also the Open of the next bar! This is not a problem by itself; I may have to tweak getIntradayWindow() to take this into consideration? <– Fixed
    • I still see issues, though, because bar.Count is getting reset after the Session is crossed! :-( => my RangeBarsAlt is messed up at these session crossovers. 162 out of 6000 of the 250R range bars cross over the Session at 1 p.m. (local time of GMT + 8. Session Template says that session ends at 12 AM in the GMT – 5 TZ => 5 + 8 hrs away = 1 PM local time). Thus, had to turn check_NT7_strictness off! :-(
  • Custom historical data export trick : http://www.optimusfutures.com/tradeblog/archives/ninjatrader-custom-historical-data-export/

Tick data & NT7 issue+ quantmod’s to.period(“seconds”)

  • Two things:
  • NT7 is somehow rounding/truncating every price to 2 digits during the import?? Close / Low price of a bar from 131.271 to 131.270, for example. <– Fixed after I set the tick size to 0.001 and re-imported the data. It was initially 0.01 by default
  • BTW, quantmod’s to.period(“seconds”) on tick data does the correct thing, by the way.For example, with the below tick data for a particular second, it correctly produces the below OHLC. Unfortunately, quantmod does not have code to do tick-data-to-CRBs.
    • > x1[1599,]
       Open High Low Close
      2011-02-01 12:46:58.97 131.519 131.526 131.511 131.511
      
    • Tick data for 12:46:58:
      GBP/JPY,20110201 12:46:58.098,131.519,131.537
      GBP/JPY,20110201 12:46:58.217,131.52,131.537
      GBP/JPY,20110201 12:46:58.359,131.526,131.537
      GBP/JPY,20110201 12:46:58.494,131.522,131.537
      GBP/JPY,20110201 12:46:58.622,131.519,131.537
      GBP/JPY,20110201 12:46:58.790,131.516,131.537
      GBP/JPY,20110201 12:46:58.850,131.516,131.528
      GBP/JPY,20110201 12:46:58.970,131.511,131.52 

Some screenshots

  • Timezone during Import:
  • Strategy Analyzer Windows showing:
    • VJCSVExport strategy
    • Session template = “Default 24/7″
    • (The historical data chart by the side)
  • Change the Session Template of the Instrument $GBPJPY from “Forex” to “Default 24/7″ in Instrument Editor (Tools –> Instrument Manager) to retain your sanity!
    • I still see issues, though, because bar.Count is getting reset after the is crossed! :-( => my RangeBarsAlt is messed up at these session crossovers. <– Fixed using “AddBar() only if bars.Count == 0 & !IsNewSession”
    • Important : Do data import after setting the tick size to 0.001. It was initially 0.01 by default and NT7 Import was truncating prices : 131.271 became 131.27, for example!
    • Changed to tick 0.005 as per what IB gives me. <– After the above data import, of course

Notes on “Volatility”, Chapter 5 from Options on Foreign Exchange by David DeRosa

This blog post is a test of publishing from OneNote to WordPress via Word ! I suppose I should post a note on how to do that.

  • “Options on Foreign Exchange” by David DeRosa, Chapter 5, “Volatility”. It’s REALLY good.
  • I came to it while searching for “risk reversal” and found out that
  • “The location of the volatility surface and the degree to which it has smile and skew are captured in quotations of the three important trades:
  • Screen clipping taken: 2013-08-13 3:06 PM

  • “The term volatility is ubiquitous in the options world. There are at least five distinct meanings that I will now introduce”
  • And for the rest, you have to read the book! (Sorry about the half baked blog post, just testing OneNote to WordPress)

How I got PHPEclipse + the DBG debugger working on Windows

Whew! I finally got PHP 5.1.1 debugging working with PHPEclipse on Windows XP.

My plan was to use XAMPP for the Apache, PHP, and MySQL part, and then set up PHPEclipse. There are many pages describing how to do this on the net, but getting it working involved some subtleties that took up 1 full day of tweaking.

My setup :

  1. OS : Windows XP
  2. XAMPP 1.5.1, i.e., 
    • MySQL 5.0.18
    • Apache 2.2.0
    • PHP 5.1.1
    • phpMyAdmin 2.7.0 pl1
  3. Then I installed PHPEclipse (for Eclipse 3.1) using the Update Manager as described on this plog4u page. This was a breeze.
  4. Then I downloaded and set up DBG and PHPEclipse as described here on plog4u. Of particular mention on this wiki page is Robert Kraske’s php_dbg.dll for PHP 5.1.1, which you will want unless you are ok with building it from scratch.

The whole plog4u wiki, and that page (“Installing the DBG Debugger”) in particular are gems. Thanks to whoever took all the screenshots, man!!

But after I got all the pieces in place as per the instructions on the above pages, I faced some issues. Here’s a list of issues and how I resolved them:

O========= Issues and resolutions ===========O

  • Issue : php_dbg.dll was not loading up (How do you know? Use Process Explorer from sysinternals.com and look at the apache process DLLs)
  • Resolution : I was working with the wrong php.ini. You have to work with the php.ini in apache/bin, not php/bin !!
  • Issue : The eclipse debugger just hangs.
  • Resolution : php_dbg.dll was being loaded with zend_extension_ts. You have to use extension=, NOT the zend_extension_ts=

Sample from my apache/bin/php.ini:

;[Zend]
; VJ : this doesn’t work, use extension= in the debugger section
;zend_extension_ts = “C:\xampp\php\ext\php_dbg.dll?
;zend_extension_ts = “C:\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll?
;zend_extension_manager.optimizer_ts = „C:\xampp\php\zendOptimizer\lib\Optimizer“
;zend_optimizer.enable_loader = 0
;zend_optimizer.optimization_level=15
;zend_optimizer.license_path =

[debugger]
extension=php_dbg.dll
debugger.enabled=on
debugger.profiler_enabled=on
debugger.hosts_allow=localhost 127.0.0.1
;debugger.hosts_deny=ALL
debugger.ports=7869, 10000/16
debugger.JIT_host = clienthost
debugger.JIT_port = 7869

  • Issue : Eclipse complains An internal error occurred during: “Debug Source lookup?
  • Resolution : I was giving the full path to the file in Remote Sourcepath. Instead, you should just give the path up to the directory in which your php file is located.
  • Issue : Clicking on the source screws up the PHP Browser display! This is obviously bad, since I will need to see the output web page as well as look around the code!
  • Resolution : Uncheck this option in the PHP preferences : “Refresh PHP browser view when opening editor?

I also tried using the debugbreak() method which some people recommended. This works, but native eclipse breakpoints are of course much more convenient.

Ode to the VC++ 6 compiler/linker

I am the drained brain,
I and the ass in the pain,
I will trouble you again and again,
“Error LNK2001: unresolved external symbol _main”

(With apologies to the hard working guys that must’ve taken years to write the compiler. :). Heck, I’d take a lifetime.)

This is in rememberance of those fond days in the last century (yep, 1998 is THAT far ago) when I started using Visual Studio 6.0. ‘Twas a good IDE.

Peterson’s 2-process mutual exclusion algorithm

Was reading up about Petri Nets and chanced on this cool piece of code: This wonderful algorithm is a software-only 2-process mutual exclusion algorithm. Though it is not the first software-only 2-process mutual exclusion algorithm (Dekker’s in 1965 was the first; Peterson’s was in 1981), it is the most compact one.

I’ve put comments in the code below to explain how it works.

Let’s examine the algorithm’s properties :

1. Safety : At any time, at most one process is allowed to be in the Critical Section. In brief, when 2 processes try to enter the critical section simultaneously, in the ensuing race condition to set turn = process (line 7), the process that “wins” is stuck in the while loop, letting the other interested process enter the Critical Section.

2. Fairness : Both processes should have an equal chance of acquiring the lock on the critical section, since the race condition is impartial. (However, the algorithm is not necessarily fair in the sense that both processes execute their Critical Section an equal number of times over long periods of time. That is an analysis that is more involved.)

3. Liveness : When one or more processes have expressed their intentions to enter the Critical Section, one of them eventually enters. (See explanation above).

4. Freedom from Starvation: In addition to these properties, the following is a desirable property: Any process that expresses its intention to enter the critical section will be able to do so in finite time. This is also true for Peterson’s algorithm. Once the process that has entered the critical section leaves, interested[other] becomes FALSE for the blocked process, allowing it to enter the critical section.

O======O======O======O======O======O

1 int turn;
2 int interested[2];


/*
The two processes have ids process = 0 and process = 1.
*/

3 void enter_region(int process) {
4 int other;

5 other = 1 – process;
6 interested[process] = TRUE;
7 turn = process;


/*
1. If interested[other] == FALSE, there is no competition from the other process
(say, due to it being slow), and we enter the critical section.

2. If interested[other] == TRUE, but turn is still == us, then the other process
must have executed line 6 but not yet line 7. In this case, we block in the while
loop. The other process process then sets turn to itself, then
basically turn == process will become false, and we enter the critical section.

(leave_region() ensures that the other process gets to enter the critical section later.
Thus, the algorithm is fair.)

(If the first process “loses” the race to line 7, and the 2nd one wins, the same reasoning
as above applies (, but w.r.t. the 2nd process,) since the code is symmetric.)

*/

8 while ( turn == process && interested[other] == TRUE ) ;
}

void leave_region(int process) {
interested[process] = FALSE;

/*
If the other process is blocked in enter_region(), this releases it
from the while loop on line 8, allowing it to acquire the lock.
*/

}

O======O======O======O======O======O

Follow

Get every new post delivered to your Inbox.