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

previous day's low, high and some arithmetic operations.

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

    previous day's low, high and some arithmetic operations.





    people with nt,



    i have been having a torrid time with horizontal lines.


    i'm working with the previous day's low, high and some arithmetic operations on those values.


    i want to have those values both inside a strategy as conditions to trigger trades and also visually in a separate indicator. i always do that, evaluate strategies and for the most attractive create indicators that replicate their signals.


    i tried to modify the keltner channel indicator to plot the lines i'm interested in, but even when i created as many series as required, it seems that the plot command won't work with horizontal lines. the indicator will compile but then it just won't plot anything.


    i also tried to work with Draw.Line(this, "previous low"+CurrentBar,false,1,(value),0,(value),Brushe s.Blue,DashStyleHelper.Solid,4); commands but then only the low and the high for the previous day will be plotted, the other values i'm calculating (additions, deductions, multiplications, divisions) will not work.




    so, please, ¿what structure should i use so that the previous day's low, high and other values i calculate derived from those will be available in a strategy? ¿doubles, series, anything else? just for illustration, i would like to calculate the previous day's low, high, low minus 50% of the 20 period atr and high plus 50% of the period atr.


    and, ¿what structure must an indicator have so that it will plot those same horizontal lines?


    ideally, i would want to create an indicator that could then be used inside a strategy but in this particular case it seems like it will be impossible. i have all these studies ready in a crappier ts el platform and things are nowhere near as convoluted and or exasperating as can be the case with nt. i persevere with nt because the backtesting engine is very robust, but nt never makes it easy to work with ninjascript or nt.
    Last edited by rtwave; 03-15-2021, 06:05 PM.

    #2
    Hello rtwave,

    Thanks for your post.

    I would suggest as a starting point to use the NinjaTrader indicator PriorDayOHLC which provides the prior days Open, High, Low and Close values based on the charts data and trading hours. You can copy the indicator and modify it to suit your needs.

    From a strategy perspective, you would want to work with indicator plots as these can be read by the strategy whereas a line drawn with a draw method would not be directly available to the strategy.

    While the PriorDayOHLC will produce "horizontal" lines it is important to understand that these are not the same as a drawn horizontal line created with a draw method. A plot consists of a series of values where for each bar on the chart, the plot would have a value (in most cases). In the case of the PriorDayOHLC, at the beginning of the session, all of the prior day's values are known so as each new bar is created the lines are plotted at the calculated OHLC values from the prior session which will be the same values for the duration of the current session making it look like a horizontal line but is in fact a bar by bar plot.

    I understand your frustration as development and debugging can be tedious. That said, we are here to answer any questions to help you along your way. If this becomes too difficult for you, you might consider using a NinjaTrader Ecosystem developer to provide exactly what you want.
    Paul H.NinjaTrader Customer Service

    Comment


      #3




      i have an update to report; i have been able to get an indicator to work using the plot structure.



      but there's an unbelievable amount of nonsense with nt.



      i started by creating an indicator with multiple double variables and series to plot horizontal lines. initially i started working on the structure of the keltner channel indicator and made numerous changes to it.


      - the thing as i first structured it would compile but it would not even appear in the indicators list. that is incomprehensible.

      - through trial and error i figured that i had to put the low between parenthesis if i wanted to then add any amount to it. then the indicator would at least appear in the indicators list, still nothing would plot.

      - i then created an experimental double variable and series as i realized that moronic syntactic minutiae were preventing my indicator from working. MIN(Low, CurrentBar > Period ? Period : CurrentBar)[0]; worked fine, and MIN(Low, CurrentBar > Period ? Period : CurrentBar)[0]; - 30 also worked fine.

      - however, if i wanted to add or deduct a percentage, once again the thing would compile but the value would not be plotted.

      - through further trial and error, i discovered that a number divided by 100 ( percentage / 100 ) would not plot. however, the same number multiplied by .01 ( percentage * .01 ) would compile and plot. that is just insane.



      so, even when the first formulation i was working with had no mathematical errors whatsoever, the indicator would compile but then would not do anything. i had to make several unnecessary and obscure syntactic changes and only then would nt plot the horizontal lines. unbelievable.



      now i will try to use this structure in a strategy. who knows what kind of challenges will nt throw against perfectly good formulations this time around.
      Last edited by rtwave; 03-19-2021, 07:37 PM.

      Comment


        #4
        Hello rtwave,

        Thanks for your post/update.

        When you have a situation where an indicator will compile and then not function when running it is because there is a "run time" type error that cannot be detected when compiling which is in a static environment. When an indicator does not display anything the first check should be the "Log" tab of the control center as any run-time type errors will be displayed there.

        If there are no errors, then likely the values of the plot are not within the price range of the chart. Simple print statements should be used to examine/confirm the actual values.

        If you have an indicator that compiles but then does not show up in the indicator list, then there would be an early run time error, typically in OnStateChange(). The "Log" tab again would specifically show this.

        In addition to observing the Log tab when developing the script, keep an open Ninjascript output window as errors would also be displayed there.

        NinjaTrader's ninjascript is based on C# programming language so the syntax requirements are well specified.

        Math does work and is based on the C# programming language. If something is not working, the first debugging step is to always print out the values of any variables being used in the calculations.

        Going forward, if you have specific questions, please provide a small reduced code example that illustrates the issue.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        943 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        9 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        5 views
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        28 views
        0 likes
        Last Post wzgy0920  
        Working...
        X