PlaceOrder needs proper arguments

Hi,

I have coded as below to place bracket order.

_SECTION_BEGIN("Order"); 

if(LastValue( Buy ))
{
  ibc = GetTradingInterface("IB");   // check if we are connected OK
  
  if( ibc.IsConnected() )
  {
     if( ibc.GetPositionSize( Name() ) == 0 )
     {   
		  
		parentID = ibc.Placeorder(Name(), "Buy", 1, "MKT", 0, 0,  "Day", False); 
		ibc.Placeorder( Name(), "Sell", 1, "LMT", brd1, 0,  "Day", False, 1, "", parentID); 
		ibc.Placeorder( Name(), "Sell", 1, "STP", bpd, bpd, "Day", True, 1, "", parentID);

         }
	}
}

_SECTION_END();

I am getting an error

Error 19: COM method/function Placeorder call failed. COM error:Type mismatch on one or more argument(s) (Ln:138, Col:84)

image

BH = ValueWhen (Buy , H);    // Todays high              
BL = ValueWhen (Buy , L);     // todays low              
BC = ValueWhen(Buy , C);    // todays close              
BR = BH - BL;          
      
Bpd = (BH+ BL + BC )/3;        
Bsd1 = (2*Bpd)-BH;            
Bsd2 = Bpd -BR;        
Bsd3 = BSd1 - BR;       
Brd1 = (2*Bpd)-BL;        
Brd2 = Bpd + BR;       
Brd3 = Brd1 + BR;   

Please help me.

You need to pass SCALAR, not array. Currently all your B* variables are arrays.

https://forum.amibroker.com/search?q=scalar%20not%20array

Before you try auto-trading you should LEARN AFL basics

1 Like

Thank you. I am trying to use pivot points as my target and SL. For my buy transaction target would be resistance1 (brd1) and SL as pivotpoint (bpd). Can you please advise how to modify the existing code.

You'll typically find that you want to use the LastValue() function to extract the last value from an array when it comes to getting real-time or close-to-real-time values to place actual trades through IB.

1 Like

Thank you,

I have created the below code to create auto orders. But the sell order is not executing. Can you please advise.

BH = ValueWhen (Buy , H); // Todays high
BL = ValueWhen (Buy , L); // todays low
BC = ValueWhen(Buy , C); // todays close
BR = BH - BL;

Bpd = (BH+ BL + BC )/3;
Bsd1 = (2Bpd)-BH;
Bsd2 = Bpd -BR;
Bsd3 = BSd1 - BR;
Brd1 = (2
Bpd)-BL;
Brd2 = Bpd + BR;
Brd3 = Brd1 + BR;

Sell=Cross(C,Brd1) OR TimeNum()>=152500;

_SECTION_BEGIN("Order execute");

ibc = GetTradingInterface("IB");

if( ibc.IsConnected() )

{

if( LastValue( Buy ) )

{ if( ibc.GetPositionSize( Name() ) == 0 )
{ ibc.PlaceOrder( Name(), "Buy", 5, "MKT", 0, 0, "Day", True );}
}

if( LastValue( Sell ) )

            { if( ibc.GetPositionSize( Name() ) != 0 )
                           { ibc.PlaceOrder( Name(), "Sell", 5, "MKT", 0, 0, "Day", True ); }  
 }

}
_SECTION_END();

I'd suggest you put some _TRACE statements along the path to the sell order to prove LastValue(Sell) returns true and the position size is not zero. Whenever you have some logic that doesn't work the way you expect it will, it's best to make no assumptions on the values of the variables involved in real-time.