Previous Bars OHLC

hzang12345's Avatar

hzang12345

11 Jun, 2010 04:51 PM via web

I was wondering how I would set something like..

Open 2 Bars Ago > Open Last Bar , Low 3 Bars ago < Low 2 Bars ago (etc...)

I was thinking it was something like the getBars.ago () - but wasn't exactly sure how to set it up

If you could provide me with just a simple example I should be able to take it from there. One thing I have to say is that although I have 0 experience in Java - this seems pretty simple, much simpler than other programs & this software seems really quick. Especially because I am coming from an Excel programming environment.

Look forward to the conversation.

Regards,

  1. 2 Posted by hzang12345 on 12 Jun, 2010 11:41 AM

    hzang12345's Avatar

    Also,

    I believe your ES Futures contract information is not accurate. In the attached picture you will see, but in the year 2000-2001 it is showing the ES Futures to be in the 1700+ Range.

    I believe the intraday high was hit somewhere in 2007 for around 1550 points or so - somewhere in that ballpark. Am wondering to your knowledge if you are privy to any other information that is faulty?

    _____________________________________________________

    I guess while I am writing this as well - was wondering if you have chosen any strategies from any clients/producers such as I? I guess my main concern is if there is no precedent how much time should I be theoretically be spending learning the new environment ... etc...

    Appreciate it.

  2. Support Staff 3 Posted by Mathieu on 14 Jun, 2010 08:04 AM

    Mathieu's Avatar

    Hi,

    What you can do to get the previous OHLC bars is simply using getBars().ago(n), as you already guessed. For instance, lets say we want to do :

    Open 2 Bars Ago > Open Last Bar
    

    Simply use this:

    getBars().ago(2).getOpen() > getBars().ago(1).getOpen()
    

    (you'll probably use it in an "If" statement, surrounded by parenthesis)

    Don't worry about the performance hit for the moment. It should be very efficient to get bars this way. If you happen to use the same very often, you can assign it to a variable. Suppose you want to reuse the bar from 4 days ago :

    Bar fourDaysAgo = getBars().ago(4);
    

    Where fourDaysAgo is a name you choose for the variable.

  3. Support Staff 4 Posted by Mathieu on 14 Jun, 2010 08:05 AM

    Mathieu's Avatar

    Regarding ES data, you're most probably misslead by the fact that we are using rolled future contracts. Get there to see how.

  4. Support Staff 5 Posted by Mathieu on 14 Jun, 2010 08:12 AM

    Mathieu's Avatar

    Finally, thanks for your comments on the environment. We aim at making it as simple and useful as possible.
    To answer your question on experience and learning the environment, it vastly depends on your involvment, and your other experiences with programing. But it also mostly depends on what level of proficiency you want to achieve.
    Expect to master the basics of programming for Market Runner in a few weeks. It should be sufficient to express most of the strategies in Java.

    In hope this answers all of your questions,

    Mathieu

  5. 6 Posted by hzang12345 on 14 Jun, 2010 01:30 PM

    hzang12345's Avatar

    OK,

    Will try to implement these suggestions.

    Appreciate it,

  6. 7 Posted by hzang12345 on 14 Jun, 2010 02:47 PM

    hzang12345's Avatar

    I am having a small problem trying to overcome the NullPointerException.. I am not sure what this error means - but I am guessing it has to do with my PublicVoid statement in the beginning?

    @Override
    public void onOpen(OpenPrice open)
    {
    if ( getBars().ago(1).getLow() > getBars().ago(2).getOpen())
    {
        buy(1, "Buy At Open");
    }
    }

    I am guessing the PUBLIC VOID lines is where I am getting in trouble? What exactly does this coding do? For example, as I browse through the tutorials etc. I am seeing that this line is different in many such as onOpen(OpenPrice openPrice) .... etc. There are many variations that I see, but I guess my problem is that I am not sure what this is exactly doing - and how I am messing this up as opposed to making sure it is correct?

    Is there like a simple way of knowing exactly what to put in these lines to match the correct information below? Hopefully this makes sense.

    Appreciate it.

  7. Support Staff 8 Posted by Eric on 14 Jun, 2010 03:05 PM

    Eric's Avatar

    Hi,

    public void is a statement that tells Java that the following method (onOpen() in your case) is visible to the entire rest of the code (public) and that it does not return any value (void). This is required by our framework for technical reasons and is not related to the exception you see.

    In the case of the code you suggested, the problem is in the fact that, on the first call to onOpen() at the beginning of the simulation, you have no bars at all (since the first bar will only complete after the close).

    getBars().ago(1) means "take the bar prior to the last one". The framework tries to do so, but finds none. In Java, this generally results in a null value. When this null value is being used, the virtual machine fails and explains that this is because of the null value (NullPointerException).

    The fix is very simple. Just check that you have more than the necessary number of bars.

    @Override
    public void onOpen(OpenPrice open)
    {
    if ( getBars().getCount() > 2 && getBars().ago(1).getLow() > getBars().ago(2).getOpen())) {
        buy(1, "Buy At Open");
    }
    }
    

    This means that, if more than 2 bars have been recorded in the past, AND the 'low' value of the previous is higher than the 'high' value of the bar before it, then buy a contract.

    I hope this helps,

    Eric

  8. Eric closed this discussion on 14 Jun, 2010 03:05 PM.

  9. hzang12345 re-opened this discussion on 14 Jun, 2010 03:20 PM

  10. 9 Posted by hzang12345 on 14 Jun, 2010 03:20 PM

    hzang12345's Avatar

    Ahh..

    I saw something like that in one of the tutorials as well - good call - so basically you have to tell it exactly when to look for it, makes a lot of sense.

    _________________________________________________

    Also, just real quick - in your TUTORIAL 1 that is provided with marketrunner etc.. I notice that the actual coding for the execution on the buy is located within the parameters of the sell coding..

    @Override
    public void onOpen(OpenPrice open) {
        if (buyNextBar) {
            buy(quantity, "Buy at Open");
        }
    }
    
    @Override
    public void onClose(Bar bar) {
        if (hasPosition()) {
            closePosition("Sell at Close");
        }
    
        buyNextBar = bar.getClose() / bar.getOpen() < openCloseThresholdPct + 1;
    }

    Is this just illustrating one way to write it, meaning the buy execution can be written anywhere, or is there a deeper meaning to this?

    Thanks again, you guys are making this into a very usable format IMO.

  11. Support Staff 10 Posted by Eric on 15 Jun, 2010 08:00 AM

    Eric's Avatar

    Well, the buy() clause can be written anywhere.

    However, the idea of this code is to demonstrate that, sometimes, you must take a decision at one point (at the closing of a bar) in order to issue a buy() request at a later point (the opening of the following bar).

    You'll find more details in the description of the tutorial here.

  12. Eric closed this discussion on 15 Jun, 2010 08:00 AM.

  13. hzang12345 re-opened this discussion on 15 Jun, 2010 08:04 AM

  14. 11 Posted by hzang12345 on 15 Jun, 2010 08:04 AM

    hzang12345's Avatar

    Got it.

    Thanks for the help

  15. Mathieu closed this discussion on 18 Jun, 2010 03:09 PM.

Comments are currently closed for this discussion. You can start a new one.