Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

KAMA and HULL MA - is anybody able to covert to NINJA script?

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

    KAMA and HULL MA - is anybody able to covert to NINJA script?

    /************************************************** *******************
    Title:Kaufman Adaptive Moving Average for eSignal 7.x
    By: Chris D. Kryza (Divergence Software, Inc.)
    Email: [email protected], [email protected]
    Web:http://www.sr-analyst.com/eSignal.htm
    Incept: 02/18/2004
    Version: 1.0.0


    ================================================== ===================
    Fix History:

    02/18/2004 - Initial Release
    1.0.0

    ================================================== ===================
    Project Description:

    Kaufman Adaptive Moving Average.

    Dislaimer: For educational purposes only! Obviously, no guarantees
    whatsoever and use at your own risk.

    ************************************************** ********************/


    //Global Variables
    var grID = 0;
    var nBarCounter= 0;
    var nPeriod= 0;
    var nFast= 0;
    var nSlow= 0;
    var aAMA= null;
    var aFPArray= new Array();
    var bInitialized= false;


    //== PreMain function required by eSignal to set things up
    function preMain() {
    var x;

    setPriceStudy(true);
    setStudyTitle("KAMA");
    setCursorLabelName("KAMA", 0);
    setDefaultBarFgColor( Color.blue, 0 );
    setShowTitleParameters( false );
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.black);




    //unrem this if you don't want the labels in cursor window
    //setShowCursorLabel(false);

    //unrem this if you don't want the study to update on every tick
    //setComputeOnClose();
    grID = 0;

    //initialize formula parameters
    x=0;
    aFPArray[x] = new FunctionParameter( "Period", FunctionParameter.NUMBER);
    with( aFPArray[x] ) {
    setName( "KAMA Period" );
    setLowerLimit( 5 );
    setUpperLimit( 125 );
    setDefault( 10 );
    }
    x++;
    aFPArray[x] = new FunctionParameter( "xFast", FunctionParameter.NUMBER);
    with( aFPArray[x] ) {
    setName( "Fast Len" );
    setLowerLimit( 1 );
    setUpperLimit( 125 );
    setDefault( 2 );
    }
    x++;
    aFPArray[x] = new FunctionParameter( "xSlow", FunctionParameter.NUMBER);
    with( aFPArray[x] ) {
    setName( "Slow Len" );
    setLowerLimit( 1 );
    setUpperLimit( 125 );
    setDefault( 30 );
    }
    x++;
    aFPArray[x] = new FunctionParameter( "lColor", FunctionParameter.COLOR);
    with( aFPArray[x] ) {
    setName( "Line Color" );
    setDefault( Color.teal );
    }

    x++;
    aFPArray[x] = new FunctionParameter( "lThick", FunctionParameter.NUMBER);
    with( aFPArray[x] ) {
    setName( "Line Thickness" );
    setLowerLimit( 1 );
    setUpperLimit( 10 );
    setDefault( 2 );
    }



    }

    //== Main processing function
    function main( Period, xFast, xSlow, lColor, lThick ) {
    var x;
    var nNoise;
    var nSignal;
    var nSmooth;

    //script is initializing
    if ( getBarState() == BARSTATE_ALLBARS ) {
    return null;
    }

    if ( bInitialized == false ) {

    setDefaultBarFgColor( lColor, 0 );
    setDefaultBarThickness( lThick, 0 );

    nPeriod = Math.round( Period );

    nFast = 2 / ( xFast + 1 );
    nSlow = 2 / ( xSlow + 1 );

    setStudyTitle( "KAMA (" + nPeriod + ")" );

    aAMA = new Array( nPeriod );
    for ( x=0; x<nPeriod; x++ ) {
    aAMA[x] = 0.0;
    }

    bInitialized = true;
    }

    //called on each new bar
    if ( getBarState() == BARSTATE_NEWBAR ) {

    aAMA.pop();
    aAMA.unshift(0);

    nBarCounter++;

    }

    if ( nBarCounter<nPeriod+1 ) {
    aAMA[0] = close();
    return;
    }


    nSignal = Math.abs( close() - close(-Period) );

    x=0;
    nNoise = 0;
    while( x<nPeriod ) {
    nNoise += Math.abs( close(-x)-close(-(x+1)) );
    x++;
    }

    if ( nNoise==0 ) nNoise = 1.0;

    nSmooth = Math.pow( ( nSignal/nNoise ) * ( nFast - nSlow ) + nSlow , 2 );

    aAMA[0] = aAMA[1] + nSmooth * ( close() - aAMA[1] );

    if ( aAMA[0]>aAMA[1] ) {
    setBarFgColor( Color.green, 0 );
    }
    else {
    setBarFgColor( Color.red, 0 );
    }

    if(close()>aAMA[0]){
    setPriceBarColor(Color.RGB (144, 238, 144),Color.RGB (144, 238, 144),true,false)
    }
    if(close()<aAMA[0]){
    setPriceBarColor(Color.red,Color.red,true,false)
    }



    return( aAMA[0] );

    }


    /*************************************************
    SUPPORT FUNCTIONS
    **************************************************/

    //== gID function assigns unique identifier to graphic/text routines
    function gID() {
    grID ++;
    return( grID );
    }



    HULL MA INDICATOR:





    function preMain() {

    setPriceStudy(true);
    setStudyTitle("Hull MA");
    setCursorLabelName("HMA", 0);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarFgColor(Color.green, 0);
    setDefaultBarThickness(1, 0);
    setPlotType(PLOTTYPE_LINE, 0);
    setColorPriceBars(true)
    setDefaultPriceBarColor(Color.black);

    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(10);

    var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
    fp2.setDefault(0);

    var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp3.addOption("Close");
    fp3.addOption("High");
    fp3.addOption("Low");
    fp3.addOption("Open");
    fp3.addOption("HL/2");
    fp3.addOption("HLC/3");
    fp3.addOption("OHLC/4");
    fp3.setDefault("Close");
    }

    var vMA1 = null;
    var vMA2 = null;
    var vValue = 0.0;
    var aValue = null;
    var HMA = null;

    function main(Length,Offset,Source) {

    var Length2 = Length/2;
    var LengthSqrt = Math.round(Math.sqrt(Length));
    var vSum = 0.0;
    var cSum = 0.0;

    if (vMA1 == null) vMA1 = new MAStudy(Length2, Offset, Source, MAStudy.WEIGHTED);
    if (vMA2 == null) vMA2 = new MAStudy(Length, Offset, Source, MAStudy.WEIGHTED);

    var vAvg1 = vMA1.getValue(MAStudy.MA);
    var vAvg2 = vMA2.getValue(MAStudy.MA);

    if(vAvg1 == null || vAvg2 == null)
    return;

    if (aValue == null) aValue = new Array(Length);

    if (getBarState() == BARSTATE_NEWBAR) {
    aValue.pop();
    aValue.unshift(vValue);
    }

    vValue = (2*vAvg1)-vAvg2;

    if(vValue == null) return;

    aValue[0] = vValue;

    if(aValue[LengthSqrt-1] == null) return;

    for(var i = 0; i < LengthSqrt; i++) {
    vSum += aValue[i]*(LengthSqrt-i);
    cSum += (LengthSqrt-i);
    }

    HMA = (vSum/cSum);

    if(close()>HMA){
    setPriceBarColor(Color.green,Color.green,true,fals e)
    }
    if(close()<HMA){
    setPriceBarColor(Color.red,Color.red,true,false)
    }


    return HMA;
    }

    #2
    imported post

    Hi Akros,

    We have implemented the Hull MA with our upcoming NT6. Hopefully someone here may be kind enough to convert the KAMA. If we have some time, we will do it for NT6.

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      How about this?

      HMA - Orange
      KAMA - Green

      Ray
      Attached Files
      RayNinjaTrader Customer Service

      Comment


        #4
        imported post

        Great! You are working well

        Well done!

        Anynews for the Quote board?

        Comment


          #5
          imported post

          QB will be out with V6 which we anticipate should be out in beta in August.
          RayNinjaTrader Customer Service

          Comment


            #6
            HMA Moving Average

            Does Ninja have a HMA with color for trend up (Blue) and trend down (Red)?

            Thanks

            Comment


              #7
              By HMA if you mean Hull Moving Average then yes, we support it but without trend based coloring.
              RayNinjaTrader Customer Service

              Comment


                #8
                Hull ma trending color

                Thanks, what would it take to add the trending color to the indicator? I am not a programmer so if someone could accomplish this it would be great.

                Comment


                  #9
                  Maybe someone will be kind enough to help you out. If not, you can contact one of our consultants.

                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Here you go ljoe, feel free to modify the colors to suit . . . enjoy!

                    Regards,

                    Whitmark
                    Attached Files
                    Last edited by whitmark; 06-19-2007, 05:37 AM. Reason: slight code modification to be compliant with MSDN standards
                    whitmark
                    NinjaTrader Ecosystem Vendor - Whitmark Development

                    Comment


                      #11
                      Whitmark

                      Thank you very much for the indicator.

                      Comment


                        #12
                        Whitmark

                        I tried to compile the cs file but keep getting an error "error on generating Indicator." Any suggestion?

                        Thanks

                        Comment


                          #13
                          ljoe . . . I've pm'd you with my contact info. Please contact me directly and I will be happy to help.

                          Regards,

                          Whitmark
                          whitmark
                          NinjaTrader Ecosystem Vendor - Whitmark Development

                          Comment


                            #14
                            HMA indicator with color trend.

                            Just wanted to thank Whitmark for all of his assistance and provide me the cs file with the indicator. Finally figured out that one of my templates was causing all the problemd with compiling the indicator. Deleted template and Whitmark's color indicator compiled with out any problem. Indicator is working great, thanks again to Whitmark.

                            Larry

                            Comment


                              #15
                              My pleasure, and thanks for posting a follow-up!
                              whitmark
                              NinjaTrader Ecosystem Vendor - Whitmark Development

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X