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 Blairski, Yesterday, 09:19 AM
        2 responses
        9 views
        0 likes
        Last Post Blairski  
        Started by tonynt, Today, 09:33 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by minotti1, Today, 08:31 AM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by SmartArtsStudio, 05-15-2021, 10:46 AM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Airwave, Today, 06:02 AM
        2 responses
        23 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X