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

  • wbennettjr
    replied
    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

    Leave a comment:


  • PDT123
    replied
    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!

    Leave a comment:


  • wbennettjr
    replied
    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

    Leave a comment:


  • TrendTracker
    replied
    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.

    Leave a comment:


  • wbennettjr
    replied
    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

    Leave a comment:


  • ronb107
    replied
    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.

    Leave a comment:


  • wbennettjr
    replied
    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

    Leave a comment:


  • wbennettjr
    replied
    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

    Leave a comment:


  • wbennettjr
    replied
    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

    Leave a comment:


  • marci02
    replied
    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!

    Leave a comment:


  • Serialcoder
    replied
    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.

    Leave a comment:


  • aligator
    replied
    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.

    Leave a comment:


  • Serialcoder
    replied
    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?

    Leave a comment:


  • mlarocco
    replied
    Originally posted by Serialcoder View Post
    In the code line 556 add this

    if (newIdentifierName.GetType() != typeof(QualifiedNameSyntax))
    {
    replacements.Add(identifierName, newIdentifierName);
    }

    then fix by hand the ChartBars.FromIndex etc which is causing the error
    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?

    Leave a comment:


  • Serialcoder
    replied
    In the code line 556 add this

    if (newIdentifierName.GetType() != typeof(QualifiedNameSyntax))
    {
    replacements.Add(identifierName, newIdentifierName);
    }

    then fix by hand the ChartBars.FromIndex etc which is causing the error

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by bortz, 11-06-2023, 08:04 AM
47 responses
1,606 views
0 likes
Last Post aligator  
Started by jaybedreamin, Today, 05:56 PM
0 responses
9 views
0 likes
Last Post jaybedreamin  
Started by DJ888, 04-16-2024, 06:09 PM
6 responses
19 views
0 likes
Last Post DJ888
by DJ888
 
Started by Jon17, Today, 04:33 PM
0 responses
6 views
0 likes
Last Post Jon17
by Jon17
 
Started by Javierw.ok, Today, 04:12 PM
0 responses
15 views
0 likes
Last Post Javierw.ok  
Working...
X