Dear Sir,
Greetings!
I tested my afl in live market, but find unexpected results, very different from when I tested it off-line. When the Buy signal is generated, the system(afl) keeps on buying, repeatedly, until the Sell signal is generated. And, when the Sell signal is generated, the system keeps on selling, repeatedly, until the Buy signal is generated.
I have tried using program control methods like Boolean flags, state control, etc, but still the problem persists.
Here is the code
_ib = GetTradingInterface( "IB" );
if( LastValue( TimeNum() ) < 152930 AND _ib.IsConnected() ){
_mfi = mfi( 2 );
_mfi_prev = Ref( mfi( 2 ), -1 );
if( LastValue( _mfi ) > LastValue( _mfi_prev ) ){
_position = _ib.GetPositionSize( Name() );
if( _position == 0 ){
_order_id = _ib.PlaceOrder( Name(), "BUY", _lot_size, "MKT", 0, 0, "DAY", True);
_position = _ib.GetPositionSize(Name());
}
}
if(_position > 0){
_order_id = _ib.PlaceOrder( Name(), "SELL", _position, "MKT", 0, 0, "DAY", True);
_position = _ib.GetPositionSize(Name());
}
}
How do I prevent such repeated Buy or Sell in the afl?
Could you kindly advice?
Thank you
Sincerely
Subhash Nayak