NexusFi: Find Your Edge


Home Menu

 





NT8 - Horizontal line label with sound alert function


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one mastadee with 2 posts (0 thanks)
    2. looks_two zoticus with 2 posts (0 thanks)
    3. looks_3 aquarian1 with 1 posts (1 thanks)
    4. looks_4 Vale Zaragoza with 1 posts (0 thanks)
    1. trending_up 6,081 views
    2. thumb_up 3 thanks given
    3. group 6 followers
    1. forum 7 posts
    2. attach_file 3 attachments




 
 

NT8 - Horizontal line label with sound alert function

 
 
mastadee's Avatar
 mastadee 
Mexico City, Mexico
 
Experience: Advanced
Platform: IB & NinjaTrader
Broker: Interactive Brokers
Trading: ES, CL
Posts: 733 since Jul 2013
Thanks Given: 1,262
Thanks Received: 3,029

Hi all,

I recently switched to NT8 and I've been trying to mess with the code of an indicator I found to label the value on the horizontal line drawing tool (F6). The indicator works perfect, however I'm trying to add a function when price crosses that horizontal line that it plays a sound file (.wav file from my NT8 folder).

I've attached the NT8 version as zip and the NT7 version as the .cs file which I was using and worked well.

Here is the NT8 code and any suggestion would be highly appreciated, thanks in advance:

#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.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
using SharpDX;
using SharpDX.DirectWrite;
using SharpDX.Direct2D1;
#endregion

//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class LabelHorizLinesCL : Indicator
{

public enum SideEnum { Left, Right }
public enum PositionEnum { Below, Above }


protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Label Horizontal Lines.";
Name = "LabelHorizLinesCL";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
Side = SideEnum.Right;
Size = 10;
Position = PositionEnum.Above;
Bold = true;
Opacity = 180;
SoundFile = @"C:\Program Files (x86)\NinjaTrader 8\sounds\Oil.wav";
}
else if (State == State.Configure)
{
}
}


protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
foreach (Gui.NinjaScript.IChartObject co in ChartControl.ChartObjects)
{
if (co is HorizontalLine)
{
HorizontalLine l1 = (co as HorizontalLine);
string priceformat = Core.Globals.GetTickFormatString(TickSize);

float x, y;

System.Windows.Media.Color col = ((System.Windows.Media.SolidColorBrush)ChartControl.Properties.ChartBackground).Color;
using (SharpDX.Direct2D1.Brush backbr = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, new SharpDX.Color() { A = Opacity, R = col.R, G = col.G, B = col.B }))
using (SharpDX.Direct2D1.Brush br = l1.Stroke.Brush.ToDxBrush(RenderTarget))
using (var factory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared))
using (var textFormat = new TextFormat(factory, "Arial", (Bold) ? SharpDX.DirectWrite.FontWeight.Bold : SharpDX.DirectWrite.FontWeight.Normal, SharpDX.DirectWrite.FontStyle.Normal, Size * 96 / 72))
{

string text = l1.Anchors.First().Price.ToString(priceformat);
using (var textLayout = new SharpDX.DirectWrite.TextLayout(factory, text, textFormat, float.MaxValue, float.MaxValue))
{
if (Side == SideEnum.Right)
x = ChartPanel.W - textLayout.Metrics.Width;
else
x = 0;

y = chartScale.GetYByValue(l1.Anchors.First().Price);

if (Position == PositionEnum.Above)
{
y -= textLayout.Metrics.Height + l1.Stroke.Width / 2.0f;
}
else
{
y += l1.Stroke.Width / 2.0f;
}

RenderTarget.FillRectangle(new RectangleF(x, y, textLayout.Metrics.Width, textLayout.Metrics.Height), backbr);
RenderTarget.DrawText(text, textFormat, new SharpDX.RectangleF(x, y, textLayout.Metrics.Width, textLayout.Metrics.Height), br);
}

{
// Here I want to add a code which will trigger the sound file when the horizontal line is touched, however I couldnt fint a solution. I know in NT7 you could use linetriggered but it just doesnt work when I use it in NT8..

// if (CurrentBars = l1)

// { Alert("Alert", Priority.High, SoundFile);}


}
}
}
}
}

#region Properties

[Display(Name = "Font Size", GroupName = "Settings", Order = 0)]
public int Size
{ get; set; }

[Display(Name = "Bold", GroupName = "Settings", Order = 1)]
public bool Bold
{ get; set; }

[Display(Name = "Side", GroupName = "Settings", Order = 2)]
public SideEnum Side
{ get; set; }

[Display(Name = "Position", GroupName = "Settings", Order = 3)]
public PositionEnum Position
{ get; set; }

[Display(Name = "BackGround Opacity(0-255)", GroupName = "Settings", Order = 4)]
public byte Opacity
{ get; set; }

[Display(Name="Alert sound file", Order=5, GroupName="Parameters")]
[PropertyEditor("NinjaTrader.Gui.Tools.FilePathPicker", Filter="Wav Files (*.wav)|*.wav")]
public string SoundFile
{ get; set; }






#endregion

}



}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private LabelHorizLinesCL[] cacheLabelHorizLinesCL;
public LabelHorizLinesCL LabelHorizLinesCL()
{
return LabelHorizLinesCL(Input);
}

public LabelHorizLinesCL LabelHorizLinesCL(ISeries<double> input)
{
if (cacheLabelHorizLinesCL != null)
for (int idx = 0; idx < cacheLabelHorizLinesCL.Length; idx++)
if (cacheLabelHorizLinesCL[idx] != null && cacheLabelHorizLinesCL[idx].EqualsInput(input))
return cacheLabelHorizLinesCL[idx];
return CacheIndicator<LabelHorizLinesCL>(new LabelHorizLinesCL(), input, ref cacheLabelHorizLinesCL);
}
}
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.LabelHorizLinesCL LabelHorizLinesCL()
{
return indicator.LabelHorizLinesCL(Input);
}

public Indicators.LabelHorizLinesCL LabelHorizLinesCL(ISeries<double> input )
{
return indicator.LabelHorizLinesCL(input);
}
}
}

namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.LabelHorizLinesCL LabelHorizLinesCL()
{
return indicator.LabelHorizLinesCL(Input);
}

public Indicators.LabelHorizLinesCL LabelHorizLinesCL(ISeries<double> input )
{
return indicator.LabelHorizLinesCL(input);
}
}
}

#endregion


Attached Files
Elite Membership required to download: Horizontal line CL Sound.zip
Elite Membership required to download: LabelHorzLinesAlerts-Oil.cs
Visit my NexusFi Trade Journal Started this thread

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Cheap historycal L1 data for stocks
Stocks and ETFs
ZombieSqueeze
Platforms and Indicators
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
What is Markets Chat (markets.chat) real-time trading ro …
70 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
Bigger Wins or Fewer Losses?
24 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
The Program
20 thanks
 
 
aquarian1's Avatar
 aquarian1 
Point Roberts, WA, USA
 
Experience: Advanced
Platform: IB and free NT
Broker: IB
Trading: ES
Posts: 4,034 since Dec 2010
Thanks Given: 1,509
Thanks Received: 2,593


I'm not a coder

Perhaps you can just use these two (ported from NT7 to NT8) and add both to your chart.
of course it may be you've tried this already. :-)


..........
peace, love and joy to you
.........
Visit my NexusFi Trade Journal
Thanked by:
 
 
mastadee's Avatar
 mastadee 
Mexico City, Mexico
 
Experience: Advanced
Platform: IB & NinjaTrader
Broker: Interactive Brokers
Trading: ES, CL
Posts: 733 since Jul 2013
Thanks Given: 1,262
Thanks Received: 3,029


aquarian1 View Post
I'm not a coder

Perhaps you can just use these two (ported from NT7 to NT8) and add both to your chart.
of course it may be you've tried this already. :-)

thanks, no I havent tried that yet. Will check the code and see if i can somehow make it work

Visit my NexusFi Trade Journal Started this thread
 
 zoticus 
London, UK
 
Experience: Advanced
Platform: NT8
Broker: APEX - Interactive Brokers (Equities only)
Trading: CL GC ES 6E
Posts: 24 since Jul 2012
Thanks Given: 4
Thanks Received: 4

Anyone able to recode these Line Alerts form NT7 to NT8?

 
 zoticus 
London, UK
 
Experience: Advanced
Platform: NT8
Broker: APEX - Interactive Brokers (Equities only)
Trading: CL GC ES 6E
Posts: 24 since Jul 2012
Thanks Given: 4
Thanks Received: 4

Did you ever get this tool or something like it work ?

 
Vale Zaragoza
16400 SPAIN
 
Posts: 14 since Jun 2019
Thanks Given: 30
Thanks Received: 8


zoticus View Post
Did you ever get this tool or something like it work ?

Hello.
The indicator works. It indicates the price level but does not play sound. This is not yet implemented.

 
 
Jasonnator's Avatar
 Jasonnator 
Denver, Colorado United States
 
Experience: Intermediate
Platform: NT8 + Custom
Broker: NT Brokerage, Kinetick, IQFeed, Interactive Brokers
Trading: ES
Posts: 159 since Dec 2014
Thanks Given: 40
Thanks Received: 166

The documentation has an example of how to do this. Of note, indicators handle the call to PlaySound method a bit differently so watch out for that. Here is the link.

Essentially, you define your logic, such as with if statements, then if your criteria is met, put your call to PlaySound in that conditional logic block.

Remember, it won't work during a backtest or when you're loading data. (State.Historical)


 



Last Updated on September 30, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts