Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ind OnPriceChange in MA with Alert OnConditionReversed Rearm

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

    Ind OnPriceChange in MA with Alert OnConditionReversed Rearm

    Dear NT support, or someone familiar with ninjascript,

    I created an indicator and I would like to use it as one of the conditions for an alert in the Market Analyzer. Unfortunately, even though everything works fine in the chart, in the Market analyzer I came across a small thing that makes it impossible to use it this way. I came to the conclusion that the value of the indicator in the MA is set to 0 when a new candle is opened. So if at that time the new candle has a range of 0, i.e. the update of the indicator value was not called because the price change did not take place.
    Is it possible for me to somehow set the same value from the previous candle for the moment until OnBarUpdate (on price change) is called for the new candle? Or am I wrong somewhere?
    I would like to avoid OnEachTick - which unfortunately also has this manifestation. Also, I would not like to create a special indicator for MA. This internally uses 1m TF + D TF for calculations, but can be used on 5m TF or other - that's why OnPriceChange is important.
    Ideas?
    Thank you for the suggestions.​

    #2
    Hello ToNovy,

    You can carry over the previous value by using the following:

    if(CurrentBar < 1) return;
    YourPlot[0] = YourPlot[1];

    Comment


      #3
      Hi Jesse,

      thank you for the answer. I tried that, unfortunately this didn't work for me because I tried it inside OnBarUpdate() (OnPriceChange Calc) which was not called on the new candle at that time because Close[1] = Open[0] = Close[0]​.
      Last edited by ToNovy; 11-08-2024, 11:03 AM.

      Comment


        #4
        As you can see, some instruments open on a new candle with Close[1] = Open[0] = Close[0] so I get a value 0 in MA and only after Close[0] != Open[0] a new value was calculated
        thanks to that, I get an alert because OnConditionReversed Rearm even if Value[1] = Value[0]

        Click image for larger version  Name:	2024-11-08_18-17-07.gif Views:	0 Size:	29.0 KB ID:	1324053
        Last edited by ToNovy; 11-08-2024, 11:36 AM.

        Comment


          #5
          Hello ToNovy,

          A value of 0 would indicate that your logic is setting a value of 0 at some point during that event. Have you tried using a print to confirm that and if so have you tried to print the previous bar value of your plot at that time? You could potentially toggle from setting the plot how you are now to using the previous bar plot value to carry a value over when the calculated value returns 0.

          Comment


            #6
            Hi Jesse,

            yes, tried it, I have been using this indicator for a long time in a chart where no 0 has ever appeared. The values ​​range from 1 to 4. But I'll try to put this piece of code into a separate simplified indicator for testing purposes.​
            And/or I will try to capture a situation where the same indicator with the same settings gives me different values ​​on the chart and in the market analyzer.

            Click image for larger version  Name:	image.png Views:	0 Size:	35.5 KB ID:	1324086

            Click image for larger version  Name:	image.png Views:	0 Size:	71.4 KB ID:	1324084
            Last edited by ToNovy; 11-08-2024, 11:43 PM.

            Comment


              #7
              Ok here... on simulated ETHUSD the MA gives me 0 on the new bar when Close[1] = Open[0] = Close[0] and the OnPriceChange calculation is used
              on the other hand, the information on the chart still shows the last value from Bar[1] until the first Close[0] != Open[0] when the update takes place and both the MA and the chart show the new value​

              Click image for larger version

Name:	2024-11-09_08-35-09_Chart_-_1m.ETHUSD.gif
Views:	34
Size:	76.3 KB
ID:	1324092

              Comment


                #8
                Hello ToNovy,

                From the image's I don't see any prints being used to explore how that logic is working, that would still be my suggestion here to find out why a 0 is being used.

                Comment


                  #9
                  ​Hi Jesse,

                  maybe I'm doing something wrong in multi-bar. The indicator works normally on the chart, no 0 is ever displayed. The indicator logic does not even have a value of 0, it returns values ​​from 1-4. This value is only observed in MA, if the update is OnPriceChange and Close[1]=Open[0]=Close[0], i.e. on the open of a new candle.
                  I made a simple indicator that always returns 1 - at least it should.​

                  Click image for larger version

Name:	2024-11-11_16-22-33_NinjaScript_Editor_-_Indicator_-_MyCustomIndicator.gif
Views:	34
Size:	85.6 KB
ID:	1324248

                  Comment


                    #10
                    Hello ToNovy,

                    From the image you are using a variable to set the plot which should have a default value of 0, if you don't set the variable it would plot 0. A print can be used to explore that.

                    Plots also need to be set from BarsInProgress 0 which is the primary series, if you are not setting it on each primary bar the analyzer won't be able to see the value for events where you didn't set it on the primary bar.

                    Comment


                      #11
                      Hi Jesse,

                      ok i think i understand So how to achieve this when I want the indicator to run on 5m TF (primary) on chart, but the calculation and update is based on 1m and D TF (added Data Series 1 and 2)
                      if I understand correctly, the problem is if the value calculated on Data Series 1 is not available so I get 0 because it has to be set.
                      And then I can't use the OnConditionReversed alert because it alerts almost every start of a new period. I also can't use 0 as the default value, it would cause the same problem.
                      So, do I have to write a special indicator for MA needs with only primary data series? Or is there an option to use the same indicators for both chart and MA​?

                      Comment


                        #12
                        Hello ToNovy,

                        You would have to change your plotting logic to be in BarsInProgress 0 to avoid that, you can use prices from other series in conditions within BIP 0 but the setting of the plot would have to be in BIP 0 to ensure every primary update has a value.

                        Comment


                          #13
                          Thanks a lot Jesse for the explanation,
                          one more question, is it possible to get information from the level of the indicator whether it is running in MA or in Chart?​

                          Comment


                            #14
                            Hello ToNovy,

                            What information are you trying to access?

                            Comment


                              #15
                              Hi Jesse,
                              sorry for my english, my thought was that it would be nice if there is an option to automatically set the indicator for the needs of the run within the Market Analyzer and for the needs of the Chart (default settings).
                              I have also been thinking for a long time whether there is a possibility to save the default settings for Instrument + Timeframe with the option of automatically loading it when I open a chart with a given instrument and timeframe, instead of manually reloading it from a template.​

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              65 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              41 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              23 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              26 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              52 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X