#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 = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
// 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 = "@XXXXXXX";
// 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 == 2)
{
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
Comment