Announcement

Collapse
No announcement yet.

IB instructions not executing... pls help

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

  • IB instructions not executing... pls help

    Would there be someone kind enough to have a look at this (very) rough draft IB EFS.

    The problem is that if a condition is met then it should do 3 things: 1. execute an IBBroker buy or sell; 2. show an alert and 3. sound off a wav (see lines 395-412).

    I can not get the IBBroker buy/sell to execute. The alert is shown and the debugln says that the IB is executed.

    I have a suspicion that it has to do with my wrong getBarState() == BARSTATE_NEWBAR routine.

    Better leave all the other problems of this EFS else everything will have to be rewritten.

    Thanking you in advance.

    Andrei
    Attached Files

  • #2
    You are probably right...

    I would suggest the following....

    First, I create a main loop within my code that contains everything necessary for RT trade Execution. Like this...

    if (getCurrentBarIndex() == 0) {

    // Do RT Trading Stuff here

    }

    You are using this type of function as subroutines in your backtest code.. This is fine, but what you are attempting to do is identify when a new bar starts forming, then execute some type of order.

    I would suggest using my timestamp function rather than the getBarState() function...

    For example...

    var nLastBarTime = 0;

    function main() {

    if ((getValue("rawtime",0) != nLastBarTime) && (getCurrentBarIndex() == 0)) {
    // a new bar with a new timestamp has formed.
    // also, this bar is a RT bar - not a past bar..
    .. do your trading stuff here.
    }

    nLastBarTime = getValue("rawtime",0);
    } // end of main()

    The way I've structured the code (above), the system will be allowed to execute trades ONLY when a new bar forms on the chart - and only ONCE (when the new bar forms on the chart).

    You may have to duplicate my timestamp idea for multiple trading functions (like Entries, Stops, Timed Exits...) In other words, have multiple timestamps running within your code.

    BTW, this is how I handle stuff like this. I find it is easier to create and use timestamps because I can control the actions of my system easier. I can create a timestamp or a barstamp that allows my system to act a certain way - ie: no stops for the first two bars or tighten profit targets after 5 bars (if not hit before the fifth bar). Things like that.

    Hope this helps..

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thank you very much for your advice.
      Should the problem not be resolved, I always know where to go to get what I really need: www.ment.com.

      Cheers.

      Andrei

      Comment


      • #4
        I'm here to help if needed...

        You know I'll assist you (if I can).

        I have done this type of thing before (about a hundred times). So I should be able to assist you - when you need it.

        The best advice I can offer you is to step through your code (possibly adding "debugPrintln()" statements to see if your code is executing properly. That is how I do it.

        I have also found (by trial and error) what I find works well (for me), and continue to use these same components over and over. Like my timestamps... These have been a lifesaver when it comes to complex code.

        Let me know if I can assist.

        Brad
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment

        Working...
        X