• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CalculateOnBarClose in strategy vs indicator

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

  • NinjaTrader_ChelseaB
    replied
    Hello Tony,

    dataseries[2] would refer to the 2 bars ago value of that data series and would not be a way of selecting that dataseries.

    Also, custom dataseries will be synced with 1 bar series (typically the primary) and will not have a series for every bar series.

    Using if (BarsInProgress == 2) { } would mean that Close, Open, Time, FirstTickOfBar, all refer to the 3rd dataseries.

    Using if (BarsInProgress != 2) return; would do the same for any code below that point.

    Leave a comment:


  • tonynt
    replied
    Chelsea,

    thank you for your support. I resolved it this moring and changed from

    "if (BarsInProgress!=0) return;" and in the Code "&& BarsInProgress==2" and referring to dataseries[2] (just wondering why no one told me that this doesnt work!?)

    to "if (BarsInProgress!=2) return;" and in the code only refer to dataseries [2]

    Best
    Tony

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Tony,

    Its hard for me to answer this question.
    I have already said that FirstTickOfBar will refer to the BarsInProcess that is currently processing.
    I am unsure of how to answer this question;
    The series that FirstTickOfBar is referencing changes depending on what is being processed in OnBarUpdate.

    At this point I think we need to have a conversation on the phone, as I don't think I will be able to further explain this through text. Please send an email to platformsupport [at] ninjatrader [dot] com.

    Leave a comment:


  • tonynt
    replied
    Hi Chelsea,,

    my conditions works accurately in a 2 Range Chart. But when I change dataseries to 1min and in the code "Close[1]" to "Closes[2][1]"............... and add "BIP==2" there is no entry.

    I tried with FirstTickOfBar and without FirstickOfBar. (what I still didnt understand is if "FirstTickOfBar" refers to BIP==0 or BIP==2.

    The condition is simple:
    if(Position.MarketPosition == MarketPosition.Flat
    && BarsInProgress==2
    && Closes[2][2] <= Opens[2][2] && Closes[2][2] < Highs[2][2]
    && Closes[2][1] >= Opens[2][1] && Closes[2][1] > Lows[2][1]
    && FirstTickOfBar)

    Thank you for your support
    Tony
    Last edited by tonynt; 09-24-2015, 04:18 PM. Reason: typo

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi Tony,

    I would not expect the 4:30 bar to have evaluated as true.
    The print has multiple items that are false.
    (If this were true the order would appear on the 4:31 bar if Calculate on bar close is True)

    Do you have a print in the condition that is evaluating as true? Does this print print the time that the condition was true?
    Please post this output if so.

    Can you post the exact print and the exact condition?

    Leave a comment:


  • tonynt
    replied
    Hello Chelsea,

    thank you for your reply and all your support!

    I didnt add it the first line of OBU (didnt know to do there, sorry)

    Yes, it plots now, but what I do not understand is why there is true eg the following statement, even when the referring bar was an upbar and close .75 is not <= open .50.

    9/24/2015 4:30:00 PM | Position: Flat == Flat && BarsInProgress: 2 && entryOrderLa: null == null && entryOrderLb: null == null && Closes[2][2]: 1919.75 <= Opens[2][2]: 1919.5 && Closes[2][2]: 1919.75 < Highs[2][2]: 1919.75 && Closes[2][1]: 1920.5 >= Opens[2][1]: 1920 && Closes[2][1]: 1920.5 > Lows[2][1]: 1920 && FirstTickOfBar: True

    Thank you
    Tony

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi Tony,

    I'm not quite sure what you did.

    Have you added this as the first line of OnBarUpdate()?

    Is this not printing anything? If so, then there is no BarsInProgress 2. If there were this should print. (Even if entryOrderkLa or entryOrderkLb are null it should just print that they are null)

    Are you sure there are 2 added series to this script?

    Leave a comment:


  • tonynt
    replied
    Hello Chelsea,

    thank your for your reply. I added this with copy and paste of course to the "do-the-following-part of the script {}". But when there is a reversal-up-bar in the 2nd added dataseries (= Range2) there is no information in the output window, and no entry as well.

    The script is running in a 1-min-chart.

    Thank you
    Tony
    Last edited by tonynt; 09-21-2015, 01:54 PM. Reason: translation error

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi tonynt,

    FirstTickOfBar will refer to the BarsInProgress that is currently processing.

    If BarsInProgress is 2, then FirstTickOfBar will be for the Range bars when they close.

    If the order is not making a trade, then add a print to find out why.

    What prints from the following print?:
    Code:
    if (BarsInProgress == 2)
    {
    Print(string.Format("{0} | Position: {1} == Flat && BarsInProgress: {2} && entryOrderLa: {3} == null && entryOrderLb: {4} == null"
    		+ " && Closes[2][2]: {5} <= Opens[2][2]: {6} && Closes[2][2]: {5} < Highs[2][2]: {7}"
    		+ " && Closes[2][1]: {8} >= Opens[2][1]: {9} && Closes[2][1]: {8} > Lows[2][1]: {10}"
    		+ " && FirstTickOfBar: {11}", Time[0], Position.MarketPosition, BarsInProgress,
    		(entryOrderkLa == null ? "null" : "not null"), (entryOrderkLb == null ? "null" : "not null"),
    		Closes[2][2], Opens[2][2], Highs[2][2], Closes[2][1], Opens[2][1], Lows[2][1], FirstTickOfBar));
    }

    Leave a comment:


  • tonynt
    replied
    Hello,

    We are discussing about FirstTickOfBar and different dataseries and this doesn´t work when there are additional dataseries!

    When I run a script-strategy in a 1-min-chart and in onbarupdate and for having an entry in a 2-RangeBar Reversal I code simply

    protected override void Initialize()
    {
    Add(PeriodType.Custom2,1);//1
    Add(PeriodType.Range,2);//2
    }
    if(Position.MarketPosition == MarketPosition.Flat
    && BarsInProgress==2
    && entryOrderkLa == null
    && entryOrderkLb == null
    && Closes[2][2] <= Opens[2][2] && Closes[2][2] < Highs[2][2]
    && Closes[2][1] >= Opens[2][1] && Closes[2][1] > Lows[2][1]
    && FirstTickOfBar
    )

    There is no entry!

    It only works when I change the primary dataseries to the Range2 and remove "s[2]" from the code!

    OR might it be that the problem occurs only with simulated datafeed? As I did the testing of different possibilites on the weekend with simulated datafeed.

    Best
    Tony
    Last edited by tonynt; 09-20-2015, 03:41 PM. Reason: translation error

    Leave a comment:


  • tonynt
    replied
    Hello,

    what is in this situation please:

    I´m running a script-strategy on a 1-min-chart with COBCfalse. In onbarupdate I have condition for additional Range-Bar-Dataseries if (BarsInProgress==2 && "Closes[2][0]>Opens[2][0]" && FirstTickOfBar then enterlong".

    Will the "enterlong" be with first tick of primary dataseries (= with next 1 minute bar) or with first tick of dataseries[2] (= open of next Rangebar, which I want to have).

    Thank you
    Tony

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Tony,

    This means that there is no guarantee to the order that OnBarUpdate and OnMarketData are going to fire for any particular tick.

    Specifically, I said this because FirstTickOfBar could possibly be skipped over completely in OnMarketData. I understand that you said to forget this, however, I just wanted to make you aware of the behavior.

    Leave a comment:


  • tonynt
    replied
    Hello Chelsea,

    thank you again for your reply. Yes, they will return the called information at the time of being called.

    But when COBC==false, means it is called not with close of bar in onbarupdate but with every tick, why is then a difference to onmarketdata?

    I thought all is clear now but I´m confused, sorry.

    Thank you for your support.
    Tony

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Tony,

    Yes, you can use Closes[1][bar index] and Opens[1][bar index] when Calculate on bar close is set to False.

    You can also use these in OnMarketData and they will reference the same information.

    What I want you to be aware of, is that OnMarketData and OnBarUpdate do not trigger at the same time.

    Lets say you print Closes[1][0] in OnBarUpdate and also print this in OnMarketData when Calculate on bar close is False, you may get two different prices because the events were triggered at different times.

    However, yes, that code will compile and will return the called information at the time of being called.

    Leave a comment:


  • tonynt
    replied
    Hello Chelsea,

    thank you for your reply! Sorry for causing misunderstandings with my translations maybe.

    I understood that not to use FirstTickOfBar in OnMarketData. Lets get rid off FirstTickOfBar.

    Let me do the question again different: I work in a 1-minute-bar and I need to have the open and close of 4-Range-Bars (let say this is secondary dataseries). So I have in my conditions "if (SMA,20 primary dataseries rising && Closes[1][0]>Opens[1][0] then golong" will this work with having the strategy running COBCfalse when the Closes[1][0]>Opens[1][0] is in onbarupdate and will it work when I have it in onmarketdata?

    When the close of the 4-Range-Bar is before close of 1 Minute bar I want the entry, so the strategy has to run COBCfalse. But where in the strategy can I (or do I have) to put Closes[1][0]>Opens[1][0] so that the entry "golong" is done with the Close of 4-Range-Bar.

    I hope I could explain better this time.

    Thank you
    Tony
    Last edited by tonynt; 09-17-2015, 09:55 AM. Reason: typo

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by Gorkhaan, Today, 02:55 AM
0 responses
11 views
0 likes
Last Post Gorkhaan  
Started by mbell.irves, Today, 12:36 AM
0 responses
11 views
0 likes
Last Post mbell.irves  
Started by cutzpr, Yesterday, 09:18 PM
0 responses
9 views
0 likes
Last Post cutzpr
by cutzpr
 
Started by CoffeeOutlaw, Yesterday, 05:59 PM
3 responses
23 views
0 likes
Last Post CoffeeOutlaw  
Started by Da vinci, Yesterday, 04:19 PM
2 responses
16 views
0 likes
Last Post Da vinci  
Working...
X