NexusFi: Find Your Edge


Home Menu

 





ninjatrader messages to telegram


Discussion in NinjaTrader

Updated
    1. trending_up 1,787 views
    2. thumb_up 2 thanks given
    3. group 6 followers
    1. forum 2 posts
    2. attach_file 3 attachments




 
Search this Thread

ninjatrader messages to telegram

  #1 (permalink)
arturo8317
cali valle
 
Posts: 4 since May 2021
Thanks Given: 1
Thanks Received: 1

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

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
How to apply profiles
Traders Hideout
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
28 thanks
Tao te Trade: way of the WLD
24 thanks
Diary of a simple price action trader
21 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
10 thanks
  #2 (permalink)
 sbgtrading 
Chicago
 
Experience: Advanced
Platform: NinjaTrader, MT4, TS
Posts: 17 since Mar 2010
Thanks Given: 3
Thanks Received: 9

Hi Arturo,

I can help...but the code you sent isn't the complete indicator.

Do you have the original zip file that you used to install the TelegramBot?

If you send it to me, and tell me what signals you want to generate, I can have a look.

Reply With Quote
Thanked by:
  #3 (permalink)
arturo8317
cali valle
 
Posts: 4 since May 2021
Thanks Given: 1
Thanks Received: 1


hello sbgtrading
you just have to follow these step

Import libraries into NinjaTrader

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

Attached Files
Elite Membership required to download: Newtonsoft.Json.dll
Elite Membership required to download: Telegram.Bot.dll
Elite Membership required to download: telegrammensajes.txt
Reply With Quote
Thanked by:




Last Updated on May 16, 2021


© 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