Announcement

Collapse
No announcement yet.

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.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      82 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      43 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      56 views
      0 likes
      Last Post CarlTrading  
      Working...
      X