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 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 wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        27 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 02-22-2024, 01:11 AM
        5 responses
        32 views
        0 likes
        Last Post wzgy0920  
        Started by wzgy0920, 04-23-2024, 09:53 PM
        2 responses
        49 views
        0 likes
        Last Post wzgy0920  
        Started by Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        193 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,235 views
        0 likes
        Last Post xiinteractive  
        Working...
        X