namespace NinjaTrader.NinjaScript.Indicators.Lucky
{
public class SessionTrendLine : Indicator
{
private int startBar = -1;
private int endBar = -1;
private double closeBar = -1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Indikátor, který vytváří trendovou linii spojující první a poslední svíčku v seanci.";
Name = "SessionTrendLine";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
AddPlot(Brushes.Transparent, "InvisiblePlot");
}
}
protected override void OnBarUpdate()
{
// Pokud není zvolena daily, weekly nebo monthly svíčka
if (BarsInProgress != 0)
return;
// Zjisti, zda se jedná o první svíčku v seanci
if (Bars.IsFirstBarOfSession)
{
startBar = CurrentBar;
}
// Zjisti, zda se jedná o poslední svíčku v seanci
if (Bars.IsLastBarOfSession)
{
endBar = CurrentBar;
closeBar= Close[0];
// Vytvoření trendové linie
if (startBar >= 0 && endBar >= 0)
{
Print(startBar);
Print(endBar);
Print(closeBar);
Draw.Line(this, "tag1" + CurrentBar, false, startBar, closeBar, endBar, closeBar, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
}
}
}
}
}

Comment