Forex Trading With API

Discussions about trading the Forex markets.
Post Reply
Pac Man
Contributing Member
Contributing Member
Posts: 5
Joined: Wed Apr 05, 2006 5:58 am

Forex Trading With API

Post by Pac Man »

Hi Guys,

I have just found your site and read thorugh alot of your posts. Seams like there is some good info here.

I currently trade FX via API at Oanda.com and am looking for some feedback on a system I use.

The system is based on Bollinger Bands and has been performing well. The problem is when the market starts to trend in one direct the win/loss ratio drops off and the system losses some of it's appeal.

What I would like to do is add a bias to the system that will make it harder to trade short in an up trend and eaiser to go long in the same trend.

E.g. If the standard deviation of the BB is 2.4 then I want to change that to 2.5 for the upper band and 2.3 for the lower band. This is in an up trend and vice versa for a down trend.

The question is has anybody done anything like this? If so was it to your advantage?

Do you have any back testing software that could do this type of analysis?

Any suggestions on detecting a trend that does not lag to much?

I currently trade on a 5 min chart. The reason for wanting to add this feature is I was up 32% last month then ended up at +1.5% for the month.

Most of the loss was due to a few fundamental events (The API now has a built in calendar that stops trading, hedges, revereses position, halfs position size or half and reverse position) but the rest was when EUR/USD went into uptrend.

Every trade was a short trade and every one was a loser.

Any ideas?

Thanks
RedRock
Roundtable Knight
Roundtable Knight
Posts: 944
Joined: Fri Jan 30, 2004 3:54 pm
Location: Arizona

Post by RedRock »

:twisted: Have you explored the impact of lunar cycles on the world markets. http://www.billmeridian.com/articles-files/lunar.htm
Pac Man
Contributing Member
Contributing Member
Posts: 5
Joined: Wed Apr 05, 2006 5:58 am

Post by Pac Man »

Interesting read. Not sure how it relates to my question though.

I think moon cycles have a roll in things like wheat simply becase of the season.

The moon will aline with a seson here and there and as wheat is a seasonal thing it may have an affect on supply and demand.

Just my 0.000002c worth. I have never paid any real attention to it.
BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI »

pac man, is your strategy based on buying once the price penetrated the lower band and shorting once it penetrated the upper band? If so, I've been working a bit on such a system. I have 4 bars bands and the standard deviation of the BB is 1 each. This system inters on market and exits on market the next no matter what it has profit or loss so only 1 day hold. Started with 300k
Here are results on North Americ an futures

Image
Image

your observatrion is correct, once there's a strong trend this system will get killed. You can play with a stop loss strategy, for instance if it goes below the low of the entry 5 min bar get out of the market if you're long, vice versa for the short side. By the way how many bars your system uses to calculate bands?
Pac Man
Contributing Member
Contributing Member
Posts: 5
Joined: Wed Apr 05, 2006 5:58 am

Post by Pac Man »

H i BARLI,

Yep when I get a move outside the top band (Bid Price) I short the currency, If I get a move outside the bottom band (Ask Price) I go long.

Based on 13 bars and 2.4 STDV 15 min time frame.

It does get flogged in a strong trend market so I have gone looking for two solutions.

1. Create a trend following system to trade on the same currency which is non correlated. So when one is working the other does not and vice versa. The trixck to this is ensuring the MM is correct. Use more on the system that is working and reduce the other. Timing is the key but. I think the overall performance willbe down but it will be smother and more reliable.

2. Trade other currencies that are non correlated to the pair I trade now. (EUR/USD)

At the moment the latest version is performing well at 0.86% per day over the last 25 days. It is still new and only done 37 trades with win/loss of 45%

I need to wait for 100+ trades before it gives a reliable reseult.
BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI »

I'll test your parameters on EOD on futures , I dont have 15 min data
RedRock
Roundtable Knight
Roundtable Knight
Posts: 944
Joined: Fri Jan 30, 2004 3:54 pm
Location: Arizona

Post by RedRock »

Hmmmmm
Pac Man
Contributing Member
Contributing Member
Posts: 5
Joined: Wed Apr 05, 2006 5:58 am

Post by Pac Man »

What is the Hmmmm in reagards to...?
BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI »

RedRock is being bored :wink:
BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI »

Backtest on Euro (Dm before Euro) futures, trades 1 contract only. Parameters are yours 14;2.4 holds one day only.
Image
Image
this is how it takes/exits trades

Image

On Forex it performed the best on EU60000$

Image

If we change 14 to 13 and use 2.4 here's what we get on EU60000$

Image
Pac Man
Contributing Member
Contributing Member
Posts: 5
Joined: Wed Apr 05, 2006 5:58 am

Post by Pac Man »

What are you using as the Take Profit and Stop loss?

I use preset TP's and SL's

Edit:

I see you only hold for one day. I hold for as long as it take to hit my SL or TP.
RedRock
Roundtable Knight
Roundtable Knight
Posts: 944
Joined: Fri Jan 30, 2004 3:54 pm
Location: Arizona

Post by RedRock »

BARLI wrote:pac man, is your strategy based on buying once the price penetrated the lower band and shorting once it penetrated the upper band? If so, I've been working a bit on such a system. I have 4 bars bands and the standard deviation of the BB is 1 each. This system inters on market and exits on market the next no matter what it has profit or loss so only 1 day hold. Started with 300k
Here are results on North Americ an futures
?
On your four bar test. are you entering with a limit order intraday or on close, next open??? Exiting when? Using previous day bb value?

Any stops with these results or just one day exit. Tried two or three day?

What is the average PL per contract on the portfolio?

How much slip and comm factored in.

Just curious... Interesting stuff.
RedRock
Roundtable Knight
Roundtable Knight
Posts: 944
Joined: Fri Jan 30, 2004 3:54 pm
Location: Arizona

Post by RedRock »

Pac Man wrote:What is the Hmmmm in reagards to...?
Just hmmm... I hadnt tested this concept on a portfolio. Sort of tastes like turtle soup.
BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI »

Pac Man wrote:What are you using as the Take Profit and Stop loss?

I use preset TP's and SL's

Edit:

I see you only hold for one day. I hold for as long as it take to hit my SL or TP.
no stop losses and no profit targets were used in the simulation that BB system on Euro and Forex of Euro/dollar . Once the upper band was penetrated the system goes short at the market on the opening the next day and gets out of the trade the next day if position was taken.
See here again:

Image


RedRock wrote:
On your four bar test. are you entering with a limit order intraday or on close, next open??? Exiting when? Using previous day bb value?

Any stops with these results or just one day exit. Tried two or three day?

What is the average PL per contract on the portfolio?

How much slip and comm factored in.

Just curious... Interesting stuff.
Market at the open orders only, 1 day hold only -all trades, so exits are all same: once in a position exit at the open on market next day and no stops (the idea was to test if such a thing can work catching market moves with low risk). I didn't add slippage into that 4 days simulation, neither commissions (commissions wouldn't influence results much.slippage of course would, but in real life I'd do limit orders only)
avg P/L is 873$. I haven't tried it with 3, 4 day exit.
Give it some work on TBB and bring some results to see how it'll do , bring some of your tests with you ;)
RedRock
Roundtable Knight
Roundtable Knight
Posts: 944
Joined: Fri Jan 30, 2004 3:54 pm
Location: Arizona

Post by RedRock »

I make no claim to being but a beginner at coding in blox. However, I am unable to come up with any simple counter BB system which shows a profit as your testing describes. The results are similar to the built in counter trend BB system that ships with TBB. A nice steady decline of equity from start till bankruptcy.

Perhaps any other Tbb users can confirm or dispute this observation??
BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI »

have you asked Tim for coding help?
here's a code in Wealth Lab language that my 4 days 1 S.Dev system uses:

Code: Select all

var BBDown, BBUp: integer;
var Bar, p: integer;
BBDown := BBandLowerSeries( #Close, 4, 1 );
BBUp := BBandUpperSeries( #Close, 4, 1 );
PlotSeries( BBDown, 0, 559, #Thick );
PlotSeries( BBUp, 0, 559, #Thick );
for Bar := 20 to BarCount - 1 do
begin
  if LastPositionActive then
  begin
    p := LastPosition;
    if PositionLong( p ) then
    begin
      SellAtMarket( Bar + 1, p, '' );
    end;
    if PositionShort( p ) then
    begin
      CoverAtMarket( Bar + 1, p, '' );
    end;
  end
  else
  begin
    if not LastPositionActive then
    begin
      if CrossUnder( Bar, #Close, BBDown ) then
      begin
        BuyAtMarket( Bar + 1, '0' );
      end;
    end;
    if not LastPositionActive then
    begin
      if CrossOver( Bar, #Close, BBUp ) then
      begin
        ShortAtMarket( Bar + 1, '3' );
      end;
    end;
  end;
end;

enablenotes (false)
RedRock
Roundtable Knight
Roundtable Knight
Posts: 944
Joined: Fri Jan 30, 2004 3:54 pm
Location: Arizona

Post by RedRock »

I see one thing different. You are entering following a close beyond bb. I was using any penetration to triger next entry. Does make some difference. Interesting idea to play with...


This includes $20rt comm and NO skid on a very broad portfolio from 1980. One contract traded.



Trading Performance

CAGR % 6.80%
Maximum Total Equity Drawdown % 22.01%
MAR Ratio 0.31

Margin to Equity Ratio 4.50%
Daily Return % 0.0274%
Daily Geometric Return % 0.0224%
Daily Standard Deviation % 0.67%
Daily Downside Deviation % 0.49%
Daily Sharpe % 0.02
Daily Sortino % 0.03

Modified Sharpe Ratio 0.64
Annual Sharpe Ratio 0.25
Annual Sortino Ratio 0.74
Monthly Sharpe Ratio 0.08
Monthly Sortino Ratio 0.13
Calmar Ratio 0.39

Longest Total Equity Drawdown (months) 55.89
Maximum Monthly Total Equity Drawdown % 17.40%
Maximum Closed Equity Drawdown % 21.31%
Average Closed Equity Drawdown % 0.81%

Round Turns Per Million 4,917

Start Account Balance $150,000.00
Total Win Dollars $9,835,668.38
Total Loss Dollars $9,481,358.55
Total Profit $354,309.82
Earned Interest $348,269.68
Margin Interest $0.00
End Account Balance $852,579.51
End Open Equity $0.00
End Total Equity $852,579.51

Highest Total Equity $914,965.92
Highest Closed Equity $916,823.04

Total Commissions $512,720.00
Total Slippage $0.00
Total Forex Carry $0.00



Test Period

First Test Date 1980-01-02
Last Test Date 2006-06-09


Win/Loss Statistics

Wins 25735 50.2%
Losses 25537 49.8%

Total 51272 100.0%

Winning Months 182 57.2%
Losing Months 136 42.8%

Total 318 100.0%

Average Risk Percent 0.00%
Average Win Percent 0.09%
Average Loss Percent 0.09%
Average Win Dollars $382.19
Average Loss Dollars $371.28
Average Trade Percent 0.00%
Average Trade Dollars $6.91

Profit Factor 1.04
Percent Profit Factor 1.05
Expectation 0.00



Equity Management


Test Starting Equity ($) $150,000.00
Attachments
bb barli.png
bb barli.png (15.65 KiB) Viewed 20401 times
BARLI
Roundtable Knight
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA

Post by BARLI »

yes it is, do you also hold for one day only? cagr of 6% is low we need to optimize it to come to something tradeable
Post Reply