Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

HAMAVeroot Indicator Transfer from TD Ameri to NT8 HELP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HAMAVeroot Indicator Transfer from TD Ameri to NT8 HELP

    Click image for larger version  Name:	Screenshot 2023-06-24 at 2.51.33 PM.png Views:	0 Size:	1.13 MB ID:	1257439Hello all,
    I have a rather interesting indicator that I use to spot swing trades on TD Ameritrade and would like to have it transferred over to NT8 for visual use and also have it usable in a backtesting strategy for the system if possible. Attached is a picture of what it looks like and the code for it. I like to buy once the price closes above the blue line and create a stop once the price closes back below the blue line in up trends (vice versa for the purple line at the bottom for shorts). I also like to have the ability to just trade once the color of the current bar changes to either green/red and trade in that given direction, put a stop at the high/low from the previous bar before the color change, or simply exit the trade once the current bar turns grey again. I don't have much coding experience to transfer it over but does anyone else know where to start? Thanks.

    plot Data = close;
    #// © wallneradam
    #indicator("Heiken Ashi Swing High/Low with Smoothed HA"
    # Created and mod by Sam4@Samer800 based on @wallneradam code - 11/2022
    # Updated - Added differnt candleType and style - Sam4@Samer800 11/2022
    input showPricePlot = yes;
    input ColorBars = no;
    input useChartTime = yes;
    input Aggregation = AggregationPeriod.FIFTEEN_MIN;
    input ShowBand = yes;
    input HeikenAshiStyle = {Default "Don't Show", "Candle", "Parabolic"};
    input ParabolicPercent = 0.2; # Parabolic Squeeze Percent
    input candleCalcType = {Default "Default", "Valcu", "Vervoort"};
    input SourceCalcMethod = {Default "High/Low", "Candle Close"};
    input ShowWick = yes;
    input PaintHaCandle = no;
    input smoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
    input MaSmoothLength = 1;
    input smoothLength = 10; # "Smooth Length"
    input afterSmoothMaType = {default EMA, SMA, WMA, TEMA, LSMA, VWMA, HMA, ALMA};
    input afterSmoothLength = 10;#

    hidePricePlot(!showPricePlot);
    def na = Double.NaN;
    def HeikStyle = if HeikenAshiStyle==HeikenAshiStyle."Candle" then 2 else
    if HeikenAshiStyle==HeikenAshiStyle."Parabolic" then 1 else 0;
    #def chartTime = GetAggregationPeriod();
    def mtfc = if(useChartTime,close,close(Period=Aggregation));
    def mtfh = if(useChartTime,high,high(Period=Aggregation));
    def mtfl = if(useChartTime,low,low(Period=Aggregation));
    def mtfo = if(useChartTime,open,open(Period=Aggregation));
    #// ] -------------- FUNCTIONS : Moving Avg ------------------ [
    export tema(float src, simple int len)=>
    script tema {
    input src = close;
    input len = 14;
    def ema1 = ExpAverage(src, len);
    def ema2 = ExpAverage(ema1, len);
    def ema3 = ExpAverage(ema2, len);
    def tema = 3 * (ema1 - ema2) + ema3;
    plot return = tema;
    }
    #vwma(source, length)
    script VWMA {
    input x = close;
    input y = 15;
    def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    Plot result = VWMA;
    }
    script ALMA {
    input Data = close;
    input Window = 9;
    input Sigma = 6;
    input Offset = 0.85;
    def m = (Offset * (Window - 1));
    def s = Window/Sigma;
    def SumVectorData = fold y = 0 to Window with WS do
    WS + Exp(-(sqr(y-m))/(2*sqr(s))) * getvalue(Data, (Window-1)-y);
    def SumVector = fold z = 0 to Window with CW do
    CW + Exp(-(sqr(z-m))/(2*sqr(s)));
    plot ALMA = SumVectorData / SumVector;
    }
    export multiMa(float source, simple int length, string type) =>
    script anyma {
    input source = close;
    input length = 14;
    input type = "SMA";
    def multiMa =
    if type == "SMA" then SimpleMovingAvg(source, length) else
    if type == "EMA" then ExpAverage(source, length) else
    if type == "SMMA" then WildersAverage(source, length) else
    if type == "WMA" then WMA(source, length) else
    if type == "TEMA" then TEMA(source, length) else
    if type == "LSMA" then Inertia(source, length) else
    if type == "ALMA" then ALMA(source, length) else
    if type == "VWMA" then VWMA(source, length) else
    if type == "HMA" then HullMovingAvg(source, length ) else Double.NaN;
    plot return = multiMa;
    }
    #heiken_ashi(simple int smooth_length = 1, simple string smooth_ma_type = "EMA",
    script heiken_ashi {
    input src_open = open;
    input src_close = close;
    input src_high = high;
    input src_low = low;
    input after_smooth_length = 10;
    input after_smooth_ma_type = yes;
    input wick = yes;
    def haopen = src_open;
    def haclose= src_close;
    def hahigh = src_high;
    def halow = src_low;
    def hiWick = if(wick,hahigh,haclose);
    def loWick = if(wick,halow,haopen);
    def SmoothO = anyma(haopen, after_smooth_length, after_smooth_ma_type);
    def SmoothH = anyma(hiWick, after_smooth_length, after_smooth_ma_type);
    def SmoothL = anyma(loWick, after_smooth_length, after_smooth_ma_type);
    def SmoothC = anyma(haclose,after_smooth_length, after_smooth_ma_type);
    def dir = SmoothO>SmoothC;
    plot OpenHA = SmoothO;
    plot HighHA = if(!dir,SmoothH,if(wick,SmoothH,SmoothO));
    plot LowHA = if(dir,SmoothL,if(wick,SmoothL,SmoothO));
    plot CloseHA = SmoothC;
    }
    def haopen; def haclose; def hahigh; def halow;
    def mao = anyma(mtfo, MaSmoothLength, smoothMaType);
    def mah = anyma(mtfh, MaSmoothLength, smoothMaType);
    def mal = anyma(mtfl, MaSmoothLength, smoothMaType);
    def mac = anyma(mtfc, MaSmoothLength, smoothMaType);
    switch(candleCalcType) {
    case "Default":
    haclose = (mao + mah + mal + mac) / 4.0;
    haopen = CompoundValue(1, (haOpen[1] + haClose[1]) / 2, haClose);
    hahigh = Max(mah,Max(haopen, haclose));
    halow = Min(mal,Min(haopen, haclose));
    case "Valcu":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = (mao + mah + mal + mac)/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow = Min(mal,Min(haopen, haclose));
    case "Vervoort":
    haOpen = CompoundValue(1, ((haOpen[1] + (mao + mah + mal + mac)/4.0)/2.0), mao);
    haClose = ((mao + mah + mal + mac)/4.0 + haOpen + Max(mah, haOpen) + Min(mal, haOpen))/4.0;
    hahigh = Max(mah,Max(haopen, haclose));
    halow = Min(mal,Min(haopen, haclose));
    }
    def o = haOpen;
    def h = hahigh;
    def l = halow;
    def c = haClose;

    def upper;
    def lower;

    if c[1] > o[1] and c < o {
    upper = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfh[1], c[1]);
    lower = lower[1];
    } else {
    if c[1] < o[1] and c > o {
    upper = upper[1];
    lower = if(SourceCalcMethod==SourceCalcMethod."High/Low", mtfl[1], o[1]);
    } else {
    upper = upper[1];
    lower = lower[1];
    }}

    plot UpBand = if !ShowBand or isNaN(mtfc) then na else upper; # "Upper"
    plot LoBand = if !ShowBand or isNaN(mtfc) then na else lower; # "Lower"
    UpBand.SetDefaultColor(Color.CYAN);
    LoBand.SetDefaultColor(Color.MAGENTA);

    #--- Smoothed
    # Plot the new Chart
    def smO = anyma(o, smoothLength, smoothMaType);;
    def smH = anyma(h, smoothLength, smoothMaType);;
    def smL = anyma(l, smoothLength, smoothMaType);;
    def smC = anyma(c, smoothLength, smoothMaType);;

    def HAo = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afte rSmoothMaType,ShowWick).OpenHA;
    def HAh = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afte rSmoothMaType,ShowWick).HighHA;
    def HAl = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afte rSmoothMaType,ShowWick).LowHA;
    def HAc = heiken_ashi(smO,smC,smH,smL,afterSmoothLength,afte rSmoothMaType,ShowWick).CloseHA;

    def dir = HAo>HAc;
    AddChart(high = if HeikStyle==2 and !dir then HAh else na , low = HAl ,
    open = if(PaintHaCandle,HAc,HAo), close = if(PaintHaCandle,HAo,HAc),
    type = ChartType.CANDLE, growcolor = CreateColor(4,127,145));

    AddChart(high = if HeikStyle==2 and dir then HAh else na , low = HAl ,
    open = if(PaintHaCandle,HAo,HAc), close = if(PaintHaCandle,HAc,HAo),
    type = ChartType.CANDLE, growcolor = CreateColor(123,3,143));

    #--- Par Calc

    def percentHL = ((HAo - HAc) / ((HAo + HAc)/2)) * 100;

    def high_squeeze= AbsValue(percentHL) < ParabolicPercent and percentHL>0;
    def low_squeeze = AbsValue(percentHL) < ParabolicPercent and percentHL<0;

    def crossPlot;
    if dir {
    crossPlot = HAh;
    } else {
    crossPlot = HAl; }
    def o2_cross_under_long = crosses(HAo,HAc, CrossingDirection.BELOW);
    def c2_cross_over_short = crosses(HAo,HAc, CrossingDirection.ABOVE);

    def plotColor = if high_squeeze then -1 else
    if low_squeeze then 1 else
    if !dir then 2 else -2;

    plot haLine = if(HeikStyle!=1, na, crossPlot);#, color = plotColor, style = plot.style_cross, linewidth = 2)
    haLine.SetStyle(Curve.POINTS);
    haLine.AssignValueColor(if plotColor==-1 then Color.DARK_RED else
    if plotColor==1 then Color.DARK_GREEN else
    if plotColor==2 then Color.GREEN else Color.RED);

    #---- Bar Color---
    AssignPriceColor(if !ColorBars or HeikStyle==1 then Color.CURRENT else
    if mtfc>HAh and !dir then color.GREEN else
    if mtfc>HAh and dir then color.DARK_GREEN else
    if mtfc<HAl and dir then Color.RED else
    if mtfc<HAl and !dir then Color.DARK_RED else Color.GRAY);

    AssignPriceColor(if !ColorBars or HeikStyle!=1 then Color.CURRENT else
    if plotColor==2 then Color.GREEN else
    if plotColor==1 then Color.Dark_GREEN else
    if plotColor==-1 then Color.DARK_RED else Color.RED);

    #---END CODE​
    Last edited by chasep7328; 06-24-2023, 02:19 PM.

    #2
    Hello chasep7328,

    Thanks for your post.

    The C# programming language is used for developing NinjaScript indicators and strategies.

    To create a NinjaScript indicator, open a New > NinjaScript Editor window, select the '+' tab at the bottom of the Editor window, select 'New Indicator'. Then, you could set up as much of the indicator as possible in the Indicator Builder. This will create the framework of the indicator or strategy

    Once you finish setting up as much as possible in the Indicator Builder, you must manually program the rest of the indicator.

    When first starting to convert scripts, you should open the TD Ameritrade developer help guide and the NinjaTrader 8 help guide so that you could compare methods and properties between the two platforms. The majority of code supported by NinjaTrader is included in the help guides.

    Below is a link to a forum post with helpful information about getting started with NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040

    Here is a link to our publicly available training video, 'NinjaScript Editor 401', for you to view at your own convenience.

    NinjaScript Editor 401 - https://youtu.be/H7aDpWoWUQs?list=PL...We0Nf&index=14

    I am also linking you to the Educational Resources section of the Help Guide to help you get started with NinjaScript:
    https://ninjatrader.com/support/help..._resources.htm

    If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our help guide first:
    https://ninjatrader.com/support/help...g_concepts.htm

    And the MSDN (Microsft Developers Network) C# Language Reference.
    https://ninjatrader.com/support/help...erence_wip.htm

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. To find a list of affiliate consultants who would be happy to create this script or any others at your request, please see the link below.

    NinjaTrader Ecosystem: ​https://ninjatraderecosystem.com/search-results/?



    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X