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

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
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by carnitron, Today, 08:42 PM
    0 responses
    5 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    6 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,974 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    8 views
    0 likes
    Last Post rbeckmann05  
    Started by rhyminkevin, Today, 04:58 PM
    4 responses
    58 views
    0 likes
    Last Post dp8282
    by dp8282
     
    Working...
    X