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

accessing different MAs

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

    accessing different MAs

    Hi,

    I would like to know how I can determine in a strategy program what the colors are for 3 different moving averages. I created 3 separate MAs on a chart and am writing a strategy, part of which is to determine the colors of these 3 MAs. Is this possible to do? Can someone recommend the best direction to take. I've done some ninja scripting but I'm a novice to scripting with C#. However, any advice would be appreciated.
    Thanks
    Spartacus

    #2
    Hi Spartacus, for this you would need to check for the conditions that lead to the plot coloring - you can directly access the MA values by calling their method in your strategy code compared to the SMA or other indicator methods for example.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      Thanks for the response.

      Below is the simple moving average script.

      Can you give me an example below, with a snippet of inserted code, how I can reference the Color offset into Plot after declaring the plot of the moving average?

      I'm having difficulty knowing how to access it to test its color attribute.

      Thanks
      Spartacus

      protectedoverridevoid Initialize()
      {
      Add(
      new Plot(Color.FromKnownColor(KnownColor.Orange),PlotS tyle.Line, "Plot1"));
      }

      protectedoverridevoid OnBarUpdate()
      {
      double sum = 0;
      // Do not calculate if we don't have enough bars
      if (CurrentBar < Period) return;
      for (int barsAgo = 0; barsAgo < Period; barsAgo++)
      {
      sum = sum + Input[barsAgo];
      }
      Plot0.Set(sum / Period);
      }

      Comment


        #4
        Hi Spartacus, I'm sorry I'm not following what you seek here, the average script you posted does not set any specific colors, it only uses one plot with the default orange color here.

        If you want to code a strategy for an indicator that change colors according to inbuild rules you would need to recreate those rules in your strategy script, for example if you color bars blue on a rising 14 period SMA, then check in the strategy for the rising condition to then enter a trade, move a stop etc.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, Today, 01:16 PM
        2 responses
        9 views
        0 likes
        Last Post cre8able  
        Started by chbruno, 04-24-2024, 04:10 PM
        3 responses
        48 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by samish18, Today, 01:01 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by WHICKED, Today, 12:56 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by WHICKED, Today, 12:45 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X