Bridge code will work good as long as your AFL code generates valid and error free signals.
Most of the AFLs downloaded from the internet will not work in real time, it may show Buy/Sell arrows on static chart and even generate signals in backtest.
The 4 evil issues with the improperly coded AFL
- Signal Repainting
- Not declaring all signal variables BUY/SELL/SHORT/COVER
- Using Functions which uses Future Bars
- Entry and Exit signals at same Bar
Below check points may help you to fire orders in real-time from your AFL.
- Your AFL should have declared all 4 signal variables – ‘BUY/SELL/SHORT/COVER’
- Variables ‘BUYPRICE/SELLPRICE/SHORTPRICE/COVERPRICE’ should have assigned correct values. (Assigning wrong price value will give wrong back-test results)
- Make sure ‘BUY/SELL/SHORT/COVER’ signal comes at the last bar (If no signal at last bar, then the condition If (LastValue(Buy)) will fail, hence no order firing)
- Exrem is used to remove excess signals
- Ensure Signal does not repaint (If your signal logic uses ‘Close’ price array, then it will repaint. Most of the AFL codes available in the internet uses ‘Close’)
- Signal logic does not uses future bars. If used it will generate false signals (Some alleged developers uses this to cheat people, using future bars will give huge profit in back test, but in reality, you will never get signal in real-time)
- No entry and exit signal at the same bar(very critical issue, Your Sell logic should also include Buy==0 condition, and Cover logic include Short==0 condition to avoid entry and exit signal at same bar)
- Each Entry signal has corresponding Exit signal
- Open signals are properly closed at Square off (in case of Intra-day systems)
- Exit signal is not generated first. (Use conditional Exrem to remove invalid Sell/Cover signals)
Every order fired from AFL through Bridge code is logged in the below files. Replace [DDMMMYYYY] with respective date.
This log files will help you to troubleshoot your order firing issues.
Log Folder:
C:\Users\Public\Documents\Data\AmiTools
Log Files:
BRACKET_ORDER_REQUESTS_UPSTOX_[DDMMMYYYY].txt
COVER_ORDER_REQUESTS_UPSTOX_[DDMMMYYYY].txt
SIMPLE_ORDER_REQUESTS_UPSTOX_[DDMMMYYYY].txt
BRACKET_ORDER_REQUESTS_UPSTOX_[DDMMMYYYY].txt
COVER_ORDER_REQUESTS_UPSTOX_[DDMMMYYYY].txt
REGULAR_ORDER_REQUESTS_ZERODHA_[DDMMMYYYY].txt