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

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.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        That was it

        Thank You!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by f.saeidi, Today, 08:01 PM
        0 responses
        2 views
        0 likes
        Last Post f.saeidi  
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        3 views
        0 likes
        Last Post Rapine Heihei  
        Started by frslvr, 04-11-2024, 07:26 AM
        5 responses
        96 views
        1 like
        Last Post caryc123  
        Started by algospoke, 04-17-2024, 06:40 PM
        6 responses
        49 views
        0 likes
        Last Post algospoke  
        Started by arvidvanstaey, Today, 02:19 PM
        4 responses
        11 views
        0 likes
        Last Post arvidvanstaey  
        Working...
        X