Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

ADXVMA – Indicator – Amibroker AFL Code

1 min read

ADXVMA is a volatility moving average using ADX as a core concept to identify trends. The trend filter acts as support during uptrending markets (color green) and resistance during downtrending markets(color red). The indicator also plots the neutral zone (color yellow) which can be used to identify sideways/volatile markets.

Above is a 3min charts of Nifty Futures

Here is the Amibroker AFL Code for ADXVMA Indicator

Masterclass on AmiBroker AFL coding

AMIBROKER

Masterclass on AmiBroker AFL coding

Write trading systems, explorations and backtests in AFL, and use ChatGPT to code faster.

  • AFL from basics to trading systems
  • Backtesting and optimisation done right
  • 7 courses in one masterclass
Learn AFL coding →by Marketcalls
//Coded by Rajandran R
//Founder of www.marketcalls.in
//Coded on 20th Sep 2023


_SECTION_BEGIN("ADXVMA Indicator");



adxvma_period = param("ADXVMA Period",15,1,100,1);
atr_period = Param("ATR Period",200,1,300,1);


ups = 0.0;
downs = 0.0;
index = 0.0;
adxvma = 0.0;
trend = 0;
up = 0.0;
down = 0.0;

k = 1.0 / adxvma_period;

volatility = atr(atr_period);

currentUp = Max((Close - Ref(Close,-1)),0);
currentDown = Max((Ref(Close,-1) - Close),0);

for(i=1;i<BarCount;i++)
{
up[i] = (1 - k) * nz(up[i-1]) + (k * currentUp[i]);
down[i] = (1 - k) * nz(down[i-1]) + (k * currentDown[i]);
}


//Plot(up,"up",colorGreen,styleLine|styleThick);
//Plot(down,"down",colorRed,styleLine|styleThick);

isum = up + down;

fractionUp = 0.0;
fractionDown = 0.0;

fractionUp = IIf(iSum>0,up/iSum,0);
fractionDown = IIf(iSum>0,down/iSum,0);

for(i=1;i<BarCount;i++)
{
ups[i] = (1 - k) * nz(ups[i-1]) + (k * fractionUp[i]);
downs[i] = (1 - k) * nz(downs[i-1]) + (k * fractionDown[i]);
}

normDiff = abs(ups - downs);
normSum = ups + downs;

normFraction = IIf(normSum > 0.0, normDiff / normSum, 0);


for(i=1;i<BarCount;i++)
{
index[i]= (1 - k) * Nz(index[i-1]) + (k * normFraction[i]);
ups[i]= (1 - k) * Nz(ups[i-1]) + (k * fractionUp[i]);
downs[i] = (1 - k) * Nz(downs[i-1]) + (k * fractionDown[i]);
}

epsilon = 0.1 * Nz(Ref(volatility,-1));
hhp = Ref(hhv(index, adxvma_period),-1);
llp = Ref(llv(index, adxvma_period),-1);

ihhv = max(index, hhp);
illv = min(index, llp);

vIndex = 0.0;

vIndex = IIf((ihhv - illv) > 0.0, (index - illv) / (ihhv - illv), 0);
adxvma = 0;

for(i=1;i<BarCount;i++)
{
adxvma[i] = (1 - k * vIndex[i]) * Nz(adxvma[i-1]) + (k * vIndex[i] * close[i]);
}




color = IIf(adxvma>Ref(adxvma,-1),colorGreen,IIf(adxvma<Ref(adxvma,-1),colorRed,colorYellow));


Plot(adxvma,"ADXVMA",color,styleThick);

Plot( C, "Price", ParamColor( "Color", colorDefault ), ParamStyle( "Style", styleCandle, maskPrice ) );



_SECTION_END();
Marketcalls Elite Traders Club

MEMBERSHIP

Marketcalls Elite Traders Club

Every Marketcalls course and live mentorship in one membership: 127 courses and 2,500+ hours of learning.

  • Market Profile, Orderflow, AFL, Pine Script and Python
  • Live mentorship and TradEdge trading room
  • Premium tools and the Elite Slack community

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

3 Replies to “ADXVMA – Indicator – Amibroker AFL Code”

  1. Hi Sir,

    very interesting stuff, thanks a lot for sharing.
    One question:
    the PARAM : ATR Period is just used to calculate “epsilon” , but epsilon is not used in the afl-code.

    What’s the purpose of “epsilon”, where might it be used?

    Kind Regards
    Alex

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More