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 andrewtrades, Today, 04:57 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      3 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      7 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X