Algorithmic and Mechanical Forex Strategies | OneStepRemoved

  • Articles
  • Sophisticated Web Sites
  • Automated Trading
  • Testimonials
  • Contact

Using Parabolic SAR vs MACD

July 5, 2016 by Lior Alkalay 1 Comment

Parabolic SAR and MACD are both very effective in spotting pivots and yet there is a difference. In some cases, you will find the Parabolic SAR is more effective while in others you might find the MACD more useful. That is why, in order to make the best of both, you must know the advantages and weaknesses of each.

Parabolic SAR has Higher Sensitivity

The first thing you will notice when comparing a Parabolic SAR to an MACD indicator is that the Parabolic SAR signals many more pivots. That is because the Parabolic SAR has, by default, more sensitivity to minor changes. Of course, you can reduce the level of sensitivity, but even so, it delivers more signals than the MACD. The benefit of such sensitivity is that, at times, the Parabolic SAR predicts a pivot before the MACD. But that sensitivity has a downside. In small fluctuations the Parabolic SAR can occasionally produce fake pivots. As you can see from point A to point B, the pair has been trending sideways and still the Parabolic SAR delivered plenty of signals, most are falls. However, the MACD during the same time frame was much more effective.

Parabolic SAR

MACD is better at Momentum

One advantage the MACD has over Parabolic SAR is the measurement of momentum. As can be seen in the chart above, the MACD indicator, through the lows and the highs of its histogram, illustrates how strong the momentum is to either direction. If the histogram falls sharply lower, the momentum is strongly bearish, if it rises sharply higher, the momentum is highly bullish, if the histogram is fluctuating close to 0, the momentum is weak.

While the Parabolic SAR does a good job in identifying the direction of momentum quicker, it is much less effective in identifying the strength of a pair’s momentum. And that is why, when it comes to momentum, MACD is more effective than Parabolic SAR.

Limit/Stop Loss

Another way in which MACD and Parabolic SAR differentiate is in the way they influence stop loss and limit strategy.

Parabolic SAR, being an upper indicator, is overlaid on the price rather than being presented below. The dots of the Parabolic SAR are natural stop loss and limit levels for the short term. Moreover, when used in conjunction with Fibonacci levels, can also be effective in placing long term stop loss and limit orders.

MACD, however, being a lower indicator, i.e. presented below the chart rather than overlaid, has a more complex relationship with stop loss and limits. The MACD can be effective as an indicator for a stop loss when momentum shifts to the other direction, thus pointing to a pivot. But for the MACD to be effective as a stop loss indicator it needs a Gann Fan or an area where the MACD momentum converged more than once, indicating a strong support, or resistance if the trend is bearish.

In Conclusion

Both the Parabolic SAR and the MACD are strong tools for working with pivots, but are different in their effectiveness. One is better in identifying pivots quickly and in placing limits and stop loss, the other is better at analyzing momentum strength and timing entry. Knowing the advantages of each can allow you to optimize the use of both and, more importantly, optimize your performance.

Filed Under: Trading strategy ideas Tagged With: limit, MACD, parabolic SAR, stop loss, Take Profit

How badly do I want in?

March 22, 2016 by Shaun Overton 10 Comments

You absolutely must check your trading system’s performance on a regular basis. You’re going to miss most of the problems from watching your equity curve alone.

That almost happened to me a few weeks ago. When I observed my account, I noticed that the real results had dramatically underperformed the hypothetical results. A quick review showed me that I only took 271 trades over the prior week, whereas my backtest expected to find 360.

I was only trading 75% of the setups! What could explain the missing trades?

Finding the flaw

One feature that I wrote into the MetaTrader version of the Dominari was a maximum spread feature. I’m paying commissions, so the idea of the rare but possible scenario of paying a 10 pip spread to enter a trade seemed intolerable. I added a maximum spread feature to prevent getting ripped off.

I also didn’t put much thought into what happens if the spread is too wide. My initial instinct was to put the EA into hibernation for a few seconds. It would then wake up and check the spread. If the spread narrowed enough, it would send a market order. But in my haste to start trading, I forgot to also require that the price be near my original requested price. That design would have allowed the market to drift up 10 pips and then, if the spread narrowed, dramatically overpay to get in the trade.

The new method for capping the spread paid uses limit orders if the spread is too wide. The advantage to this method is that it solves two simultaneous problems. The first one is easy to understand. A limit order has a limited price. It’s not possible for the price drift described in the above paragraph to occur. I either get the price I want or the market moves without me and I miss the trade.

Equity curve since I made the execution changes on March 16.

Equity curve since I made the execution changes on March 16.

The second advantage to using limit orders on entry is the fact that a limit order rests on the broker’s server. The hibernating method could potentially miss fractions of a second where the spread temporarily narrows to an acceptable price. Limit orders catch all price quotes, improving my theoretical likelihood of a fill.

Reality proved the theory after a week of trading. Instead of taking 75% of all possible signals, I’m now taking 87.5% of signals. That’s a result of the new limit method and my willingness to pay a wider spread to enter a trade.

More improvement

The question at the top of my mind was, “Should I be willing to pay even more to enter these trades?” Like a good quant, I immediately decided to calculate the question instead of haphazardly guessing.

I wrote a script in MetaTrader to search for every limit order in my account which was cancelled. I then looked at what the hypothetical performance of those trades would have been if I had simply paid the exorbitant spread.

It turns out that I should be willing to pay a lot more money to enter these trades.

There have been 50 cancelled limit orders within the past week, 44 of which were theoretically profitable. The average theoretical profit per trade was €1.28 compared to €0.33 for all executed trades. That’s a massive 287% difference in profitability!

The other shocker was the percent accuracy. 44 out of 50 implies an accuracy of 88%, compared to 64% accuracy on executed trades. 50 signals isn’t a lot. Am I getting too excited about missed profits or is that bad luck?

Basic statistics gives an answer with a high degree of precision. If the real accuracy is 64%, then you would expect to see 50 * 0.64 = 32 winning trades in a random sampling. My observed, theoretical accuracy with these limit orders was 44 orders out of 50, which is 88% accurate.

It turns out that I should be willing to pay a lot more money to enter these trades.

The standard deviation for 64% accuracy on 50 orders is 0.48, which we can then use to calculate the standard error. The standard error on 50 orders is sqrt(50) * 0.48 = 3.42 orders.

And finally, the standard error gives us enough information to compute the z-score. The z-score is the observed values-expected values/standard error, which is (44-32) / 3.42 = 3.5. A z-score of 3.5 has a probability of 0.000233 occurring due to random chance, or about 1 in 4,299 tests.

Conclusion: The statistics say with high confidence that my non-executed orders are substantially more accurate than my executed orders.

With the orders being both more accurate and having a higher per trade value, I increased the maximum spread that I’m willing to pay by 53%. While that sounds oddly precise, the per trade value might be substantially overestimated. I ball parked a guess that paying 40% in trade costs for a high quality trade seems reasonable. That number may have to go higher in order for me to measure the details.

Ideas for exploration

The amazing extrapolation from the live order analysis is that the spread seems to predict my likelihood of success. Wider spreads make me more likely to succeed and with a better risk:reward ratio. My project over the next few days will be to start logging my spreads at signal generation time to evaluate whether the spread predicts the profitability of my signals.

Oddly enough, there might even be a paradoxical outcome where narrow spreads predict my failure. More on that when I have enough data to answer the question.

Filed Under: Dominari Tagged With: execution, limit, quant, slippage, standard deviation, standard error, statistics, Z-score

Live demo testing a new strategy with limit orders

November 24, 2015 by Shaun Overton 17 Comments

I come up with amazing looking backtests all the time. This is the latest example using the SB score.

backtested equity curve

The equity curve of the new strategy without trading costs.

The free and hypothetical version of the strategy yielded $79,618.82 for an uncompounded return of 796.19% over a period of 3 years. The strategy trades all major FX crosses. As you can tell, the signal quality remains nearly constant across multiple market conditions. It looks great.

The problem is trading costs. It’s always trading costs that make life difficult.

Trading costs drop the profits by 98.22%

Trading costs drop the profits by 98.22%

I always take a heavily pessimistic view when it comes to assuming trading costs and slippage. It requires a lot of intellectual honesty, but making an effort to avoid rosy assumptions saves a lot of pain and disappointment down the road. The assumptions are really severe on cross currencies where we assume spreads and slippage north of 5 pips.

Performance with pessimistic trading cost assumptions drops to only making $1,000 in profit. The strategy doesn’t need to go in the rubbish bin, but it’s far from ready for prime time. There’s no scenario where it makes sense to trade with market orders.

General characteristics

Average trades per day: 39
Currency pairs traded: 27
Percent accuracy: 66.52%
Style: Mean reversion
Charts: Hourly

How to trade on the cheap

I’m notoriously frugal. One of my fraternity brothers in college still tells stories about me counting loose change and tracking it in MS Money.

That kind of mentality drives my wife crazy… but it’s a real asset for a trader! Traders make their money on the margins like every other business person.

I spent yesterday afternoon coding this new strategy with a slight twist. Instead of paying the spread on every single trade, what if I use limit orders to try and earn the spread?

The current raw spread on EURUSD is 0.3 pips, which is worth $0.03 per microlot. The trading commissions are $0.03 per microlot. If I earn an extra $0.03 per microlot, that at least covers the trading costs. On pairs like NZDCHF where the raw spread is 1 pip, that adds an extra $0.04 ($0.10 – $0.03) per side. I.e., the entry signal makes an extra $0.04 and the exit also makes an extra $0.04 on every single trade.

Even quiet pairs on NZDCHF still exhibit a degree of noise on every bar. I haven’t done any research to back it up, but my subjective experience says that the wicks of 90% or more of bars will be at least as long as the spread is wide.

Traders make their money on the margins like every other business person.

Said another way, if the spread on EURUSD is 0.3 pips, then the difference between the open and low price on 90% of bars should be at least 0.3 pips, too. That’s my assumption, anyway.

An example of twisting the strategy to use limit orders

Say that my signal to enter the market just popped up. The current price for EURUSD is 1.06457 x 1.06462, which is 0.5 pips. The backtests assume that I’ll hit the 1.06462 asking price and pay the spread.

The idea for my test is to set my limit order at 1.06457. Since I’m a retail trader, that means I’m asking the market to move down half a pip before I’ll get to have a position. Requiring a small move in my favor theoretically earns more than jumping into the market with both feet.

Live demo testing begins

I could theoretically model the idea in a backtest, but there are critical assumptions that make it pointless.

1) The average spreads available in my 2009-2011 backtest period were far wider than they are today
2) The spread varies significantly throughout the day. EURUSD is routinely as low as 0.2 pips in the European sesssion, but can easily hit over 1.0 pips in the dullest portions of Asian trading.

The second item could be completely detrimental in a backtest. It’s better to test the idea on a live demo and get something closer to real trading data.

Demo testing

The first 15 hours of live demo testing.

I’m only 15 hours into the test, but at least everything is off to a good start.

The goal for the test is simple: place at least 300 trades in the account. That should only take about 2 weeks since the strategy is so hyperactive.

The criterion for success is equally simple: does the real-time demo trading performance meet or exceed the backtesting performance over the same time period?

I started trading in the evening of November 23, which means that I should hit my 300 trade threshold around the 10th day of trading. The trading frequency does fluctuate, but that should occur sometime around December 4th.

Even though I have live demo data, I’m going to run a market entry backtest from November 23 to December 4. If the demo trading, which uses limit orders, exceeds the market entry backtest, then I have a reasonable basis for assuming that the strategy is ready to trade on a small live account.

comparison scale

I’m also ironing out bugs that appear during the live simulation. More than likely, these dates will be pushed back. I already found 2 issues that require investigation after only 22 trades. There’s no point in judging a strategy if it’s not performing exactly as specified.

Code the same strategy twice?

You probably noticed that the forward test equity curve is from MetaTrader. Why would I test in one platform but execute in another? All of my backtests were done in Seer.

If you have two people work on a problem and they both arrive at the same answer, then they probably answered the problem correctly. The same logic applies to programming. If I program a version of the strategy and Jingwei programs a version of the strategy, they’re supposed to place the exact same trades. Any discrepancies mean that someone’s programming is wrong.

I routinely use this method because the slightest errors in logic can lead to dramatically different trading outcomes. It’s the difference between making a lot of money and losing a lot of money. Yes, I’m sacrificing efficiency. The stakes for a strategy are so high that it’s better to make 2 people do the same work in exchange for the confidence of knowing that it was done properly.

MetaTrader is inferior to Seer by every measure. The only reason that I wrote my code in MetaTrader was that I’m anxious to test the idea. MQL4 is easy for me to code – programming for MetaTrader is one of our main services.

After Jingwei finishes programming the Seer version next week (she’s off for Thanksgiving), I’ll have the basis for comparing my MT4 version against hers. It’s terribly inefficient, but I also know how likely I am to waste weeks on analyzing trades placed according to rules that don’t exactly match my strategy. Better safe than sorry!!!

How to fatten the margins

One thing I hate about retail trading is that very few venues offer a true ECN. Trading on a traditional retail forex broker means that I have to wait for the spread come down to touch my order. In the example I gave using EURUSD, it requires that the market move 0.5 pips in my favor before I get a fill.

Trading on an ECN would significantly increase the probability of receiving a fill on the limit order. Using the EURUSD example where the current prices are 1.06457 x 1.06462, I would place a buy limit order on the bid at 1.06457. If anyone in the market sells at that time, it means that at least a portion of the order would be filled almost immediately.

In effect, trading on the retail spreads contains the worst case scenario for execution. The price has to adjust 0.5 pips in your favor in order to get filled. If you trade on an ECN and the price fell 0.5 pips, you would get filled every single time. But you also get the chance to get filled earlier and faster because if anyone comes in and goes short at market, the order sits on the book waiting for someone to hit it.

fat margin

Smart traders do everything in their power to fatten up the margins

I’m proceeding with the demo test now. If it meets or exceeds the backtest results, I’ll then know with the highest degree of confidence possible that the method is ready for live trading. I’ll probably start with a few thousand dollars for the first month. Then, if it succeeds, I’ll really start to scale it.

There’s no reason that all trades must occur on H1 charts. I can always shift the trading intervals by one minute, two minutes… fifty-nine minutes. And even there, it’s possible

My ideal scenario is to trade the strategy on an ECN venue, which requires a minimum balance of $250,000. That amount of money is far higher than I’m comfortable risking. The old rule of trading is that you never risk more than you’re comfortable losing.

That means I’ll likely be looking for a partner to make sure the strategy runs in the best environment possible (an ECN). Are you possibly that partner? If so, send an email to info@onestepremoved.com and introduce yourself. Nothing will happen for several months, but it always takes awhile to build relationships and feel comfortable with a project.

Filed Under: Dominari, Test your concepts historically, Trading strategy ideas Tagged With: backtest, limit, spread

Limit Order Book

August 28, 2013 by Timothy Lewkow 3 Comments

I remember the first time that I really sat down and thought about it. Why exactly does a stock price change? Shrinking the economy and the number of shares helped. Examples starting with 10 oranges together with supply and demand arguments sparked good ideas. But, expanding a simple scenario into a full blown economy with high volumes and different order types never made any sense.

The story is not complete without considering the information contained in a limit order book. It’s the absolute best source for highlighting buying and selling power in a market in real time. The information within the data often results in more desirable entry and exits points.

A simple example of a limit order book

limit order book example

The orange squares represent units of stock that you can buy at market

Suppose that each block represents one share of stock on both the bid and ask side of the market frozen in time. The volume of shares in the above plot are limit orders waiting for execution or cancellation.

Say that Frank comes along and wants to buy 5 shares using a market order. In that case, his order will be filled immediately.

Remarkably, the current quote displayed  of $20,26 is not where Frank can trade- there are no shares available at that price. The quoting convention reflects the spread rather than tradeable prices.

The 5 empty colored squares represents the 5 shares that Frank bought with his market order

The 5 empty colored squares on the right represents the 5 shares that Frank bought with his market order

The order is filled by sellers in a first in, first out (FIFO) process. Those who waited the longest in the order book receive the first execution.

Frank’s market order for 5 shares receives execution at two different prices. The first 2 shares fill at $20.27. The depth of market at that price is only 2 shares, forcing him to sweep the $20.27 price and move on to the next available price at $20.28.

4 total shares are available at $20.28. Because Frank only needs an extra 3 shares, he completes his total order at this level.

The best offer displayed when Frank placed the trade was $20.27, but his average fill is $27.276 (2 * $20.27 + 3 * $20.28). The slightly worse price doesn’t have anything do with slimy brokers. Slippage is the natural result of buying more shares than there are shares available.

Try making Frank a more aggressive buyer. Say he wants nine shares. Large orders receive worse fills because they suck up most of the liquidity on one side of the market.

Why A Spread Exists

Before answering this question, it is first worth understanding the difference between a quote driven and an order driven market.

Order driven market:

• Displays all of the current bids and asks across the market

• Has complete transparency

Quote driven market:

• Displays bid and ask prices from market makers, dealers, or specialists.This is the norm among retail forex brokers

• Often provides a guarantee that an order is filled

A quote driven market has more moving parts and will likely be involved in any market you wish to trade in. Therefore, it is a good idea to think about the existence of a spread in this setting.

When you post an order in a quote driven market, the dealer will either fill it with their own inventory or match you with another market participant. For this reason, part of your transaction cost goes to the dealer who has done this work for you.

In a simple model, the bid ask spread is the price that aggressive traders must pay to have their order immediately filled– think buying and selling the same security at almost the same instant. The spread is the compensation to a dealer for offering that immediacy.

A good way to think about the size of the spread is to consider a market with several competing dealers. In this case, there are two primary scenarios:

1. If the spread is too high, more dealers will enter the market to gain profit from the large bid/ask spread

2. If the spread is too low, dealers will lose money, and exit the market

These two factors ensure that the liquid market dealers make normal profits, and that spreads are of reasonable size.

Supply and Demand

The existence of a spread is quite natural and leads back to the simplicity of supply and demand. Start the argument small and work your way up! I found a great example in an article by Glenn Curtis on August 19 with the following story.

Suppose that a one-of-a-kind diamond is found in the remote countryside of Africa by a miner. An investor hears about the find, phones the miner and offers to buy the diamond for $1 million. The miner says she wants a day or two to think about it. In the interim, newspapers and other investors come forward and show their interest. With other investors apparently interested in the diamond, the miner holds out for $1.1 million and rejects the $1 mil- lion offer. Now suppose two more potential buyers make themselves known and submit bids for $1.2 million and $1.3 million dollars, respectively. The new asking price of that diamond is going to go up. The following day, a miner in Asia uncovers 10 more diamonds exactly like the one found by the miner in Africa. As a result, both the price and demand for the African diamond will drop precipitously because of the sudden abundance of the once- rare diamond.

Imagine the diamond becomes more popular. More buyers want it. More mines open, and more sellers emerge. In a rational setting, this creates a quote driven a bid ask spread. Add enough volume, and before long, you are back to the first example.

Filed Under: What's happening in the current markets? Tagged With: ask, bid, FIFO, limit, order book, slippage, spread

Picking Trade Entry Signals

May 17, 2013 by Edward Lomax 3 Comments

So far in this series about building a solid trading strategy, I’ve gone over time frame, trend direction and using higher time frames and trend direction to filter trades. Now it is time to go over what most traders focus on when creating a trading system… entry signals. Basically, when do I pull the trigger and buy or sell in the market?

Before I start, I want to make one thing clear…

When to enter the market is not necessarily the most important part of your trading strategy.

Many traders think that if they can just nail down the right entry signals, nothing else matters. This is just not true. While deciding when you are going to enter the market is important, the other characteristics of a solid trading system are just as important or even more so.

Entry signals are exciting

Signals to enter the market are exciting. Just make sure that you don’t neglect the other important elements in a trading system.

Entry signals get a lot of attention because the topic is exciting, and things like money management and trade management are boring. But if you want to be successful, you cannot just focus on the things you like. You need to create a trading strategy that addresses every characteristic of solid trading, even the boring stuff.

Obviously your trading strategy needs a set of rules to tell it when to get into the market. I’m not going to claim to have the magic entry that always wins and can make you rich in a month. Frankly, that is not what you should be looking for either. I just want to go over some issues you are going to have to come to grips with when building your trading strategy.

Types Of Entry Orders

There are a few types of orders you can use to get into the market. Some wait for price to reach a certain level in the market before taking action, and some are immediate.

Pending Orders: A pending order is an order you place above or below current price action. When price reaches that level, an action (Buy or Sell) takes place.

  • Buy Stop Orders: An order is placed ABOVE price action. If price reaches this level a Buy trade is entered.
  • Sell Stop Orders: An order is placed BELOW price action. If price drops to this level a Sell trade is entered.
  • Buy Limit Orders: An order is placed BELOW price action. If price drops to this level a Buy trade is entered.
  • Sell Limit Orders: An order is placed ABOVE price action. If price reaches this level a Sell trade is entered.

Market Orders: A Market Order gets you into the market immediately. If you you want to take action at the current price level, you use a market order to Buy or Sell instantly.

Types Of Entry Signal Criteria

There are limitless ways to get into the market. They can range from the very simple to the incredibly complex. Here are some types of entry signals that can be used either alone or in combination.

Time Based Entry Signals – At a specific time a day, you place a market or pending order based on previous price action.

Set And Forget Entry Signals – These are either market or pending orders that you set up once, and then let price run to either the take profit or stop loss. Orders that have not triggered or are still running are normally closed the next day when new orders are placed.

Straddle Entry Signals – These are pending orders that straddles market price. At a certain time a day you place a Buy Stop order above price and a Sell Stop order below price. (These are normally set and forget style trades where you set take profit and stop loss for each order and come back the next day to see what happened).

Price Pattern Entry Signals – There are many price patterns (triangles, wedges, head and shoulders, etc.) that can be used to determine when to get into the market. There are also Harmonic Patterns (butterfly, bat, etc.) that have their own trading rules.

Candlestick Entry Signals – Candlestick patterns can be used to determine market reversals or continuation moves and pinpoint entries.

Divergence Entry Signals – Divergence happens when price action and an indicator (like MACD) are out of alignment. For example, price is trending up, but the MACD is going down. The thought is that price will follow the indicator at some point, and can be used to look for trade opportunities.

Indicator Alignment Entry Signals – There are thousands of indicators. There are also thousands of different settings for the indicators. This makes for a unlimited combination of indicators that can be put on your charts. When these indicators line up for a buy signal, you can enter the market long. When the indicators line up for a sell signal, you can enter the market short.

2 Considerations Regarding Entry Criteria And Expert Advisors

Since we are primarily talking about programming a trading strategy into an expert advisor, there are a couple of things you should take into consideration.

Complex Is Not Always Better – Many people think the more entry criteria they have, the better and more accurate the system will be. But that is not always the case. Sometimes a system can be so complex you get conflicting data which makes making a confident trading decision impossible.

The point of your entry criteria is to give you an edge in the market and identify high probability opportunities. You are never going to be able to create a system that wins all the time… so don’t try. Identify entry criteria that gives you an edge and avoid trying to search for the Holy Grail of trading systems.

Limiting The Times Of Day You Enter The Market – A lot of people want to build robots because they can look for trading opportunities 24 hours a day. I agree, this is one of the benefits of programming your strategy into an expert advisor. However, limiting the trading times might increase the effectiveness of your system.

The market is more active at certain times of the day like during the London open or when the London and New York markets are open at the same time. Sometimes limiting the hours a day your robot can trade improves accuracy and profitability.

Read the next article in the series: How to decide where to place your stop loss and take profit

Filed Under: Trading strategy ideas Tagged With: limit, market, pending, signal, stop

High Frequency NinjaTrader Strategy

January 30, 2012 by Shaun Overton 7 Comments

I’ve been working on a high frequency trading system for NinjaTrader on behalf of a long term client. My live account is with MB Trading. Rather than placing market orders and paying a commission, I changed the order types to limit orders. We want to receive a small commission for the market making strategy rather than paying a commission to accept the displayed prices.

MetaTrader suffers two major disadvantages that make NinjaTrader a superior option for high-frequency trading. MT4 does not offer charts lower than the M1 time frame and the trade context is busy error prevents multiple charts from running simultaneously. NinjaTrader is complex enough to where I can control most details, but simple enough that I don’t need to invest hundreds of hours to test an idea. After extensively testing the strategy on M1 charts as a price taker, I feel very confident that the strategy is sound. The only issue now is determining whether or not whether taking a passive (i.e., market making) approach will result in enough fills to make the strategy worthwhile.

The first issue that I came across wasn’t with NinjaTrader; it was with MB Trading’s API. The strategy worked fine on the simulation account, which only routes orders to NinjaTrader (NT). NT then makes guesses when fills would occur. The goal of that phase was not to test the strategy. I only wanted to test the programming to make sure that it worked properly.

100 trades went off without a hitch in the Sim account. The strategy only made it through 2-3 microlot trades on the live account before the pending orders hung. NinjaTrader pending orders pass through 3 states before they actually hit the market. For the programmers out there, these are the OrderState properties of IOrder objects.

  1. Pending submit – the strategy sent the order to the broker and is waiting to hear back
  2. Accepted – the broker acknowledges receipt of the order, but is still placing the order into the market
  3. Working – the order is available for others to trade

The strategy updated orders on every tick. What often happened was that the pace would go far too quickly, creating a major communications backlog during fast markets. NinjaTrader never threw an exception. The only evidence of a problem was that I would see a hanging order with the PendingChange property. The inconvenient solution was to exit NinjaTrader and reload everything.

I figured that perhaps that the managed order state caused the issue. I changed my approach to unmanaged orders, but that did not make a difference. I eventually came to the realization that the MB Trading API cannot handle more than one order every few seconds.

The strategy found the sweet spot after changing from tick to second charts. Updates of 6 seconds or longer seem to give the MB Trading API enough time to update wihle still preserving something of a high frequency approach. Any trades that need to run faster than that threshold at MB Trading need to use the FIX protocol.

The other element that drove me crazy is that NinjaTrader limit orders automatically delete themselves once per bar. I nearly tore my hair out, and I don’t have all that much hair, for several hours trying to figure out why orders deleted themselves automatically. Many people identify with the school of hard knocks approach to learning. I’m as thick headed as most. I figured out the cause when I revisitied NinjaTrader’s online documentation and discovered a limit entry method that allows good till cancelled (GTC) orders.

The speed problem also manifested with overfills. An overfill is when a strategy requests to cancel a pending order, but the broker fills the order before the cancellation takes effect. The biggest concern with overfills is that NinjaTrader automatically disables a strategy and exits positions at market when an overfill occurs. The only way to programmatically prevent this is to change the entry methods to an unmanaged approach.

The easiest way to develop for a high frequency strategy in NinjaTrader (but not ultra-high frequency) is to use managed orders. Whenever an exit is needed, place the limit entry in the opposite direction. NinjaTrader takes care of placing the exit order for the open market positoin. Limit the updates to every handful of seconds. It allows the broker API to catch up and helps avoid the problem of overfills.

Filed Under: NinjaTrader Tips, Trading strategy ideas, Uncategorized Tagged With: API, GTC, high frequency, IOrder, limit, MB Trading, metatrader, mt4, ninjatrader, OrderState, overfill, strategy, tick, trade context is busy

Stop & Limit Order

December 22, 2011 by Shaun Overton 3 Comments

Stop and limit orders are direct opposites. A limit order is jargon for “better price”, while a stop order means “worse price”. Many find it especially confusing that a stop entry order uses the same terminology as a stop loss. Technically, they are the same thing. A stop entry and stop loss are both prices worse than what you would get if you accepted the current market price.

Stop entry versus limit entry

Stop entries are used with momentum or breakout strategies. The theory is that if the price moves up, then it will be more likely to continue moving up. The trader loses out on the difference between the price at the time he decided to trade and the actual entry price. What he hopes to gain is the extra information that the price has moved, which might imply a higher probability trade.

A price that is worse the current market price for buying in the future is up. So, buy stops go above the current market price. Sell trades receive a worse price in the future if they wait and the price goes down.

Limit entries take the opposite approach. Market often tend to wander. They very rarely shoot off in a single direction without wiggling a little bit up and down. The idea behind a buy limit order is that you think that the price will increase in the future, but that you might be able to pick up the fx pair at a better price than what you’re seeing now. A buy limit goes below the current market price. A price improvement for a sell entry requires a price increase, so sell limit entries always go above the current market price.

Stop loss exit and limit exit

Most people find this part a lot simpler. Here, a stop loss means you lose money. The buy trade that you opened is going down. If it hits your stop loss, then the loss is realized. Stop losses go below the entry price for a buy trade and above the entry price for a sell trade.

Limits are the opposite. An open long trade is a bet that the price will increase. If it hits your limit exit, it means that you’re satisfied with the amount of profit on the table. Long trades place the limit above the entry price. Short trades place the limit exit below the entry price.

Filed Under: How does the forex market work?, Uncategorized Tagged With: limit, stop, stop loss

ECN MT4 Forex brokers are few and far between

December 8, 2011 by Shaun Overton 3 Comments

ECN originally stood for an electronic communication network, a description that falls well short of describing its purpose. ECNs developed around the beginning of the internet to allow stock traders to freely trade with one another and bypass the exchanges. The system added a dramatic increase in pricing and transparency. That’s why the investment banks bought them all out; they don’t want the small fish thinking that they deserve actual price discovery and low costs.

Fast forward twenty years and everyone bounces the word back and forth like it applies to the retail forex market. Well, it doesn’t, but I know that I’m going to lose this battle. The real structure of an ECN offers all participants the ability to act as price takers or market makers. With the exception of MB Trading, every single MT4 broker today only offers half of what an ECN offers. Traders either accept the prices appearing on the screen or they do not. The brokers don’t offer any alternatives. The word ECN in popular parlance has been debased to mean a brokerage that is passing liquidity from one side to another.

This structure, in my opinion, is one of the largest ills of the retail forex market. Everything about the system encourages traders to act as captive sheep. They can only accept the prices that the broker deigns to offer.

Although the stock market is also corrupt, at least setting a limit order actually shows through on the ticker. Most forex traders, amazingly, are not aware that this is how most markets work.

Consider a currency that trades at a bid-ask spread of 145-147 with a typical forex broker. If I want to buy at 146 limit, I must wait for the ask to drop to 146 before my order will fill.

The same order traded in the equities or futures markets would behave completely differently. The spread changes the exact moment that I post my 146 buy limit. The spread now appears as 146-147.

I do the market a favor by posting my order out there. The spread decreases, reducing the spread cost for the next person to sell a position. Additionally, that trader got to sell a whole point higher at 146 instead of 145. It works to everyone’s benefit.

Go back to the definition of a limit order. It means an order to buy at a price better than the prevailing market. That action requires a seller. Otherwise, no trade would occur. The broker or exchange posts that buy order for whichever seller wants to come along and take me up on the trade.

You can think of it just like eBay. My limit buy order is like the auction advertisement. eBay is like the broker. The person going short acts like the person buying used stuff off of the internet. Both parties walk away happy with the trade. The purchaser trades cash for goods. The person listing the auction trades goods for cash. eBay gladly stands in the middle and takes a small commission for the service. That is genuine price discovery.

For all the silly rules that the NFA creates, the one that they ought to focus on is this complete lack of price discovery. Any brokerage promoting themselves as an ECN ought to actually offer the services of a real ECN.

Filed Under: How does the forex market work?, MetaTrader Tips, Uncategorized, What's happening in the current markets? Tagged With: ecn, forex, limit, metrader, mt4

FREE trading strategies by email

Trending

Sorry. No data so far.

Archives

  • Dominari
  • How does the forex market work?
  • Indicators
  • MetaTrader Tips
  • MQL (for nerds)
  • NinjaTrader Tips
  • Pilum
  • QB Pro
  • Stop losing money
  • Test your concepts historically
  • Trading strategy ideas
  • Uncategorized
  • What's happening in the current markets?

Translation


Free Trading Strategies

Privacy PolicyRisk Disclosure

Copyright © 2023 OneStepRemoved.com, Inc. All Rights Reserved.