[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] autotrading: multiple signals being generated on the previous bar



PureBytes Links

Trading Reference Links

After posting this message:
http://finance.groups.yahoo.com/group/amibroker/message/137490

Which brings up a point on signals on the current bar in real time.  Namely, they may occur many times until that bar is finally written/printed.  I tried my strategy with the bar replay tool and found that I indeed was generating multiple signals to the (IB) auto-trader.  

I tried users/Thomas' suggestion of using 
buy=ref(buy, -1), but I still get multiple signals.  

http://finance.groups.yahoo.com/group/amibroker/message/132762
http://finance.groups.yahoo.com/group/amibroker/message/132761

Is there something else that I am missing to make the buy on prev bar work.  All I REALLY want to do is have a signal generated on the current bar, and then act (open a trade) on that signal on the NEXT bar open.  Basically simulating the settradedelay(1,1,1,1) function, but with real trading.  

here is my code below...you will see multiple traces showing multiple buy signals.  Note that useIB is false so AT is turned off.

useIB=0;

starttime=TimeNum() >= 094500 AND TimeNum() <=154500;
test=0;
Minprice=5;
PositionSize = -20; // use minuse for -xx% of equity

if (useIB)
{
	ibc = GetTradingInterface("IB");
}

//delay=Optimize("tradeDelay", 1, 1, 1, 1);
//SetTradeDelays(delay, delay, delay, delay);

Buy = Cross((Close),(EMA(Close,9))); 

// this should delay the signal for the next bar - right? 
Buy=Ref(Buy, -1);

Buystop = Ref(EMA(Close,9),-1); 
BuyPrice = Max(Buystop,Low); 

// not worried about delaying the sell signal until I get the buy signal working
Sell = Cross(EMA(Close,9),(Close));
Sellstop = Ref(EMA(Close,9),-1); 
SellPrice = Min(sellstop,High); 

Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

if (LastValue(Buy))
{
		_TRACE("BUYprice: " + BuyPrice + ", time=" + TimeNum()); 
	
		if (useIB)
		{
 			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( Name() ) == 0 )
     			{
	   	   			// transmit order
					ibc.PlaceOrder( Name(), "Buy", 10, "MKT", 0, 0, "Day", True );
	     		}
  			}
		}
}

if (LastValue(Sell))
{
	_TRACE("Sellprice: " + SellPrice + ", time=" + TimeNum()); 

  	if (useIB)
	{
	  ibc = GetTradingInterface("IB");

	  // check if we are connected OK
	  if( ibc.IsConnected() )
	  {
	     // need to have open position
	     if( ibc.GetPositionSize( Name() ) > 0 )
	     {
	        // transmit order
	        ibc.PlaceOrder( Name(), "Sell", 10, "MKT", 0, 0, "Day", True );

 			 StaticVarSet(Name(), 0);
	     }
	  }
	}
}

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorBlue, colorRed ), 0, IIf( Buy, Low, High ) );
PlotShapes(IIf(Buy ==1, shapeUpArrow,shapeNone),colorBlue,0,0,10);
PlotShapes(IIf(Sell ==1, shapeHollowUpArrow,shapeNone),colorRed,0,0,10);





------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/