NinjaTrader 8
Guide on how to integrate licensing library into NinjaScripts
Adding licensing to your NinjaScript
using System;
using System.Reflection;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using PoshTrader.Licensing;
namespace NinjaTrader.NinjaScript.Indicators
{
[Item(ID, "Sample Indicator", Version = "1.0.0", Author = "John Doe")]
public class SampleIndicator : Indicator
{
private ItemLicense _license;
protected override void OnStateChange()
{
if (State == State.Configure)
{
try
{
var assembly = Assembly.GetAssembly(typeof(ItemLicense));
var certificate = X509Certificate.CreateFromSignedFile(assembly.Location);
if (certificate.GetCertHashString() != "07FF85A977EF497368AA1ADEB64D43B2B55BD4D8")
{
throw new Exception("Could not validate 'PoshTrader.Licensing' assembly origin.");
}
}
catch (CryptographicException)
{
throw new Exception("Could not load 'PoshTrader.Licensing' assembly certificate. Platform restart might be required.");
}
}
else if (State == State.DataLoaded)
{
_license = new Licensing(this);
if (!_license.IsValid())
{
throw new Exception("Product license validation failed.");
}
}
}
protected override void OnBarUpdate()
{
if (!_license.IsValid())
return;
// Put your OnBarUpdate logic here
}
}
}Creating a distribution file
Last updated