Here is a simple WL script. How do I program TWSLink to send orders to IB?
*************************
var Bar: integer;
for Bar := 2 to BarCount - 2 do
begin
if not LastPositionActive then
begin
if (priceClose(bar) < priceOpen(bar)) then
buyAtStop(bar+1, (priceOpen(bar+1) + (priceClose(bar) - priceLow(bar))), 'open+1/2 entry');
if (priceClose(bar) > priceOpen(bar)) then
shortAtStop(bar+1, (priceOpen(bar+1) - (priceHigh(bar) - priceClose(bar))), 'open-1/2 entry');
end
else
begin
if PositionLong(LastPosition) then
if (priceClose(bar) > priceOpen(bar)) then
SellAtStop(bar+1, (priceOpen(bar+1) - (priceHigh(bar) - priceClose(bar))), LastPosition, 'open-1/2 exit');
if PositionShort(LastPosition) then
if (priceClose(bar) < priceOpen(bar)) then
CoverAtStop(bar+1, (priceOpen(bar+1) + (priceClose(bar) - priceLow(bar))), LastPosition, 'open+1/2 exit');
end;
end;
********************
Thank you.