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

Moving Average Cross colors

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

    Moving Average Cross colors

    Please help! I'm trying to color two moving averages based on when MA1 is above MA2.

    What I'm trying to achieve is to have both MA's Green when MA1 is above MA2 and Both MA's Red when MA1 is below MA2.

    Here is the code I have been working on but it doesnt do what I am trying to achieve. Any help would be appreciated.

    thanks.

    Jason


    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.SpringGreen), PlotStyle.Line, "FastAbove"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "FastBelow"));
    Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "SlowAbove"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "SlowBelow"));
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    bool Bearish=(EMA(6)[0] < SMA(14)[0]);
    bool Bullish=(EMA(6)[0] > SMA (14) [0]);


    if (Bearish)
    FastBelow.Set(EMA(6)[0]);
    if (Bearish)
    SlowBelow.Set(SMA(14)[0]);

    if (Bullish)
    FastAbove.Set(EMA(6)[0]);
    SlowAbove.Set(SMA(14)[0]);
    }

    #2
    Hi Jason, please work alongside this reference sample here for your coding task - http://www.ninjatrader.com/support/f...ead.php?t=3227
    BertrandNinjaTrader Customer Service

    Comment


      #3
      MA crossover

      Guess this is doing what you are looking. Coded for NT7
      Regards.

      Finn "Jurbol"
      Last edited by finnbjurvoll; 11-10-2011, 05:10 PM.

      Comment


        #4
        Finnbjurvoll -

        Yes ! Thank you! That is exactly what I was looking for. I was looking for the indicator in the 'edit ninja script' section of the tools menu and I cant find this indicator listed with the other indicators in NinjaTrader. I'm not able to edit the indicator. Do you know why? Does it have something to do with the DLL file?

        The indicator does what I was looking but I was trying to edit it so the longer MA was an SMA and the Shorter MA was an EMA.

        Excellent work. Thanks.

        Comment


          #5
          Edit Indicator

          If you imported it in NT7, you should be able to edit the indicator. How did you install the indicator? Didi you use : File > Utilities > Import NinjaScript?

          Comment


            #6
            Yes. That is how I imported it but I'm not able to see it in the available list of indicators to edit. Its really strange.

            I looked in the directory : documents/NinjaTrader7/bin/Custom
            and it looks like the .cs and .dll files are in there. Is that where they are supposed to be? I'm not sure why NinjaTrader would put them there.

            Comment


              #7
              Jason

              Ok, I think maybe i exported it the wrong way However, I reprogrammed it so the slow is now a sma. I guess you will be able to open this one. Please let me know i you need more help. Finn
              Attached Files

              Comment


                #8
                Please ignore previous message

                Jason, please ignor the previous file, I did a mistake in the code, this is the one you want.
                Attached Files

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by BarzTrading, Today, 07:25 AM
                2 responses
                14 views
                1 like
                Last Post BarzTrading  
                Started by devatechnologies, 04-14-2024, 02:58 PM
                3 responses
                19 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by tkaboris, Today, 08:01 AM
                0 responses
                3 views
                0 likes
                Last Post tkaboris  
                Started by EB Worx, 04-04-2023, 02:34 AM
                7 responses
                162 views
                0 likes
                Last Post VFI26
                by VFI26
                 
                Started by Mizzouman1, Today, 07:35 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X