Announcement

Collapse
No announcement yet.

IB execution question

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

  • IB execution question

    Why will this code execute the IB Buy:

    if(getBarState() == BARSTATE_NEWBAR) {

    if(vStoch.getValue(StochStudy.FAST,-2) < vStoch.getValue(StochStudy.SLOW,-2)&&
    vStoch.getValue(StochStudy.FAST,-1) > vStoch.getValue(StochStudy.SLOW,-1)){
    Alert.addToList(getSymbol(),"BUY S21 (Crossing Up)",Color.black,Color.blue);
    trade.Buy(getSymbol(), 1, IBBroker.MARKET);

    }

    and not this one:

    if ((nsignal > 0)) {
    nNewTrade = 0;
    drawShapeRelative(0, low() -1.25, Shape.UPARROW, null, Color.green, Shape.ONTOP, getValue("rawtime") + "B");
    if (LongEntryOption == 0) {
    Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR, DefEntryContracts);
    Alert.addToList(getSymbol(),"BUY MA 10e-15e (Crossing Up)",Color.black,Color.blue);
    trade.Buy(getSymbol(), 1, IBBroker.MARKET);
    ProfitTargetStage = 0;
    TradeType = 1;

    Of course ' var trade = new IBBroker; ' is declared in both cases.

    In both cases the Alert is properly being shown.

    Thank you for your help...

    Cheers,

    Andrei

  • #2
    Hello Andrei,

    I would first recommend removing any Strategy.xxx calls. The Strategy object is for back testing on historical bars only. It may be causing you some problems when the formula is executing in real time. If that doesn't do it for you then you'll need to use the debugPrintlin() function and check to see that the value of nsignal is greater than 0 and that LongEntryOption is equal to 0. Try something like the following:

    PHP Code:
    debugPrintln(getCurrentBarIndex() + "  nsignal= " nsignal);
    if ((
    nsignal 0)) {
        
    nNewTrade 0;
        
    drawShapeRelative(0low() -1.25Shape.UPARROWnullColor.greenShape.ONTOPgetValue("rawtime") + "B");
        
    debugPrintln(getCurrentBarIndex() + "  LongEntryOption= " LongEntryOption);
        if (
    LongEntryOption == 0) {
            
    //Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR, DefEntryContracts);
            
    Alert.addToList(getSymbol(),"BUY MA 10e-15e (Crossing Up)",Color.black,Color.blue);
            
    trade.Buy(getSymbol(), 1IBBroker.MARKET);
            
    ProfitTargetStage 0
            
    TradeType 1
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment

    Working...
    X