Here is how I built it in Strategy Builder:
Calculate on bar close
Created variables for long stop loss and short stop loss
Conditions and Actions Set 1: market position = flat. set the long stop loss as the low of current candle. Set short stop loss as high of current candle.
Set 2: Long entry conditions creating long entry order
Set 3: Market position = long. Create stop loss order using long stop loss variable for price. Create take profit order using middle bollinger band as target.
Set 4: Short entry conditions creating short entry order
Set 5: Market position = short. Create stop loss order using short stop loss variable for price. Create take profit order using middle bollinger band as target.
This generally works well, except for the situation identified above. For example, a long order is set to enter at 1.02. That order gets filled early in next candle. Stop loss order should be set at 1.01, but isn't set until the next candle closes. The candle reverses hard and closes at 1.005 preventing a stop loss order from being set.
The solution to this would be for stop loss and take profit to be set immediately after the entry order fills. I have tried to use the Stops and Targets section of Strategy Builder for this (which does set them immediately), but that did not work either.
Does anyone know how I can fix this? I imagine it is probably a pretty simple fix, but I just can't figure it out. I expect that I will probably need to make a manual change to the code. I am not an experienced coder, but do have some working knowledge of ninjascript.
Any help would be greatly appreciated!
Comment