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 stafe, 04-15-2024, 08:34 PM
        11 responses
        57 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by pechtri, 06-22-2023, 02:31 AM
        5 responses
        115 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Tim-c, Today, 03:54 AM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by FAQtrader, Today, 12:00 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by gnocchi, Today, 11:56 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Working...
        X