TradingView
GordonR
17 יולי 2017 13:00

Help needed with strategy - Entry is off by 2 candles 

GOLD (US$/OZ)TVC

תיאור

Hi,

I'm new to TradingView, and would greatly appreciate some help with figuring out where I'm going wrong with this script.

This is a overly simplified version of what I'm actually trying to do, but hopefully it's easier to see the problem.

Here I'd like to create a Buy signal when the fast moving average crosses over the slow moving average, and Sell when the reverse happens.


If I draw arrows when the condition is met then they are one candle later than expected (probably because I'm using the closing values ??).
That not great, but workable.

My real problem comes when I try turning this into a strategy.
Now the signal only triggers 2 candles after the crossover.

What am I doing wrong here?

Thanks,
Gordon
תגובות
MrGlass_
Add this to your strategy statement in the top:
process_orders_on_close=true
bpu4211
@netfastnl, Awesome bro!!!!!!!!! <-- This fixed it for me
quantient
@netfastnl, thank you so much
Skywalking2874
@MrGlass_, Thanks this solved the problem. The reason this works for anybody who is interested:
- Strategies are only calculated once per bar, triggered by the bar close event
- No orders can be executed on that bar since the market is already closed at the time the strategy is calculated
- Setting the process_orders_on_close to true allows the broker emulator to execute orders on the bar even though the market is closed
Cotya224
@MrGlass_, Thanks a lot bro. you are a life saver
kaka900
Hi, did you manage to solve the problem?
robott
Not sure, but perhaps the crossover (which compares last bar vs current bar) and using close as the source, are adding up for the two bars delay. Perhaps using >= and <=, instead of the crossover function can improve your entry time.
GordonR
@robott, sorry I forgot to say thanks for the advice. It's helped me improve my indicators.
AKR_79
@GordonR, Hey Gordon.. I know its long since you asked this question.. Were you able to fix this ? for me the >= or <= is also not working.. I have a 1 candle delay and this causes significant mistakes is strategy profit/loss calculations.. Let me know if you fixed it..
עוד