Friday, April 18, 2014

You Wanted Rock Bottom, You Got It. April Speculation.

Forex can be a painful environment sometimes.  Whereas stock traders have a number of different mathematical ways to derive the 'true value' of an investment the world of forex is a bit more perplexing.  It's a battlefield; every inch of ground is a war fought between high frequency traders, scalpers, swing trader, and any other number of strange techniques, often times movements seem to happen for next to no reason at all, but there is one constant unavoidable property.

The Law of Retracement

Forex markets never touch a support they don't intend to test again and we've been living on borrowed time since December.  What is initially seen as purely a result of panicked selling some time later becomes an inevitable support target.




I'd hypothesize that this property has something to do with the underlying psychology that drives forex markets.  Even though the crash results from panic, having seen the market crash to these lows before traders don't feel comfortable buying in turbulent markets till we hit the lowest low we know is possible.

Whatever the reason ~419 is the number that's been in the back of all of our minds for the last few months now, and we've hit it.  

So What Now?

Don't assume that because we're below sea level we have to go to the top of Mt. Everest, all this means is 'the debt is payed'.  I doubt we'll go much lower, as a scalper/channel trader my overall strategy doesn't change much with the trend but I've got a policy about not pissing in the wind.  Don't short in an uptrend, and don't long in a downtrend, so what this should mean for short/medium interval traders like myself is its time to close short position and wait.  For swing and long interval traders this might mean its time to start looking for a long entry.

A Good Entry Target would be below ~419 or close to it with stops just outside of the average true range.  To give an example, my long entry for a position I plan on sitting on for a couple of weeks was 399, and my stop for this position is ~370, but I warn you now this is not a position you want to gamble on.  I know I said this is rock bottom but the risk on long positions is still very high.  CryptoForex doesn't have regulations to protect your positions from flashcrashes and mass panic.

Take Profit Targets will be dodgy, and I highly recommend managing positions according to Ruien's (Ryan Sanden) 3 bar trailing stop method.



If the market does flip over into a rally we can expect some significant resistance in the upper 500's and an absolute impasse in the upper 600's.  The small upside to this crippling downtrend is we now have everything between 300 and 1000 mapped for just about all resistances and supports.





Blogger Tricks

Sunday, March 16, 2014

crypto-php-api: Glue code for your PHP crypto trading robot

I've open sourced some of my PHP trading robot's code. You can find the repository at https://github.com/sectioaurea/crypto-php-api. I hope it is useful for anyone setting up a price monitor or trading robot in PHP. Originally, I used some of this code in a web monitor to watch certain markets.

What you'll find currently: modules to help you get prices from BTC-e and Cryptsy, and the API connector glue which every bot uses. Although the API connector glue code was sourced from Pastebin and broker docs, the orderbook depth traversal code is entirely original and solved an important problem for me: slippage.

If you've programmed a trading robot, or done a lot of trading by hand, you know the top order in the book is not always large enough to fill a trade. I wrote a function to step down the list of orders until the desired size is met, then calculate the overall price of the trade per unit.

What is missing:
- My proprietary trading engine
- The main control loop, which still is hardcoded to call my trading engine.

What will be added:
- The main control loop, once it's refactored to not call the proprietary trading engine.

Enjoy!

Friday, February 28, 2014

Position Management: Trailing Stops

About a month ago, we posted an analysis that turned out to be both 100% correct and 100% wrong. Quite the paradox, right?

What I mean is that after-the-fact look back at that analysis shows that:
  • A trader who followed the signals that the analysis produced made money
  • A non-trader who looks back at the analysis probably thinks it was wrong
This demonstrates a very important aspect of trading in general, but rarely is a very clear example available to illustrate it. So, we're lucky, because we're going to learn something about position management today.

Let's start with a true story. Back in December, a friend asked what I thought would be a good buy, and I said Litecoin - which was trading about $16 then. We didn't discuss Litecoin again until a few days ago, when this same friend noted that LTC is now back below $16. In fact, following that, LTC proceeded to fall as low as $10.70.

So, was the recommendation to buy at $16 good advice, or bad advice? Let's look at a chart:


If your analysis shows that price will go up, and you buy at the right time, and it does go up, then you should make money. This should be true even if the price later falls to below what you paid. Logically, that makes sense. But in order to actually do that, we need a good methodology for managing where we sell. This is the concept of the trailing stop loss.

First entering your position can be done according to the Trade Execution article. So, if we were trying to enter at $16 as described above, we would have done so and placed our stop below the recent low plus Average True Range, here:

As an aside, that's a huge stop. If you're willing to manage the trade on 4-hour bars (that means moving your trailing stop up on 4-hour bars instead of daily bars) you can use 4-hour bars for your initial stop loss. That would be smaller, and looks more like this:
That seems a lot better (a smaller stop means you can buy more for the same risk percentage), but since we'll be managing our stop on a lower time frame, it may or may not make more money in the end -- we'll likely get stopped out sooner as a result. Understanding that time-frame trade-off is really important.

In either case, the stop is about to get a lot smaller as soon as we get some movement in the right direction, because we'll be using a three-bar trailing stop.

For illustrative purposes, we'll follow both of these examples (Daily and 4-Hour), starting with the Daily one.

Firstly, you start with a trailing stop as soon as the first minor pivot is exceeded. This pivot should be the one nearest the price at which you would feel confirms a move in the direction you expect. Since we're entering at $16, I think the previous day's high which comes in at $18.77 is fairly reasonable:
If we get above the pink line, I'd say that should be far enough that I shouldn't actually lose money on this trade anymore. At that point, I'll sell a portion (1/3) of my investment and move the stop to break-even:

By selling 1/3 and moving the stop to breakeven, you (mostly) guarantee a profitable trade. You're now trading on the market's money, not your money. You also have cleared your "risk budget" and now have room to add more new trades.

At the point at which the minor pivot is exceeded, we also switch to a 3-bar trailing stop. This is defined as the lowest price of the last 3 bars from (and including) the most recent high, excluding inside bars. An example should make that clearer:
I've shown the 3-bar trailing stop level in blue. Starting from the recent highest bar (last candle in the above chart) and counting back 3 bars starting from and including that same bar, the lowest low of those bars is the blue line. None of those bars are inside bars, included in the previous bar, so it's that simple.

Because the blue line is above our current stop, we move the stop up to that level instead. We never move our stop down, only up:
The amber line represents our entry price, and the red line represents our current stop loss. Everything's good so far, so now let's move time forward by one bar:
This was a nice profitable candle. If I'm really happy with profits right now, I might just close the rest of the trade and walk away rather than risking a collapse back down to my stop loss. Usually though it's best to leave at least some left for a long run, so it's perfectly acceptable to close the next 1/3 of the trade here. In either case, this made a new highest bar, so we count back 3 bars again to get the new stop loss shown above.

Now, we just wait until we either hit our stop loss or get a new high. That doesn't happen for awhile:

Since none of these bars either (1) hit our stop loss, or (2) made a new high, we do nothing.

The next bar after these, though, makes a new high, so we count back 3 bars again and move our stop loss to the lowest point of the three bars:
At this point, we've locked in a lot of profit, and we're still in the game. We probably wish that we didn't already sell 2/3 of our position by this point, but not all trades work out as beautifully as this one did, and the cash flow and risk control from higher-probability exits helps a lot.

Now what happens?:


Looks like they knew where we were hiding. Actually, a more robust trailing stop also incorporates some element of the ATR, just like we did for the initial stop loss level. Having some ATR buffer around your stops usually helps to avoid stop gunning like this (using ATR/2 is decent). Sure, it means wider stops, but that's why we've been taking profits so far.

As far as active profit-taking, there were a few big price targets hit on that last candle, actually. You don't have to (and usually never should!) wait for a trailing stop to take you out once you've hit a great price target. (Or, you can move your trailing stop in very close - same thing):
But, anyway, let's assume that we did indeed get stopped out at the original 3-bar trailing stop shown earlier. Assuming a $10,000 account and 1% risk, what ended up happening?
  • Entered @ $16, stop at $9.68. Bought 10.74 LTC.
  • Exit 3.58 LTC @ $18.77
  • Exit 3.58 LTC @ $24.00
  • Exit 3.58 LTC @ $23.00
For an average exit price of $21.92, for a profit of 10.74*($21.92 - $16.00) = $63.58 = 0.64% in 15 days. That's a very small profit, but it was very low risk, and still represents about 17% profit annualized, so it's not terrible.

But, I prefer 4-hour bars. Let's do the same trade on 4-hour bars.

We start off with an entry at $16 and a stop at the recent low minus 1 ATR (calculated at the bar where the low occurred). The ATR in 4-hour bars is about 1.85, so the stop is at $13.54:

Nothing happens until we hit the minor pivot at $18.77, at which point we sell 1/3 of the position, and switch to either breakeven or a 3-bar trailing stop, whichever is higher:

A new high bar, so we move the stop up again:

Same thing. This time we also hit a price target and sell another 1/3 as soon as that target is hit ($23.04). We leave the rest for either another really nice target or the trailing stop:

We get a new high, so we move the trailing stop up. In this case, we ignore a bar because it's an inside bar of a previous counted bar -- that is, the bar that we have labeled "2" completely contains the ignored bar. In a nutshell, we ignore a bar when ignoring it would place it completely inside of any bar which is later included in the final count (it's a recursive algorithm). There are a some minor details with this rule but they're not usually very important.

That leaves us with this:

 Another high, another stop:

And we're stopped out:

Again assuming a $10,000 account and 1% risk, what ended up happening here?
  • Entered @ $16, stop at $13.54. Bought 40.65 LTC.
  • Exit 13.55 LTC @ $18.77
  • Exit 13.55 LTC @ $23.04
  • Exit 13.55 LTC @ $21.60
For an average exit price of $21.14, for a profit of 40.65*($21.14 - $16.00) = $208.94 = 2.09% in 5.5 days, for an annualized profit of about 295%. Much better.

Finally, these examples showed long-side (bullish) trades, but all of these techniques apply equally well to short-side (bearish) trades. They are also scalable, which means that they automatically scale to changes in market volatility.

Saturday, February 15, 2014

An Odd Sense of Familiarity, Dogecoin Speculation.

Dogecoin has become an interesting microcosm of cryptocurrency market development, and has proudly become one of the first coin markets 'independent' of Bitcoin.  To clarify, by independent I mean Dogecoin seems to have evolved in such a way that it doesn't follow Bitcoin's market movements in the same way currencies like Litecoin, or Namecoin do.

An interesting phenomena though is how Dogecoin seems to be showing the same developmental explosion as Bitcoin did in November 2013, except Dogecoin seems to be following the steps at nearly ten times the pace.



Dogecoin 1h Timescale


Bitcoin 1w Timescale

With very little background in technical analysis one can see the similar 'bubble formation' however as addressed in another article, 'bubble formation' doesn't always mean its a bubble.  This is just a movement characteristic of a previously undiscovered market.

So does this mean Dogecoin will go the way of Bitcoin?

Not at all actually.  For those of you following my monthly speculation articles you'll recall I described the post November growth period as a 'sensitive' period in Bitcoins history.  Making the point that without the right developments and mix of positive media Bitcoin will (and did) crash.  Shortly after this period, in a strange flurry of events that almost seemed like a concerted attack on Bitcoin the markets crashed.

Dogecoin is in the same 'sensitive' period, and there seems to be much more reason to be optimistic that Dogecoin will pull through.  In our Dogecoin vs Litecoin we mentioned how Dogecoin has grown into something unexpectedly great because of its community.  Dogecoin users are the best tippers, most active community (when taking into account proportional size), and have overall presented a coin even the least tech-savy can access.  It is for these reasons I believe Dogecoin will rally where Bitcoin previously stumbled.

Back to the Technicals.

Unfortunately, I haven't found a great way to provide readers with the quality of graphs we normally provide so most of what I tell you I can't really show you.

Dogecoins major area of support seems to be around the 200 Satoshi and I doubt we will see it fall through this support anytime soon.  That being said, those looking to swing trade should look to scoop up an entry between 205 and 220.  Looking further into the month StochRSI cycles seem to be leading us into an upward 'stair stepper' pattern in the short term, with markets carefully reaching slightly higher plateaus.  However, a careful trader never plans trades around new highs.  This being said a good take profit point for the month would be around 257 Satoshi.

Good luck, and good work to the whole Dogecoin community!  It's been a pleasure to watch this market evolve into something truly unique. 

Recovery? What Recovery? February Speculation.

It's been a rough month for Bitcoin and it doesn't seem to be getting any better.  With Mt.Gox halting withdrawals, and the massive network wide attack on the Bitcoin protocol media catalysts are giving strong downward signals with no sign of reprieve.   The media would be tolerable but the technical factors seem to converging on the same downward movement.



Plotting resistance and supports for longterm PSAR reversal points it's apparent this downtrend has largely been fueled by stacking resistances against lower and lower supports.  At the same time the markets seem to be stalling at what can only be described as denial channels.  These channels seem to be characterized by short term rallies, followed by narrowing sideways channels.

January 'denial channel' later crashed to current levels

This same channel pattern can be observed in January movements.  The overall market sentiment seems to be bearish however traders seem to be willing to risk going long for smaller and smaller potential gains till eventually gains hardly beat commission.  At this point the channel seems to collapse at what I've been referring to as the end of the cycle.

Based on Fisher transformation transposed against polarized Stochastic Oscillator it seems that the high/low movements of the recent denial channel seem to be cycling faster than the previous January channel.

It is for this reason that I believe we will be seeing a crash to lower 500 supports relatively soon.


Typically I determine 'major supports' based on confluence of three methodologies in cryptocurrency markets; Fibonacci Retracements plotted outward from major pivots, 4 day equidistant channel bottoms, and PSAR reversals.  From the above charts it appears all of these methods converge on somewhere between the 500-515 range.  This range seems to be confirmed by previous crashes, excluding the outliers arising from the flash crash earlier this month.

The Take Home.

As we've been saying on the @Cryptoforexteam twitter channel, don't sleep long without stops.  Try to find long entries in the lower 500 range, and short entries in the upper 600 range.  If you're looking to trade on big swings avoid getting caught up in the signal noise of the denial channel.

Thursday, January 30, 2014

Dogecoin vs Litecoin, Nothing but the Truth.



When Dogecoin was first released there were a lot of skeptics, including us admittedly.  But there's an essential truth to be told that Dogecoin's critics aren't facing up to.

Dogecoin is no less viable than Litecoin

That's right, I said it.  To the Litecoin fans that one is going to hurt.

Cryptocurrency is a new ecosystem and although Bitcoin has always been regarded as the 'apex coin' Litecoin has always been seen as the runner up.  But the world of cryptocurrency is too new and too competitive to remain on the winner's podium because you've always been there, and Litecoin has done very little lately to justify its position.

As Bitcoin has slowly expanded its root system into the mainstream with advances in payment processing, and adoption by companies like Overstock and Tigerdirect, Litecoin has done almost nothing to keep up.  Sure, it has a few more mining pools, and is accepted on a couple more exchanges, but like I mentioned previously, these are just consolation prizes it has received for always being number two.  Meanwhile, as Litecoin is lazily enjoying its undeserved admiration, Dogecoin is sending the Jamaican Bobsled team to the Olympics, along with three other Indian athletes.  So what really  makes Litecoin better than Dogecoin?



Nothing. That's the truth of it.  Dogecoin is a Litecoin clone with an adorable Shibe mascot, and that may be all it needs to take the number two spot.  Dogecoin is like one of the joke ideas you have with your friends and then find out a month later someone actually turned into a real marketable idea; it's subtle genius tucked away in a ridiculous meme that some people don't even find funny for some reason.

What makes Dogecoin special? 


I really enjoyed finding pictures for this article

Never underestimate the power of a meme.  Dogecoin has managed to take something as esoteric as cryptocurrency and made it approachable to the public at large.  If you want proof of the power of the Doge, do an experiment; talk to someone who knows very little about cryptocurrency, show them a picture of Dogecoin, and a picture of Litcoin then ask them which one they would buy.  I did this with a few friends and family members and all of them so far went for the Shibe.  This is the power of Dogecoin and the market has responded.  As of January 31st, 2014, Dogecoin has taken the 6th highest total market cap of all the cryptocurrencies according to CoinMarketCap, and I don't think it's going to stop there.

But What About the Pump and Dump?


There is some truth that Dogecoin owes a lot of its current value to a pump that began sometime in mid January.  But I would argue that clever pump and dumpers target coins for a reason.  The most significant 'pumps' almost always occur on currencies with significant potential anyway.  I remember in my early days of trading cryptocurrency a popular pumper called Fontas would regularly pump Litecoin.  At the time Litecoin was trading at about 1.5 USD, as of today it's 21.1 USD.  I've talked to a few pumpers and I imagine their choices are made based on two main factors:



1.) Coins with that are attracting a lot of attention are easier to pump because many traders actively watching them anyway.
2.) Coins that have a lot of potential pose less risk to the pumper.

I wouldn't say Dogecoin is the future of cryptocurrency but than again I can't say it isn't.  I can say one thing for certain though-- Dogecoin is attracting a demographic of users that neither Bitcoin or Litecoin could get the attention of, and at least in the short term that makes Dogecoin worthy of its spot at number six in the coin market cap.




Wednesday, January 29, 2014

Perfect Position Sizing

There is a perfect position sizing formula, which I derived many years ago (see derivation) and dub the Sanden Criterion. It is as follows:

Where:
  • f = Optimum fraction (percentage) of portfolio to invest on this opportunity
  • W = Winning percentage (chance to earn G percent profit)
  • G = Gains on win (percentage)
  • L = Loss on lose (percentage)
The key is that average profit and loss over the long term depend on how much you invest on each trade. If you invest too little, or if you invest too much, you lose. After you've made about 100 manual trades, analyze your trade statistics and determine your personal best trading size.

Let's look a bit deeper and understand this, because it's important.

A 5% loss followed by a 5% gain always loses money. So does a 5% gain followed by a 5% loss.

Now imagine a coin flip carnival game. You can bet any amount of money, and flip a coin. If you bet $10, and get Heads, then you get $10 profit. If you get Tails, you lose the $10 that you bet. Simple right?

Now let's make it more interesting. You've been watching this carnival game for the past few weeks, and been taking statistics. The coin is actually unfair -- it doesn't come up 50% Heads and 50% Tails -- but it's actually unfair in your favor. In other words, it's coming up 55% Heads and only 45% Tails. You start to get pretty excited.



You walk up to the table with $1000 and grab the coin. The carny smiles. Now here's the question: How much do you bet?

This is the problem. Even though the coin flip is going to land in your favor 55% of the time, you'll still lose all your money if you bet too much. For example, pretend we invest 25% each time:




That is, start with $1000; gain 25% 55 times and lose 25% 45 times. You end up with $510. Again start with $1000; gain 25% 550 times and lose 25% 450 times. You end up with $1. We're losing money even though we have the advantage!

Investing 25% of our capital in each coin flip will ruin us in the long run. Interestingly, however, instead investing 10% each time maximizes profits:




Now we're making money. It's all the same system (double-or-nothing with 55% chance to win), just with a different percentage of the total portfolio invested each time (10% vs 25%).

Anyone can see that the underlying system inherently represents a good deal. Furthermore, investing 10% shows it makes money. The problem is that a neophyte might naturally feel that if you are making money by putting in 10%, then you can only make more by putting in 25%. But we see that this is not the case. Even in a double-or-nothing bet game in which you win 90% of the time, invest 100% of your capital every time and in 10 trades you'll still likely go broke.

So, where did the 10% come from in this example? This is the maximum-profit investment-percentage, given by the Sanden Criterion shown earlier:


W = 55% chance to win
G = 100% gain on win
L = 100% loss on lose



In real trading, you should assume that the optimum investment percentage is 1%, until you have sufficient results data from your own trading to raise or lower that number.

Finally, an astute reader may note that the Sanden Criterion is similar to the Kelly Criterion, but they're not quite the same. The Sanden Criterion accounts for the possibility of leverage and gives the optimal investment size. The Kelly Criterion never accounts for leverage and gives the optimal risk size instead. The above coin flip game with a 1% gain/loss (instead of 100%) demonstrates the difference.

Derivation: