Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SMA Crossing

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

    SMA Crossing

    Hello,

    I'm trying to print an arrow when the SMA(x) crosses above or below an instrument. I thought that the SMA function would do that but when I edit the SMA built in indicator I get the following code:

    if (CurrentBar == 0)
    Value.Set(Input[
    0]);
    else
    {
    double last = Value[1] * Math.Min(CurrentBar, Period);
    if (CurrentBar >= Period)
    Value.Set((last + Input[
    0] - Input[Period]) / Math.Min(CurrentBar, Period));
    else
    Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
    }

    All I want to do is something like this:

    if (CrossAbove(SMA(Period), Close[0], 1))
    {
    DrawArrowUp(
    "UP" + CurrentBar, true, 0, Low[0]- (TickSize*20), Color.Red);
    }

    if (CrossBelow(SMA(Period), Close[0], 1))
    {
    DrawArrowDown(
    "DOWN" + CurrentBar, true, 0, High[0] + (TickSize*20), Color.Orange );
    }

    But when I try to assign a value to my condition I get something like cannot convert implicit Ninja series to double.

    Help?

    Thanks!
    Tex

    #2
    Originally posted by TexFly View Post
    Hello,

    I'm trying to print an arrow when the SMA(x) crosses above or below an instrument. I thought that the SMA function would do that but when I edit the SMA built in indicator I get the following code:



    But when I try to assign a value to my condition I get something like cannot convert implicit Ninja series to double.

    Help?

    Thanks!
    Tex
    [/SIZE][/FONT][/SIZE][/FONT]
    ???

    I'm not sure what editing the SMA indicator has to do with this?


    The error means what it means, You can't assign a variable of type double to a series.

    If you need help, you should post the code where you are trying to assign a value to your condition.

    I don't think you have posted the line of code with the error.

    Post the line of code and we'll probably know how to fix it pretty quick.

    Comment


      #3
      I was trying to understand the difference between the code inside the SMA indicator and the SMA function. My code is below. I'm trying to print an arrow if the SMA(Period) crosses above or below the instrument. Thanks.

      double smacalc;

      if (CurrentBar == 0)
      Value.Set(Input[
      0]);
      else
      {
      double last = Value[1] * Math.Min(CurrentBar, Period);
      if (CurrentBar >= Period)
      Value.Set((last + Input[
      0] - Input[Period]) / Math.Min(CurrentBar, Period));
      smacalc = Value;
      else
      Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
      smacalc = Value;
      }

      smacalc=Value;

      if (CrossAbove(smacalc, Close[0], 1))
      {
      DrawArrowUp(
      "UP" + CurrentBar, true, 0, Low[0]- (TickSize*20), Color.Red);
      }

      if (CrossBelow(smacalc, Close[0], 1))
      {
      DrawArrowDown(
      "DOWN" + CurrentBar, true, 0, High[0] + (TickSize*20), Color.Orange );
      }

      Comment


        #4
        This should fix the issue:

        smacalc = Value[0];

        Value is a series. You need to access only 1, not the whole series/array.


        Originally posted by TexFly View Post
        I was trying to understand the difference between the code inside the SMA indicator and the SMA function. My code is below. I'm trying to print an arrow if the SMA(Period) crosses above or below the instrument. Thanks.

        double smacalc;

        if (CurrentBar == 0)
        Value.Set(Input[
        0]);
        else
        {
        double last = Value[1] * Math.Min(CurrentBar, Period);
        if (CurrentBar >= Period)
        Value.Set((last + Input[
        0] - Input[Period]) / Math.Min(CurrentBar, Period));
        smacalc = Value;
        else
        Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
        smacalc = Value;
        }

        smacalc=Value;

        if (CrossAbove(smacalc, Close[0], 1))
        {
        DrawArrowUp(
        "UP" + CurrentBar, true, 0, Low[0]- (TickSize*20), Color.Red);
        }

        if (CrossBelow(smacalc, Close[0], 1))
        {
        DrawArrowDown(
        "DOWN" + CurrentBar, true, 0, High[0] + (TickSize*20), Color.Orange );
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        563 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        329 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X