#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 _Merlin_2Clouds : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Merlin 2 Clouds Indicator";
Name = "_Merlin_2Clouds";
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 _Merlin_2Clouds[] cache_Merlin_2Clouds;
public _Merlin_2Clouds _Merlin_2Clouds(int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return _Merlin_2Clouds(Input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
public _Merlin_2Clouds _Merlin_2Clouds(ISeries<double> input, int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
if (cache_Merlin_2Clouds != null)
for (int idx = 0; idx < cache_Merlin_2Clouds.Length; idx++)
if (cache_Merlin_2Clouds[idx] != null && cache_Merlin_2Clouds[idx].Range1 == range1 && cache_Merlin_2Clouds[idx].Range2 == range2 && cache_Merlin_2Clouds[idx].Range3 == range3 && cache_Merlin_2Clouds[idx].Range4 == range4 && cache_Merlin_2Clouds[idx].ShowST == showST && cache_Merlin_2Clouds[idx].ShowMT == showMT && cache_Merlin_2Clouds[idx].BandOpacity == bandOpacity && cache_Merlin_2Clouds[idx].EqualsInput(input))
return cache_Merlin_2Clouds[idx];
return CacheIndicator<_Merlin_2Clouds>(new _Merlin_2Clouds(){ Range1 = range1, Range2 = range2, Range3 = range3, Range4 = range4, ShowST = showST, ShowMT = showMT, BandOpacity = bandOpacity }, input, ref cache_Merlin_2Clouds);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators._Merlin_2Clouds _Merlin_2Clouds(int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return indicator._Merlin_2Clouds(Input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
public Indicators._Merlin_2Clouds _Merlin_2Clouds(ISeries<double> input , int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return indicator._Merlin_2Clouds(input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators._Merlin_2Clouds _Merlin_2Clouds(int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return indicator._Merlin_2Clouds(Input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
public Indicators._Merlin_2Clouds _Merlin_2Clouds(ISeries<double> input , int range1, int range2, int range3, int range4, bool showST, bool showMT, int bandOpacity)
{
return indicator._Merlin_2Clouds(input, range1, range2, range3, range4, showST, showMT, bandOpacity);
}
}
}
#endregion