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

Level ZZ Semphor Conversion or Re-Write for Ninja Trader 8

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

    Level ZZ Semphor Conversion or Re-Write for Ninja Trader 8

    I need someone that can convert or re-write code for NT8. For a Level 3 ZZ Semaphor indicator: Below is the Code in MQL4.

    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    //+------------------------------------------------------------------+
    //| 3_Level_ZZ_Semafor.mq4 |
    //+------------------------------------------------------------------+
    property copyright ""
    property link ""

    // В основу расчета зигзага взÿт алгоритм [email protected]
    // За что ему огромное спасибо

    property indicator_chart_window
    property indicator_buffers 6
    property indicator_color1 Chocolate
    property indicator_color2 Chocolate
    property indicator_color3 DarkTurquoise
    property indicator_color4 DarkTurquoise
    property indicator_color5 Yellow
    property indicator_color6 Yellow

    //---- input parameters
    extern double Period1=0;
    extern double Period2=13;
    extern double Period3=34;
    extern string Dev_Step_1="0";
    extern string Dev_Step_2="8,5";
    extern string Dev_Step_3="21,12";
    extern int Symbol_1_Kod=0;
    extern int Symbol_2_Kod=141;
    extern int Symbol_3_Kod=142;

    //---- buffers
    double FP_BuferUp[];
    double FP_BuferDn[];
    double NP_BuferUp[];
    double NP_BuferDn[];
    double HP_BuferUp[];
    double HP_BuferDn[];

    int F_Period;
    int N_Period;
    int H_Period;
    int Dev1;
    int Stp1;
    int Dev2;
    int Stp2;
    int Dev3;
    int Stp3;

    //+------------------------------------------------------------------+
    //| Custom indicator initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    // --------- Корректируем периоды длÿ построениÿ ЗигЗагов
    if (Period1>0) F_Period=MathCeil(Period1*Period()); else F_Period=0;
    if (Period2>0) N_Period=MathCeil(Period2*Period()); else N_Period=0;
    if (Period3>0) H_Period=MathCeil(Period3*Period()); else H_Period=0;

    //---- Обрабатываем 1 буфер
    if (Period1>0)
    {
    SetIndexStyle(0,DRAW_ARROW,0,1);
    SetIndexArrow(0,Symbol_1_Kod);
    SetIndexBuffer(0,FP_BuferUp);
    SetIndexEmptyValue(0,0.0);

    SetIndexStyle(1,DRAW_ARROW,0,1);
    SetIndexArrow(1,Symbol_1_Kod);
    SetIndexBuffer(1,FP_BuferDn);
    SetIndexEmptyValue(1,0.0);
    }

    //---- Обрабатываем 2 буфер
    if (Period2>0)
    {
    SetIndexStyle(2,DRAW_ARROW,0,2);
    SetIndexArrow(2,Symbol_2_Kod);
    SetIndexBuffer(2,NP_BuferUp);
    SetIndexEmptyValue(2,0.0);

    SetIndexStyle(3,DRAW_ARROW,0,2);
    SetIndexArrow(3,Symbol_2_Kod);
    SetIndexBuffer(3,NP_BuferDn);
    SetIndexEmptyValue(3,0.0);
    }
    //---- Обрабатываем 3 буфер
    if (Period3>0)
    {
    SetIndexStyle(4,DRAW_ARROW,0,4);
    SetIndexArrow(4,Symbol_3_Kod);
    SetIndexBuffer(4,HP_BuferUp);
    SetIndexEmptyValue(4,0.0);

    SetIndexStyle(5,DRAW_ARROW,0,4);
    SetIndexArrow(5,Symbol_3_Kod);
    SetIndexBuffer(5,HP_BuferDn);
    SetIndexEmptyValue(5,0.0);
    }
    // Обрабатываем значениÿ девиаций и шагов
    int CDev=0;
    int CSt=0;
    int Mass[];
    int C=0;
    if (IntFromStr(Dev_Step_1,C, Mass)==1)
    {
    Stp1=Mass[1];
    Dev1=Mass[0];
    }

    if (IntFromStr(Dev_Step_2,C, Mass)==1)
    {
    Stp2=Mass[1];
    Dev2=Mass[0];
    }


    if (IntFromStr(Dev_Step_3,C, Mass)==1)
    {
    Stp3=Mass[1];
    Dev3=Mass[0];
    }
    return(0);
    }
    //+------------------------------------------------------------------+
    //| Custor indicator deinitialization function |
    //+------------------------------------------------------------------+
    int deinit()
    {
    //----

    //----
    return(0);
    }

    //+------------------------------------------------------------------+
    //| Custom indicator iteration function |
    //+------------------------------------------------------------------+
    int start()
    {
    if (Period1>0) CountZZ(FP_BuferUp,FP_BuferDn,Period1,Dev1,Stp1);
    if (Period2>0) CountZZ(NP_BuferUp,NP_BuferDn,Period2,Dev2,Stp2);
    if (Period3>0) CountZZ(HP_BuferUp,HP_BuferDn,Period3,Dev3,Stp3);
    return(0);
    }
    //+------------------------------------------------------------------+
    // дополнительные функции
    //int Take



    //+------------------------------------------------------------------+
    //| Функц формированиÿ ЗигЗага |
    //+------------------------------------------------------------------+
    int CountZZ( double& ExtMapBuffer[], double& ExtMapBuffer2[], int ExtDepth, int ExtDeviation, int ExtBackstep )
    {
    int shift, back,lasthighpos,lastlowpos;
    double val,res;
    double curlow,curhigh,lasthigh,lastlow;

    for(shift=Bars-ExtDepth; shift>=0; shift--)
    {
    val=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)];
    if(val==lastlow) val=0.0;
    else
    {
    lastlow=val;
    if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0;
    else
    {
    for(back=1; back<=ExtBackstep; back++)
    {
    res=ExtMapBuffer[shift+back];
    if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0;
    }
    }
    }

    ExtMapBuffer[shift]=val;
    //--- high
    val=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)];
    if(val==lasthigh) val=0.0;
    else
    {
    lasthigh=val;
    if((val-High[shift])>(ExtDeviation*Point)) val=0.0;
    else
    {
    for(back=1; back<=ExtBackstep; back++)
    {
    res=ExtMapBuffer2[shift+back];
    if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0;
    }
    }
    }
    ExtMapBuffer2[shift]=val;
    }
    // final cutting
    lasthigh=-1; lasthighpos=-1;
    lastlow=-1; lastlowpos=-1;

    for(shift=Bars-ExtDepth; shift>=0; shift--)
    {
    curlow=ExtMapBuffer[shift];
    curhigh=ExtMapBuffer2[shift];
    if((curlow==0)&&(curhigh==0)) continue;
    //---
    if(curhigh!=0)
    {
    if(lasthigh>0)
    {
    if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0;
    else ExtMapBuffer2[shift]=0;
    }
    //---
    if(lasthigh<curhigh || lasthigh<0)
    {
    lasthigh=curhigh;
    lasthighpos=shift;
    }
    lastlow=-1;
    }
    //----
    if(curlow!=0)
    {
    if(lastlow>0)
    {
    if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0;
    else ExtMapBuffer[shift]=0;
    }
    //---
    if((curlow<lastlow)||(lastlow<0))
    {
    lastlow=curlow;
    lastlowpos=shift;
    }
    lasthigh=-1;
    }
    }

    for(shift=Bars-1; shift>=0; shift--)
    {
    if(shift>=Bars-ExtDepth) ExtMapBuffer[shift]=0.0;
    else
    {
    res=ExtMapBuffer2[shift];
    if(res!=0.0) ExtMapBuffer2[shift]=res;
    }
    }
    }

    int Str2Massive(string VStr, int& M_Count, int& VMass[])
    {
    int val=StrToInteger( VStr);
    if (val>0)
    {
    M_Count++;
    int mc=ArrayResize(VMass,M_Count);
    if (mc==0)return(-1);
    VMass[M_Count-1]=val;
    return(1);
    }
    else return(0);
    }


    int IntFromStr(string ValStr,int& M_Count, int& VMass[])
    {

    if (StringLen(ValStr)==0) return(-1);
    string SS=ValStr;
    int NP=0;
    string CS;
    M_Count=0;
    ArrayResize(VMass,M_Count);
    while (StringLen(SS)>0)
    {
    NP=StringFind(SS,",");
    if (NP>0)
    {
    CS=StringSubstr(SS,0,NP);
    SS=StringSubstr(SS,NP+1,StringLen(SS));
    }
    else
    {
    if (StringLen(SS)>0)
    {
    CS=SS;
    SS="";
    }
    }
    if (Str2Massive(CS,M_Count,VMass)==0)
    {
    return(-2);
    }
    }
    return(1);
    }​

    #2
    Hello JRMorales,

    Our support can only assist with providing learning materials, for example if you wanted to code this yourself and you had a question on a specific topic. You can reach out to third party developers to pay to have this type of item created for you if you didn't want to make it yourself. If any users feel inclined to take on this task I am sure they will post here as well.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I coded this with no errors, but now I cannot use it on chart? Please help.
      using System;
      using System.Windows.Media;
      using NinjaTrader.NinjaScript.Indicators;

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class ZigZagIndicator : Indicator
      {
      // Define indicator parameters
      private int period1 = 0;
      private int period2 = 13;
      private int period3 = 34;
      private int deviation1 = 0;
      private int deviation2 = 8;
      private int deviation3 = 21;
      private int backstep1 = 0;
      private int backstep2 = 5;
      private int backstep3 = 12;
      private int symbol1Kod = 0;
      private int symbol2Kod = 141;
      private int symbol3Kod = 142;

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = "ZigZag Indicator";
      Calculate = Calculate.OnEachTick;

      // Use AddParameter or a similar method instead of AddInt
      // AddInt("Period1", 0);
      }
      else if (State == State.DataLoaded)
      {
      // Retrieve parameter values using a hypothetical method GetIntParameter
      // period1 = GetIntParameter("Period1");
      }
      }

      protected override void OnBarUpdate()
      {
      // ... Rest of the ZigZag calculation code ...

      // Use a specific index when working with PriceSeries
      if (CurrentBars[0] >= period1)
      {
      // Use a hypothetical method PlotArrow for plotting
      // PlotArrow("ZigZagArrow1", Colors.Green, "ArrowDown", Highs[0][0] + 1 * TickSize);
      }

      if (CurrentBars[0] >= period2)
      {
      // Use a hypothetical method PlotArrow for plotting
      // PlotArrow("ZigZagArrow2", Colors.Blue, "ArrowDown", Highs[0][0] + 1 * TickSize);
      }

      if (CurrentBars[0] >= period3)
      {
      // Use a hypothetical method PlotArrow for plotting
      // PlotArrow("ZigZagArrow3", Colors.Purple, "ArrowDown", Highs[0][0] + 1 * TickSize);
      }
      }
      }
      }

      // The remaining NinjaScript generated code remains unchanged.


      region NinjaScript generated code. Neither change nor remove.

      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private ZigZagIndicator[] cacheZigZagIndicator;
      public ZigZagIndicator ZigZagIndicator()
      {
      return ZigZagIndicator(Input);
      }

      public ZigZagIndicator ZigZagIndicator(ISeries<double> input)
      {
      if (cacheZigZagIndicator != null)
      for (int idx = 0; idx < cacheZigZagIndicator.Length; idx++)
      if (cacheZigZagIndicator[idx] != null && cacheZigZagIndicator[idx].EqualsInput(input))
      return cacheZigZagIndicator[idx];
      return CacheIndicator<ZigZagIndicator>(new ZigZagIndicator(), input, ref cacheZigZagIndicator);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.ZigZagIndicator ZigZagIndicator()
      {
      return indicator.ZigZagIndicator(Input);
      }

      public Indicators.ZigZagIndicator ZigZagIndicator(ISeries<double> input )
      {
      return indicator.ZigZagIndicator(input);
      }
      }
      }

      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.ZigZagIndicator ZigZagIndicator()
      {
      return indicator.ZigZagIndicator(Input);
      }

      public Indicators.ZigZagIndicator ZigZagIndicator(ISeries<double> input )
      {
      return indicator.ZigZagIndicator(input);
      }
      }
      }

      #endregion​

      Comment


        #4
        It is not recognizing file or indicator?

        Comment


          #5
          Helllo JRMorales,

          You dont have a name specified for the indicator which may be part of the problem. I would suggest using an existing indicator like the SMA as an example to see how a normal script looks to compare what you are missing. You need to add Name = "MyName"; to State.SetDefaults.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thanks for your response. But I cannot use sma for calculations.I am using percentages.

            Comment


              #7
              Hello JRMorales,

              You can use the SMA as a general template for a correctly coded NinjaScript file, that shows the required properties and overrides. The code you previously provided was not valid because you are missing the default name property in set defaults. I would suggest looking at how some of the stock indicators are coded before trying to make your own fie so that you make sure to set up your indicator correctly.

              Alternatively delete the indicator you made and then right click on the indicators folder in the NinjaScript editor and generate a new indicator, that will include all the required code and then you can start from that point in developing your own script.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by burtoninlondon, Today, 12:38 AM
              0 responses
              5 views
              0 likes
              Last Post burtoninlondon  
              Started by AaronKoRn, Yesterday, 09:49 PM
              0 responses
              13 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Yesterday, 08:42 PM
              0 responses
              11 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Yesterday, 07:51 PM
              0 responses
              13 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,982 views
              3 likes
              Last Post jhudas88  
              Working...
              X