Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

collaboration - help, concretum bands.

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

    collaboration - help, concretum bands.




    regards to everyone.



    very recently i found an indicator called concretum bands and it is very interesting.


    its authors have published a detailed report with their findings with this title: Beat the Market: An Effective Intraday Momentum Strategy for S&P500 ETF (SPY).



    i'm interested in adapting this indicator to nt to integrate it into my strategies.



    Code:
    // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © foreignHead16013
    
    //@version=5
    indicator("Concretum Bands",overlay = true,max_bars_back = 5000,max_lines_count = 500)
    
    k=input.int(10,"Length")
    vm=input.float(1,"Volatility Multiplier")
    ncol=input.color(color.rgb(255, 235, 59, 70),"NoiseArea color")
    ucol=input.color(color.rgb(1, 1, 1, 70),"Upperbound color")
    lcol=input.color(color.rgb(1, 1, 1, 70),"Lowerbound color")
    extend=input.int(30,"Extend Plotting",maxval=250,inline = "one")
    useext=input.bool(true,"",inline="one")
    if useext==false
        extend:=0
    var n=0 // n is number of bars in the current timeframe
    var bool first=true
    
    
    if first
        n:=n+1
    
    if session.islastbar and first
        first:=false
    
    var bool skipper=true
    var skipper_counter=0
    if skipper
        skipper_counter:=skipper_counter+1
    
    if skipper_counter==k*n+1
        skipper:=false
    //----------------------------------------------
    var candle_counter=0
    var float upperbound=0
    var float lowerbound=0
    var float firstconstant=0
    var float secondconstant=0
    
    candle_counter:=candle_counter+1
    if session.isfirstbar
        candle_counter:=0
        firstconstant:=open>close[1]?open:close[1]
        secondconstant:=open<close[1]?open:close[1]
        upperbound:=open
        lowerbound:=open
    if skipper==false and candle_counter!=0
        //                       num             deno                        -1
        j=1
        sigma=0.0
        while j<=k
            move=math.abs(       (  close[n*j]/open[j*n+candle_counter] )   -1          )
            sigma:=sigma+move
            j:=j+1
        sigma:=sigma/k
        upperbound:=firstconstant*(1+vm*sigma)
        lowerbound:=secondconstant*(1-vm*sigma)
    
    u=plot(upperbound,color=ucol)
    l=plot(lowerbound,color =lcol)
    fill(u,l,color=ncol)
    
    // plotting forward
    prevuy=upperbound
    prevlt=lowerbound
    
    if skipper==false  and  barstate.isrealtime
        
        lm=1
        while lm<=(n-candle_counter)
            j=1
            sigma=0.0
            while j<=k
                move=math.abs(       (  close[(n*j)-lm]/open[j*n+candle_counter] )   -1          )
                sigma:=sigma+move
                j:=j+1
                
            sigma:=sigma/k
            extu=firstconstant*(1+vm*sigma)
            extl=secondconstant*(1-vm*sigma)
            //log.info(str.tostring(extu)+" ----- "+str.tostring(extl))
            line.new(bar_index+lm-1,prevuy,bar_index+lm,extu,color = ucol)
            line.new(bar_index+lm-1,prevlt,bar_index+lm,extl,color= lcol)
            prevuy:=extu
            prevlt:=extl
            lm:=lm+1
            if lm>extend
                break

    as i see it should be perfectly possible to adapt this indicator to ninjascript and it would be much faster if it was done collaboratively, so hopefully there will be some interest. i took a look over the internet and it seems that large language models could assist in this adaptation.



    very well, regards.


    #2
    Hello rtwave,

    Below I am proving a link to a support article with helpful resources on getting started with C# and NinjaScript.


    I am happy to answer any specific questions about NinjaScript as you build the script.

    This thread will remain open for any community members that would like to build this script as a convenience to you.

    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 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.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3



      the logic for the indicator is described as follows:





      How the Indicator is Calculated
      The bands at time HH:MM are computed by taking the open price of day t and then adding/subtracting the average absolute move over the last n days from market open to minute HH:MM. The bands are also adjusted to account for overnight gaps. A volatility multiplier can be used to increase/decrease the width of the bands, similar to other well-known technical bands. The bands described in the paper were computed using a lookback period (length) of 14 days and a Volatility Multiplier of 1.​





      pretty straightforward, however, i can't see the mechanisms to adjust for overnight gaps in the code.


      and, i intend to try and adapt this indicator to ns myself but it can take me weeks or months, which is really frustrating. but well, we'll see.


      Comment


        #4


        these are some backtests using this strategy - indicator. the results are just brilliant.


        Click image for larger version

Name:	20240614 concretum strategy performance 0001.jpg
Views:	486
Size:	57.3 KB
ID:	1307199



        and those are results on 5 minute bars. i know of zero competitive strategies on 5 minute bars.

        Comment


          #5



          people with nt,



          i will try to convert this indicator myself. the operations required are completely elementary: a difference between two values, the absolute value for said difference and then a simple average of that value over several trading sessions. the difficulty for me comes with obtaining that average for all different bar numbers or bar positions in a session and from having another index to calculate the average over multiple trading sessions.



          i have not found any nt indicators with a similar structure and when it comes to coding i'm mostly restricted to imitation and then trial and error.



          i will start with a very concise question for the nt staff: ¿how does nt identify the first bar in a trading session, the second and so forth? and also very importantly, the bar size one selects (1 minute per bar, 2, 3 and up to 1440 minutes per bar) determines how many bars can exist inside one trading session, ¿how is nt aware of the number of bars in a trading session? in mathematical terms this is easy for me, ¿how can one create an index j from first to last bar in a session which nt must calculate the differences and absolute values over?



          very well, regards.


          Comment


            #6
            Hello rtwave,

            Thanks for the questions.

            "how does nt identify the first bar in a trading session, the second and so forth?"

            The first bar of a session can be found two ways, from Bars.IsFirstBarOfSession and from Bars.BarsSinceNewTradingDay.



            // Check if the current bar is the first bar of the session
            if (Bars.IsFirstBarOfSession)
            {
            Print("This is the first bar of the session");
            }
            else
            {
            // Calculate the bar number within the current session
            int barNumberInSession = CurrentBar - Bars.BarsSinceNewTradingDay;
            Print("This is bar number " + barNumberInSession + " in the current session");
            }

            "how is nt aware of the number of bars in a trading session"

            It'd be necessary to wait until the Bars.IsLastBarOfSession, and then Bars.BarsSinceNewTradingDay will be the number of bars in the session.


            "how can one create an index j from first to last bar in a session which nt must calculate the differences and absolute values over"

            for (int j = CurrentBar - Bars.BarsSinceNewTradingDay - 1; j < CurrentBar; j++)
            {
            Print( Math.Abs(High[0] - Low[0]) );
            }


            Chelsea B.NinjaTrader Customer Service

            Comment


              #7



              people with nt, NinjaTrader_ChelseaB,



              i have been going over the pinescript code as it has been published.



              there is a very significant issue, the indicator as it has been published does not anticipate or adjust to shortened sessions in any way. shortened sessions are frequent and will make the calculations useless if one does not make adjustments as necessary. as published, the indicator will just loop through all the values of bar number multiplied by length (or number of days). in the presence of a shortened session, all the results will be critically affected until it falls out of the calculation period. i work with years and years of data and this deficiency would make my strategies unreliable and erratic.



              i can easily sketch the structure i would like to follow, however, getting this to work in nt will take some time for me. i want the indicator to count the number of bars in each session for the first 4 sessions and then use the largest of these values as the correct number of bars for the instrument. then, only use the values of the sessions which have as many bars as previously determined. and then proceed with the intended calculations.


              and i have two very concise questions, ¿how can one identify the 4th bar in a session (or in every session)? ¿and how can one keep count of the number of sessions in a chart? ¿does nt have any natively coded commands to request this information or will it be necessary to use indices and counters for everything?



              very well, thanks, regards.

              Comment


                #8
                Hello rtwave,

                "how can one identify the 4th bar in a session (or in every session)"

                if (Bars.BarsSinceNewTradingDay == 4)
                {
                // this is the 4th bar of a session
                }

                "and how can one keep count of the number of sessions in a chart"

                private int sessionCount;

                if (Bars.IsFirstBarOfSession)
                {
                sessionCount++;
                }

                "does nt have any natively coded commands to request this information or will it be necessary to use indices and counters for everything?"

                NinjaTrader has Bars.BarsSinceNewTradingDay and Bars.IsFirstBarOfSession.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9



                  people with nt,




                  this indicator was designed for the spy etf but when used on thinly traded instruments there will be significant issues.



                  i have two questions regarding nt: 1) ¿how does nt proceed when there is no traded price for the fourth bar in a session (no open or close. this is frequent for some instruments outside of regular session hours) but an indicator does have a valid value to display? i'm thinking of a situation where an instrument has not been traded, ¿will nt leave a blank space in the place that corresponds to this particular bar and will nt plot the indicator? 2) and similarly, regarding historical data, ¿how would nt proceed when there is missing data in a series? i'm thinking of a situation where there are values for the open of a session, close of the first, second and third bars but no values for the fourth bar. ¿is there any mechanism so that nt would use the value for the previous observed bar (in this case use the close for bar 3 in bar 3 and bar 4)?


                  the logic for the indicator is quite simple, but the more i study the code as published the more i think of improvements and adjustments to deal with shortened sessions and missing data as i have posted recently.
                  Last edited by rtwave; 07-16-2024, 01:12 PM.

                  Comment


                    #10
                    Hello rtwavem,

                    "how does nt proceed when there is no traded price for the fourth bar in a session"

                    If there are no ticks received during the elapsed bar time, no indicators would be updating and you may see there is no bar for that time.

                    "how would nt proceed when there is missing data in a series"

                    There would not be a bar on the chart for that elapsed time.

                    "is there any mechanism so that nt would use the value for the previous observed bar"

                    As there would be no bar update, I would have to assume that you are referring to a timer that continues updating when OnBarUpdate is not updating. In which case, any series would return the most recently updated value (which would be from the previous bar).
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11



                      people with nt,



                      a member of this fora has done a fantastic job and produced a c# - ns version of this indicator.



                      and once i have deployed it to a chart all the weaknesses that i had anticipated have been confirmed. the calculations for this indicator are quite different from the usual moving averages and oscillators and one must take this into consideration and refine the code as necessary.


                      this is the indicator on the met contract during the regular session on a 2 minute chart. there are multiple ticks for every single bar and the correspondence between indicator and bars behaves as expected throughout.


                      Click image for larger version

Name:	20240722 concretum band thic 0001.jpg
Views:	456
Size:	86.3 KB
ID:	1311529



                      this is the indicator on the same met contract during the wee hours of a yankee holiday on a 2 minute chart. it is self evident that there are multiple missing bars and nt will not leave a blank space for those periods when there are no ticks observed. this means that even when it would be possible to plot a valid value for the indicator, if there is no price bar plotted the indicator will not be plotted either. this is something that i had asked about previously and these charts show how the nt platform will proceed in the case of missing data.


                      Click image for larger version

Name:	20240722 concretum band thin 0001.jpg
Views:	367
Size:	69.6 KB
ID:	1311530




                      this generates two questions to nt staff:


                      - ¿is it possible to have nt plot the indicator in every single slot regardless of the presence of a price bar or not?


                      - also, once the final bar for a session finishes plotting, all the data for all the bars of the next session is known and as soon as there is an opening value for the next session, the indicator could be plotted into all the future bar slots. ¿how can one get nt to plot the indicator for the next 15 or 30 or n bars that have not been plotted yet? i think that the ichimoku clouds are a widely used indicator where plots will extend to bars that have not been plotted, so this would be a similar situation.




                      and lastly, at the moment, the values for the indicator are calculated using these expressions:


                      for(int i = 0; i < Len; i++) {
                      int sessionStartBar = CurrentBar - sessionStartBars.ElementAt(i);
                      sigma += Math.Abs(( Close[sessionStartBar - Bars.BarsSinceNewTradingDay] / Open[sessionStartBar]) -1d);
                      }
                      sigma /= (double)Len;

                      Lowerband[0] = firstConstant*(1d + VolMul * sigma);
                      Upperband[0] = secondConstant*(1d - VolMul * sigma);​



                      ¿can nt staff suggest any way to identify shortened sessions and only include regular, full sessions in these calculations? possibly checking for the number of bars at the end of each session and including in a public Series<double> only those which have the expected number of bars?


                      missing data and shortened sessions are the most important corrections in the case of this piece of code and it is what i have been trying to figure out.

                      Comment


                        #12
                        Hello rtwave,

                        "is it possible to have nt plot the indicator in every single slot regardless of the presence of a price bar or not?"

                        No, this would not be possible. If there is no bar, there is no slot for the plot series (or any series).


                        "how can one get nt to plot the indicator for the next 15 or 30 or n bars that have not been plotted yet"

                        You could use displacement to shift the plot forward. Then set values on the current bar where you would want these to appear in the blank space to the right.



                        "can nt staff suggest any way to identify shortened sessions and only include regular, full sessions in these calculations"

                        You can check the hours of the current session as defined in the Trading Hours template (including early close days and holidays) using a session iterator.





                        As far periods where there is no data, there wouldn't be a good way to check for this for all bar types. On a time based bar type you could subtract the previous bars time from the current bars time and if this greater than a certain amount it could mean there was no data during that period. But this would not work on non-time-based bar types.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Has anybody completed this indicator?

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          558 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          324 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          101 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          545 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          547 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X