Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Increment Indicator for Strategy Builder

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

    Increment Indicator for Strategy Builder

    Hi NT Team,

    Was hoping to get some help on a conceptual idea. I understand that currently there is no way to increment user variables within the strategy builder.

    How about we write a simple indicator that holds the increment value for a nominated user variable which can then be assigned to the user variable once a condition is matched in the strategy builder? This could also be used to plot user variables easily.

    Pseudo code:

    Incrementor (string variabletoincrement, double incrementAmount) {

    var currentVarValue = application.eval(variableToIncrement)
    Plot1 = currentVarValue

    var incrementedValue = currentVarValue + incrementAmount
    Plot2 = incrementedValue

    return = incrementedAmount
    }

    Does this look like a feasible approach to achieving an incrementing approach in strategy builder?

    Thinking about it more I think it boils down to the eval function and returning the current value of a given user variable (the name of which is passed to the indi as a string). The ootb offset function on every indicator could take care of the increment.

    Feedback would be great before committing more time on this...




    #2
    Hi Adfra, thanks for your question.

    Unfortunately, Indicator methods can not be called from the strategy builder. The script would need to be unlocked to go further with arithmetic/methods and hosting indicators. I always introduce those who are new to NinjaScript to this starter guide from our colleague Chelsea:


    Kind regards.

    Comment


      #3
      Hi Chris,

      I've actually quickly put together how I envisaged this and despite your answer still can't see why my approach isn't working. Would you be able to have a quick look at the attached image - it has the strategy which should just plot effectively a bar counter (but doesn't). The indicator "ToffiIncrementor" takes as an input the strategy user variable "Incrementee" and returns it's incremented value. The strategy then should assign this back to the user variable Incrementee. Hence on the next close I would expect Incrementee to be incremented and the cycle repeats...

      Strategy builder and indicator were all happy with my inputs / settings etc and it looks really quite straight forward. Would you be able to have a quick look?

      Kind regards
      Frank

      Comment


        #4
        Hi Frank, thanks for your reply.

        This test worked fine for me:

        Code:
        public class Increment : Indicator
        {
        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        //setup
        }
        else if (State == State.Configure)
        {
        AddPlot(Brushes.Yellow, "theplot");
        }
        
        }
        
        protected override void OnBarUpdate()
        {
        Period++;
        Value[0] = Period;
        Print(Period);
        }
        
        [Range(1, int.MaxValue), NinjaScriptProperty]
        [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
        public int Period
        { get; set; }
        }
        Note we also have the CurrentBar property that counts up from the first bar on the chart.

        -ChrisL

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        573 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        575 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X