Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

help easy language indicator to ninja script

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

    help easy language indicator to ninja script

    Hello guys,

    This is a TS indicator that creates and update ascii data file in real time as new data appears on the TS chart. Is it possible to convert this into a NT script ?

    Code:
    {This file is source code for the Easy Language interface to DT. }
    
    Vars:Directory("C:\DTTSDATA"),Interval(" "),FileName(""),x(0),wParm(0),ThisVolume(0),Count( 0),LastDate(0),LastTime(0),fname("");
    
    definedllfunc:"C:\dttsdata\DTTS.DLL",int,"SendData ",float,lpstr,lpstr,lpstr,float,float,float,float, float,float,float,float;
    
    
    ThisVolume = Ticks;
    
    if barnumber = 1 then
    begin
    
    if DataCompression = 0 then Interval = NumToStr(Highest(upticks + downticks,5),0);
    if DataCompression = 1 then Interval = NumToStr(BarInterval,0);
    if DataCompression = 2 then Interval = "Daily";
    if DataCompression = 3 then Interval = "Weekly";
    if DataCompression = 4 then Interval = "Monthly";
    
    fname = MidStr(getsymbolname,+0,3)+ MidStr(getsymbolname,+5,7) + "_"+Interval+"."; {name & extension only}
    
    if DataCompression = 0 then fname = fname + "dtt";
    if DataCompression = 1 then fname = fname + "dti";
    if DataCompression = 2 then fname = fname + "dtd";
    if DataCompression = 3 then fname = fname + "dtw";
    if DataCompression = 4 then fname = fname + "dtm";
    
    FileName = Directory + fname;
    
    Input: cf(4);
    
    FileDelete(FileName);
    FileAppend(FileName,"cf= " + NumToStr(cf,0) + newline);
    if DataCompression = 0 then FileAppend(FileName,"ticks= " + Interval + NewLine);
    if DataCompression = 1 then FileAppend(FileName,"min= " + Interval + NewLine);
    if DataCompression > 1 then FileAppend(FileName, LeftStr(Interval,1) + NewLine);
    FileAppend(FileName,"DATE TIME OPEN HIGH LOW CLOSE VOLUME" + NEWLINE);
    
    for x = MaxBarsBack downto 1
    begin
    ThisVolume = iff(DataCompression =0,Upticks[x] + DownTicks[x],Ticks[x]);
    fileappend(FileName,numtostr(date[x],0) + " " + numtostr(time[x],0) + " " +
    numtostr(open[x],4) + " " + numtostr(high[x],4) + " " + numtostr(low[x],4) + " " + numtostr(close[x],4) + " " +
    numtostr(ThisVolume,0) + newline);
    LastDate = Date; {Date & Time of last whole bar stored in file}
    LastTime = Time;
    end;
    end;
    
    wParm=BarStatus(1); {NOTE: Does not return 0 for opening tick as specified in docs!}
    
    if wParm = 2 then
    begin {Last Tick Of Bar, print new line}
    fileappend(FileName,numtostr(date,0) + " " + numtostr(time,0) + " " +
    numtostr(open,cf) + " " + numtostr(high,cf) + " " + numtostr(low,cf) + " " + numtostr(close,cf) + " " +
    numtostr(ThisVolume,0) + newline);
    end;
    
    if LastBarOnChart then
    begin
    if (wParm<>2 or (date <> LastDate) or (time <> LastTime)) then {we're not duplicating last bar in file}
    value1 = SendData(wParm,MidStr(getsymbolname,InStr(getsymbo lname,":")+1,20),Interval,fname,Date,Time,Open,Hig h,Low,Close,ThisVolume,OpenInt);
    end;
    Thanks,
    Noy
    Last edited by noy_cabildo; 09-21-2022, 01:34 AM.

    #2
    Hello Noy,

    Thanks for your post.

    It is likely that this TS script could be converted to a NinjaScript indicator for NinjaTrader 8.

    That said, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services in our support. This is so that we can maintain a high level of service for all of our clients as well as our partners.

    My advice is to start by creating as much of the indicator as possible in the Indicator Builder. This will create the framework of the NinjaScript indicator.​

    To create a NinjaScript indicator, open a New > NinjaScript Editor window, select the '+' tab at the bottom of the Editor window, and select 'New Indicator'. You could set up as much of the indicator as possible in the Indicator Builder.

    Then, you could open the TS documentation and the NinjaTrader 8 help guide to compare which NinjaScript methods and properties are equivalent to the TS methods/properties used in the code you shared. 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

    Let me know if I may further assist.​​​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Brandon for the quick reply, can you please point to any easylanguage to NT script conversion services.

      Regrads,
      Noy

      Comment


        #4
        Hello Noy,

        Thanks for your note.

        I am not aware of any EasyLanguage to NinjaScript conversion services that are available.

        You could consider reaching out to vendorsupport[AT]ninjatrader.com for a list of affiliate consultants who would likely be happy to create this script or any others at your request.

        Or, you could do a quick Google search for something like 'EasyLanguage to NinjaScript conversion' to find third-party developers that convert code.

        Let me know if I may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Did tried machine based translation service below, unfortunately got some bunch of errors upon pasting it ninjascript editor

          Code:
          NinjaScript File    Error                                                                Code    Line
          MyCustomIndicator.cs    " expected.                                                                    68
          MyCustomIndicator.cs    ')' expected.                                                                   77
          MyCustomIndicator.cs    ';' expected.                                                                   77
          MyCustomIndicator.cs    " expected.                                                                    82
          MyCustomIndicator.cs    " expected.                                                                    83
          MyCustomIndicator.cs    " expected.                                                                    84
          MyCustomIndicator.cs    Identifier expected.                                                         85
          MyCustomIndicator.cs    " expected.                                                                    96
          MyCustomIndicator.cs    " expected.                                                                    97
          MyCustomIndicator.cs    " expected.                                                                    98
          MyCustomIndicator.cs    " expected.                                                                  100
          MyCustomIndicator.cs    ')' expected.                                                                 104
          MyCustomIndicator.cs    ')' expected.                                                                  116
          MyCustomIndicator.cs    Only assignment, call, increment, decrement, and new object expressions can be used as a statement.        129
          MyCustomIndicator.cs    ';' expected.                                                                   129
          MyCustomIndicator.cs    Class, delegate, enum, interface, or struct expected.        179
          MyCustomIndicator.cs    Class, delegate, enum, interface, or struct expected.        211
          MyCustomIndicator.cs    Class, delegate, enum, interface, or struct expected.        211
          MyCustomIndicator.cs    Class, delegate, enum, interface, or struct expected.        211
          MyCustomIndicator.cs    Class, delegate, enum, interface, or struct expected.        212
          ​
          Code:
          #region Using declarations;
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.ComponentModel.DataAnnotations;
          using System.Linq;
          using System.Text;
          using System.Threading.Tasks;
          using System.Windows;
          using System.Windows.Input;
          using System.Windows.Media;
          using System.Windows.Media;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Gui;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.SuperDom;
          using NinjaTrader.Gui.Tools;
          using NinjaTrader.Data;
          using NinjaTrader.NinjaScript;
          using NinjaTrader.Core.FloatingPoint;
          using NinjaTrader.NinjaScript.Indicators;
          using NinjaTrader.NinjaScript.DrawingTools;
          #endregion;
          namespace NinjaTrader.NinjaScript.Strategies
          {
          public class test_easy : Strategy
          {
              protected override void OnStateChange()
              {
                      if (State == State.SetDefaults)
                      {
                          Description                                    = "@Enter the description for your Strategy here.";
                          Name                                        = "test_easy";
                          Calculate                                    = Calculate.OnBarClose;
                          EntriesPerDirection                            = 1;
                          EntryHandling                                = EntryHandling.AllEntries;
                          IsExitOnSessionCloseStrategy                = true;
                          ExitOnSessionCloseSeconds                    = 30;
                          IsFillLimitOnTouch                            = false;
                          MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                          OrderFillResolution                            = OrderFillResolution.Standard;
                          Slippage                                    = 0;
                          StartBehavior                                = StartBehavior.WaitUntilFlat;
                          TimeInForce                                    = TimeInForce.Gtc;
                          TraceOrders                                    = false;
                          RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                          StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                          BarsRequiredToTrade                            = 20;
                          // Disable this property for performance gains in Strategy Analyzer optimizations
                          // See the Help Guide for additional information
                          IsInstantiatedOnEachOptimizationIteration    = true;
                          Test_var1                    = 1;
                          Testvar2                    = 1;
                      }
                      else if (State == State.Configure)
                      {
                          AddDataSeries("xxxx", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
                          SetStopLoss(@"xxxx", CalculationMode.Currency, 0, false);
                      }
              }
          #region Varaibles
          int     x = { 0};
          int     wparm = { 0};
          int     thisvolume = { 0};
          int     count = { 0};
          int     lastdate = { 0};
          int     lasttime = { 0};
          String     fname = { "\"};
          #endregion
          
          protected override void Initialize()
          {
          }
          
          protected override void OnBarUpdate()
              {
              dll.addFunction("SendData \", DLL.INT, DLL.STDCALL, "SendData \", DLL.FLOAT, DLL.STRING, DLL.STRING, DLL.STRING, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT);
              thisvolume = Ticks;
              if (Barnumber == 1)  {
                  if (datacompression == 0)  interval = numtostr(highest((upticks + downticks), 5), 0);
                  if (datacompression == 1)  interval = numtostr(BarInterval, 0);
                  if (datacompression == 2)  interval = "Daily\";
                  if (datacompression == 3)  interval = "Weekly\";
                  if (datacompression == 4)  interval = "Monthly\";
                  fname = midstr(getsymbolname, 0, 3) + midstr(getsymbolname, 5, 7) + "_\" + interval + ".\";
                  if (datacompression == 0) /* {name & extension only} */
            fname = fname + "dtt\";
                  if (datacompression == 1)  fname = fname + "dti\";
                  if (datacompression == 2)  fname = fname + "dtd\";
                  if (datacompression == 3)  fname = fname + "dtw\";
                  if (datacompression == 4)  fname = fname + "dtm\";
                  filename = directory + fname;
           /* {Input: cf(4);
           */
                  filedelete(filename);
                  fileappend(filename, "cf= \" + numtostr(cf, 0) + newline);
                  if (datacompression == 0)  fileappend(filename, "ticks= \" + interval + newline);
                  if (datacompression == 1)  fileappend(filename, "min= \" + interval + newline);
                  if (datacompression > 1)  fileappend(filename, leftstr(interval, 1) + newline);
                  fileappend(filename, "DATE TIME OPEN HIGH LOW CLOSE VOLUME\" + newline);
                  for(x = maxbarsback; x <= 1; x++)
                      {
                      thisvolume = iff(datacompression == 0, (upticks[x] + downticks[x]), Ticks[x]);
                      fileappend(filename, numtostr(Date[x], 0) + " \" + numtostr(Time[x], 0) + " \" + numtostr(Open[x], 4) + " \" + numtostr(High[x], 4) + " \" + numtostr(Low[x], 4) + " \" + numtostr(Close[x], 4) + " \" + numtostr(thisvolume, 0) + newline);
                      lastdate = Date;
           /* {Date & Time of last whole bar stored in file} */
                      lasttime = Time;
                      }
                  }
          
              wparm = barstatus(1);
              if (wparm == 2) /* {NOTE: Does not return 0 for opening tick as specified in docs!} */
            /* {Last Tick Of Bar, print new line} */
          
           {
                  fileappend(filename, numtostr(Date, 0) + " \" + numtostr(Time, 0) + " \" + numtostr(Open, cf) + " \" + numtostr(High, cf) + " \" + numtostr(Low, cf) + " \" + numtostr(Close, cf) + " \" + numtostr(thisvolume, 0) + newline);
                  }
              if (lastbaronchart)  {
                  if (((wparm != (2 || Date != lastdate || Time != lasttime))))  value1 = senddata(wparm, midstr(getsymbolname, (instr(getsymbo, ":\") + 1), 20), interval, fname, Date, Time, Open, hig, Low, Close, thisvolume, OpenInt);
                  }
          
          }
          #region Properties
          [Description("")]
          [GridCategory("Parameters")]
          public int Directory
          {
              get { return directory; }
              set { directory  = Math.Max(1,Value);}
           }
          public int Interval
          {
              get { return interval; }
              set { interval  = Math.Max(1,Value);}
           }
          public int Filename
          {
              get { return filename; }
              set { filename  = Math.Max(1,Value);}
           }
          public int X
          {
              get { return x; }
              set { x  = Math.Max(1,Value);}
           }
          public int Wparm
          {
              get { return wparm; }
              set { wparm  = Math.Max(1,Value);}
           }
          public int Thisvolume
          {
              get { return thisvolume; }
              set { thisvolume  = Math.Max(1,Value);}
           }
          public int Count
          {
              get { return count; }
              set { count  = Math.Max(1,Value);}
           }
          public int Lastdate
          {
              get { return lastdate; }
              set { lastdate  = Math.Max(1,Value);}
           }
          public int Lasttime
          {
              get { return lasttime; }
              set { lasttime  = Math.Max(1,Value);}
           }
          public String Fname
          {
              get { return fname; }
              set { fname  = Value;}
           }
          }
          }
          #endregion
          static void  Function(int cf = 4)
              {
              int     x = {     0};
              int     wparm = {     0};
              int     thisvolume = {     0};
              int     count = {     0};
              int     lastdate = {     0};
              int     lasttime = {     0};
              String     fname = {     "\"};
              dll.addFunction("SendData \", DLL.INT, DLL.STDCALL, DLL.STDCALL, "SendData \", DLL.FLOAT, DLL.STRING, DLL.STRING, DLL.STRING, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT, DLL.FLOAT);
              thisvolume = Ticks;
              if (Barnumber == 1)  {
                  if (datacompression == 0)  interval = numtostr(highest((upticks + downticks), 5), 0);
                  if (datacompression == 1)  interval = numtostr(BarInterval, 0);
                  if (datacompression == 2)  interval = "Daily\";
                  if (datacompression == 3)  interval = "Weekly\";
                  if (datacompression == 4)  interval = "Monthly\";
                  fname = midstr(getsymbolname, 0, 3) + midstr(getsymbolname, 5, 7) + "_\" + interval + ".\";
                  if (datacompression == 0)  fname = fname + "dtt\";
                  if (datacompression == 1)  fname = fname + "dti\";
                  if (datacompression == 2)  fname = fname + "dtd\";
                  if (datacompression == 3)  fname = fname + "dtw\";
                  if (datacompression == 4)  fname = fname + "dtm\";
                  filename = directory + fname;
                  filedelete(filename);
                  fileappend(filename, "cf= \" + numtostr(cf, 0) + newline);
                  if (datacompression == 0)  fileappend(filename, "ticks= \" + interval + newline);
                  if (datacompression == 1)  fileappend(filename, "min= \" + interval + newline);
                  if (datacompression > 1)  fileappend(filename, leftstr(interval, 1) + newline);
                  fileappend(filename, "DATE TIME OPEN HIGH LOW CLOSE VOLUME\" + newline);
                  for(x = maxbarsback; x <= 1; x++)
                      {
                      thisvolume = iff(datacompression == 0, (upticks[x] + downticks[x]), Ticks[x]);
                      fileappend(filename, numtostr(Date[x], 0) + " \" + numtostr(Time[x], 0) + " \" + numtostr(Open[x], 4) + " \" + numtostr(High[x], 4) + " \" + numtostr(Low[x], 4) + " \" + numtostr(Close[x], 4) + " \" + numtostr(thisvolume, 0) + newline);
                      lastdate = Date;
                      lasttime = Time;
                      }
                  }
          
              wparm = barstatus(1);
              if (wparm == 2)  {
                  fileappend(filename, numtostr(Date, 0) + " \" + numtostr(Time, 0) + " \" + numtostr(Open, cf) + " \" + numtostr(High, cf) + " \" + numtostr(Low, cf) + " \" + numtostr(Close, cf) + " \" + numtostr(thisvolume, 0) + newline);
                  }
          
              if (lastbaronchart)  {
                  if (((wparm != (2 || Date != lastdate || Time != lasttime))))  value1 = senddata(wparm, midstr(getsymbolname, (instr(getsymbo, ":\") + 1), 20), interval, fname, Date, Time, Open, hig, Low, Close, thisvolume, OpenInt);
                  }
          
          }
          #region Wizard settings, neither change nor remove
          #endregion
          ​
          Attached Files

          Comment


            #6
            Hello Noy,

            Thanks for your note.

            I am not aware of any EasyLanguage to NinjaScript translation services available.

            That said, I see you have multiple compile errors after using the translation service you mentioned. You must resolve each compile error that appears for the script to be usable. You would need to ensure that you have the correct amount of opening and closing parentheses '( )', the correct number of opening and closing curly braces '{ }', the correct number of quote marks " "', have class-level variables set up when they are needed, and more.

            Something you could do is thoroughly review each individual line of code for any syntax issues, such as missing parentheses, curly braces, or quotation marks, and add the missing item to the script. Then you could review the remaining errors by checking the compile error to see which lines of code are throwing errors.

            If you have questions about what a specific compile error means, you could do a quick google search for the error in question to find out how to resolve it, such as 'compile error Identifier expected C#'.

            See this help guide page for information about Debugging your NinjaScript Code: https://ninjatrader.com/support/help...script_cod.htm

            Below is a link to a forum post that demonstrates how to use prints to understand behavior.

            https://ninjatrader.com/support/foru...121#post791121

            Please note that in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services in our support. This is so that we can maintain a high level of service for all of our clients as well as our partners.​

            Let me know if I may assist further.
            Last edited by NinjaTrader_BrandonH; 09-21-2022, 07:05 AM.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              I can convert this from EasyLanguage to NinjaScript.

              Authorised NinjaTrader Vendor

              Click image for larger version

Name:	NTVendor.png
Views:	103
Size:	36.1 KB
ID:	1216930
              Attached Files
              Last edited by dibDab; 09-26-2022, 05:19 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Balage0922, Today, 07:38 AM
              0 responses
              3 views
              0 likes
              Last Post Balage0922  
              Started by JoMoon2024, Today, 06:56 AM
              0 responses
              6 views
              0 likes
              Last Post JoMoon2024  
              Started by Haiasi, 04-25-2024, 06:53 PM
              2 responses
              19 views
              0 likes
              Last Post Massinisa  
              Started by Creamers, Today, 05:32 AM
              0 responses
              6 views
              0 likes
              Last Post Creamers  
              Started by Segwin, 05-07-2018, 02:15 PM
              12 responses
              1,786 views
              0 likes
              Last Post Leafcutter  
              Working...
              X