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

Comparing Close to SMA value failing - why?

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

    Comparing Close to SMA value failing - why?

    Hi everyone. I'm hoping someone can help me with a simple code snippet here.

    I want to know when the Close price is great than the SMA(50). Here is the code I'm using to do it. I'm simply sending the info to the output window for now.

    The output gives me the Close price and the SMA(50) value for each bar. It is then suppose to compare the values and tell me if Close is greater than SMA(50) (if Close is less than SMA(50), nothing should be printed in the Outpute Window).

    Problem is, it tells me that Close is ALWAYS greater than SMA(50) even when the output of the variables clearly show cases when Close is less than SMA(50).

    ---> Code Snippet <---

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    double myCloseValue = Close[0];
    double mySMA50Value = SMA(50)[0];

    Print("The current Close value is " + myCloseValue.ToString());
    Print("The current SMA 50 value is " + mySMA50Value.ToString());

    // Condition set 1
    if (myCloseValue > mySMA50Value);
    {
    Print("Close is > than SMA50");
    }
    }

    ---> End Code Snippet <---

    ---> Output Window Snippet (comments added for this post and do not appear in actual Output Window output <---

    The current Close value is 1.5633
    The current SMA 50 value is 1.563874
    Close is > than SMA50 .................comment added - this is an error
    The current Close value is 1.5565
    The current SMA 50 value is 1.56362
    Close is > than SMA50 .................comment added - this is an error
    The current Close value is 1.5634
    The current SMA 50 value is 1.563456
    Close is > than SMA50
    The current Close value is 1.5665
    The current SMA 50 value is 1.563496
    Close is > than SMA50

    ---> End Output Window Snippet <---

    What am I doing wrong here?

    Much thanks.

    - Iggy

    #2
    The problem is this line
    Code:
    if (myCloseValue > mySMA50Value)[COLOR=Red];[/COLOR]
    You are not suppose to have the semicolon there.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      D'OH!

      Much thanks.

      That did it.

      It's the little things that are so very important (and that screw everything up!!).

      Best,

      - Iggy

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by lightsun47, Today, 03:51 PM
      0 responses
      4 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      8 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      44 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      13 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      9 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X