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

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.
    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 alifarahani, Today, 09:40 AM
        4 responses
        19 views
        0 likes
        Last Post alifarahani  
        Started by gentlebenthebear, Today, 01:30 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by PhillT, Today, 02:16 PM
        2 responses
        7 views
        0 likes
        Last Post PhillT
        by PhillT
         
        Started by Kaledus, Today, 01:29 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by frankthearm, Yesterday, 09:08 AM
        14 responses
        47 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X