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 SalmaTrader, 07-07-2026, 10:26 PM
      0 responses
      31 views
      0 likes
      Last Post SalmaTrader  
      Started by CarlTrading, 07-05-2026, 01:16 PM
      0 responses
      18 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 06-17-2026, 10:32 AM
      0 responses
      9 views
      0 likes
      Last Post CaptainJack  
      Started by kinfxhk, 06-17-2026, 04:15 AM
      0 responses
      16 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 06-17-2026, 04:06 AM
      0 responses
      19 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X