As the ApplyStop(); function only works for backtesting functionalities I was wondering how I would use this feature for the IBcontroller WITHOUT doing a bracket order. I say this because on my back test I dont have the SetOption("ActivateStopsImmediately", True); meaning that if the stop/tp is indeed hit it close the position on the close of the current bar at the next bars open if you get what I am saying. I thought coding somthing that actually returns a array would work such as:
exit = C >= Ref(LastValue(Buy) + ATR(14), -1) OR C <= Ref(LastValue(Buy)-ATR(14), -1)<=C;
PlotShapes(exit * shapeUpArrow, colorYellow);
However that did not work and all it did was just plot a bunch of random yellow arrows on my screen lol. What I am trying to do is have it so I can a tp/sl array is returned whenenver the current bars high/low is >/< then the value when the last buy signal was plotted + ATR of when the buysignal occurred so I can write a code that looks something like this:
if( LastValue( exit ) )
{
ibc = GetTradingInterface("IB");
// check if we are connected OK
if( ibc.IsConnected() )
{
// check if we do not have already open position on this stock
if( ibc.GetPositionSize( "ESH1-GLOBEX-FUT" ) > 0 )
{
// transmit order
ibc.PlaceOrder("ESH1-GLOBEX-FUT", "Sell", 1, "MKT", 0, 0, "GTC", True );
ibc.Sleep( 4000 ); // sleep for 4000 milliseconds = 4 second (Time require for Ib to prove the buy )
}
}
}
ps I know its not best practice to have to have ibc.Sleep(); however because this algo is based off of closing values I feel its ok. If you believe other wise please explain your perspective