Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

diamond draw on chart when

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

    diamond draw on chart when

    Hi everyone,

    I am trying to setup a simple strategy that draws a diamond on the chart when price touches a certain moving average.

    I would like to apply that strategy to imported historical data.

    I have used the strategy wizard, that generates the following code:


    // 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 Touched800 : 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()
    {
    Add(SMA(800));

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (GetCurrentBid() == SMA(800)[0])
    {
    DrawDiamond("800 touched" + CurrentBar, false, 0, 0, Color.Red);
    }
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }

    when I run the strategy in the strategy analyzer, nothing happens (I see the chart, but no diamonds...).

    Could you help me to understand what is missing?

    thank you,

    John.

    #2
    Hi John,

    In the future, please work from existing threads already created for this.

    The diamond draws at Y value 0 so you would never see it. Draw at High[0] or Low[0] to place near bars.

    You need to print all values to check if your condition is true. You're checking that an indicator requiring many bars to calculate is exactly equal to close, so start printing these both and see if they are ever true.

    Make sure MaximumBarsLookBack is set to infinite.

    Should add a simple confirmation to that block as well: Print("My Condition is true");

    You're using GetCurrentBid() which is real time only. Close[0] is substituted when used in backtest.
    Last edited by NinjaTrader_RyanM1; 10-21-2011, 09:10 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,

      thank you.

      to me, it would be ok also to have a vertical line drawn as indicated (instead of a diamond).
      Unfortunately, I've tried to implement you suggestions, but I wasn't able to obtain the result (my falut oviously).

      is it possibile for you to indicate how the code presented would be modified?

      thank you,

      John.

      Comment


        #4
        Our role is to help you work through the debugging process but we unfortunately cannot actually do it for you. In my post I provided a few different areas to explore so that you can work through it on your end. There's no shortcut to debugging through the use of Print statements, which are critical here to verify values and understand code flow. If any of the suggested items are not clear, please let me know.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        8 responses
        31 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by helpwanted, Today, 03:06 AM
        2 responses
        21 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by DayTradingDEMON, Today, 09:28 AM
        0 responses
        7 views
        0 likes
        Last Post DayTradingDEMON  
        Started by navyguy06, Today, 09:28 AM
        0 responses
        2 views
        0 likes
        Last Post navyguy06  
        Started by rjbtrade1, 11-30-2023, 04:38 PM
        2 responses
        77 views
        0 likes
        Last Post DavidHP
        by DavidHP
         
        Working...
        X