Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issues using the VHF indicator

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

    Issues using the VHF indicator

    Hello,

    I'm using the VHF indicator in a strategy I'm creating, but it seems to have issues. First of all, the threshold is decimal...so in my strategy I use a double. However, no matter what I do, it will not take my double value and instead puts a 1.

    Here's the code though:
    public class UHF : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int vHFperiod = 8; // Default setting for VHFperiod
    private double vHFthreshold = 0.82; // Default setting for VHFthreshold
    // User defined variables (add any user defined variables below)
    #endregion

    }

    No matter what I do, it will not take the .82 value, and instead puts a 1. Even when I try to change it in backtest, it will not change.

    Here's the parameter also:

    [GridCategory("Parameters")]
    public double VHFthreshold
    {
    get { return vHFthreshold; }
    set { vHFthreshold = Math.Max(1, value); }
    }
    #endregion


    All I want to do is if the line crosses the threshold to filter a trade.

    if (VHF(VHFperiod, VHFthreshold).VHFLine[0] > vHFthreshold && ...)


    any help would be appreciated.


    DT

    #2
    This is the solution (I hope!):

    set { vHFthreshold = Math.Max(0, value); }

    Comment


      #3
      Hello Darth_Trader,

      Thanks for your post and thanks to arbuthnot for the correct focus.

      The Math.Max compares the two items (1 and value) and returns the higher of the two items. value is obtained from your user parameters. In the code example you show setting the value to less than 1 (0.82) so the Math.Max in this case would return 1 and that is what you have observed.

      arbuthnot has suggested Math.Max(0, value); which will work as 0.82 is greater than 0.0.

      Depending on the range of values needed, you could also use the Math.Min (1, value) which would be useful if you need to protect against value being greater than 1.

      In general Math.Max and Math.Min are used to make sure that the user input does not provide a value that would cause issues with the performance of the ninjascript.

      Comment


        #4
        That was it

        Thank You!

        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