Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

help telegram messages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    help telegram messages

    Hello, I have this code, send the message and an image of the graph every time you activate it in the graph, what I do not know is how to change the way to send messages of the operations to the telegram since it is not programmed if someone knows how to program, maybe they will help me. the complete code this code if you send messages with a picture thank you


    #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

    #2
    Hello arturo8317,

    Thanks for your post.

    TelegramBotClient would not be supported NinjaScript and would not be a topic we could assist with. We will leave this thread open for any community members that may have insight using it with NinjaScript.

    If you have any other questions involving NinjaScript that is documented in the Help Guide, we could assist there in another thread.

    Good luck with your project!
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by gbajaj, Yesterday, 11:16 PM
    0 responses
    1 view
    0 likes
    Last Post gbajaj
    by gbajaj
     
    Started by PWillard, Yesterday, 10:30 PM
    0 responses
    1 view
    0 likes
    Last Post PWillard  
    Started by waldoalvarez, 06-19-2021, 05:50 AM
    2 responses
    16 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Noongun, Yesterday, 03:17 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_EricB  
    Started by Reardon, Yesterday, 12:48 PM
    1 response
    21 views
    0 likes
    Last Post NinjaTrader_EricB  
    Working...
    X