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.
- Separate-Entry-Exit.afl
- Buy-Sell-Double
- Intraday
- Options
- Options Auto Strike Selection
- PlotAll-Signals.afl
- 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:
- Instrument Name: Select the instrument name for the market segment you want to trade
- 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
- Strategy Tag: You can use any strategy tag to manage signals coming from mutiple strategies in Amibroker. Eg. STG1, STG2, STG3 etc.
- Disable Long: If you want to disable all Long signals (use only Short side for trading), then turn this Yes
- 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:
- Instrument Name: Select the instrument name for the market segment you want to trade
- 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
- Strategy Tag: You can use any strategy tag to manage signals coming from mutiple strategies in Amibroker. Eg. STG1, STG2, STG3 etc.
- Disable Long: If you want to disable all Long signals (use only Short side for trading), then turn this Yes
- Disable Short: If you want to disable all Short signals (use only Long side for trading), then turn this Yes
- Initial qty- quantity you want to trade . it will get double after the 1st trade signal
- Previous Session Position- If yes it will double the quantity from 1st trade signal else it will double from second trade signal
- Reset – reset the trading quantity to initial quantity
Intraday
Click here to download this AFL
This is advanced template useful for intraday trading.
Parameters:
- 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.
- Trade Entry From(HHMM): Time when you want to start trading, example 930.
- (HHMM) Trade Entry Upto: Time upto which you want to take fresh trades, example 1430 (for 2:30pm).
- Trade Exit(HHMM): Time at which you want to exit all open positions, example 1515.
- StopLoss(%): Stoploss in percentage from Buy/Short signals.
- Trail Stop(%): Trail Stop in percentage from Buy/Short signals.
- Target(%): Target in percentage from Buy/Short signals.
- 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.
- 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.
- 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.
- You can use it on any chart of cash/future to trade in options based on signals generated in the chart.
- If Buy signal generated, it will Buy Call and exit Long position in Put.
- If Sell signal generated, it will Buy Put and exit Long position in Call.
Parameters:
- Base symbol- symbol of derivative you want to trade in.
- Expiry- Expiry of that Put/Call.
- Put Strike – strike for selecting Put for trading.
- Call strike- strike for selecting Cut for trading.
- Instrument Name: should be OPTIDX or OPTSTK.
- 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.
- 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.
- Add all strikes in which you may trade in Symbol Settings. See here how to import option symbols.
- You can use this AFL on any chart of cash/future to trade in options based on signals generated in the chart.
- If Buy signal generated, it will Buy Call and exit Long position in Put.
- If Sell signal generated, it will Buy Put and exit Long position in Call.
- 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:
- Base symbol- symbol of derivative you want to trade in.
- Expiry- Expiry of that Put/Call.
- Strike Dist: To trade in ATM, input Strike Dist 0; to trade in 100 point OTM, input Strike Dist 100… and so on.
- Instrument Name: should be OPTIDX or OPTSTK.
- 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.
- 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
sir we i want trade with amibroker plat form with using API bridge for algo trading with simultaneous with 40 stock with my own custom algo strategy.
any really i dont now about how to integrate api bridge with ami broker .
Hi in Buttons or any afl I want to See P/L, Buy Price, LTP on Amibroker chart itself . How to do that.
sir, how to send co orders to api bridge?, if any configuration is needed for co order?, it will be great if u provide a sample afl for placing co order