Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Here's a script to convert indicators and strategies

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

    #31
    edit: I changed this method:

    Code:
      private SyntaxNode ReplacePropertyNames(SyntaxNode node, Dictionary<string, string> propertyNameLookup)
                {
                    // HACK: Find properties by looking for identifiers that are not Types. This is simplier than
                    //       adding all the different cases for different constructs.
                    //
                    // Should work for most cases but using semantic analysis will be better.
                    IEnumerable<NameSyntax> identifiers = node
                        .DescendantNodes()
                        .OfType<NameSyntax>()
                        .Where(n => propertyNameLookup.ContainsKey(n.ToString()));
    
                    IEnumerable<NameSyntax> types = GetDescendantNodesOfTypeWithPropertyName<NameSyntax>(node, "Type",
                        "ReturnType");
                    IEnumerable<NameSyntax> propertyIdentifiers = identifiers.Except(types);
                    var replacements = new Dictionary<SyntaxNode, SyntaxNode>();
    
                    foreach (NameSyntax identifierName in propertyIdentifiers)
                    {
                        string newName = propertyNameLookup[identifierName.ToString()];
                        SyntaxNode newIdentifierName = SyntaxFactory.ParseName(newName).WithTriviaFrom(identifierName);
                        if (newIdentifierName.GetType() != typeof(QualifiedNameSyntax))
                        {
                            replacements.Add(identifierName, newIdentifierName);
                        }
                    }
    
                    return node.ReplaceNodes(replacements.Keys, (n, _) => replacements[n]);
                }
    Originally posted by mlarocco View Post
    This is what I have a line 556 In red....

    private SyntaxNode UpdateMinMaxMethod(SyntaxNode node)
    {
    MethodDeclarationSyntax minMaxMethod = node
    .DescendantNodes()
    .OfType<MethodDeclarationSyntax>()
    .FirstOrDefault(n => n.Identifier.ToString() == "OnCalculateMinMax");

    if (minMaxMethod != null)
    {
    node = ReplacePropertyNames(
    node,
    new Dictionary<string, string>
    {
    { "min", "MinValue" },
    { "max", "MaxValue" },
    });
    }

    Is that the correct place?

    Comment


      #32
      Originally posted by Serialcoder View Post
      edit: I changed this method:

      Code:
        private SyntaxNode ReplacePropertyNames(SyntaxNode node, Dictionary<string, string> propertyNameLookup)
                  {
                      // HACK: Find properties by looking for identifiers that are not Types. This is simplier than
                      //       adding all the different cases for different constructs.
                      //
                      // Should work for most cases but using semantic analysis will be better.
                      IEnumerable<NameSyntax> identifiers = node
                          .DescendantNodes()
                          .OfType<NameSyntax>()
                          .Where(n => propertyNameLookup.ContainsKey(n.ToString()));
      
                      IEnumerable<NameSyntax> types = GetDescendantNodesOfTypeWithPropertyName<NameSyntax>(node, "Type",
                          "ReturnType");
                      IEnumerable<NameSyntax> propertyIdentifiers = identifiers.Except(types);
                      var replacements = new Dictionary<SyntaxNode, SyntaxNode>();
      
                      foreach (NameSyntax identifierName in propertyIdentifiers)
                      {
                          string newName = propertyNameLookup[identifierName.ToString()];
                          SyntaxNode newIdentifierName = SyntaxFactory.ParseName(newName).WithTriviaFrom(identifierName);
                          if (newIdentifierName.GetType() != typeof(QualifiedNameSyntax))
                          {
                              replacements.Add(identifierName, newIdentifierName);
                          }
                      }
      
                      return node.ReplaceNodes(replacements.Keys, (n, _) => replacements[n]);
                  }
      Serialcoder, Hi.
      Can you please elaborate where and how this method is used. So far I have had no success converting any NT7 custom indicators to NT8, other than the default @ADL as an example.

      Any one is having success? Is there a recent version of the conversion script that include all of the fixes since it was posted here?

      Some of the questions above regarding failed conversion still remain unanswered. Would someone care to share experience with conversion using the script?

      Thanks.

      Comment


        #33
        Originally posted by aligator View Post
        Serialcoder, Hi.
        Can you please elaborate where and how this method is used. So far I have had no success converting any NT7 custom indicators to NT8, other than the default @ADL as an example.

        Any one is having success? Is there a recent version of the conversion script that include all of the fixes since it was posted here?

        Some of the questions above regarding failed conversion still remain unanswered. Would someone care to share experience with conversion using the script?

        Thanks.
        Hi aligator,

        I just found that the mentioned System.InvalidCastException occurs in that method and made a quick change to not let it process the piece of code that upsets it. i.e. leave it as the original NT7 line of code for you to change manually.

        The author of this converter has a deep knowledge of the .net framework handling of custom languages and it a bit beyond my scope of explanation.

        Having said that even after my hack of a fix, this converter is by no means a complete solution and creating a complete one would be near impossible to a mammoth task. It does save a lot of manual labour, but I've found you will need to change a few things by hand still even after it has processed an indicator or strategy. For instance any graphics/rendering stuff you will need to redo yourself.

        Comment


          #34
          Thanks wbennettjr for the code!! It really helped me convert some of my indicators. I do have an error compiling on one of my indicators and hoping you can help.

          Error:
          'NinjaTrader.Gui,Chart.Chartcontrol' does not contain a definition for "ChartStyleType' and no extension method 'ChartStyleType' accepting a first argument of type ' NinjaTrader.Gui.Chart.ChrartControl' could not be found. (are you missing a using directive or an assembly reference?).

          This is the code it is referring to:
          averageTrueRange = ATR(20);
          if (ChartControl != null && ChartControl.ChartStyleType == ChartStyleType.CandleStick)

          I've looked at the NT8 information (http://ninjatrader.com/support/helpG...zordertype.htm) and I'm not clear as to where to place the code and if any additional code in the properties/"variables", create an enum or other sections. Any ideas to help me out? Thanks!

          Comment


            #35
            Hi Marci,

            Thanks and you're welcome!

            One of the ninjas may be better able to help you with this but I'll give it a shot.

            Based on what I see, it looks like this property was removed. If you take a look at the OnStateChange method of @LineBreakBarsType.cs, for example, the code they have is:
            Code:
            DefaultChartStyle = Gui.Chart.ChartStyleType.OpenClose;
            I'm guessing your code needs to change to be:

            Code:
            if (DefaultChartStyle == Gui.Chart.ChartStyleType.CandleStick)...
            There may be some nuance to this (given the name DefaultChartStyle) so I would confirm with a ninja.

            Let me know if that works for you.

            Wil

            Comment


              #36
              Thanks so much for your assistance Serialcoder!

              I apologize for not responding sooner. For some strange reason, I have not been getting emails about new posts.

              Aligator,

              Do you still have issues with conversion? Let me know and include the stacktrace and I'll look into it.

              Wil

              Comment


                #37
                Hi GFullmer,

                Sorry for the late response. I haven't been getting notifications of new posts.

                I looked at your script and I think the issue is that you are trying to add chart indicators in the SetDefaults state. This is causing the initialization to fail. This should be done in the Configure state instead.

                Add the following to OnStateChange:
                Code:
                case State.Configure:
                   [move all the AddCharIndicator lines from Initialize() to here]
                    break;
                Let me know how it goes.

                Wil

                Comment


                  #38
                  Error on Run

                  I am new to C# so I probably need to link to some Microsoft code (I assume).

                  Here are the lines that are causing error messages...

                  <Query Kind="Program">
                  <NuGetReference>Microsoft.CodeAnalysis.CSharp</NuGetReference>
                  <Namespace>Microsoft.CodeAnalysis</Namespace>
                  <Namespace>Microsoft.CodeAnalysis.CSharp</Namespace>
                  <Namespace>Microsoft.CodeAnalysis.CSharp.Syntax</Namespace>
                  </Query>

                  The messages are...

                  CS1519 Invalid token '<' in class, struct, or interface member declaration

                  CS1525 Invalid expression term '<'


                  Thanks for your help.

                  Comment


                    #39
                    Hi RonB,

                    How are you opening the file? What you have posted is a snippet of a Linqpad file which needs to be opened using Linqpad.

                    Wil

                    Comment


                      #40
                      I’ve had 20+ years of programming in another popular charting package (TS) and I consider myself pretty doggone good at it, but when it comes to doing similar work in NinjaTrader it’s always a struggle for me. I was able to gimp along in NT7, but when it comes to converting NT7 code to work in NT8 it is obvious that I am misunderstanding some core concepts. I used wbennettjr’s script to do the initial grunt work (thank you very much for providing that. I’m sure that it’s gotten me a lot further than I would have gotten on my own!) But I keep getting a bunch of those namespace errors. I understand that the code is looking for something that’s not being provided, but I don’t know how to go about finding the thing that it is looking for – is it always another DLL, and if so how do I find out which DLL it is missing and do I simply get it from the NT7 installation? Any help would be greatly appreciated.


                      The errors that I am getting are:
                      The type or namespace name 'HLCCalculationMode' does not exist in the namespace 'NinjaTrader.Data' (are you missing an assembly reference?)
                      The type or namespace name 'SolidBrush' could not be found (are you missing a using directive or an assembly reference?)
                      The type or namespace name 'PivotRange' does not exist in the namespace 'NinjaTrader.Data' (are you missing an assembly reference?)
                      The type or namespace name 'StringFormat' could not be found (are you missing a using directive or an assembly reference?)


                      Thank you very much in advance for any help provided.

                      Comment


                        #41
                        Hi TrendTracker,

                        It seems you are using WoodiesPivot. Looking at the help, it appears there are name changes and that some overloads have been removed. "HLCCalculationMode" has been renamed to 'HLCCalculationModeWoodie'. It seems "PivotRange" no longer exists. "SolidBrush" should be "SolidColorBrush" - if I remember correctly. I believe "StringFormat" no longer exists. If I remember correctly, this is only used in drawing and the drawing tools have been changed to use DX. You are seeing this used in OnRender, correct? This will have to be manually updated to use DX.

                        The NT8 help is here: http://ninjatrader.com/support/helpGuides/nt8/en-us
                        The NT7 help is here: http://ninjatrader.com/support/helpGuides/nt7

                        Search for WoodiesPivots in both of the help pages to see the overloads.

                        Let me know if you need more assistance.

                        Wil

                        Comment


                          #42
                          I am having a problem when I run the script and get the following error:

                          Conversion failed!

                          System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.QualifiedNam eSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSy ntax'.

                          Any help would be greatly appreciated!!

                          Thanks!

                          Comment


                            #43
                            Hi Pdt,

                            That is a bug in the converter. Can you send me a sample file to reproduce with? If not, try to narrow it down to the line in the indicator/strategy that is causing the error and send that to me.

                            Wil

                            Comment


                              #44
                              Great script

                              @wbennettjr
                              Thanks for all of your efforts in this conversion script.

                              It works well and I have converted some of my indicators.

                              My question is, are there any scripts to convert bar type files also?

                              I love to use the PointO bar type by Richard Todd and I would like to convert it but have not had any success at doing it.

                              Thanks

                              Comment


                                #45
                                I converted it, if you want. The thing is, before NT made those breaking session iterator changes, this matched NT7 perfectly. But since then it doesn't and I have no idea why. (Or at least it seemed to back when I fixed all those bar types I converted.) But here it is with the appropriate disclaimer.
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by traderqz, Today, 12:06 AM
                                3 responses
                                6 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Started by RideMe, 04-07-2024, 04:54 PM
                                5 responses
                                28 views
                                0 likes
                                Last Post NinjaTrader_BrandonH  
                                Started by f.saeidi, Today, 08:13 AM
                                1 response
                                8 views
                                0 likes
                                Last Post NinjaTrader_ChelseaB  
                                Started by DavidHP, Today, 07:56 AM
                                1 response
                                7 views
                                0 likes
                                Last Post NinjaTrader_Erick  
                                Started by kujista, Today, 06:23 AM
                                3 responses
                                11 views
                                0 likes
                                Last Post kujista
                                by kujista
                                 
                                Working...
                                X