Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access OHLC data for the last 5 days

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

    Access OHLC data for the last 5 days

    I have created a strategy that works on the 1 minute timeframe and now I would like to insert checks on the daily candles to see if there may be situations where it is better not to let the bot work if the price has behaved in a certain way in the previous days. I tried to make the following function (with PriorDayOHLC) but it seems that the values are incorrect.


    Code:
    private bool PatternBase (int Pattern)
    {
    double open1 = PriorDayOHLC().PriorOpen[0] // Open of yesterday
    double close1 = PriorDayOHLC().PriorClose[0] // Close of yesterday
    double high1 = PriorDayOHLC().PriorHigh[0] // High of yesterday
    double low 1 = PriorDayOHLC().PriorLow[0] // Low of yesterday
    
    double open2 = PriorDayOHLC().PriorOpen[1] // open 2 days ago
    ...
    ...
    ...
    
    
    if (Pattern == 1)
    {
    if(Math.Abs(close1 - open1) < 0.5 * (high1 - low1))
    return true
    
    }
    
    if (Pattern == 2)
    {
    ....
    ....
    }
    
    return false
    }  ​
    And I would like to use the result of this function inside the OnBarUpdate function before my input to check if the conditions are there.
    Currently even applying the filter with pattern 1 on the trading system which makes about 1/2 entries per day, I still find the number of entries too high on the backtest. Am I wrong trying to use the PriorDayOHLC function? Or am I making some other mistake? Thanks


    #2
    Hello mmmf84,

    Thanks for your post.

    PriorDayOHLC returns the prior day (session) open, high, low, and close values of the referenced bar. For example, PriorDayOHLC().PriorOpen[0] will return the prior day's open price at the current bar since you are referencing barsAgo 0.

    If you are running your script on a 1-minute chart and pass in a barsAgo value of 1 into the PriorDayOHLC method, such as PriorDayOHLC.PriorOpen[1], you will get the same value as calling PriorDayOHLC().PriorOpen[0]. This is because the script is only looking 1 bar back from the currently forming bar to see what the PriorDayOHLC().PriorOpen value is. Since the PriorOpen value of the previous session is the same on the CurrentBar (barsAgo 0) and the previous bar (barsAgo 1)

    See this forum thread that explains how you could get the PriodDayOHLC values of other days in a NinjaScript: https://forum.ninjatrader.com/forum/...43#post1245543

    Ultimately, you should add debugging prints to a NinjaScript to see exactly how it is behaving and processing logic. Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    53 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X