Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

telegram help

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

    telegram help


    hello

    can someone help me understand what i doing wrong .

    trying to make a indicator send me a message to my telegram account with the below code but dont work













    //Set-up for telegram BOT
    private DateTime dateTime;
    private string botUrl = "https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text={2}";
    private string apiKey = "4902146:AAHrSh0GVj_2TDeGiXiSDTr0DVKsF02y9J A";
    private string chatId = "-1001278608";
    private string messageText = "";
    private string instrumentName = "";
    private string contractMonth = "";
    private string signalSeries = "";
    private string CurrentDate = "";
    private string dataSeriesDate = "";
    private string indicatorName = "HeikenAshi CandleSticks Entry \n";




    /For Telegram Bot
    if (CurrentDate == dataSeriesDate && TelegramAlert == true)
    {
    signalSeries = indicatorName + instrumentName + " " + contractMonth + " " + vCall.ToString() + " CE";
    messageText = signalSeries;
    botUrl = "https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text={2}";
    botUrl = String.Format(botUrl, apiKey, chatId, messageText);
    WebRequest request = WebRequest.Create(botUrl);
    request.GetResponse();





    #2
    Hello jhontorres,

    Thanks for opening the thread.

    WebRequests would be C# code that is not specific to NinjaScript. This is something we cannot provide assistance with.

    We will leave this thread open for any community members who wish to share their insight, however.

    If you have any other questions pertaining to NinjaScript specific code, please do not hesitate to open a new thread.

    Comment


      #3
      Hello Jhontorres, 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 from the operations to the telegram since it is not programmed if you know how to program maybe Help me I'll leave you the complete code this if you send messages with images




      #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


        #4
        You can find a solution here:
        Telegram Shareservice for Ninjtrader 8 is the best solution to receive alerts from your Ninjatrader 8 on your telegram. Check it now!

        Comment


          #5
          Originally posted by arturo8317 View Post
          Hello Jhontorres, 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 from the operations to the telegram since it is not programmed if you know how to program maybe Help me I'll leave you the complete code this if you send messages with images




          #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



          hey
          so you will need a telegram toke id and you get that with botfather

          in your cide aou token and char_id you get that information from botfather





          // 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";


          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          637 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          571 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X