Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Zero parameters on a method

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

    Zero parameters on a method

    Hello.

    I created a StringSeries value in an indicator using the following code:

    Indicator name = rcsHeikenAshi

    #region Variables

    private StringSeries heikenAshiDirection;

    ...

    protected override void Initialize()

    heikenAshiDirection = new StringSeries(this);

    ..

    later in code ..

    heikenAshiDirection.Set(0,"red");

    #properties

    [Browsable(false)]
    [XmlIgnore()]
    public StringSeries HeikenAshiDirection
    {
    get { return heikenAshiDirection; }
    }

    Then in a STRATEGY, I try to access the value using ..

    if ( rcsHA == null ) { rcsHA = rcsHeikenAshi(); }
    if ( rcsHA.HeikenAshiDirection[0] == "blue" ) { haColor = "blue"; }
    if ( rcsHA.HeikenAshiDirection[0] == "red" ) { haColor = "red"; }

    This is not working. If I put PRINT values in the indicator, rcsHeikenAshi, I see that heikenAshiDirection is being updated correctly, but I can't access the values from the strategy.

    I've coded this sequence many times in the past, without error. The only difference I can see is that there are zero parameters for rcsHeikenAshi. All the other indicators I've used has had at least one parameter. So for example, if rcsHeikenAshi had a bool value for a parameter, I would code "rcsHeikenAshi(true)".

    Does it make a difference that the indicator has zero parameters? Do I have the syntax correct?

    Thanks

    #2
    Hello rcsingleton,

    No, using zero parameters shouldn't be an issue here. I followed your example and it's working OK here. Maybe review the attached file and check what the differences may be.
    Attached Files
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I see one additional difference.

      In the indicator, rcsHeikenAshi, the code "heikenAshiDirection.Set(0,"red") is located in the following method, public override void Plot(Graphics graphics, Rectangle bounds, double min, double max).

      But that method is NOT located inside "protected override void OnBarUpdate()"

      Question. Does "heikenAshiDirection.Set(0,"red") have to be located inside "protected override void OnBarUpdate()" in order for it be accessed by the strategy?

      Comment


        #4
        Any *Series should be set in OnBarUpdate(). This assures 1 value per bar which is what the structure is designed for.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Question about when "public override void Plot(..)" gets called.

          I have this code in "public override void Plot(..)"
          {
          graphics.FillRectangle(brushDown, x - barPaintWidth / 2, y1, barPaintWidth, y4 - y1);
          whichWay = "red";
          }

          Back in "protected override void OnBarUpdate()"
          {
          ...
          if ( whichWay == "red" ) heikenAshiDirection.Set(0,"red");
          }

          That is not working. From the Print, I can see that "whichWay" is being set correctly in the Plot method, but when it reaches OnBarUpdate(), whichWay == null.

          How do I get the value, "whichWay", which is calculated in Plot() to be accessible in OnBarUpdate()?

          Comment


            #6
            Where is whichWay declared?

            Comment


              #7
              hello koganam,

              If I declare, "whichWay" in the "Variables" section, the value is set in Plot(), but not accessible from OnBarUpdate().

              If I declare, "whichWay" in the Plot() method, I get the compile error, CS0103, "The name 'whichWay' does not exist in the current context. Because under OnBarUpdate(), "whichWay" is no longer defined.

              Comment


                #8
                Originally posted by rcsingleton View Post
                hello koganam,

                If I declare, "whichWay" in the "Variables" section, the value is set in Plot(), but not accessible from OnBarUpdate().

                If I declare, "whichWay" in the Plot() method, I get the compile error, CS0103, "The name 'whichWay' does not exist in the current context. Because under OnBarUpdate(), "whichWay" is no longer defined.
                So far, I do not see anything that requires you to set whichWay in the Plot() method. Why not simply write a method to set it in the OnBarUpdate() method? In fact, given what you have written, I do not even see why you need to override the Plot() method.

                There are two suggestions that I can make:
                1. Handle your StringSeries in OnBarUpdate() and pass the values to your Plot(), or
                2. Just do the drawing inside OnBarUpdate() and not bother to override the Plot(). It is just C# after all.

                Comment

                Latest Posts

                Collapse

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