Select Page

Here is a quick 5-minute tutorial to understand how you can modify AFL, and how real-time trading works with AFL. Scroll down for all required AFLs which are shown in video.

  1. Separate-Entry-Exit.afl
  2. Buy-Sell-Double
  3. Intraday
  4. Options
  5. Options Auto Strike Selection
  6. PlotAll-Signals.afl
  7. Buttons with full functionality for Developers

Download a basic supertrend strategy from here. Apply it on a chart.

Download any AFL from toolkit below. Open it in notepad. Press Ctrl+A and Ctr+C to copy this.

Right click on chart, then click Edit Code. Go to bottom of code. Press Ctrl+V to paste it here.

Apply on chart to see changes

Play around with AFL parameters to see how they change the buy/sell arrows on chart!

Separate-Entry-Exit.afl

This is basic AFL useful for automation. Click here to download this AFL.

Parameters:

  1. Instrument Name: Select the instrument name for the market segment you want to trade
  2. Trade Intrabar: If you want to trade immediately when signal appears, select Yes. If you want to wait for signal confirmation until completion of candle, select Candle Completion
  3. Strategy Tag: You can use any strategy tag to manage signals coming from mutiple strategies in Amibroker. Eg. STG1, STG2, STG3 etc.
  4. Disable Long: If you want to disable all Long signals (use only Short side for trading), then turn this Yes
  5. Disable Short: If you want to disable all Short signals (use only Long side for trading), then turn this Yes

Buy-Sell-Double

Click here to download this AFL

This is a simple and powerful auto trading template for strategies where you want to trade DOUBLE quantity on reverse signal. It should be used only for strategies where buy= cover and sell= short.

Parameters:

  1. Instrument Name: Select the instrument name for the market segment you want to trade
  2. Trade Intrabar: If you want to trade immediately when signal appears, select Yes. If you want to wait for signal confirmation until completion of candle, select Candle Completion
  3. Strategy Tag: You can use any strategy tag to manage signals coming from mutiple strategies in Amibroker. Eg. STG1, STG2, STG3 etc.
  4. Disable Long: If you want to disable all Long signals (use only Short side for trading), then turn this Yes
  5. Disable Short: If you want to disable all Short signals (use only Long side for trading), then turn this Yes
  6. Initial qty-  quantity you want to trade . it will get double after the 1st trade signal
  7. Previous Session Position- If yes it will double the quantity from 1st  trade signal else it will double from second trade signal
  8. Reset – reset the trading quantity to initial quantity

Intraday

Click here to download this AFL

This is advanced template useful for intraday trading.

Parameters:

  1. Activate Intrade Mode? If turned yes, it makes even a positional trading or indicator based strategy for intraday trading only. To apply the intraday timings rule, you should turn this on.
  2. Trade Entry From(HHMM): Time when you want to start trading, example 930.
  3. (HHMM) Trade Entry Upto: Time upto which you want to take fresh trades, example 1430 (for 2:30pm).
  4. Trade Exit(HHMM): Time at which you want to exit all open positions, example 1515.
  5. StopLoss(%): Stoploss in percentage from Buy/Short signals.
  6. Trail Stop(%): Trail Stop in percentage from Buy/Short signals.
  7. Target(%): Target in percentage from Buy/Short signals.
  8. Color of Modified Signals: This AFL displays on chart both original signals and modified signals, you can set colors. The stoploss, trail stop and target lines are also drawn on chart with same color.
  9. Exposure  and Quantity both parameters are available. If exposure is 0, it will take the defined Quantity. Exposure example: If you want to buy/sell each stock with Rs. 100,000, you can se the exposure =100000 and run the AFL on multiple stocks. It will automatically trade 1000 share for a 100 rs. stock, and 250 shares of a 400 rs. stock.
  10. Qty Using SL: If this is given non-zero value, it calculates quantity based on SL as defined in percentage. It will ignore Quantity given in parameter or Quantity calculated from Exposure.

Options

Click here to download this AFL

This is a basic template used for trading in options.

  1. You can use it on any chart of cash/future to trade in options based on signals generated in the chart.
  2. If Buy signal generated, it will Buy Call and exit Long position in Put.
  3. If Sell signal generated, it will Buy Put and exit Long position in Call.

Parameters:

  1. Base symbol- symbol of derivative you want to trade in.
  2. Expiry- Expiry of that Put/Call.
  3. Put Strike – strike for selecting Put for trading.
  4. Call strike- strike for selecting Cut for trading.
  5. Instrument Name: should be OPTIDX or OPTSTK.
  6. Trade Intrabar: If you want to trade immediately when signal appears, select Yes. If you want to wait for signal confirmation until completion of candle, select Candle Completion.
  7. Quantity- Total quantity in which you want to trade. For example, in Nifty 1 lot use 75, Nifty 2 lot use 150…

Options Auto Strike Selection

Click here to download this AFL

Very often, you may like to trade in the option strike base on underlying price. For example, you want to trade in 200 points OTM.

  1. Add all strikes in which you may trade in Symbol Settings. See here how to import option symbols.
  2. You can use this AFL on any chart of cash/future to trade in options based on signals generated in the chart.
  3. If Buy signal generated, it will Buy Call and exit Long position in Put.
  4. If Sell signal generated, it will Buy Put and exit Long position in Call.
  5. This AFL works with only NIFTY and BANKNIFTY which have options at 100 strike differences. It will roundoff the the underlying price to nearest 100, then generate signals in the strike based on “Strike Distance”

Parameters:

  1. Base symbol- symbol of derivative you want to trade in.
  2. Expiry- Expiry of that Put/Call.
  3. Strike Dist: To trade in ATM, input Strike Dist 0; to trade in 100 point OTM, input Strike Dist 100… and so on.
  4. Instrument Name: should be OPTIDX or OPTSTK.
  5. Trade Intrabar: If you want to trade immediately when signal appears, select Yes. If you want to wait for signal confirmation until completion of candle, select Candle Completion.
  6. Quantity- Total quantity in which you want to trade. For example, in Nifty 1 lot use 75, Nifty 2 lot use 150…

You can also refer the old webinar video given below, which is relevant for auto strike selection

PlotAll-Signals.afl

90% of AFLs found over internet have repainting/fake signals. Sometimes you may find an Order placed but no signal in Amibroker Chart. This can happen only if AFL has fake signals. The actual signals triggered by AFL may be different then the signals plot on chart. To check signals, use the AFL plotALLsignals.afl with bar-replay.

Click here to download the PlotAll-Signals.afl

Buttons with full functionality for Developers

The Button AFL for Developers allow to use APIBridge with full power. You can send all important values in parameter like strike, expiry for OPTIDX. You can also send custom Stoploss, SquareOff and Trail for Bracket Orders.

How to Use: Provide complete symbol settings for chart symbol on which you apply the AFL. Next, start testing the buttons each time by filling one parameter value at a time. You can also play at the same time with symbol settings. For example, leave Qty blank in Symbol Settings, and change Qty in AFL parameters do dynamically send Qty from Amibroker.

IMPORTANT: Different brokers have different rules for BO/CO. Example, your broker may allow only Limit order in BO, not StopLimit. Or your broker may reject BO if Trail is not provided. To verify these functionalities, you should try placing manual BO/CO order and consult your broker’s API document.

Port: If you change the port in AFL, you also need to change it in APIBridge under Application Settings -> Signal Settings

Click here to download the Buttons AFL for Developers

How can I modify AFL strategy without any coding?