IBcontroller Order becomes presubmited (Scalein order with IBcontroller)

Greetings,

I tried sending orders with the IBcontroller, at first it went smoothly with BUY and SELL orders as usual.

openposition       = StaticVarGet(Symbol + "openposition");

if (IsEmpty(openposition)){ 
    openposition = 0;
}
RequestTimedRefresh(1);
ibc = GetTradingInterface("IB");

Transmit = ParamToggle("Transmit to IB","OFF|ON", 0); 
if (Transmit){
    StartIBClockTime = Now(4); 
    ibc = GetTradingInterface("IB");
    SetChartBkColor( colorBlue); 
}

if( LastValue(Ref(BUY,-1)) AND openposition==0 AND transmit==1){
    orderid=ibc.PlaceOrder( Name(), "BUY1", 100, "MKT", 0, 0, "Day", Transmit );
    openposition=1;
    StaticVarSet(Symbol + "openposition", 1);
}

if(  LastValue(Ref(Sell,-1)) AND openposition==1 AND transmit==1 ){
  ibc.PlaceOrder( Name(), "SELL", 100, "MKT", 0, 0, "Day", Transmit );
  openposition=0;
}

Then I want to change it with a Scalein order and suddenly the status changes to presubmited,

openposition       = StaticVarGet(Symbol + "openposition");

if (IsEmpty(openposition)){ 
    openposition = 0;
}
RequestTimedRefresh(1);
ibc = GetTradingInterface("IB");

Transmit = ParamToggle("Transmit to IB","OFF|ON", 0); 
if (Transmit){
    StartIBClockTime = Now(4); 
    ibc = GetTradingInterface("IB");
    SetChartBkColor( colorBlue); 
}
//////////////////////First buy////////////////////////////
if( LastValue(Ref(BUY1,-1)) AND openposition==0 AND transmit==1){
    orderid=ibc.PlaceOrder( Name(), "BUY1", 100, "MKT", 0, 0, "Day", Transmit );
    openposition=1;
    StaticVarSet(Symbol + "openposition", 1);
}
//////////////////////Second Buy///////////////////////////
if( LastValue(Ref(BUY2,-1)) AND openposition==1 AND transmit==1){
    orderid=ibc.PlaceOrder( Name(), "BUY1", 100, "MKT", 0, 0, "Day", Transmit );
    openposition=2;
    StaticVarSet(Symbol + "openposition", 2);
}

if(  LastValue(Ref(Sell,-1)) AND openposition==2 AND transmit==1 ){
  ibc.PlaceOrder( Name(), "SELL", 100, "MKT", 0, 0, "Day", Transmit );
  openposition=0;
}

what's my mistake here?

need your help and thank you

You can't use "BUY1". It is not valid string for second parameter (i.e. Action) of PlaceOrder call. Valid action strings are "BUY", "SELL" and "SSHORT" as documented IBController 1.3.8 READ ME and only such value can be used.

1 Like

Thank you Tomasz! it's work now.

Do you have input regarding scale in order to the iBcontroller?
what do you think about my code ? is there a better way?

Scaling at IB does not differ from opening any other order. If you buy a stock that you already have it will just add to your position (scale in). Nothing special about it.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.