Showing posts with label amibroker. Show all posts
Showing posts with label amibroker. Show all posts

April 25, 2020

ATR Trailing Stoploss AFL

This is a very simple AFL which plots the SL for a long or short position 3 ATR stops away from close of the currently selected bar.

While the AFL does not define entry, you can consider SL hit as trend reversal and initiate reverse trade.

NOTE:
- ATR stands for Average True Range.... google for more info
- ATR is displayed for currently selected bar (i.e. it is not trailing)
- for a long position, the SL should only move up only when a new high is made and vice versa
- you can use this to define position sizing
- ATR is based on close and default 14 days (or bars).
- ATR stop is set at 3... using 2 will give faster exit at cost of more whipsaws
- you can use this on 5 min, 15 min or daily, weekly charts etc
- this AFL is for Amibroker... ignore it if you don't have/ know Amiboker

AFL Code:

February 9, 2020

Magnified close AFL

Edit: this code was first posted in 03/2015 and is now modified to change color depending on whether the bar close is in positive or negative.

Green vertical line is currently selected bar.

Modified code is highlighted.

Close in positive:



Close in negative:





Code is pretty simple - use low level graphics functions. The AFL is:

November 20, 2018

Algostudio 2.0 – Amibroker AutoTrading Bridge for Upstox API Users

Algostudio is a simple and clean user interface which is built on top of Upstox REST API with a large feature set, helping you to automate your quantitative trading who is looking to streamline their processes through automation and effective management of their day-to-day trading activities. 

Algostudio converts amibroker trading signals to automated orders. It is a single interface where provisions are made to execute and monitor your trade positions at one single place.

Features of Algostudio

Supports Automated Trading.
Supports Bracket and Cover Orders.
Supports Place Order/Order Modification/Order Cancellation (Limit/Market/StopLoss/Bracket/Cover).
Close remaining positions from Amibro

Read more at https://www.marketcalls.in/algostudio/introduction-to-algostudio-2-0-amibroker-autotrading-bridge-for-upstox-api-users.html

August 5, 2018

AFL to explore stocks closing at All Time High

>>>
Filter=Cross(C,Ref(Highest(H),-1)) AND C>20 AND Ref(C,-120)>0;

AddColumn(C,"Close",1.2);
AddColumn(ROC(C,1),"% Ch 1D",1.2);
<<<

Result:



NOTE: Filter ignores stocks < Rs.20/- and trading for less than 120 days.

July 6, 2018

AFL to plot vertical lines in Amibroker

_SECTION_BEGIN("KPL vlines");
segments =
IIf(Interval() < in15Minute, Hour(), IIf(Interval() < inDaily, Day(), Month() ) );
segments = segments !=
Ref( segments , -1 );
Plot(segments, "", colorGold, styleHistogram | styleOwnScale ); _SECTION_END(); 


Save above as vlines.afl file and then drag drop on price chart.

Warning: may not work on log scale charts

See in action

June 8, 2018

Trailing SL added to kplswing indicator

The light grey line is the trailing SL and is half the default value of N.

Amibroker code and documentation is at http://www.vfmdirect.com/kplswing

Here is the chart...

March 16, 2018

AFL to display All Time High / Low for stocks (Amibroker only)

This AFL displays list of stocks at their All Time High and Low.


>>> AFL starts
//copyright kpl@vfmdirect.com
//This AFL displays all time high and low for stocks

Filter=(H==Highest(H) OR L==Lowest(L)) AND C>20;

AddColumn(C,"Close",1.2);
AddColumn(Highest(H),"All time Hi",1.2,colorDefault,IIf(H==Highest(H),colorLightBlue,colorDefault));

AddColumn(Highest(L),"All time Lo",1.2,colorDefault,IIf(L==Lowest(L),colorOrange,colorDefault));

<<< AFL ends 




July 11, 2017

AFL to clean up messed up EOD data

Yesterday's EOD data had tons of weird high and lows which completely messed up charts. Since the affected charts were in hundreds, I wrote a quick AFL to clean up the data.

Logic is simple... the close is the only sacrosanct data you can get in any exchange. Using yesterday's close as open for today, the AFL takes these values and creates the high and low for the day.

The results are then exported to a csv file and imported into Amibroker.

Here is the AFL.

>>>
Filter=1;

AddColumn(Ref(C,-1),"open",1.2); // yesterday's close is today's open
AddColumn(IIf(C>Ref(C,-1),C,Ref(C,-1)),"hi",1.2); // sets the high for the day
AddColumn(IIf(C>Ref(C,-1),Ref(C,-1),C),"lo",1.2); // sets the low for the day
AddColumn(C,"close",1.2); // this is final close
AddColumn(V,"vol",1.2);
<<<

NOTE: this is to be used only in the rarest of rare cases.

May 28, 2016

AFL: Monthly crossover signals

This AFL will scan a database and generate buy/ sell signals whenever a stock closes above last month's high or below last month's low.

This is a beautiful system and can yield fantastic results if risk management is properly done.

As usual, none of my AFLs have targets so one should hold a trade with a trailing SL (last month's low for long positions).

Note: there is no volume filter so restrict your analysis / scans to the top 100-200 most liquid stocks

Here is the code:

>>>
Buy=Cross(C,TimeFrameGetPrice("H",inMonthly,-1)); Sell=Cross(TimeFrameGetPrice("L",inMonthly,-1),C); 
Buy=ExRem(Buy,Sell); 
Sell=ExRem(Sell,Buy);
<<<


Note:
- Run in scanner mode
- ExRem removes multiple signals.
- Refer Amibroker help file for more assistance.

April 20, 2016

Open interest changes AFL

Many traders study changes in open interest with change in price and then try and anticipate what will happen next.

This AFL lists the % change of the underlying and also the change in the open interest. You can then sort the respective columns and develop your trading strategy.

More info on open interest is available at http://www.vfmdirect.com/info/open.html


And this is the AFL

>>>
Filter=1; AddColumn(C,"Close",1.2); AddColumn(ROC(C,1),"% change",1.2); AddColumn(ROC(OpenInt,1),"% OI change",1.2);

<<<


October 25, 2015

AFL to identify top gainers and losers

This AFL will show stocks gaining or losing more than 5% on daily charts.

Volume filter is predefined at 5 crores  (50 day average) - you can change this via the parameters dialog box.

This is the AFL

no=Param("Vol in crores",5,0,500,5);
Filter=MA(C,50)*MA(V,50)>10000000*no AND abs(ROC(C,1))>5;
AddColumn(C,"Close",1.2);
AddColumn(ROC(C,1),"ROC_1D %",1.2);
AddColumn(MA(C,50)*MA(V,50)/10000000,"Vol Cr",1.0);



This is the output

October 24, 2015

How to identify trendline breakouts in Amibroker

This post focuses on a very powerful feature of Amibroker - the ability to identify hand drawn trendline breakouts.

Following chart is of INFY and I have drawn 3 trendlines... the red is for resistance (RE), blue for support (SU) and the black line is the standard trendline (TE).

For various reasons, you may want to know when the stock crosses the resistance or breaks the support or crosses the black trendline.

August 4, 2015

Using kplswing to identify 52 week high lows

Download the kplswing indicator from http://www.vfmdirect.com/kplswing and then follow instructions for installing.

Load the indicator in Amibroker.

Now change the parameters - set the value of N as 52 using the Parameters option.

Then change the timeframe mode to Weekly using the Settings option

Define a filter using the Filter option. I used a watchlist of CNX 200 stocks.

Hit the scan button ....




August 3, 2015

How stocks have profited since 2003

The year 2003 was the start of the previous bull run. If you were an invest and forget type of investor, this is the return you could have got had you invested in some stocks that time.

For this, I wrote a crude AFL. The code is as follows:


Filter=1;
AddColumn(Ref(O,-13),"Open 2003",1.2); 

AddColumn(C,"Close 2015",1.2); 
AddColumn((C-Ref(O,-13))/Ref(O,-13), "ROC",1.2);

The Close 2015 is today's close.

Above exploration should be run on Yearly mode.



July 26, 2014

Support and resistance AFL for day traders

This AFL will plot support, resistance and pivot levels on intraday charts. For the formula and some theory on this, visit this wikipedia link.

This is the way the indicator looks when plotted on a chart.

June 24, 2014

Color formatting Amibroker exploration results

Sometimes you need an AFL which makes it easier to identify certain stocks. At times like this, color coding helps a stock visually stand out so it gets your attention.

An example is this report which visually highlights stocks gaining or losing more than 2%, close above/ below 10 DMA and RSI more / less than 80/ 20.


June 11, 2014

Removing excessive signals in Amibroker

Very often, when you write a code for trading signals, you get multiple signals. What you are interested is in the first signal and you would like to ignore the subsequent ones.

This AFL will help you achieve this.


May 30, 2014

Question: how to get buy/ sell signals in Amibroker

I use Ami. Suppose I install mechanical trading system or good indicator ( like Supertrend ) based trading system in Ami to trade these stock, can I get notification of buy/ sell signal of these stocks in separate window in Ami. To see buy/sell signals in Ami. we have to select stock from drop-down list to see the signals.It will be very difficult to check the signals every time from the large list of stocks if we use hourly or two hourly TF. 

Is there any AFL for getting notification of the signals in separate window.


Dr.Suhas Kothavale.

May 21, 2014

AFL for ATR based SL

Some time ago, I posted an AFL for a simple trailing stoploss.

Today I will write about ATR based stoplosses and how it differs from other stoplosses.

May 15, 2014

Simple AFL for trailing stoploss

Here is a simple AFL which plots the trailing SL for any stock.

Default SL is 5% though I recommend setting 10% for delivery trades.


I have not kept any code for SL for a short trade... this is left as an exercise for the end user.

Share this...