Hi,
I want to place orders to all stocks in a watchlist at a specific time. From the AFL Formula Editor window, if I simply click Apply button, the code will apply to the chart window and the order for that stock is placed in IB. But how do I apply the code to every stocks in a watchlist? The simple code for testing is like this:
TimeFrameSet(inDaily);
stockgapup=LastValue(Ref(C,-1))<LastValue(O);
stockgapdown = LastValue(Ref(C,-1))>LastValue(O);
r1=LastValue(Ref(ATR(3),-1))/12;
share=round(10/r1)*10;
TimeFrameRestore();
ibc = GetTradingInterface("IB");
if (Now(4) == 105458)
{
if( ibc.GetPositionSize( Name() ) == 0)
{
if(stockgapup)
{
high1 = LastValue(H);
limitPriceLong = high1 * 1.001;
stopPriceLong = high1+0.01;
stopLossPriceLong = stopPriceLong - r1;
takeProfitPriceLong = stopPriceLong + r1*2;
parentID = ibc.PlaceOrder(Name(), "BUY", share, "STP", limitPriceLong, stopPriceLong, "GTC", False );
ibc.PlaceOrder(Name(), "SELL", share, "LMT", takeProfitPriceLong, 0, "GTC", False, 100, "", parentID );
ibc.PlaceOrder(Name(), "SELL", share, "STP", 0, stopLossPriceLong, "GTC", False, 100, "", parentID );
}
else
{
low1 = LastValue(L);
limitPriceShort = low1 * 0.999;
stopPriceShort = low1-0.01;
stopLossPriceShort = stopPriceShort + r1;
takeProfitPriceShort = stopPriceShort - r1*2;
parentID = ibc.PlaceOrder(Name(), "SELL", share, "STP", limitPriceShort, stopPriceShort, "GTC", False );
ibc.PlaceOrder(Name(), "BUY", share, "LMT", takeProfitPriceShort, 0, "GTC", False, 100, "", parentID );
ibc.PlaceOrder(Name(), "BUY", share, "STP", 0, stopLossPriceShort, "GTC", False, 100, "", parentID );
}
}
}
Thanks,
HWM