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 quantismo, 04-17-2024, 05:13 PM
    4 responses
    30 views
    0 likes
    Last Post quantismo  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    31 views
    0 likes
    Last Post love2code2trade  
    Started by cls71, Today, 04:45 AM
    2 responses
    10 views
    0 likes
    Last Post eDanny
    by eDanny
     
    Started by proptrade13, Today, 11:06 AM
    0 responses
    5 views
    0 likes
    Last Post proptrade13  
    Started by kulwinder73, Today, 10:31 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X