Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: ATR Study
Author/Uploader: steve wiser - slwiserr [at] erols.com
Date/Time added: 2001-11-23 18:09:31
Origin:
Keywords: ATR
Level: medium
Flags: system,exploration,indicator

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

This was simply a study at seeing how I could use the ATR function in a trading system.
System settings:
25 $ per trade
Buy and sell on signal one day delay for both
Start equity of $10000
Long trades only on daily selection
Stops controlled by code

Formula:

//* ATR Study:  */

Exclude = MA(V,50)<200 ;
MaxGraph = 12;
Graph0 = C;
Graph0Color = 1;
Graph0Style = 64;

BuyOffSet = 18;//Optimize("BuyOffSet",18,15,20,1);
SellOffset = BuyOffSet;//Optimize("SellOffset",2,2,14,2);
RegLength = 5;//Optimize("RegLength",5, 2,11,2);
BuyATRPeriod = 2;//Optimize("BuyATRPeriod",2,2,5,1);
SellATRPeriod = BuyATRPeriod;//Optimize("SellATRPeriod",4,2,11,2);
ATRMultiplier = 1;//Optimize("ATRMultiplier",1,0.7,1.25,.05);


Graph8 = HHV(H-ATRMultiplier*ATR(BuyATRPeriod),BuyOffset);   /* RED */
Graph9 = LLV(L+ATRMultiplier*ATR(SellATRPeriod),SellOffset);  /*  GREEN */

Graph8Style=Graph9Style = 5;
Graph9Color=  5;  /* 5 is green */
Graph8Color = 4;  /* 4 is red */

ticker = 0.0;//Optimize("Tickerk",0,0,1,0.125);

Buy = Cross(C,Graph8) AND C>Graph9 AND LinRegSlope(EMA(C,17),2)>0;
Sell = Cross(Graph8,C) AND LinRegSlope(C,2)<0;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
BuyStop = Ref(Graph8,-1)+ ticker;
BuyPrice = Max(BuyStop,Low);
SellStop= Ref(Graph8,-1);   //IIf(Cross(Graph8,C),Ref(Graph8,-1),0);
SellPrice = Min( SellStop, High )- ticker; 

//ApplyStop(2,3,Optimize("TrailingStop",15,0,20,5),1);

Filter=   (Buy OR Sell)      ;      
NumColumns = 8;
Column0 =  IIf(Buy==1,1,IIf(Sell==1,-1,0) );
Column0Format = 1.0;
Column0Name = "Long/Sell";
Column1 = C;
Column1Name = "Close       ";
Column1Format = 1.2;
Column2 = MA(V,17);
Column2Name = "17 Ma Vol   ";
Column2Format = 1.0;
Column3 = MA(C,17)/MA(C,50);
Column3Name = "% 17/50 ";
Column3Format = 1.2;
Column3Format = 1.2;
Column4= MA(C,17);
Column4Name="17 C ma";
Column4Format = 1.2;
Column5= MA(C,50);
Column5Name="50 C ma";
Column5Format = 1.2;

Column6= BuyPrice;
Column6Name="BuyPrice";
Column6Format = 1.2;
Column7= SellPrice;
Column7Name="Sellprice";
Column7Format = 1.2;

Comments:

Marek Chlopek
mchlopek [at] post.pl
2001-11-26 14:22:40
Steve,
The system is simply too good that it could be true ;-)
I have some problems to understand buy/sell prices.
Could you please explain in few (or more then few ;-) words this part bellow:

Buy = Cross(C,Graph8) AND C>Graph9 AND LinRegSlope(EMA(C,17),2)>0;
Sell = Cross(Graph8,C) AND LinRegSlope(C,2)<0;

BuyStop = Ref(Graph8,-1)+ ticker;
BuyPrice = Max(BuyStop,Low);
SellStop= Ref(Graph8,-1);
SellPrice = Min( SellStop, High )- ticker;

How I can invest at the price Low or High when there is the gap between Sell/BuyPrice and H/L?

What does also mean two lines of code:
Exclude = MA(V,50)<200 ;
Filter= (Buy OR Sell) ;

Thanks,
Marek
Marek Chlopek
mchlopek [at] post.pl
2001-11-26 14:23:48
Steve,
The system is simply too good that it could be true ;-)
I have some problems to understand buy/sell prices.
Could you please explain in few (or more then few ;-) words this part bellow:

Buy = Cross(C,Graph8) AND C>Graph9 AND LinRegSlope(EMA(C,17),2)>0;
Sell = Cross(Graph8,C) AND LinRegSlope(C,2)<0;

BuyStop = Ref(Graph8,-1)+ ticker;
BuyPrice = Max(BuyStop,Low);
SellStop= Ref(Graph8,-1);
SellPrice = Min( SellStop, High )- ticker;

How I can invest at the price Low or High when there is the gap between Sell/BuyPrice and H/L?

What does also mean two lines of code:
Exclude = MA(V,50)<200 ;
Filter= (Buy OR Sell) ;

Thanks,
Marek
steve wiser
slwiserr [at] erols.com
2001-12-09 11:35:30
I am continuing to study what is going on with the stops. The stops do appear to be to give us to much advantage.
Luca Meroni
luca.meroni [at] easyconsult.it
2002-04-24 11:31:14
I'm studying your system, but I also need an help on how to use this very interesting system.

Thanks, Luca
K Quamme
kquamme [at] hotmail.com
2002-05-10 12:20:56
I believe this system is suffering from a crystel ball effect. (Using future data to make a buy decision)

The Buy/Sell decisions use the Close data, but
===>Buy = Cross(C,Graph8) AND C>Graph9 AND LinRegSlope(EMA(C,17),2)>0;

the BuyPrice and SellPrice:
===>BuyStop = Ref(Graph8,-1)+ ticker;
===>BuyPrice = Max(BuyStop,Low);

If I am reading this correctly if BuyStop is less than the low for the day the BuyPrice is set to the low, but we can't buy at the low for the day because the Buy is determined by the closing price.

I don't think this system could be traded effectively.

Or am I missing something?

-KQ
Robert Gervais
WinWallStreet [at] AOL>\
2002-08-18 04:00:55


Steve
I've been working on the same system as you and getting similar results my buys and sells are not as complicated as yours. but I'am using an adaptive approach and letting market conditions determine the ATRMultiplier, HHV(period), and ATR(period). In this you not only have buy/sells but short/cover and when to stay out, as this is very good in indicating trend/trade zones.

Will upload my system when finished.
Robert Gervais
WinWallStreet [at] AOL>\
2002-08-18 04:00:55


Steve
I've been working on the same system as you and getting similar results my buys and sells are not as complicated as yours. but I'am using an adaptive approach and letting market conditions determine the ATRMultiplier, HHV(period), and ATR(period). In this you not only have buy/sells but short/cover and when to stay out, as this is very good in indicating trend/trade zones.

Will upload my system when finished.
Robert Gervais
WinWallStreet [at] AOL>\
2002-08-18 04:00:55


Steve
I've been working on the same system as you and getting similar results my buys and sells are not as complicated as yours. but I'am using an adaptive approach and letting market conditions determine the ATRMultiplier, HHV(period), and ATR(period). In this you not only have buy/sells but short/cover and when to stay out, as this is very good in indicating trend/trade zones.

Will upload my system when finished.
Mark Bremer
Formula with dynaorder
2003-01-09 02:49:22
Is anybody out there who is able to program a dll - working together with "dynaorder" (order execution system) and this ATR-Study?

help could be find under:
http://www.dynaorder.com/efs-examples.asp

You need to program the system using AMIBroker Formula language with calling DO functions.

Who can help?
Hans Baier
mediabroadcast [at] yahoo.de
2003-01-10 08:00:02
Hello Steve!

I´m actually working with the ATR-Study and its really impressing!
In the "Automatic Analysis" Modus - i´m using a 12 Minutes time frame in the backtest settings. The Backtest is up to 5% te last 7 days! But i have still a problem. The system produce too much signals by itself. Is it possible to modify the formula that it produce signals by a 12 minutes time frame only? Then i could use the Alert-Function for buy and sell signals.
Who can help me?

Greetings
Hans Baier
mediabroadcast [at] yahoo.de
2003-01-10 08:00:23
Hello Steve!

I´m actually working with the ATR-Study and its really impressing!
In the "Automatic Analysis" Modus - i´m using a 12 Minutes time frame in the backtest settings. The Backtest is up to 5% te last 7 days! But i have still a problem. The system produce too much signals by itself. Is it possible to modify the formula that it produce signals by a 12 minutes time frame only? Then i could use the Alert-Function for buy and sell signals.
Who can help me?

Greetings
mayoor_vaghela
mayoor_vaghela [at] yahoo.com
2003-01-14 23:51:18
Dear Steve
I have downloaded your above formula and uploaded in Amibroker, but I didn't see anything but graph only. In interpretation window i get following

Long/Sell
Close
17 Ma Vol
% 17/50
17 C ma
50 C ma
BuyPrice
Sellprice

but not any signal or value. How to get the value ?
Mayoor

Ron
ronecooper [at] adelphia.net
2003-11-13 13:06:43
Steve,

This is intriguing. However, the buyprice and sellprice seem to require realtime pricing rather than eod pricing in order to achieve the buys and sells at the prices indicated. If you were to use eod pricing and have the buy or sell occur in the next day of trading, how could you set up backtesting to show an average price for the next day? Any help with this would be appreciated.
Ron
ronecooper [at] adelphia.net
2003-11-13 14:11:11
Steve,

Your description says that you are using a one day delay for both buy and sell signals. I have set up an alertif function to give the indicated buy and sell signals. It appears rare if not impossible to buy or sell at the buyprice or sellprice given on the next day of trading. Am I missing something or am I looking at the system a day late?
Brian
brianrichard99 [at] hotmail.com
2004-06-18 16:34:59
I tested this system against my own (which does not use ATR whatsoever), and used the same specifications. This system performed less than half as well as mine did, using hourly data over a 5-month period. I like to test systems using the more realistic code:

SetTradeDelays( 1,1,1,1 ); // long,sell,short,cover delays

since it is rare that I will enter a trade as the signal is being created within the system.

I may use this ATR system to add to my own system, however.
gty

2004-06-30 08:06:43
Well, this system won't work (too bad)

Buy = Cross(C,Graph8) AND C>Graph9 AND LinRegSlope(EMA(C,17),2)>0;
Sell = Cross(Graph8,C) AND LinRegSlope(C,2)<0;

BuyStop = Ref(Graph8,-1)+ ticker;
BuyPrice = Max(BuyStop,Low);
SellStop= Ref(Graph8,-1);
SellPrice = Min( SellStop, High )- ticker;

Signal is generated basing on Close (which we don't know yet) crossing Graph8 (which has H of today which we don't know) and using yesterday price ;-)(which we can't buy)

Clement Chin
share [at] manyit.com
2004-11-12 03:18:42
Apparently, it fell into one of the bias as explained in Van Tharp's book.
Chris

2005-01-14 00:48:20
The real concerns seem to be:

BuyPrice = Max(BuyStop,Low); -and-
SellPrice = Min( SellStop, High )- ticker;

The problem being buy at the low and sell at the high. That said, I modified the system in 2 ways:

1. Changed out Low/High with Open/Close respectively.
2. Set purchase delays of 1 day on open and sell delay of 1 day on open.

Even after those 2 modifications, the system still performed very well. Am I still missing something?
Chantal

2005-06-24 06:52:07
I think it's necessary make calculation at close of today, and buy/sel at open tomorrow
Chantal

2005-06-24 06:52:48
So it's more real
RallyArtist
kensoh [at] gmail.com
2009-02-22 12:13:53
Hi Steve,

The comments above makes sense. Loophole in the system is you are buying at lowest price of day when the signal is generated based on closing price. Hence in practice its not possible.

Adding the following 2 lines will make the results realistic but still impressive!

// buy at open next day after signal
SetTradeDelays(1, 1, 1, 1);
BuyPrice = Open; SellPrice = Open;

Your method is based on buy at breaking short-term resistance, sell on breaking short-term resistance-turned-support. It yields good results, however a catch is the high number of trades, which after including commissions and slippages it is harder to implement in practice.

Perhaps experimenting with a longer term timeframe can yield interesting results?

// buying next day after signal at open
SetTradeDelays(1, 1, 1, 1);
BuyPrice = Open; SellPrice = Open;

Your method is based buy on breaking short-term resistance, sell on breaking the short-term resistance-turned-support. It yield good results, however a catch is the high number of trades, which after including commissions and slippages it is harder to implement in practice.

Perhaps experimenting with a longer term timeframe can yield interesting results?
RallyArtist
kensoh [at] gmail.com
2009-02-22 12:16:17
Hi Steve,

The comments above makes sense. Loophole in the system is you are buying at lowest price of day when the signal is generated based on closing price. Hence in practice its not possible.

Adding the following 2 lines will make the results realistic but still impressive!

// buy at open next day after signal
SetTradeDelays(1, 1, 1, 1);
BuyPrice = Open; SellPrice = Open;

Your method is based on buy at breaking short-term resistance, sell on breaking short-term resistance-turned-support. It yields good results, however a catch is the high number of trades, which after including commissions and slippages it is harder to implement in practice.

Perhaps experimenting with a longer term timeframe can yield interesting results?

// buying next day after signal at open
SetTradeDelays(1, 1, 1, 1);
BuyPrice = Open; SellPrice = Open;

Your method is based buy on breaking short-term resistance, sell on breaking the short-term resistance-turned-support. It yield good results, however a catch is the high number of trades, which after including commissions and slippages it is harder to implement in practice.

Perhaps experimenting with a longer term timeframe can yield interesting results?
adadadadog
godadada [at] yahoo.com
2009-10-14 04:12:20
Amibroker backtester is often arbitrary for uninitiated. E.g. it assigns the best available price between h/l if a limit order is out of range. This practice is extremely misleading. Other factors can make a huge difference in test results, such as choice among average, open, close, high, or low price in entry/exit. This kind makes backtester not only useless, but often waste user a lot of time. This script result falls into as an example. What a shame!
Tomasz Janeczko
tj [at] amibroker.com
2009-10-19 10:22:22
You have completely WRONG conception about how backtester works. The backtester WILL NOT assign \\\'aribitrary\\\' values to anything but only
values that YOU HAVE SET in the settings.

Also if the TRADE PRICE that YOU HAVE coded is outside of H-L range than it won\\\'t allow you to trade on such outside of range prices (and will use either H if your price is too high and L if it is too low).

No program is able to think instead of the user and it is user responsibility to fix HIS/HER errors.

Each formula that uses buyprice/sellprice MUST CHECK for high/low if you are trying to implement \\\"limit order\\\".

Buy = IIF( BuyPrice >= Low, Buy, 0 );
Sell = IIF( SellPrice <= High, Sell, 0 );


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM