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 -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Updated February 19, 2023
Top Posters
looks_one
sam028
with 5 posts (6 thanks)
looks_two
Belltalks
with 4 posts (3 thanks)
looks_3
bobwest
with 3 posts (1 thanks)
looks_4
cutzpr
with 2 posts (0 thanks)
Best Posters
looks_one
vspatrick
with 4 thanks per post
looks_two
sam028
with 1.2 thanks per post
looks_3
Belltalks
with 0.8 thanks per post
looks_4
bobwest
with 0.3 thanks per post
trending_up
11,853 views
thumb_up
15 thanks given
group
21 followers
forum
23 posts
attach_file
2 attachments
October 11th, 2020, 12:44 PM
NEW BRUNSWICK
Experience: Intermediate
Platform: ninjatrader
Trading: nq
Posts: 11 since Jun 2020
Thanks Given: 2
Thanks Received: 0
sam028
Hard to say without more details about the error message.
Don’t get a error just don’t get any message in telegram
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
May 20th, 2021, 11:17 PM
cali valle
Posts: 4 since May 2021
Thanks Given: 1
Thanks Received: 1
hi I have the code of an indicator that sends messages with screenshots from ninjatrader to telegram but for the moment it only sends the message when I add it to the chart and I want to combine the function so that it sends the code when a short or a long or when I close an order but I don't know anything about codes and I want help to give that order to the code this is the 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;
using System.Windows.Media.Imaging;
using System.IO;
using Telegram.Bot;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators.Utilities
{
public class Zi8ScreenSnapShot : Indicator
{
// Token del bot que he creado desde 'BothFather' en Telegram:
private const string API_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Nombre del canal de Telegram donde se enviarán los mensajes (el bot tiene que
// estar autorizado como administrador en el canal):
private const string CHAT_ID = "@xxxxxxxxx";
// Variable para referenciar el Bot en Telegram:
private TelegramBotClient Bot;
// Variable para referenciar al Chart y poder capturar la pantalla:
private Chart ch;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "Zi8ScreenSnapShot";
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;
}
else if (State == State.DataLoaded)
{
Bot = new TelegramBotClient(API_TOKEN);
}
else if (State == State.Historical)
{
if (ChartControl != null)
{
Dispatcher.BeginInvoke(new Action(() =>
{
ch = Window.GetWindow(ChartControl) as Chart;
}));
}
}
}
protected override void OnBarUpdate()
{
if (CurrentBar == 20)
{
sendCombiMessage();
}
}
private async Task sendCombiMessage()
{
Dispatcher.Invoke(new Action(async () =>
{
try
{
Chart _chart = Window.GetWindow(ChartControl) as Chart;
if (_chart != null)
{
RenderTargetBitmap screenCapture = _chart.GetScreenshot(ShareScreenshotType.Chart);
if (screenCapture == null)
return;
BitmapFrame outputframe = BitmapFrame.Create(screenCapture);
using (MemoryStream ns = new MemoryStream())
{
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(outputframe);
png.Save(ns);
byte[] bb = ns.ToArray();
MemoryStream nsbb = new MemoryStream(bb);
await Bot.SendTextMessageAsync(CHAT_ID, "orden a mercado ....");
await Bot.SendPhotoAsync(CHAT_ID, nsbb);
}
}
}
catch (Exception ex)
{
Print(ex.ToString());
}
}));
}
}}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private Utilities.Zi8ScreenSnapShot[] cacheZi8ScreenSnapShot;
public Utilities.Zi8ScreenSnapShot Zi8ScreenSnapShot()
{
return Zi8ScreenSnapShot(Input);
}
public Utilities.Zi8ScreenSnapShot Zi8ScreenSnapShot(ISeries<double> input)
{
if (cacheZi8ScreenSnapShot != null)
for (int idx = 0; idx < cacheZi8ScreenSnapShot.Length; idx++)
if (cacheZi8ScreenSnapShot[idx] != null && cacheZi8ScreenSnapShot[idx].EqualsInput(input))
return cacheZi8ScreenSnapShot[idx];
return CacheIndicator<Utilities.Zi8ScreenSnapShot>(new Utilities.Zi8ScreenSnapShot(), input, ref cacheZi8ScreenSnapShot);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.Utilities.Zi8ScreenSnapShot Zi8ScreenSnapShot()
{
return indicator.Zi8ScreenSnapShot(Input);
}
public Indicators.Utilities.Zi8ScreenSnapShot Zi8ScreenSnapShot(ISeries<double> input )
{
return indicator.Zi8ScreenSnapShot(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.Utilities.Zi8ScreenSnapShot Zi8ScreenSnapShot()
{
return indicator.Zi8ScreenSnapShot(Input);
}
public Indicators.Utilities.Zi8ScreenSnapShot Zi8ScreenSnapShot(ISeries<double> input )
{
return indicator.Zi8ScreenSnapShot(input);
}
}
}
#endregion
May 20th, 2021, 11:18 PM
cali valle
Posts: 4 since May 2021
Thanks Given: 1
Thanks Received: 1
the 2 DLL's, must be copied to the \ Documents \ NinjaTrader 8 \ bin \ Custom directory.
After we start NinjaTrader, we open the NinjaScript Editor, right click to open the context menu, click on References…, click on add and add the 2 previous DLL's.
create a new indicator with the data from the notebook
I send you the attached DLLS thank you very much
July 3rd, 2021, 04:52 PM
Buenos Aires
Posts: 1 since Jun 2012
Thanks Given: 0
Thanks Received: 0
arturo8317
the 2 DLL's, must be copied to the \ Documents \
NinjaTrader 8 \ bin \ Custom directory.
After we start NinjaTrader, we open the NinjaScript Editor, right click to open the
context menu, click on References…, click on add and add the 2 previous DLL's.
create a new indicator with the data from the notebook
I send you the attached DLLS thank you very much
hi!, thanks for this, any news? I tried to get it work but no messages arrived on the group
-create the bot with BotFather
-start the bot with /start
-add the bot to the group and set as administrator
August 31st, 2021, 08:35 AM
rochester new york/USA
Experience: Advanced
Platform: ThinkOrSwim & NT
Broker: NT, TOS
Trading: ES NQ RTY CL NG
Posts: 78 since Feb 2021
Thanks Given: 245
Thanks Received: 48
arturo8317
the 2 DLL's, must be copied to the \ Documents \
NinjaTrader 8 \ bin \ Custom directory.
After we start NinjaTrader, we open the NinjaScript Editor, right click to open the
context menu, click on References…, click on add and add the 2 previous DLL's.
create a new indicator with the data from the notebook
I send you the attached DLLS thank you very much
Hi,
DLL is not allowed here?
August 31st, 2021, 10:51 AM
Western Florida
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,170 since Jan 2013
Thanks Given: 57,799
Thanks Received: 26,369
arturo8317
the 2 DLL's, must be copied to the \ Documents \
NinjaTrader 8 \ bin \ Custom directory.
After we start NinjaTrader, we open the NinjaScript Editor, right click to open the
context menu, click on References…, click on add and add the 2 previous DLL's.
create a new indicator with the data from the notebook
I send you the attached DLLS thank you very much
Hi @arturo8317 ,
I have deleted the attachments to your post. Forum policy does not allow attaching or uploading dll files.
See the Terms and Conditions:
Quoting
As a general policy, we make a best-effort to not allow DLL files. Never upload a DLL file. This is because a .dll file is an executable file that does not contain source code (the human-readable program) that can be examined to determine what it does. Instead, it is in a compiled form that contains only computer-readable instructions that are directly executed by the computer, without the possibility of human review. It therefore represents a potential risk and we cannot allow these types of files (files of either type ".dll" or ".exe") to be posted on the site. If you encounter a DLL file on the site, please Report it to the moderators.
( https://nexusfi.com/disclaimer/#content-not-permitted )
If you can upload files containing the source code, there would be no problem.
Thanks.
Bob.
When one door closes, another opens.
-- Cervantes, Don Quixote
September 1st, 2021, 01:38 PM
rochester new york/USA
Experience: Advanced
Platform: ThinkOrSwim & NT
Broker: NT, TOS
Trading: ES NQ RTY CL NG
Posts: 78 since Feb 2021
Thanks Given: 245
Thanks Received: 48
I found the source code from github:
https://github.com/kontsevoyd/NinjaSignal/blob/main/Strategies%5CNinjaSignal.cs
NT8 -> Telegram
Maybe someone here can figure out this one..and convert it to indicator file.
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.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
using System.Net;
#endregion
namespace NinjaTrader.NinjaScript.Strategies
{
public class NinjaSignal : Strategy
{
private double last_order = 0;
private long last_order_id = 0;
private long last_order_close_id = 0;
private long canceled_order_id = 0;
private Dictionary<string, double> last_position = new Dictionary<string, double>();
private Dictionary<string, double> last_order_close = new Dictionary<string, double>();
private Dictionary<string, double> positions_count = new Dictionary<string, double>();
private List<string> message = new List<string>();
private List<List<string>> messages = new List<List<string>>();
private bool allow_reload = true;
public bool sender = true;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Calculate = Calculate.OnPriceChange;
}
else{
last_order = 0;
positions_count.Clear();
last_position.Clear();
last_order_close.Clear();
messages.Clear();
allow_reload = true;
sender = true;
}
}
public void SendMessage(List<string> list){
sender = false;
string bot_token = "<bot token>";
string chat_id = "<chat id>";
string url = "https://api.telegram.org/bot"+bot_token+"/sendMessage?chat_id="+chat_id+"&parse_mode=html&text=";
string msg = "";
if(list[0] == "close_position"){
if(list[3] == "Long"){
msg = "Закрыли шорт: "+list[1].Replace(" Globex", "").Replace(" Nymex", "")+"%0AЦена: "+Math.Round(Double.Parse(list[2]), 2);
}
else{
msg = "Закрыли лонг: "+list[1].Replace(" Globex", "").Replace(" Nymex", "")+"%0AЦена: "+Math.Round(Double.Parse(list[2]), 2);
}
}
else if(list[0] == "open_position"){
if(list[1] == "Long"){
msg = "Лонг: "+list[2].Replace(" Globex", "").Replace(" Nymex", "")+"%0AЦена: "+Math.Round(Double.Parse(list[3]), 2);
}
else{
msg = "Шорт: "+list[2].Replace(" Globex", "").Replace(" Nymex", "")+"%0AЦена: "+Math.Round(Double.Parse(list[3]), 2);
}
}
else if(list[0] == "limit_buy"){
msg = "Покупка%20"+list[1]+"%20по%20"+list[2];
}
else if(list[0] == "stop_buy"){
if(list[4] == "0"){
msg = ""+list[1]+"%20"+list[2]+"%20стоп%20"+list[3];
}
else{
msg = ""+list[1]+"%20"+list[2]+"%20стоп%20"+list[3]+"%20лимит%20"+list[4];
}
}
else if(list[0] == "order_cancel"){
msg = "Ордер%20отменен%20"+list[1]+"%20по%20"+list[2];
}
else if(list[0] == "stop_loss_buy"){
msg = "Стоп лосс: "+list[2].Replace(" Globex", "").Replace(" Nymex", "")+"%0AЦена: "+Math.Round(Double.Parse(list[3]), 2);
}
url = url + msg;
using (var wb = new WebClient()){
try
{
var response = wb.DownloadString(url);
sender = true;
}
catch (Exception ex)
{
return;
}
}
}
protected override void OnBarUpdate()
{
Dictionary<string, double> temp_count = new Dictionary<string, double>();
temp_count = positions_count;
foreach(Position pos in Account.Positions){
temp_count.Remove(pos.Instrument.ToString());
}
foreach(string name in temp_count.Keys){
if(!last_position.ContainsKey(name)){
last_position.Add(name, 0);
}
if(last_position[name] != 0){
message.Add("close_position");
message.Add(name);
for(int i = Account.Orders.Count - 1; i >= 0; i--){
if(Account.Orders.ElementAt(i).Instrument.ToString() == name){
message.Add(Account.Orders.ElementAt(i).AverageFillPrice.ToString());
if(Account.Orders.ElementAt(i).IsLong){
message.Add("Long");
}
else{
message.Add("Short");
}
break;
}
}
SendMessage(message);
message.Clear();
last_position[name] = 0;
}
}
positions_count.Clear();
foreach(Position pos in Account.Positions){
if(!positions_count.ContainsKey(pos.Instrument.ToString())){
positions_count.Add(pos.Instrument.ToString(), 1);
}
}
var temp_p = Account.Positions;
foreach(Position pos in temp_p){
if(!last_position.ContainsKey(pos.Instrument.ToString())){
last_position.Add(pos.Instrument.ToString(), 0);
}
if(last_position[pos.Instrument.ToString()] != pos.AveragePrice){
message.Add("open_position");
message.Add(pos.MarketPosition.ToString());
message.Add(pos.Instrument.ToString());
message.Add(pos.AveragePrice.ToString());
SendMessage(message);
//messages.Add(message);
message.Clear();
last_position[pos.Instrument.ToString()] = pos.AveragePrice;
return;
}
}
}
}
}
July 31st, 2022, 05:18 PM
Chicago US
Experience: Intermediate
Platform: NinjaTrader
Trading: CL GC
Posts: 26 since May 2016
Thanks Given: 4
Thanks Received: 15
Hi,
you can use the following function to send a message "msg" string to a Telegram bot:
public void SendMessage(string msg, string bottoken, string chatid)
{
bool sender = false;
string url = "https://api.telegram.org/bot"+bottoken+"/sendMessage?chat_id="+chatid+"&parse_mode=html&tex t=";
url = url + msg;
using (var wb = new WebClient()){
try
{
var response = wb.DownloadString(url);
sender = true;
}
catch (Exception ex)
{
return;
}
}
}
using System.Net is required
July 31st, 2022, 06:43 PM
Posts: 109 since Mar 2021
Thanks Given: 33
Thanks Received: 56
Belltalks
Hi,
you can use the following function to send a message "msg" string to a Telegram bot:
public void SendMessage(string msg, string bottoken, string chatid)
{
bool sender = false;
string url = "https://api.telegram.org/bot"+bottoken+"/sendMessage?chat_id="+chatid+"&parse_mode=html&tex t=";
url = url + msg;
using (
var wb = new WebClient()){
try
{
var response = wb.DownloadString(url);
sender = true;
}
catch (Exception ex)
{
return;
}
}
}
using System.Net is required
Is a chance you have similar api code or indicator to send a message & img through NT to server?
August 1st, 2022, 03:04 AM
Chicago US
Experience: Intermediate
Platform: NinjaTrader
Trading: CL GC
Posts: 26 since May 2016
Thanks Given: 4
Thanks Received: 15
TigerStripes
Is a chance you have similar api code or indicator to send a message & img through NT to server?
No, I have not. I just modified a bit the code shared by @nothingbutprofits .
For your information, there is an indicator seller that has implemented and Telegram as shared services. I don't know them and can't give an opinion about their products.
Last Updated on February 19, 2023