NexusFi: Find Your Edge


Home Menu

 





Ninjatrader Telegram Addon


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one sam028 with 5 posts (6 thanks)
    2. looks_two Belltalks with 4 posts (3 thanks)
    3. looks_3 bobwest with 3 posts (1 thanks)
    4. looks_4 cutzpr with 2 posts (0 thanks)
      Best Posters
    1. looks_one vspatrick with 4 thanks per post
    2. looks_two sam028 with 1.2 thanks per post
    3. looks_3 Belltalks with 0.8 thanks per post
    4. looks_4 nothingbutprofits with 0.5 thanks per post
    1. trending_up 11,352 views
    2. thumb_up 15 thanks given
    3. group 21 followers
    1. forum 23 posts
    2. attach_file 2 attachments




 
Search this Thread

Ninjatrader Telegram Addon

  #11 (permalink)
 darkmarine 
NEW BRUNSWICK
 
Experience: Intermediate
Platform: ninjatrader
Trading: nq
Posts: 11 since Jun 2020
Thanks Given: 2
Thanks Received: 0


sam028 View Post
Hard to say without more details about the error message.

Don’t get a error just don’t get any message in telegram

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
What broker to use for trading palladium futures
Commodities
Cheap historycal L1 data for stocks
Stocks and ETFs
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #12 (permalink)
arturo8317
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

Reply With Quote
  #13 (permalink)
arturo8317
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

Reply With Quote
  #14 (permalink)
rocker84
Buenos Aires
 
Posts: 1 since Jun 2012
Thanks Given: 0
Thanks Received: 0


arturo8317 View Post
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

Reply With Quote
  #15 (permalink)
 
nothingbutprofits's Avatar
 nothingbutprofits 
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 View Post
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?

Reply With Quote
Thanked by:
  #16 (permalink)
 
bobwest's Avatar
 bobwest 
Western Florida
Site Moderator
 
Experience: Advanced
Platform: Sierra Chart
Trading: ES, YM
Frequency: Several times daily
Duration: Minutes
Posts: 8,172 since Jan 2013
Thanks Given: 57,513
Thanks Received: 26,292


arturo8317 View Post
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/ )

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
Reply With Quote
Thanked by:
  #17 (permalink)
 
nothingbutprofits's Avatar
 nothingbutprofits 
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;
				}	

			}
						

		}
	}
}

Reply With Quote
  #18 (permalink)
 Belltalks 
Chicago US
 
Experience: Intermediate
Platform: NinjaTrader
Trading: CL GC
Posts: 20 since May 2016
Thanks Given: 1
Thanks Received: 14

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

Reply With Quote
Thanked by:
  #19 (permalink)
 TigerStripes   is a Vendor
 
Posts: 109 since Mar 2021
Thanks Given: 33
Thanks Received: 56


Belltalks View Post
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 Discord server?

Reply With Quote
  #20 (permalink)
 Belltalks 
Chicago US
 
Experience: Intermediate
Platform: NinjaTrader
Trading: CL GC
Posts: 20 since May 2016
Thanks Given: 1
Thanks Received: 14



TigerStripes View Post
Is a chance you have similar api code or indicator to send a message & img through NT to Discord 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 Discord and Telegram as shared services. I don't know them and can't give an opinion about their products.

Reply With Quote




Last Updated on February 19, 2023


© 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