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

Convert mt4 Trix TC2 indicator to Ninja

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

    Convert mt4 Trix TC2 indicator to Ninja

    Hi All,
    Could some one please try to convert this mt4 Trix Trend Cycle 2 indicator into Ninja trader code.

    #property link ""
    #property indicator_separate_window
    #property indicator_buffers 1
    #property indicator_color1 Red
    //
    //
    //
    //
    //
    extern int TrixPeriod = 4;
    extern int TrendCycle = 4;
    //
    //
    //
    //
    //
    double stcBuffer[];
    double trix_buffer1[];
    double trix_buffer2[];
    double trix_buffer3[];
    double cdBuffer[];
    double fastKBuffer[];
    double fastDBuffer[];
    double fastKKBuffer[];

    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+
    //
    //
    //
    //
    //
    int init()
    {
    IndicatorBuffers(8);
    SetIndexBuffer(0,stcBuffer);
    SetIndexBuffer(1,trix_buffer1);
    SetIndexBuffer(2,trix_buffer2);
    SetIndexBuffer(3,trix_buffer3);
    SetIndexBuffer(4,cdBuffer);
    SetIndexBuffer(5,fastKBuffer);
    SetIndexBuffer(6,fastDBuffer);
    SetIndexBuffer(7,fastKKBuffer);
    IndicatorShortName("Trix TC2 ("+TrixPeriod+","+TrendCycle+")");
    return(0);
    }
    int deinit()
    {
    return(0);
    }
    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+
    //
    //
    //
    //
    //
    int start()
    {
    double alphaCD = 2.0 / (1.0 + 3.0);
    int counted_bars = IndicatorCounted();
    int limit,i;
    if(counted_bars < 0) return(-1);
    if(counted_bars>0) counted_bars--;
    limit = Bars-counted_bars;
    //
    //
    //
    //
    //
    for(i=0; i<limit; i++) trix_buffer1[i]=iMA(NULL,0,TrixPeriod,0,MODE_SMMA,(PRICE_CLOSE+PR ICE_HIGH+PRICE_LOW),i);
    for(i=0; i<limit; i++) trix_buffer2[i]=iMAOnArray(trix_buffer1,0,TrixPeriod,0,MODE_SMMA, i);
    for(i=0; i<limit; i++) trix_buffer3[i]=iMAOnArray(trix_buffer2,0,TrixPeriod,0,MODE_EMA,i );
    //
    //
    //

    for(i = limit; i >= 0; i--)
    {
    cdBuffer[i] = cdBuffer[i+1]+alphaCD*(trix_buffer3[i]-trix_buffer3[i+1]);
    //
    //
    //
    //
    //

    double lowCd = minValue(cdBuffer,i);
    double highCd = maxValue(cdBuffer,i)-lowCd;
    if (highCd > 0)
    fastKBuffer[i] = 100*((cdBuffer[i]-lowCd)/highCd);
    else fastKBuffer[i] = fastKBuffer[i+1];
    fastDBuffer[i] = fastDBuffer[i+1]+0.5*(fastKBuffer[i]-fastDBuffer[i+1]);

    //
    //
    //
    //
    //

    double lowStoch = minValue(fastDBuffer,i);
    double highStoch = maxValue(fastDBuffer,i)-lowStoch;
    if (highStoch > 0)
    fastKKBuffer[i] = 100*((fastDBuffer[i]-lowStoch)/highStoch);
    else fastKKBuffer[i] = fastKKBuffer[i+1];
    stcBuffer[i] = stcBuffer[i+1]+0.5*(fastKKBuffer[i]-stcBuffer[i+1]);
    }
    return(0);
    }

    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+
    //
    //
    //
    //
    //
    double minValue(double& array[],int shift)
    {
    double minValue = array[shift];
    for (int i=1; i<TrendCycle; i++) minValue = MathMin(minValue,array[shift+i]);
    return(minValue);
    }
    double maxValue(double& array[],int shift)
    {
    double maxValue = array[shift];
    for (int i=1; i<TrendCycle; i++) maxValue = MathMax(maxValue,array[shift+i]);
    return(maxValue);
    }

    thanks.

    #2
    onemore, if no one is able or wants to convert this for you, you could always try contacting one of our 3rd party consultants.
    AustinNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,404 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    95 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    160 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    9 views
    0 likes
    Last Post Belfortbucks  
    Working...
    X