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

Some basic coding assistance please

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

    Some basic coding assistance please

    Hello,

    I am working on some coding for an indicator. The basic code is as follows:

    if (IndicatorA[4].ApproxCompare(20)==0 && IndicatorA[3] !=50)
    Do something.

    I am finding that "Do something" occurs even when IndicatorA[3] == 50, which is not what I want. What is the problem with my code (I suspect it may be to do with the not equal to statement)?

    Also, if I want to do some calculations on bars either side of a swing high, what is the easiest way to identify the swing high and then the barsAgo of the bars either side of it?

    Thank you

    #2
    Hello GeorgeW,

    Thank you for your note.

    It could be that IndicatorA[3] is 50.90 which may be causing it to be true. I would suggest seeing the following sample to introduce logic which would take the difference between IndicatorA[3] and 50, and see if it’s an amount smaller than an acceptable amount.



    Regarding identifying the swing high/low value you could use,

    Code:
    Print(Swing(5).SwingLow[0].ToString());
    To identify how many bars ago the swing low was, you could use something like the following to search the last 30 bars for the swing low bar.

    Code:
    Print(Swing(5).SwingLowBar(0,1,30).ToString());
    Please see the following section on using the Swing indicator via NinjaScript.


    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you AlanP.

      I had tried it with ApproxCompare but just couldn't figure out how to write the code correctly. This works:
      if (IndicatorA[4].ApproxCompare(20)==0 && IndicatorA[3].ApproxCompare(50)!=0)
      Do something.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rocketman7, Today, 02:12 AM
      6 responses
      27 views
      0 likes
      Last Post rocketman7  
      Started by guillembm, Yesterday, 11:25 AM
      3 responses
      16 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by junkone, 04-21-2024, 07:17 AM
      10 responses
      148 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by tsantospinto, 04-12-2024, 07:04 PM
      6 responses
      101 views
      0 likes
      Last Post tsantospinto  
      Started by trilliantrader, 04-18-2024, 08:16 AM
      7 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Working...
      X