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!
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
NinjaTrader
Compile error when passing a flag from njt7 to njt8 help please
Collapse
X
-
Compile error when passing a flag from njt7 to njt8 help please
I would need to help me with the error that throws me when I want to compile an indicator of njt7 to njt8 I had several errors and one I could not remove since there was almost nothing programming. I would appreciate your help. Adding image with the error.Tags: None
-
Hello castapio7,
Rather than using Set to set the data series, if you use,
Value[0] = Volume[0];
Replacing volume with your indicators data series, does that resolve the issue?
Also below I’ve provided a link to code breaking changes which you should consider when converting your scripts:
If you'd like to upload the full code I can take a look and see if anything jumps out. Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
-
THIS IS THE CODE THE ERROR WILL PUT IT IN THE ROW 110
-------------------------------------------------------------------------------------------:confuso:
#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.Xml.Serialization;
using System.Diagnostics;
using System.Drawing;
using System.ComponentModel;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
/// <summary>
/// historic volatility indicator by Michael Krause, [email protected]. http://scriabinop23.blogspot.com
/// 2/1/2008
/// </summary>
[Description("historical volatility")]
public class HistVolAny : Indicator
{
#region Variables
// Wizard generated variables
private int period = 9; // Default setting for Period
private int interval = 6; // Default setting for Interval
private double sumsqdev = 0;
private double sumnatlog = 0;
private double closeratio = 0;
private double mean = 0;
private int sessioncount = 0;
private double histvolatile = 0 ;
private double[] natlog;
private double[] squareddeviation;
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.Red, PlotStyle.Line, "Historic Volatility of any timeframe"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = true;
natlog = new double[period];
squareddeviation = new double[period];
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Only allow this to run in a minute type period.
if (CurrentBar < period+1 ||
(Bars.Period.Id == PeriodType.Tick)
||(Bars.Period.Id == PeriodType.Range)
||(Bars.Period.Id == PeriodType.Second)
||(Bars.Period.Id == PeriodType.Volume)
||(Bars.Period.Id == PeriodType.Year))
{Value.Set(0);
return;}
for (int i=0; i < period; i++)
{
closeratio = Close[i]/Close[i+1];
natlog[i] = Math.Log(closeratio);
}
for (int i=0; i < period; i++)
sumnatlog += natlog[i];
mean = sumnatlog / period;
for (int i=0; i < period; i++)
squareddeviation[i] = Math.Pow(natlog[i] - mean,2) ;
for (int i=0; i < period; i++)
sumsqdev += squareddeviation[i];
if (Bars.Period.Id == PeriodType.Minute)
histvolatile = Math.Sqrt(Math.Abs(sumsqdev/ period)) * Math.Sqrt(252*1440/Bars.Period.Value)*100;
else
if (Bars.Period.Id == PeriodType.Day)
histvolatile = Math.Sqrt(Math.Abs(sumsqdev/ period)) * Math.Sqrt(252/Bars.Period.Value)*100;
else
if (Bars.Period.Id == PeriodType.Week)
histvolatile = Math.Sqrt(Math.Abs(sumsqdev/ period)) * Math.Sqrt(52/Bars.Period.Value)*100;
if (Bars.Period.Id == PeriodType.Month)
histvolatile = Math.Sqrt(Math.Abs(sumsqdev/ period)) * Math.Sqrt(12/Bars.Period.Value)*100;
sumnatlog =0; //reset variables for next iteration
sumsqdev =0; //ditto
Value.Set(histvolatile);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Value
{
get { return Values[0]; }
}
[Description("period")]
[Category("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private HistVolAny[] cacheHistVolAny;
public HistVolAny HistVolAny()
{
return HistVolAny(Input);
}
public HistVolAny HistVolAny(ISeries<double> input)
{
if (cacheHistVolAny != null)
for (int idx = 0; idx < cacheHistVolAny.Length; idx++)
if (cacheHistVolAny[idx] != null && cacheHistVolAny[idx].EqualsInput(input))
return cacheHistVolAny[idx];
return CacheIndicator<HistVolAny>(new HistVolAny(), input, ref cacheHistVolAny);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.HistVolAny HistVolAny()
{
return indicator.HistVolAny(Input);
}
public Indicators.HistVolAny HistVolAny(ISeries<double> input )
{
return indicator.HistVolAny(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.HistVolAny HistVolAny()
{
return indicator.HistVolAny(Input);
}
public Indicators.HistVolAny HistVolAny(ISeries<double> input )
{
return indicator.HistVolAny(input);
}
}
}
#endregion
Comment
-
historical volatility
I was left with some errors I think that solving these would already be
I gave you the code and would like to thank you for the help we could do?
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Xml.Serialization;
using System.Collections.Generic;
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.Media3D;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
[Description("historical volatility")]
public class HistVolAny : Indicator
{
#region Variables
// Wizard generated variables
private int period =40; // Default setting for Period
private int interval = 6; // Default setting for Interval
private double sumsqdev = 0;
private double sumnatlog = 0;
private double closeratio = 0;
private double mean = 0;
private int sessioncount = 0;
private double histvolatile = 0 ;
private double[] natlog;
private double[] squareddeviation;
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void OnStateChange()
{
AddPlot(new Stroke(Brushes.Blue), PlotStyle.Line, "Historic Volatility of any timeframe");
Calculate = Calculate.OnBarClose;
IsOverlay = true;
PriceTypeSupported = true;
natlog = new double[period];
squareddeviation = new double[period];
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Only allow this to run in a minute type period.
if (CurrentBar < period+1 ||
(Bars.Period.Id == PeriodType.Tick)
||(Bars.Period.Id == PeriodType.Range)
||(Bars.Period.Id == PeriodType.Second)
||(Bars.Period.Id == PeriodType.Volume)
||(Bars.Period.Id == PeriodType.Year))
{Value.Set(0);
return;}
for (int i=0; i < period; i++)
{
closeratio = Close[i]/Close[i+1];
natlog[i] = Math.Log(closeratio);
}
for (int i=0; i < period; i++)
sumnatlog += natlog[i];
mean = sumnatlog / period;
for (int i=0; i < period; i++)
squareddeviation[i] = Math.Pow(natlog[i] - mean,2) ;
for (int i=0; i < period; i++)
sumsqdev += squareddeviation[i];
if (Bars.Period.Id == PeriodType.Minute)
histvolatile = Math.Sqrt(Math.Abs(sumsqdev/ period)) * Math.Sqrt(252*1440/Bars.Period.Value)*100;
else
if (Bars.Period.Id == PeriodType.Day)
histvolatile = Math.Sqrt(Math.Abs(sumsqdev/ period)) * Math.Sqrt(252/Bars.Period.Value)*100;
else
if (Bars.Period.Id == PeriodType.Week)
histvolatile = Math.Sqrt(Math.Abs(sumsqdev/ period)) * Math.Sqrt(52/Bars.Period.Value)*100;
if (Bars.Period.Id == PeriodType.Month)
histvolatile = Math.Sqrt(Math.Abs(sumsqdev/ period)) * Math.Sqrt(12/Bars.Period.Value)*100;
sumnatlog =0; //reset variables for next iteration
sumsqdev =0; //ditto
Value.Set(histvolatile);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
//public DataSeries Value
public Series<double> Value
{
get { return Values[0]; }
}
[Description("period")]
[Category("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private HistVolAny[] cacheHistVolAny;
public HistVolAny HistVolAny()
{
return HistVolAny(Input);
}
public HistVolAny HistVolAny(ISeries<double> input)
{
if (cacheHistVolAny != null)
for (int idx = 0; idx < cacheHistVolAny.Length; idx++)
if (cacheHistVolAny[idx] != null && cacheHistVolAny[idx].EqualsInput(input))
return cacheHistVolAny[idx];
return CacheIndicator<HistVolAny>(new HistVolAny(), input, ref cacheHistVolAny);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.HistVolAny HistVolAny()
{
return indicator.HistVolAny(Input);
}
public Indicators.HistVolAny HistVolAny(ISeries<double> input )
{
return indicator.HistVolAny(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.HistVolAny HistVolAny()
{
return indicator.HistVolAny(Input);
}
public Indicators.HistVolAny HistVolAny(ISeries<double> input )
{
return indicator.HistVolAny(input);
}
}
}
#endregion
Comment
-
Hello castapio7,
Please export the strategy in the following format and upload it so I may test on my end,
From the Control Center window select Tools -> Export -> NinjaScript...
Click Add>Select the indicator>OK>Export.
Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.
Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.
I look forward to your reply.Alan P.NinjaTrader Customer Service
Comment
-
attachment
He would not let me export it because he has an error. I give it to you in txtAttached Files
Comment
-
Hello castapio7,
The compile errors throughout the script are related to using code from NT7 in NT8. Converting customer code is out of the scope of NinjaScript support however if you’d like I could have someone from our business development team pass over a list of third party developers that you could contact about debugging your code.
There is not an official indicator/strategy converter which takes scripts from NT7 and converts them to NT8 however on the forum there is a post which provides script for conversion.
I’d like to mention its best to do a manual conversion for accuracy as not all scripts are simple enough to be converted directly.
Also below I’ve provided a link to code breaking changes which you should consider when converting your scripts:
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Comment
-
Hi, sorry interrupting your nice conversation,
here is my fast question:
does NT8 have the PriceTypeSupported property?
help says yes, but compiler in NT8 says no
NinjaScript File Error Code Line Column
test.cs The name 'PriceTypeSupported' does not exist in the current context CS0103 31 4
Comment
-
Hello senderz,
The default behavior is price type supported is true in NT8. You select the price type in the UI by clicking the Input series, and selecting the desired type.
Going forward if you would please open new threads when the question is not related to the earlier conversation.
Thank you.Alan P.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_AlanP View PostHello senderz,
The default behavior is price type supported is true in NT8. You select the price type in the UI by clicking the Input series, and selecting the desired type.
Going forward if you would please open new threads when the question is not related to the earlier conversation.
Thank you.
but question was - why the NT8 code breaking page is misleading?
Please remove the info shown on my picture for NT8
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Barry Milan, Today, 10:35 PM
|
2 responses
8 views
0 likes
|
Last Post
by Barry Milan
Today, 11:50 PM
|
||
Started by WeyldFalcon, 12-10-2020, 06:48 PM
|
14 responses
1,428 views
0 likes
|
Last Post
by Handclap0241
Today, 10:43 PM
|
||
Started by DJ888, Yesterday, 06:09 PM
|
2 responses
9 views
0 likes
|
Last Post
by DJ888
Today, 10:31 PM
|
||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
41 views
0 likes
|
Last Post
by jeronymite
Today, 10:10 PM
|
||
Started by bill2023, Today, 08:51 AM
|
2 responses
16 views
0 likes
|
Last Post
by bill2023
Today, 10:10 PM
|
Comment