Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

alert log with buy sell volume

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

    alert log with buy sell volume

    Hello, good morning, I am developing an indicator that sends me an alert to the Alert file. For this I use the Buy Sell Volume indicator. And the condition has to be when the sales in a bar are less than 200.


    //This namespace holds Indicators in this folder and is required. Do not change it.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class ComprasGraf1000 : Indicator
    {
    private BuySellVolume buySellVolume;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Alerta cuando el volumen de ventas en una barra es menor que 200 contratos.";
    Name = "ComprasGraf1000";
    Calculate = Calculate.OnEachTick;
    IsOverlay = false;
    //AddPlot(Brushes.Orange, "VentaPlot");
    }
    else if (State == State.DataLoaded)
    {
    buySellVolume = BuySellVolume();
    }
    }

    protected override void OnBarUpdate() zz0.hsllsi65gcmzz
    {
    if (CurrentBars[0] < 1)
    return;

    // Acceso al volumen de ventas actualizado de BuySellVolume
    double volumenDeVentas = buySellVolume.Sells[0];

    if (volumenDeVentas < 200)
    {
    Alert("CompraAlta", Priority.High, "Compras Grafico 1000: " + volumenDeVentas.ToString("N0") + " contratos", "Alert1.wav", 10, Brushes.Green, Brushes.White);
    }
    }​

    With this code what it does is write the updated sales number every few seconds (after having configured the indicator in the graph and having selected CONFIGURATE ON EACH TICK)

    If I insert the indicator and in the CONFIGURATE option I select ON BAR CLOSE, it sends a message to the alert file every time a new bar is started PURCHASES GRAPH 1000:0 CONTRACTS

    and what I want it to do is ONLY send me an ALERT when at the end of a bar the number of sales is less than 200
    Thank you very much for the help​





    #2
    Hello r68cervera,

    The closest solution for what you are asking would be to use OnBarClose, the first tick of the new bar is what closes the bar so that would be one way to know the bar was closed so you can get a value.

    Comment


      #3
      Thank you Jesse for answering so quickly, but I told you about it in the previous post.
      If I put onbarclose, it sends me a message to the log of the bar that starts, saying that the number is 0

      ​​Click image for larger version

Name:	forum-ninja2-compras1000.png
Views:	75
Size:	166.6 KB
ID:	1303740

      Comment


        #4
        Hello r68cervera,

        That would be due to how the buy sell volume indicator collects data, on the new bar it clears the collections that you are using to accumulate for the new bar so when you check the 0 bars ago value it would be 0. You would need to use the 1 bars ago value to get a value. This indicator can also only be used in realtime to pull data from its plots, that would look like the following which will show values after realtime bars elapse.

        Code:
        protected override void OnBarUpdate()
        {
            if(CurrentBar< 1) return;
           BuySellVolume().Update();
           Print(BuySellVolume().Buys[1] + " " + BuySellVolume().Sells[1]);
        }

        Comment


          #5
          Hi Jesse, thanks for your answer, but I've already tried that and it doesn't work for me either.

          // Acceso al volumen de ventas actualizado de BuySellVolume
          double volumenDeVentas = buySellVolume.Sells[1];

          BuySellVolume().Update();
          if (volumenDeVentas < 400)
          {
          Alert("CompraAlta", Priority.High, "Compras Grafico 1000: " + volumenDeVentas.ToString("N0") + " contratos", "Alert1.wav", 10, Brushes.Green, Brushes.White);
          }​

          and the result it gives me is the same

          Click image for larger version

Name:	image.png
Views:	80
Size:	63.2 KB
ID:	1303760

          and what I am looking for is that when the candle closes, if the number of sales is less than 400, send a message to the log file


          In this example, you would have to send two alerts to the log file. the first at 22:01:28 because the number of sales is 338 and the second at 22:08:11 because there are 386


          ​​
          Click image for larger version

Name:	image.png
Views:	62
Size:	84.0 KB
ID:	1303761


          Thank you very much for your help

          Comment


            #6
            Hello r68cervera,

            You need to structure the logic exactly like I had shown to get a value in realtime, you are calling Update after trying to get the value, that needs to be first.

            Comment


              #7
              Thank you, for your help and for your patience, it now works as I want
              thank you so much​

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              626 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              359 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              105 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              562 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              567 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X