Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Filter Signals with Order flow cumulative delta

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

    Filter Signals with Order flow cumulative delta

    Hello to everyone,
    I have a problem when i want filter a signal if Cumulative Delta > 0 to a buy signal or Cumullative Delta < 0 for sell signals.
    I made and indicator to reproduce delta by i can´t filter the signal into the strategy.
    Please could you help me whit this, i attach two codes, 1 with the indicator and other with a simple strategy.
    Thanks
    R.​
    Attached Files

    #2
    Hello rickyarg,

    Thank you for your note.

    In order to use the indicator values in your strategy, you need to create an instance of the indicator. This could be done in a similar way to the fast and slow SMA indicators in your strategy. You could declare it at the class level:
    private cumulativedeltacasero myCumulativeDeltaCasero;

    Next, when the state is DataLoaded, you could instantiate the indicator (and even add it to the chart like the SMAs if you'd like):

    else if (State == State.DataLoaded)
    {
    smaFast = SMA(Fast);
    smaSlow = SMA(Slow);
    myCumulativeDeltaCasero = cumulativedeltacasero();

    smaFast.Plots[0].Brush = Brushes.Goldenrod;
    smaSlow.Plots[0].Brush = Brushes.SeaGreen;

    AddChartIndicator(smaFast);
    AddChartIndicator(smaSlow);
    }

    Next, you could use the following as needed in your strategy to access the values of the indicator plots:
    myCumulativeDeltaCasero.Deltaclose[0]
    myCumulativeDeltaCasero.Deltaopen[0]
    myCumulativeDeltaCasero.Deltalow[0]
    myCumulativeDeltaCasero.Deltahigh[0]

    ​For a full sample of a Strategy that uses exposed Indicator values, I recommend reviewing the following reference sample:


    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Hello Emily, thanks for your answer I make the fixes that you proposed me but the strategy continue to no work correct, compile without errors, but never could be enabled in the chart.
      I attach the code with corrections
      Thanks!​
      Attached Files

      Comment


        #4
        Hello rickyarg,

        Thank you for your reply.

        I see you added the following line inside of State.DataLoaded:

        myCumulativeDeltaCasero.Deltaclose[0] = Deltaclose;

        You wouldn't be able to access an indicator value with a bar reference until OnBarUpdate has been processed. State.DataLoaded is only called once when all data series have loaded. OnBarUpdate() is called whenever a bar is updated and would be able to use the bar reference [0] for zero bars ago. It is also important you have enough bars on the chart in the data series you are accessing, and you also have an added 1 tick data series. It seems that you only want the indicator to calculate on the main/primary data series, so I added the following check to make sure there are enough bars and that the code beyond this point is only being run when OnBarUpdate() is called for the primary series:

        Code:
        if (CurrentBar < Fast || CurrentBar < Slow || BarsInProgress != 0)
        return;
        Additionally, I changed the following line:
        Code:
        myCumulativeDeltaCasero.Deltaclose[0] = Deltaclose;

        to this:
        Code:
        Deltaclose = myCumulativeDeltaCasero.Deltaclose[0];
        ​​
        That way the Deltaclose double will be assigned the value of myCumulativeDeltaCasero.DeltaClose for the current bar and not the other way around.

        I have attached the strategy with the mentioned edits for your reference. Please feel free to take a look and modify it as needed.

        SampleMAcrossplusdeltacumExampleEdit_NT8.zip

        Let me know if I may be of further assistance..
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hello Emily, the strategy work great, but went i put myCumulativeDeltaCasero with other indicator that need AddDataSeries(Data.BarsPeriodType.Tick, 1) like myCumulativeDeltaCasero, and the strategy not work.
          Could i send you a code via email? could you send me you email address, please?​
          Thanks!!

          Comment


            #6
            Hello rickyarg,

            Thank you for your reply.

            We are unable to provide hands-on debugging services; we do not provide C# programming education services or one on one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

            That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. Our email address is scriptingsupport[AT]ninjatrader[DOT]com. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

            From here, I recommend using Print statements to debug your script. Be sure to check the Log tab of the Control Center and the NinjaScript Output window for errors. My colleague has written a very helpful and detailed post about using prints to debug NinjaScript:


            Please try adding prints to better understand what is happening in your indicators and strategies. Based on the results of the prints and any error messages you get, this should help give you more direction on what parts of your scripts might need to be revised. If you receive any error messages you are unfamiliar with, we would be glad to assist with understanding the errors and offer some tips on how to locate/resolve the cause.

            You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.

            Please let me know if I may be of further assistance.​
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Hi Emily, thanks for your reply.
              Sorry for the inconvenience, my English is not good and can be confusing.
              I did not want to ask for something different from what was requested in the first message of the post.
              On the other hand, in other support sites such as tradestation, they facilitate the email of support people to make inquiries.
              Now I understand that in Ninja it is not possible to make queries that way.
              Thank you very much for your clarifications.
              Regarding the issue of the error, in the log it says

              error on calling onbarupdate method on bar 480 you must use the overload that has a barinprogress parameter when calling the barssiceexitexecution() method in the context of a multiframe and instrument strategy.

              The strange thing is that it didn't happen before entering the cumulativedelta filter.
              the line in the code is : && (BarsSinceExitExecution() > 1 || BarsSinceExitExecution() == -1)​

              Regards

              Comment


                #8
                Hello rickyarg,

                Thank you for your patience.

                SInce your strategy has an added data series, you need to reference a BarsInProgress index per the following method signature:
                BarsSinceExitExecution(int barsInProgressIndex, string signalName, int exitExecutionsAgo)

                There is more information about BarsSinceExitExecution at the following link:


                I recommend reviewing the following page about working with Multi-Time Frame and Instruments:


                Additionally, we have a reference sample of a strategy that uses an added data series for intra-bar granularity that demonstrates evaluating conditions on the primary series and submitting orders to the added series. This is a good way to see some of the ideas needed for working with multi-series scripts:


                Please review these resources and let me know if you have any additional questions or concerns.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you very much for your help
                  I'll be checking these resources, regards​

                  Comment


                    #10
                    Hello Emily,
                    Is working ok! is fixed
                    thanks very much for your help
                    Regards​

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Jimmyk, 01-26-2018, 05:19 AM
                    6 responses
                    834 views
                    0 likes
                    Last Post emuns
                    by emuns
                     
                    Started by jxs_xrj, 01-12-2020, 09:49 AM
                    6 responses
                    3,290 views
                    1 like
                    Last Post jgualdronc  
                    Started by Touch-Ups, Today, 10:36 AM
                    0 responses
                    9 views
                    0 likes
                    Last Post Touch-Ups  
                    Started by geddyisodin, 04-25-2024, 05:20 AM
                    11 responses
                    62 views
                    0 likes
                    Last Post halgo_boulder  
                    Started by Option Whisperer, Today, 09:55 AM
                    0 responses
                    8 views
                    0 likes
                    Last Post Option Whisperer  
                    Working...
                    X