Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Updated October 25, 2023
Top Posters
looks_one
jojojo
with 2 posts (0 thanks)
looks_two
MerlinWorld
with 2 posts (0 thanks)
looks_3
olobay
with 1 posts (0 thanks)
looks_4
Zambi
with 1 posts (0 thanks)
trending_up
1,757 views
thumb_up
0 thanks given
group
4 followers
forum
5 posts
attach_file
2 attachments
August 2nd, 2019, 07:24 PM
Montreal
Posts: 128 since Jan 2013
Hi guys,
Just want to know if there are any Multicharts .NET programmers here?
I have a few programmers that know C# but apparently, that's not enough, you need to know how to program SPECIFICALLY for Multicharts .NET
For example this is the code that a programmer wrote in C# but it seems to work only on NinjaTrader but not on MultiCharts even though both platforms uses C#.
Anyone can help?
Code
#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 NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class _MW_Clouds : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Merlin's Clouds";
Name = "_MW_Clouds";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
Range1 = 6;
Range2 = 8;
Range3 = 10;
Range4 = 12;
ShowST = true ;
ShowMT = true ;
BandOpacity = 50 ;
AddPlot(Brushes.Transparent, "MM1");
AddPlot(Brushes.Transparent, "MM2");
AddPlot(Brushes.Transparent, "MM3");
AddPlot(Brushes.Transparent, "MM4");
}
else if (State == State.Configure)
{
}
}
System.Windows.Media.Brush color1 = Brushes.White ;
System.Windows.Media.Brush color2 = Brushes.DeepSkyBlue ;
System.Windows.Media.Brush color3 = Brushes.DimGray ;
System.Windows.Media.Brush color4 = Brushes.Blue ;
double hh1 = 0 ;
double ll1 = 0 ;
double hh2 = 0 ;
double ll2 = 0 ;
double hh3 = 0 ;
double ll3 = 0 ;
double hh4 = 0 ;
double ll4 = 0 ;
int sregnum = 0 ;
int mregnum = 0 ;
DateTime start_time1 ;
DateTime start_time2 ;
System.Windows.Media.Brush pcolor1 = Brushes.Transparent ;
System.Windows.Media.Brush pcolor2 = Brushes.Transparent ;
protected override void OnBarUpdate()
{
if( CurrentBar == 0 ) { start_time1 = Time[0] ; start_time2 = Time[0] ; }
if( High[0] >= hh1 ) { hh1 = High[0] ; }
if( ll1 < ( hh1 - Range1 )) { ll1 = hh1 - Range1 ; }
if( Low[0] <= ll1 ) { ll1 = Low[0] ; }
if( hh1 > ( ll1 + Range1 ) ) { hh1 = ll1 + Range1 ; }
MM1[0] = ( hh1 + ll1 ) / 2 ; ;
if( High[0] >= hh2 ) { hh2 = High[0] ; }
if( ll2 < ( hh2 - Range2 ) ) { ll2 = hh2 - Range2 ; }
if( Low[0] <= ll2 ) { ll2 = Low[0] ; }
if( hh2 > ( ll2 + Range2 ) ) { hh2 = ll2 + Range2 ; }
MM2[0] = ( hh2 + ll2 ) / 2 ;
if( High[0] >= hh3 ) { hh3 = High[0] ; }
if( ll3 < ( hh3 - Range3 ) ) { ll3 = hh3 - Range3 ; }
if( Low[0] <= ll3 ) { ll3 = Low[0] ; }
if( hh3 > ( ll3 + Range3 ) ) { hh3 = ll3 + Range3 ; }
MM3[0] = ( hh3 + ll3 ) / 2 ;
if( High[0] >= hh4 ) { hh4 = High[0] ; }
if( ll4 < ( hh4 - Range4 ) ) { ll4 = hh4 - Range4 ; }
if( Low[0] <= ll4 ) { ll4 = Low[0] ; }
if( hh4 > ( ll4 + Range4 ) ) { hh4 = ll4 + Range4 ; }
MM4[0] = ( hh4 + ll4 ) / 2 ;
if( CurrentBar < 5 ) { return ; }
System.Windows.Media.Brush mycolor1 = MM1[0] > MM2[0] ? color1 : color2 ;
System.Windows.Media.Brush mycolor2 = MM1[0] > MM3[0] ? color3 : color4 ;
if( pcolor1 != mycolor1 )
{
start_time1 = Time[0] ;
sregnum++ ;
}
pcolor1 = mycolor1 ;
if( pcolor2 != mycolor2 )
{
start_time2 = Time[0] ;
mregnum++ ;
}
pcolor2 = mycolor2 ;
if( ShowST ) { Draw.Region(this,"SREG"+sregnum,start_time1,Time[0],MM1,MM2,null,mycolor1,BandOpacity); }
if( ShowMT ) { Draw.Region(this,"MREG"+mregnum,start_time2,Time[0],MM3,MM4,null,mycolor2,BandOpacity); }
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Range1", Description="(Short term) Range1 in Points", Order=1, GroupName="Parameters")]
public int Range1
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Range2", Description="(Short term) Range2 in Points", Order=2, GroupName="Parameters")]
public int Range2
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Range3", Description="(Medium term) Range3 in Points", Order=3, GroupName="Parameters")]
public int Range3
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Range4", Description="(Medium term) Range4 in Points", Order=4, GroupName="Parameters")]
public int Range4
{ get; set; }
[NinjaScriptProperty]
[Display(Name="Show short term band", Description="Show or hide the short term band.", Order=5, GroupName="Parameters")]
public bool ShowST
{ get; set; }
[NinjaScriptProperty]
[Display(Name="Show medium term band", Description="Show or hide the medium term band.", Order=6, GroupName="Parameters")]
public bool ShowMT
{ get; set; }
[NinjaScriptProperty]
[Range(0, 100)]
[Display(Name="Band opacity", Description="Band Opacity (0-100)", Order=7, GroupName="Parameters")]
public int BandOpacity
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> MM1
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> MM2
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> MM3
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> MM4
{
get { return Values[3]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private _MW_Clouds[] cache_MW_Clouds;
public _MW_Clouds _MW_Clouds(int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return _MW_Clouds(Input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
public _MW_Clouds _MW_Clouds(ISeries<double> input, int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
if (cache_MW_Clouds != null)
for (int idx = 0; idx < cache_MW_Clouds.Length; idx++)
if (cache_MW_Clouds[idx] != null && cache_MW_Clouds[idx].Range1 == range1 && cache_MW_Clouds[idx].Range2 == range2 && cache_MW_Clouds[idx].Range3 == range3 && cache_MW_Clouds[idx].Range4 == range4 && cache_MW_Clouds[idx].ShowST == showST && cache_MW_Clouds[idx].ShowMT == showMT && cache_MW_Clouds[idx].BandOpacity == bandOpacity && cache_MW_Clouds[idx].EqualsInput(input))
return cache_MW_Clouds[idx];
return CacheIndicator<_MW_Clouds>(new _MW_Clouds(){ Range1 = range1, Range2 = range2, Range3 = range3, Range4 = range4, ShowST = showST, ShowMT = showMT, BandOpacity = bandOpacity }, input, ref cache_MW_Clouds);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators._MW_Clouds _MW_Clouds(int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return indicator._MW_Clouds(Input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
public Indicators._MW_Clouds _MW_Clouds(ISeries<double> input , int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return indicator._MW_Clouds(input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators._MW_Clouds _MW_Clouds(int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return indicator._MW_Clouds(Input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
public Indicators._MW_Clouds _MW_Clouds(ISeries<double> input , int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return indicator._MW_Clouds(input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
}
}
#endregion
Does anyone see the bug here? This is the compiling errors it gives me in the PowerLanguage Editor...
Thanks
Merlin
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
August 2nd, 2019, 10:28 PM
Montreal
Experience: Intermediate
Platform: MultiCharts
Broker: DeepDiscountTrading.com
Trading: CL
Posts: 364 since Jul 2011
I don't know C# but for sure it won't work in MC when you are using NinjaTrader in the code.
Code
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
August 3rd, 2019, 05:50 AM
Montreal
Posts: 128 since Jan 2013
olobay
I don't know C# but for sure it won't work in MC when you are using
NinjaTrader in the code.
Code
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
he he, no shit Sherlock! I saw that the second I opened the script.
However that STILL doesn't fix it. Should I just replace NinjaTrader by Multicharts or PowerLanguage? Could it be THAT easy?
What are these "namespace" and "assembly reference" things?
Somebody will know the answer to that.
August 22nd, 2019, 07:19 AM
Scottsdale
Posts: 34 since Nov 2010
Thanks Given: 6
Thanks Received: 22
Hi Merlin.
Converted what I could, but only as far as creating the plots (kept them in different colors). The "Draw Region" part is the most important I guess, but maybe you can give that a try. I hope this helps.
Code
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator
{
[SameAsSymbol(true)]
public class _MW_Clouds : IndicatorObject
{
public _MW_Clouds(object _ctx):base(_ctx)
{
Range1 = 6;
Range2 = 8;
Range3 = 10;
Range4 = 12;
ShowST = true ;
ShowMT = true ;
BandOpacity = 50 ;
}
/*
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Merlin's Clouds";
Name = "_MW_Clouds";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
Range1 = 6;
Range2 = 8;
Range3 = 10;
Range4 = 12;
ShowST = true ;
ShowMT = true ;
BandOpacity = 50 ;
AddPlot(Color.Transparent, "MM1");
AddPlot(Color.Transparent, "MM2");
AddPlot(Color.Transparent, "MM3");
AddPlot(Color.Transparent, "MM4");
}
else if (State == State.Configure)
{
}
}
*/
private IPlotObject Plot1;
private IPlotObject MM1_plot, MM2_plot, MM3_plot, MM4_plot;
protected override void Create()
{
MM1 = new VariableSeries<Double>(this);
MM2 = new VariableSeries<Double>(this);
MM3 = new VariableSeries<Double>(this);
MM4 = new VariableSeries<Double>(this);
Plot1 =
AddPlot(new PlotAttributes("Avg", 0, Color.Yellow,
Color.Empty, 0, 0, true));
MM1_plot = AddPlot(new PlotAttributes("MM1", EPlotShapes.Line, Color.Red));
MM2_plot = AddPlot(new PlotAttributes("MM2", EPlotShapes.Line, Color.Green));
MM3_plot = AddPlot(new PlotAttributes("MM3", EPlotShapes.Line, Color.Blue));
MM4_plot = AddPlot(new PlotAttributes("MM4", EPlotShapes.Line, Color.Yellow));
}
protected override void StartCalc() {
// assign inputs
}
Color color1 = Color.White ;
Color color2 = Color.DeepSkyBlue ;
Color color3 = Color.DimGray ;
Color color4 = Color.Blue ;
double hh1 = 0 ;
double ll1 = 0 ;
double hh2 = 0 ;
double ll2 = 0 ;
double hh3 = 0 ;
double ll3 = 0 ;
double hh4 = 0 ;
double ll4 = 0 ;
int sregnum = 0 ;
int mregnum = 0 ;
DateTime start_time1 ;
DateTime start_time2 ;
Color pcolor1 = Color.Transparent ;
Color pcolor2 = Color.Transparent ;
protected override void CalcBar()
{
if( Bars.CurrentBar == 0 ) { start_time1 = Bars.Time[0] ; start_time2 = Bars.Time[0] ; }
if( Bars.High[0] >= hh1 ) { hh1 = Bars.High[0] ; }
if( ll1 < ( hh1 - Range1 )) { ll1 = hh1 - Range1 ; }
if( Bars.Low[0] <= ll1 ) { ll1 = Bars.Low[0] ; }
if( hh1 > ( ll1 + Range1 ) ) { hh1 = ll1 + Range1 ; }
MM1.Value = ( hh1 + ll1 ) / 2 ;
MM1_plot.Set(0, MM1.Value);
if( Bars.High[0] >= hh2 ) { hh2 = Bars.High[0] ; }
if( ll2 < ( hh2 - Range2 ) ) { ll2 = hh2 - Range2 ; }
if( Bars.Low[0] <= ll2 ) { ll2 = Bars.Low[0] ; }
if( hh2 > ( ll2 + Range2 ) ) { hh2 = ll2 + Range2 ; }
MM2.Value = ( hh2 + ll2 ) / 2 ;
MM2_plot.Set(0, MM2[0]);
if( Bars.High[0] >= hh3 ) { hh3 = Bars.High[0] ; }
if( ll3 < ( hh3 - Range3 ) ) { ll3 = hh3 - Range3 ; }
if( Bars.Low[0] <= ll3 ) { ll3 = Bars.Low[0] ; }
if( hh3 > ( ll3 + Range3 ) ) { hh3 = ll3 + Range3 ; }
MM3.Value = ( hh3 + ll3 ) / 2 ;
MM3_plot.Set(0, MM3[0]);
if( Bars.High[0] >= hh4 ) { hh4 = Bars.High[0] ; }
if( ll4 < ( hh4 - Range4 ) ) { ll4 = hh4 - Range4 ; }
if( Bars.Low[0] <= ll4 ) { ll4 = Bars.Low[0] ; }
if( hh4 > ( ll4 + Range4 ) ) { hh4 = ll4 + Range4 ; }
MM4.Value = ( hh4 + ll4 ) / 2 ;
MM4_plot.Set(0, MM4[0]);
if( Bars.CurrentBar < 5 ) { return ; }
Color mycolor1 = MM1[0] > MM2[0] ? color1 : color2 ;
Color mycolor2 = MM1[0] > MM3[0] ? color3 : color4 ;
if( pcolor1 != mycolor1 )
{
start_time1 = Bars.Time[0] ;
sregnum++ ;
}
pcolor1 = mycolor1 ;
if( pcolor2 != mycolor2 )
{
start_time2 = Bars.Time[0] ;
mregnum++ ;
}
pcolor2 = mycolor2 ;
//if( ShowST ) { Draw.Region(this,"SREG"+sregnum,start_time1,Time[0],MM1,MM2,null,mycolor1,BandOpacity); }
//if( ShowMT ) { Draw.Region(this,"MREG"+mregnum,start_time2,Time[0],MM3,MM4,null,mycolor2,BandOpacity); }
}
#region Properties
//[NinjaScriptProperty]
[Input]
//[Range(1, int.MaxValue)]
//[Display(Name="Range1", Description="(Short term) Range1 in Points", Order=1, GroupName="Parameters")]
public int Range1
{ get; set; }
//[NinjaScriptProperty]
[Input]
//[Range(1, int.MaxValue)]
//[Display(Name="Range2", Description="(Short term) Range2 in Points", Order=2, GroupName="Parameters")]
public int Range2
{ get; set; }
//[NinjaScriptProperty]
[Input]
//[Range(1, int.MaxValue)]
//[Display(Name="Range3", Description="(Medium term) Range3 in Points", Order=3, GroupName="Parameters")]
public int Range3
{ get; set; }
//[NinjaScriptProperty]
[Input]
//[Range(1, int.MaxValue)]
//[Display(Name="Range4", Description="(Medium term) Range4 in Points", Order=4, GroupName="Parameters")]
public int Range4
{ get; set; }
//[NinjaScriptProperty]
[Input]
//[Display(Name="Show short term band", Description="Show or hide the short term band.", Order=5, GroupName="Parameters")]
public bool ShowST
{ get; set; }
//[NinjaScriptProperty]
[Input]
//[Display(Name="Show medium term band", Description="Show or hide the medium term band.", Order=6, GroupName="Parameters")]
public bool ShowMT
{ get; set; }
//[NinjaScriptProperty]
[Input]
//[Range(0, 100)]
//[Display(Name="Band opacity", Description="Band Opacity (0-100)", Order=7, GroupName="Parameters")]
public int BandOpacity
{ get; set; }
//[Browsable(false)]
//[XmlIgnore]
public VariableSeries<double> MM1
{
get; set;//get { return Values[0]; }
}
//[Browsable(false)]
//[XmlIgnore]
public VariableSeries<double> MM2
{
get; set;//get { return Values[1]; }
}
//[Browsable(false)]
//[XmlIgnore]
public VariableSeries<double> MM3
{
get; set;//get { return Values[2]; }
}
//[Browsable(false)]
//[XmlIgnore]
public VariableSeries<double> MM4
{
get; set;//get { return Values[3]; }
}
#endregion
}
}
October 25th, 2023, 05:35 AM
FrankfurtGermany
Experience: Beginner
Platform: Tradestation
Posts: 43 since Oct 2010
Thanks Given: 4
Thanks Received: 7
well a while ago , but congrats for this conversion .
Great work .
Clouds
October 25th, 2023, 05:50 AM
FrankfurtGermany
Experience: Beginner
Platform: Tradestation
Posts: 43 since Oct 2010
Thanks Given: 4
Thanks Received: 7
I stuck with a function , compiles but then gives me an error
Null Reference Exception at line 40
using System;
using System.Drawing;
using System.Linq;
namespace PowerLanguage
{
namespace Function
{
public sealed class BWT_smooth : FunctionSeries<System.Double>
{
public BWT_smooth(CStudyControl _master) : base(_master) { }
public BWT_smooth(CStudyControl _master, int _ds) : base(_master, _ds) { }
//public static double Price{private get; set;}
public ISeries<double> Price {private get; set; }
public Int32 Length { get; set; }
//public VariableSeries<double> Var { get; set; }
protected override void Create()
{
// create variable objects and function objects
//if (Var1 != null)
//Var = new VariableSeries<double>(this);
}
protected override void StartCalc()
{
// assign inputs
}
protected override System.Double CalcBar()
{
// function logic
//Fehler in 39 NullReferenceException
double result = 0;
double Var1 = Price[0]; double Var2 = Price[0]; double Var3 = Price[0]; double Var4 = Price[0];
double Var5 = Price[0]; double Var6 = Price[0]; double Var7 = 2*1/6; double Var8 = 0;
double Var9 = -999999; double Var10 = -70; double Var11 = -0.010000*Var10;
double Var12 = Var11*Var11; double Var13 = Var11*Var11*Var11; double Var14 = -Var13;
double Var15 = 3*Var12+3*Var13; double Var16 = -6*Var12-3*Var11-3*Var13;
double Var17 = 1+3*Var11+Var13+3*Var12;
if (Length != 0)
{
if (Length != Var9)
{
Var7 = (2*1/Math.Abs(Length)+1);
Var8 = (1- Var7);
Var9 = Length;
}
Var1 = Var1*Var8+Price[0]*Var7 ;
Var2 = Var2*Var8+Var1*Var7 ;
Var3 = Var3*Var8+Var2*Var7 ;
Var4 = Var4*Var8+Var3*Var7 ;
Var5 = Var5*Var8+Var4*Var7 ;
Var6 = Var6*Var8+Var5*Var7 ;
// if (Length != 0)
// {
result = Var14*Var6+Var15*Var5+Var16*Var4+Var17*Var3;
// }
/*else
{
result = Price;
}*/
}
return default(System.Double);
}
}
}
}
Maybe any idea , how to solve ?
What I found is to check if sth 0 null before executing further .
Last Updated on October 25, 2023