Question regarding OnTick()

 

Hi, is there a simple way to specify I want my buy and sell orders only to fire up when price is within Bollinger Bands?

I've written logic that successfully fires up orders when Moving Average crosses top or bottom Bands, but once takeprofit or stop loss is reached, the next order fires up before Moving Average has a chance to go inside Bands again... I want to write something that gives Moving Average room to return to inside the Bollinger Bands and wait for the next breakout.

 Any thoughts?

Attached is a picture showing a example on detail. On the picture I'm using keltner channels though (same logic as Bollinger Bands).

First blue arrow up: buy order is fired.

First red arrow down: take profit is reached, buy order is closed 

Second blue arrow up: Shouldn't fire before red Moving Average has a chance to return inside channel.

 

Thanks! 

Files:
fires_up.png  4 kb
 
What about adding internal variable "waitNext" = true / false ?
 
Sounds like your logic might be slightly flawed somewhere. As soon as an order is closed it should be checking again for the buy/sell signal but sounds like the order trigger is "stuck on". Anton's suggestion above is a good start. If you still have no joy, maybe post some code up so others can try to help you in more detail.

Cheers
 

I would agree with roman5,

when the event happens set a variable

when the price is back in range change the variable

Reason: