• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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:
    https://ninjatrader.com/support/foru...sample-scripts

    Kind regards.
    Chris L.NinjaTrader Customer Service

    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
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by vitrxotinusa, Yesterday, 11:56 PM
        0 responses
        5 views
        0 likes
        Last Post vitrxotinusa  
        Started by vitrxotinusa, Yesterday, 11:55 PM
        0 responses
        3 views
        0 likes
        Last Post vitrxotinusa  
        Started by vitrxotinusa, Yesterday, 11:53 PM
        0 responses
        4 views
        0 likes
        Last Post vitrxotinusa  
        Started by raymonds, Yesterday, 10:23 PM
        0 responses
        4 views
        0 likes
        Last Post raymonds  
        Started by Gbnowpes, Yesterday, 09:21 PM
        0 responses
        5 views
        0 likes
        Last Post Gbnowpes  
        Working...
        X