NexusFi: Find Your Edge


Home Menu

 





Moving average with Lag reduction


Discussion in NinjaTrader

Updated
    1. trending_up 2,267 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 1 attachments




 
Search this Thread

Moving average with Lag reduction

  #1 (permalink)
 seveera 
Pune + India
 
Experience: None
Platform: new
Trading: new
Posts: 1 since Aug 2018
Thanks Given: 0
Thanks Received: 0

Hi All

I came across an indicator in Tradingview. This is based on moving average (ma)

This indicator as lag value calculated based on the MA ; the code is below (please see line:2)

*************************
Line:1 - MA3 = WMA (Close, 100)
Line:2 - MA2lagFilter = exp(20*log(MA3 / MA3[1]))*MA3
Line:3 - MA1 = wma(close,3)

q1=plot(MA3, "MOV AVG PLOT", color= MA3>MA3[1]?lime:red, transp=1, linewidth=3 )
q2=plot(filter?MA2lagFilter:na, "LAG FILTER", color= black, transp=1, linewidth=2 )
q3=plot(MA1, "3 PERIOD WMA", color= black, transp=50, linewidth=1 )
*************************

When I try to write a similar code in AFL, it doesn't give the same output as Tradingview. (please note i'm not a coder)

Looking for help or guidance, not sure where I'm going wrong.

can someone please write this code for ninjatrader-7

Have attached an image of the indicator from Tradingview

Attached Thumbnails
Click image for larger version

Name:	indicator image.png
Views:	371
Size:	72.7 KB
ID:	295173  
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Request for MACD with option to use different MAs for fa …
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
56 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
What percentage per day is possible? [Poll]
31 thanks
GFIs1 1 DAX trade per day journal
29 thanks

  #2 (permalink)
 Airsoftor 
Ladysmith BC, Canada
 
Experience: Intermediate
Platform: Meta Trader
Trading: Crude Oil
Posts: 34 since Feb 2017
Thanks Given: 16
Thanks Received: 7

Sweeet thats what an MA should look and be like.

Follow me on Twitter Reply With Quote
  #3 (permalink)
Ozquant
Brisbane Queensland Australia
 
Posts: 220 since Aug 2017
Thanks Given: 167
Thanks Received: 380



seveera View Post
Hi All

I came across an indicator in Tradingview. This is based on moving average (ma)

This indicator as lag value calculated based on the MA ; the code is below (please see line:2)

*************************
Line:1 - MA3 = WMA (Close, 100)
Line:2 - MA2lagFilter = exp(20*log(MA3 / MA3[1]))*MA3
Line:3 - MA1 = wma(close,3)

q1=plot(MA3, "MOV AVG PLOT", color= MA3>MA3[1]?lime:red, transp=1, linewidth=3 )
q2=plot(filter?MA2lagFilter:na, "LAG FILTER", color= black, transp=1, linewidth=2 )
q3=plot(MA1, "3 PERIOD WMA", color= black, transp=50, linewidth=1 )
*************************

When I try to write a similar code in AFL, it doesn't give the same output as Tradingview. (please note i'm not a coder)

Looking for help or guidance, not sure where I'm going wrong.

can someone please write this code for ninjatrader-7

Have attached an image of the indicator from Tradingview


Here is the actual correct pinescript code , no-one has any hope of translating that code above with many errors in it

study("CHK TimeSeriesLagReductionFilter[MULTI MA]", overlay=true)

//-----
//Moving Average Types

almaIn = 'ALMA: Arnaud Legoux'
emaIn = 'EMA'
etmaIn = 'ETMA: Triangular (Exponential)'
ssmaIn = 'SSMA Super Smoothed'
hullIn = 'Hull MA'
mgIn = 'McGinley Dynamic'
rmaIn = 'SMMA -/RMA/Wilders: Smoothed'
smaIn = 'SMA'
tmaIn = 'TRIMA: Triangular'
wmaIn = 'WMA'
vwmaIn = 'EVWMA : ElasticVolWMA'


////-----
//General Input

maType = input(wmaIn, "Moving Average Type",
options=[almaIn, ssmaIn ,emaIn, etmaIn, hullIn,
mgIn, vwmaIn, rmaIn, smaIn,tmaIn,wmaIn])


periodd = input(100, "MA Length input", minval=1)
lagReduce = input(20.0, title="Lag Reduction input", minval=1)
filter=input(true, title="Plot Time Series Lag Reduction Filter?")


//-----
//MA & Misc. Input

offAl = 0.85//input(0.85, "ALMA: Offset", step=0.05)
sigmaAl = 6 //FOR ALMA
//alpha = 0.7 //// FOR T3 TILSON
src = close



//-----
//MA Function Declaration

Alma(_src, _len) =>
alma = alma(_src, _len, offAl, sigmaAl)

//// ETMA EXPONENTIAL TRIANGULAR MOV AVG
//// from https://www.tradingview.com/script/UQAv1U0c-MA-Study-Different-Types-and-More-NeoButane/
//// however chnaged ema to wma
eTma(_src, _len) =>
tma = ema(ema(_src, _len), _len)


Hull(_src, _len) =>
hullma = wma(2*wma(_src, _len/2)-wma(_src, _len), round(sqrt(_len)))


Mg(_src, _len) =>
mg = 0.0
mg := na(mg[1]) ? ema(_src, _len) : mg[1] + (_src - mg[1]) / (_len * pow(_src/mg[1], 4))

Tma(_src, _len) =>
tma = sma(sma(_src, _len), _len)


Wild(_src, _len) =>
wild = 0.0
alpha = 1 / _len
wild := alpha * _src + (1.0 - alpha) * nz(wild[1], _src)

// SUPER SMOOTHED MOV AVG////////
//// SSMA SuperSmoother filter © 2013 John F. Ehlers, https://www.tradingview.com/script/3e6VWRq7-Multi-MA-Ribbon/
ssma(_src, _len) =>
if (_len>0)
a1=exp(-1.414*3.14159 / _len)
b1=2*a1*cos(1.414*3.14159 /_len)
c2=b1
c3=(-a1)*a1
c1=1 - c2 - c3
v9=0.0
v9:=c1*(_src + nz(_src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
v9
else
na

// EVWMA ELASTIC VOL WEIGHTED MOV AVG////////
func_evwma(_src, _len) =>
volumeSum = sum(volume, _len)
evwma3 = 0.0
evwma3 := ((volumeSum - volume) * nz(evwma3[1]) + volume * _src) / volumeSum
evwma3


ma(_type, _src, _len) =>
_type == almaIn ? Alma(_src, _len) :
_type == emaIn ? ema(_src, _len) :
_type == ssmaIn ? ssma(_src, _len) :
_type == etmaIn ? eTma(_src, _len) :
_type == mgIn ? Mg(_src, _len) :
_type == rmaIn ? rma(_src, _len) :
_type == smaIn ? sma(_src, _len) :
_type == tmaIn ? Tma(_src, _len) :
_type == vwmaIn ? func_evwma(_src, _len) :
_type == hullIn ? Hull(_src, _len) :
_type == wmaIn ? wma(_src, _len) : na



MA3 = ma(maType, src, periodd)
MA2lagFilter = exp(lagReduce*log(MA3 / MA3[1]))*MA3
MA1 = wma(close,3)


q1=plot(MA3, "MOV AVG PLOT", color= MA3>MA3[1]?lime:red, transp=1, linewidth=3 )
q2=plot(filter?MA2lagFilter:na, "LAG FILTER", color= black, transp=1, linewidth=2 )
q3=plot(MA1, "3 PERIOD WMA", color= black, transp=50, linewidth=1 )

/// LIME #00FF00 // #fd1206 RED

fill(q3, q2, MA1 > MA2lagFilter ? #00FF00 : #fd1206, title="FILL BETWEEN CANDLE AND LAG", transp=10)
fill(q2, q1, MA3 > MA2lagFilter ?#fd1206 : #00FF00, title="FILL BETWEEN LAG AND MOV AVG", transp=70)

Reply With Quote





Last Updated on June 16, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts