help!!

#1
Hi All,

New to programming and to this site.
Been stuck on one problem for days.
Below is part of a program I am having trouble with. Everything works fine up to:
if( LastValue(Timetobuy) )
all the trading signals show up in the right spots, but it refuses to enter that if... loop. If I change it to "if( LastValue(Buy) ), it works, but sends too many signals.
Would like to send only one trade per signal.
Thanks in advance


barcomplete = BarIndex() < LastValue(BarIndex());

Timetobuy=IIf(barcomplete AND Buy AND ATR(14)>0.50 AND CA>0 AND CA<75,1,0);

PlotShapes( IIf(Timetobuy==1, shapeSmallCircle, shapeNone ), colorGreen, layer = 0,yposition = HaLow, offset = -10);



if( LastValue(Timetobuy) )
{

ibc = GetTradingInterface("IB");
// check if we are connected OK
if( ibc.IsConnected() )
{
// place orders only if we do not have already open position on this symbol
if( ibc.GetPositionSize( Name() ) == 0 )
{
// retrieve orderID from previous run, will be empty if no order was placed before
OrderID = StaticVarGetText("OrderID"+Name());

// place or modify the order - don't transmit yet
parentID = ibc.PlaceOrder(Name(), "Buy", 1, "LMT", LastValue( C ), 0, "DAY", False );
ibc.PlaceOrder(Name(), "SELL", 1, "LMT",LastValue( C )+1, 0, "DAY", False, "", 0, parentID );
ibc.PlaceOrder(Name(), "SELL", 1, "STP", LastValue( C )-2, LastValue( C )-2, "DAY", False, "", 0, parentID );


// store orderID for next run so we know which order to modify
StaticVarSetText("OrderID"+Name(), OrderID);

}
}
}
 
Last edited:

Similar threads