Hey guys,
Ive tried and searched everything but couldnt find a solution.
Im not sure, its an issue coupled to the Demo issue or its just bad coding im really new to AFL and IBC.
Here is my Code:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// plot price //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// calculate trading signals and plot them //////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Buy = Cross(ATR(10),Ref(ATR(10),-1));
Sell = 0;
Short = 0;
Cover = 0;
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, L);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone), colorRed, 0, H);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// stop loss //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
StopLevel = 1 - Param("trailing stop %", 0.05, 0.01, 10, 0.01)/100;
trailARRAY = Null;
trailstop = 0;
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * stoplevel;
}
if( trailstop > 0 AND Low[ i ] < trailstop )
{
Sell[ i ] = 1;
SellPrice[ i ] = trailstop;
trailstop = 0;
}
if( trailstop > 0 )
{
trailstop = Max( High[ i ] * stoplevel, trailstop );
trailARRAY[ i ] = trailstop;
}
}
Plot( trailARRAY,"trailing stop level", colorRed );
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IB Controller Commands //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ibc = GetTradingInterface("IB");
// for long
if( LastValue( Buy ) )
{
// check if we are connected OK
if( ibc.IsConnected() )
{
// check if we do not have already open position on this stock
if( ibc.GetPositionSize( Name() ) == 0 )
{
// brachet order
parentID = ibc.PlaceOrder(Name(), "BUY", 100, "MKT", 0, 0, "GTC", True );
ibc.PlaceOrder(Name(), "SELL", 100, "LMT", 0, 0, "GTC", True, 100, "", parentID );
ibc.PlaceOrder(Name(), "SELL", 100, "STP", 0, 0, "GTC", True, 100, "", parentID );
}
// remove double orders in IBC (Demo Account)
ibc.Sleep( 4000 );
}
}
He is just not recognize the STP.
if im doing
ibc.PlaceOrder(Name(), "SELL", 100, "STP", trailARRAY, trailARRAY, "GTC", True, 100, "", parentID );
really weird things happens. Its transmiting the bracket order double without the stop loss.
Another Question is: Someone said, that the double order problem is solved by using "statvargettext" or something like that... Can someone can explain this?
Really appriciate some answers