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

How to plot a weekly box style bar on a daily chart?

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

    How to plot a weekly box style bar on a daily chart?

    Hello,

    I'm trying to plot a weekly box style bar on a daily chart programmatically but to no avail. I have coded the following:

    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Week, 1);
    }​

    ....

    protected override void OnBarUpdate()
    {
    if (CurrentBar == 0)
    {
    return;
    }


    if (BarsInProgress == 1)
    {


    if (Close[1][0] > Open[1][0] && ChartBars.Properties.ChartStyleType == ChartStyleType.Box)
    {
    BarBrushes[0] = Brushes.LightGreen; // How to BarBrushes a higher time frame bar?
    CandleOutlineBrushes[0] = Brushes.LawnGreen; // How to CandleOutlinerBrushes a higher time frame bar?
    }

    else
    {
    BarBrushes[0] = Brushes.Pink;
    CandleOutlineBrushes[0] = Brushes.Red;
    }
    }

    else
    {
    return;
    }
    }

    The code compiles but does not plot properly. I can do it manually by adding a data series panel by hand. Is there a way to plot a weekly (higher time frame) bar on a daily chart programmatically? I can't find any documentation or examples on how to do so.

    Any suggestions would be appreciated!

    Thank you.

    Richard​

    #2
    Hello Richard0168,

    What is the outcome that you are trying to get?

    When you have a daily series you cant plot anything less or more granular than daily in regard to scripting. All plotting or drawing that you do would be in relation to the scripts primary series.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      Thanks for your reply. I see why I can't plot the bars other than the primary series.

      Please see attached picture. This is what I want to do and I can do it manually by creating another data series panel. However, I would prefer to do it programmatically in a script.

      Richard


      Attached Files
      Last edited by Richard0168; 12-02-2022, 08:19 PM.

      Comment


        #4
        Hello Richard0168,

        You could get a similar result by re plotting the OHLC values of the weekly bar on the daily primary. When using the daily as the primary you will have 1 slot for rendering per bar so if you are using weekly data you would just be rendering the last close bar on the weekly series for each day bar to visualize its bars.

        To make rectangles similar to what you pictured it would be easiest to just use Plots and then fill in the region between the plots. For example you could replot the High and Low of the weekly bar and then draw a region between them.




        The OnBarUpdate code would end up looking similar to:


        Code:
        if (BarsInProgress == 0)
        {
            Values[0][0] = Highs[1][0];
            Values[1][0] = Lows[1][0];
            Draw.Region(this, "tag1", CurrentBar, 0, Values[0],Values[1], null, Brushes.Blue, 50);
        }​
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,

          This is an excellent suggestion. Thank you so much for your help!

          Richard

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by arvidvanstaey, Today, 02:19 PM
          4 responses
          11 views
          0 likes
          Last Post arvidvanstaey  
          Started by samish18, 04-17-2024, 08:57 AM
          16 responses
          61 views
          0 likes
          Last Post samish18  
          Started by jordanq2, Today, 03:10 PM
          2 responses
          9 views
          0 likes
          Last Post jordanq2  
          Started by traderqz, Today, 12:06 AM
          10 responses
          18 views
          0 likes
          Last Post traderqz  
          Started by algospoke, 04-17-2024, 06:40 PM
          5 responses
          48 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X