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

Turn Strategy into Indicator

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

    Turn Strategy into Indicator

    Is there a way to take the below Strategy that was created in your wizard and turn it into an Indicator? It Draws arrows by the candlesticks and plays a ding or beep. I have several Strategies that I would like to make Indicators so I don't have to load them every time. Is this possible? Thanks You for any help.


    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class AMOMOMACSTO : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {

    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (Open[0] < Close[0]
    && MACD(12, 26, 9)[0] > MACD(12, 26, 9).Avg[0]
    && Stochastics(7, 14, 3).K[0] > Stochastics(7, 14, 3).D[0]
    && MACD(12, 26, 9).Avg[0] > MACD(12, 26, 9).Avg[1]
    && StochasticsFast(3, 14).K[0] > StochasticsFast(3, 14).K[1]
    && MACD(12, 26, 9).Diff[0] > MACD(12, 26, 9).Diff[1]
    && BuyVolume()[0] > SellVolume()[0])
    {
    DrawArrowUp("My up arrow" + CurrentBar, true, 0, Low[0] + -3 * TickSize, Color.Yellow);
    PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\Ding.wav");
    }

    // Condition set 2
    if (Open[0] > Close[0]
    && MACD(12, 26, 9)[0] < MACD(12, 26, 9).Avg[0]
    && Stochastics(7, 14, 3).K[0] < Stochastics(7, 14, 3).D[0]
    && MACD(12, 26, 9).Avg[0] < MACD(12, 26, 9).Avg[1]
    && StochasticsFast(3, 14).K[0] < StochasticsFast(3, 14).K[1]
    && MACD(12, 26, 9).Diff[0] < MACD(12, 26, 9).Diff[1]
    && SellVolume()[0] > BuyVolume()[0])
    {
    DrawArrowDown("My down arrow" + CurrentBar, true, 0, High[0] + 3 * TickSize, Color.Yellow);
    PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\beep.wav");
    }

    #2
    All the code after the OnBarUpdate() is the same as indicator code. You could pretty much generate an indicator and do a copy and paste.
    This:
    Low[0] + -3 * TickSize
    Could be shortened to this too:
    Low[0] -3 * TickSize
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      I tried that but I still have no sign of the arrows showing up. Does the Market have to be open because as an indicator it will only show up in real time? When I run it as a strategy there are arrows on the previous bars when the strategy is met but not as an indicator. The ES is not open right now.
      Thanks for your previous reply and any further help.

      Comment


        #4
        Never mind. I think the problem is that my Ninja subscription ran out and the basic one that my broker gives me doesn't have the option to edit indicators or strategies. Sorry for the waste of time. But I may still convert all my strategies into indicators so your advice may still of great use to me so thank you.

        Comment


          #5
          Hi, when you move strategy code to an indicator, please also make sure to add those checks to the start of your OnBarUpdate() - http://www.ninjatrader-support2.com/...ead.php?t=3170

          Thanks!
          BertrandNinjaTrader Customer Service

          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