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

SMA cross

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

    SMA cross

    hello,
    looking at youtube video I tried to create an indicator which will print arrow when price cross sma. but I am getting an error in that, can someone please help me with the code....
    else if (State == State.Configure)
    {
    SMA1 = SMA(Close, 14);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 70)
    return;

    // Set 1
    if (CrossAbove(Close, SMA1, 1))
    {
    Draw.ArrowUp(this, @"Smacross Arrow up_1", false, 0, (Low[0] + (-4 * TickSize)) , Brushes.Lime);
    //EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if (CrossBelow(Close, SMA1, 1))
    {
    Draw.ArrowDown(this, @"Smacross Arrow down_1", false, 0, (High[0] + (4 * TickSize)) , Brushes.Red);
    //EnterShort(Convert.ToInt32(DefaultQuantity), "");
    Attached Files

    #2
    i am getting this error
    cs0103 The name "SMA1" DOSE NOT EXIST IN THE CURRENT CONTEXT

    Comment


      #3
      Hello hir04068,

      Thank you for your post.

      It looks like you just missed the variable definition for the SMA you have used. If you copied this syntax from another location, you likely just missed the variable at the top:

      Code:
      public class smasa : Indicator
          {
      [B]private SMA SMA1;[/B] 
              protected override void OnStateChange()

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by samish18, Yesterday, 08:31 AM
      4 responses
      14 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by funk10101, Yesterday, 09:43 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by TheWhiteDragon, 01-21-2019, 12:44 PM
      5 responses
      551 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by rtwave, 04-12-2024, 09:30 AM
      5 responses
      37 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by funk10101, Today, 12:02 AM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Working...
      X