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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        55 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        142 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        160 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        96 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X