Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Defining Close of Previous Week or Month - Trading w/ Daily Chart

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

    Defining Close of Previous Week or Month - Trading w/ Daily Chart

    I didn't think it would come to this but I've watched several hours of instruction and I passed C++ but having a tough time getting my arms around what seems like should be a pretty basic set of rules.

    I'm basically looking to say -

    If today's open is above the close of the previous month && above the close of the previous week && above the close of the previous day - then do something... as well as the opposite.

    I read about using the multiple time frames but I haven't found any good examples of this specific comparison being made. I know how to select last friday on the calendar specifically but I am looking to make this so it works no matter what day its being used.


    And on that same note - if I wanted to figure out how to 'filter' available markets into those which meet those ^^ requirements on any particular day, do you have a good suggestion as to how that might be done? I want to do this basic concept in an indicator as well but maybe if I can get my arms around the strategy it will make more sense when trying to make that work.

    I appreciate any and all suggestions / direction.

    #2
    Hello nxdxcx,

    Thanks for your post and welcome to the forums!

    Tackling a multi-time frame (MTF) indicator or strategy can be a bit overwhelming so we are glad you posed your question here as others may have the same or similar question.

    First, this is the best guide to understanding coding MTF and if you haven't found this then please do spend some time reading: http://www.ninjatrader.com/support/h...nstruments.htm

    If you have a chart with daily bars on it and you created your indicator or strategy you would want to use the ADD method to add the weekly and monthly dataseries because when applied to the chart the daily bars are already there. Here is the link to the ADD method: http://www.ninjatrader.com/support/h....html?add3.htm
    (Note: The help guide on Add does not show this but you can use .Week and .Month)

    The key to MTF coding is to properly access the correct dataseries. Reading the link for MTF you would want to use Opens, Highs, Lows, Closes (instead of Open, High, Low, Close in a single time frame). Further you have to specify which data series these apply to. As you know C programming numbering starts at 0 and this means that the base data series (in this example daily bars) will be identified by [0]. The next added dataseries (yes order/sequence matters) would be identified as [1] which in this case will be the weekly bars. The next added dataseries would be identified as [2] (in this case the monthly bars).

    So for example Highs[0] refers to the daily bars, Highs[1] refers to the weekly and highs[2] refers to the Monthly. Next you will need to identify the specific bar in the dataseries to use. [0] refers to the currentbar, [1] refers to the previous bar and [2] refers to the 2nd bar back, [3] refers to the 3rd bar back, etc. Next we can put these together to identify specific specific bars in the specific data series. Examples are:

    Highs[0][0] refers to the high of the current daily bar
    Lows[0][1] refers to the low of the previous daily bar
    Closes[1][0] refers to the close of the current weekly bar
    Opens[1][2] refers to the open of the weekly bar 2 weeks ago (0=current, 1 = last week, 2 = week before)
    Highs[2][0] refers to the High of the current month
    Highs[2][1] refers to the High of the previous month
    (Note: The bars identification is based on CalculateOnbarClose = false, if set to true then everything shifts back 1 bar).

    Rewriting your condition, you are looking for:
    if the open of the current day is greater than the Close of the prior day and if the open of the current day is greater than the close of the previous week and if the open of the current day is greater than the close of the prior month then do something
    code wise:

    if (Opens[0][0] > Closes[0][1] && Opens[0][0] > Closes[1][1] && Opens[0][0] > Closes[2][1])
    {
    // do something
    }

    To help drive home the dataseries & bar identification I have attached a screen shot of chart with daily, weekly and monthly and I have identified the first 3 bars in each (Note: Based on CalculateOnBarClose = false).

    Regarding the filtering, if you created an indicator using the logic above, for the // do something, you could set a public dataseries output with a +1 when the up condition exists, a -1 when the negative condition exists or a 0 (zero) when no condition exists. You can add the indicator into the market analyzer and using the cell conditions of the market analyzer you can filter based on the +1, -1 or 0 condition.
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X