Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Here's a script to convert indicators and strategies
Collapse
X
-
Hello, thank wbennettjr for the script, though some files falls out with errors, it would be nice this thing to visualize, as a variant of working not with the file once and for example by line, made a small workpiece in windose forms, open and save files one by one, can someone would be so convenient.
Excuse my bad English.
Reference to the file and source code
Last edited by Gellyus; 10-28-2015, 08:52 AM.
-
Sorry to hear that Skann .
I need a bit more context to diagnose. I've uploaded a new version of the script that adds an exception handler so I can get a stacktrace. Please download, run and send me the output so I can fix.
Thanks!
Leave a comment:
-
Originally posted by skann29 View PostGetting the error as attached.
"InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.QualifiedNam eSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSy ntax'."
Leave a comment:
-
Originally posted by wbennettjr View PostAttached is a C# script to convert NT7 indicators and strategies to NT8. It should convert most indicators without them needing any modifications. See below for limitations.
The start of the script looks as follows:
Code:bool testing = false; // "true" to convert test scripts when making changes. bool convertIndicators = true; // "true" to convert indicators. bool convertStrategies = true; // "true" to convert strategies. string indicatorSourceFolder = @"C:\Users\UserName\Documents\NinjaTrader 7\bin\Custom\Indicator"; string indicatorDestinationFolder = @"C:\Users\UserName\Documents\NinjaTrader 8\bin\Custom\Indicators"; string indicatorFilesToConvert = "*.cs"; string strategySourceFolder = @"C:\Users\UserName\Documents\NinjaTrader 7\bin\Custom\Strategy"; string strategyDestinationFolder = @"C:\Users\UserName\Documents\NinjaTrader 8\bin\Custom\Strategies"; string strategyFilesToConvert = "*.cs";
- Backup your NT7 indicators and scripts in case you enter the wrong folders below.
- Download LINQPad 5 at www.linqpad.net. It's a free C# (and VB, F#, SQL) script runner - if you don't need intellisense. The script is a text file with full source (using .Net 4.6). If you don't want to use LINQPad, you can put the code in a console application (or WPF or whatever) instead - it needs the Microsoft code analysis Nuget package.
- Download the attached script, remove the ".txt" extension, open in LINQPad and make the following changes:
- Change the indicatorSourceFolder variable to match where you have your NT7 indicators
- Change the indicatorDestinationFolder variable to match where you have your NT8 indicators.
- Change the strategySourceFolder variable to match where you have your NT7 strategies
- Change the strategyDestinationFolder variable to match where you have your NT8 strategies.
- Click the green right arrow button to run (or press F5).
Notes on conversion:- UserDefinedMethods.cs will need manual updating. If you don't have any changes to it that you need, you can just delete the NT8 converted version. If you have made changes to it that you need, you'll need to manually move the NT8 converted version into the AddOns folder and make the appropriate changes as stated in the NT8 documentation.
- The script uses only syntactic analysis - no semantic analysis is done so there are a few things it won't be able to convert and others it may get wrong. It worked for all the stock indicators (with the exceptions listed below) so I didn't feel the need to go through the extra hassle.
- Statements such as "Plots[0].Pen.DashStyle = DashStyle.Dash;" will convert to "Plots[0].Pen.DashStyle = DashStyleHelper.Dash;". This is one of the cases that would need semantic analysis to fix. Simply remove the "Helper" text.
- Some functions have changed signatures that will require simple manual fixing after conversion. Mostly the Draw* functions (16 overloads have changed - the rest are fine) are affected. Look at the sample indicator text at the bottom of the script to get an idea of what changes are needed.
- If the indicator overrides Plot, it will most likely require manual changes. There is no conversion to the DX API. This means classes such as StringFormat and SolidBrush won't convert since they are normally used for painting and the API is significantly different.
- The indicator/strategy must be the first or only class in the file.
- If something doesn't convert that you believe should have, there is a list of lookups below the initial setup portion of the script. You can try adding the appropriate lookup values.
Notes on making script changes:
If you want to make modifications to the script, you should probably set the "testing" variable to true. This will cause the indicators and strategies to be ignored and instead convert the sample indicator and strategy that are in string variables at the bottom of the script. These samples will allow you to quickly know if your changes have broken anything else. You can modify these samples to include code that allows testing the changes you are making. The output will go into the appropriate NT8 folder so you will need to remove these once you are done. The files will be named "ConversionSample.cs" for both indicator and strategy.
This was quickly put together to convert my code. I then went back and added the rest of the changes listed in the documentation. If you run into any bugs, feel free to make changes or post here and I will fix it if I have time. If you've made changes, it will probably be a good idea to post here so others may benefit.
Getting the error as attached.Last edited by skann29; 10-25-2015, 11:58 AM.
Leave a comment:
-
Thanks Joni! I've added those (and OnExecution) to the _renamedVirtualMethods lookup and uploaded the new file.
Leave a comment:
-
Joni2 I don't think any changes need to be made see ninjatrader.com/support/helpGuides/nt8/en-us/
for additional confirmation in the ninja script section
Leave a comment:
-
OnOrderUpdate, OnPositionUpdate
Hi wbennettjr.
For Strategy not converted:
OnOrderUpdate
OnPositionUpdate
Leave a comment:
-
Hi Taddypole,
Thanks for the suggestions. I've updated the procedures accordingly.
I've also added a note about StringFormat and SolidBrush. These are normally used with the Plot (OnRender) method to paint the graphics of the indicator. The API for doing this has changed significantly in NT8 - they are now using the SharpDX API. As a result, StringFormat is no longer being used - it's in System.Windows.Drawing which is not used in NT8. They have switched, it seems, to a TextLayout class for which there isn't a simple one to one mapping. StringFormat was being used with Graphics.DrawString(). Now there is a RenderTarget.DrawTextLayout() method that is being used in NT8. You can have a look at the @BarTimer.cs file for an example of how it's used (or do a search through the indicators for DrawTextLayout).
As stated in the post, there is no conversion to the SharpDX API - would be much too complicated and error prone. Plot (OnRender) methods will need to be manually updated to the new API.
Changes you need to make:
In your example, you would need to change:
Code:private SolidBrush barBrush = new SolidBrush(Brushes.FromArgb(127, Brushes.Violet));
Code:private SolidColorBrush barBrush = new SolidColorBrush(Color.FromArgb(127, Brushes.Violet.Color.R, Brushes.Violet.Color.G, Brushes.Violet.Color.B));
More on SolidBrush:
SolidBrush is also a little more complicated to convert. In NT7 (System.Windows.Drawing), it's possible to create these with the following:
Code:var solidBrush1 = new SolidBrush(Color.White); var solidBrush2 = new SolidBrush(Color.FromName("ActiveBorder")); var solidBrush3 = new SolidBrush(Color.FromKnownColor(KnownColor.ActiveBorder)); var solidBrush4 = new SolidBrush(Color.FromArgb(1, 1, 1, 1)); var solidBrush5 = new SolidBrush(Color.FromArgb(1, 1, 1)); var solidBrush6 = new SolidBrush(Color.FromArgb(1, Color.White));
Code:var solidBrush1 = new SolidColorBrush(); var solidBrush2 = new SolidColorBrush(Color.FromArgb(1, 1, 1, 1)); var solidBrush3 = new SolidColorBrush(Color.FromRgb(1, 1, 1));
Last edited by wbennettjr; 10-24-2015, 10:16 AM.
Leave a comment:
-
Help with Conversion Error Messages
I followed the procedure to convert some of my indicators but ran into some problems I can't solve. I looked in the mentioned references but could not find any reference to:
1. StringFormat
2. SolidBrush
How do I correct these errors?
regards,
taddypole...
Also in the procedure, "Steps for Conversion" 4 - 7... it took me a bit of time to figure out those steps referred to lines of code in the "NT7toNT8" file loaded into LINQPad5. Maybe a few more words in the procedure to help those like me.
Leave a comment:
-
Here's a script to convert indicators and strategies
Attached is a C# script to convert NT7 indicators and strategies to NT8. It should convert most indicators without them needing any modifications. See below for limitations.
The start of the script looks as follows:
Code:bool testing = false; // "true" to convert test scripts when making changes. bool convertIndicators = true; // "true" to convert indicators. bool convertStrategies = true; // "true" to convert strategies. string indicatorSourceFolder = @"C:\Users\UserName\Documents\NinjaTrader 7\bin\Custom\Indicator"; string indicatorDestinationFolder = @"C:\Users\UserName\Documents\NinjaTrader 8\bin\Custom\Indicators"; string indicatorFilesToConvert = "*.cs"; string strategySourceFolder = @"C:\Users\UserName\Documents\NinjaTrader 7\bin\Custom\Strategy"; string strategyDestinationFolder = @"C:\Users\UserName\Documents\NinjaTrader 8\bin\Custom\Strategies"; string strategyFilesToConvert = "*.cs";
- Backup your NT7 indicators and scripts in case you enter the wrong folders below.
- Download LINQPad 5 at www.linqpad.net. It's a free C# (and VB, F#, SQL) script runner - if you don't need intellisense. The script is a text file with full source (using .Net 4.6). If you don't want to use LINQPad, you can put the code in a console application (or WPF or whatever) instead - it needs the Microsoft code analysis Nuget package.
- Download the attached script, remove the ".txt" extension, open in LINQPad and make the following changes:
- Change the indicatorSourceFolder variable to match where you have your NT7 indicators
- Change the indicatorDestinationFolder variable to match where you have your NT8 indicators.
- Change the strategySourceFolder variable to match where you have your NT7 strategies
- Change the strategyDestinationFolder variable to match where you have your NT8 strategies.
- Click the green right arrow button to run (or press F5).
Notes on conversion:- UserDefinedMethods.cs will need manual updating. If you don't have any changes to it that you need, you can just delete the NT8 converted version. If you have made changes to it that you need, you'll need to manually move the NT8 converted version into the AddOns folder and make the appropriate changes as stated in the NT8 documentation.
- The script uses only syntactic analysis - no semantic analysis is done so there are a few things it won't be able to convert and others it may get wrong. It worked for all the stock indicators (with the exceptions listed below) so I didn't feel the need to go through the extra hassle.
- Statements such as "Plots[0].Pen.DashStyle = DashStyle.Dash;" will convert to "Plots[0].Pen.DashStyle = DashStyleHelper.Dash;". This is one of the cases that would need semantic analysis to fix. Simply remove the "Helper" text.
- Some functions have changed signatures that will require simple manual fixing after conversion. Mostly the Draw* functions (16 overloads have changed - the rest are fine) are affected. Look at the sample indicator text at the bottom of the script to get an idea of what changes are needed.
- If the indicator overrides Plot, it will most likely require manual changes. There is no conversion to the DX API. This means classes such as StringFormat and SolidBrush won't convert since they are normally used for painting and the API is significantly different.
- The indicator/strategy must be the first or only class in the file.
- If something doesn't convert that you believe should have, there is a list of lookups below the initial setup portion of the script. You can try adding the appropriate lookup values.
Notes on making script changes:
If you want to make modifications to the script, you should probably set the "testing" variable to true. This will cause the indicators and strategies to be ignored and instead convert the sample indicator and strategy that are in string variables at the bottom of the script. These samples will allow you to quickly know if your changes have broken anything else. You can modify these samples to include code that allows testing the changes you are making. The output will go into the appropriate NT8 folder so you will need to remove these once you are done. The files will be named "ConversionSample.cs" for both indicator and strategy.
This was quickly put together to convert my code. I then went back and added the rest of the changes listed in the documentation. If you run into any bugs, feel free to make changes or post here and I will fix it if I have time. If you've made changes, it will probably be a good idea to post here so others may benefit.Attached Files
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by JGriff5646, Today, 10:02 PM
|
0 responses
6 views
0 likes
|
Last Post
by JGriff5646
Today, 10:02 PM
|
||
Started by AdamDJ8, Today, 09:18 PM
|
0 responses
3 views
0 likes
|
Last Post
by AdamDJ8
Today, 09:18 PM
|
||
Started by knowmad, Today, 03:52 AM
|
2 responses
29 views
0 likes
|
Last Post
by knowmad
Today, 09:03 PM
|
||
Started by ETFVoyageur, Today, 07:05 PM
|
0 responses
11 views
0 likes
|
Last Post
by ETFVoyageur
Today, 07:05 PM
|
||
Started by Orion815, 05-02-2024, 08:39 AM
|
2 responses
18 views
0 likes
|
Last Post
by Orion815
Today, 06:24 PM
|
Leave a comment: