October 3, 2021 at 1:10 pm #66203
Hello, I am trying to do a backtest using the Divergence tool to show positive divergence between Price and a 13 period RSI but having a difficult time. It is not identifying all trades and is taking some trades that are not indicated. I have gone through all of the tutorials but I am still having trouble determining the coding syntax and what is returned. The exit criteria is the same except for type = negative, however it’s closing the trades on positive divergence and ignoring the negative divergence. Thank you.123456789//Variable for pricex1 = CLOSE();//Variable for RSIx2 = RSI(BARS=13);//Divergence ToolDIVERGENCE(x1, x2, BARS=6, type = positive)123456x1 = CLOSE();x2 = RSI(BARS=13);DIVERGENCE(x1, x2, BARS=6, type = negative)
October 5, 2021 at 10:22 am #66251Matthew
- This topic was modified 2 weeks ago by Mark.
- Topics: 5
- Replies: 430
- Posts: 435
The Divergence() function doesn’t have a Type field to reference. The way it works is a result of +1 is a positive divergence and -1 is a negative divergence.
If you wanted to buy for a positive divergence you could use:12345x1 = CLOSE();x2 = RSI(BARS=13);DIVERGENCE(x1, x2, BARS=6) > 0
and to exit on a negative divergence would be:12345x1 = CLOSE();x2 = RSI(BARS=13);DIVERGENCE(x1, x2, BARS=6) < 0
If you apply a divergence script via a Show View along the bottom of the chart you will see where it is triggering for positive / negative divergence. Not every bar in the shaded zone will be a match, to see why i’d recommend viewing the chart with training mode, you can see how the zones build as new data comes in).October 6, 2021 at 6:15 am #66263
Thank you Matthew, I appreciate the quick response and insight. Just a follow up question, how do I tell what fields a function returns. I know some of them are listed using the dot script but some either do not list anything or have fields not listed?
I saw a reference of a white paper on scripting but when I clicked the link an error message was returned.
thank you,October 6, 2021 at 6:09 pm #66269Darren
- Topics: 66
- Replies: 679
- Posts: 745
Either using the dot notation or clicking on the function text will show you the outputs available under Default Plot, eg for MACD:
The divergence function is different in that it’s a true / false signal so you will see the output values (+1 / -1) when using it in a Show View as per Matthew’s example above.
As for the whitepaper please send the link to support and we’ll get it fixed. If you haven’t already done so, I’d highly recommend the 3 scripting tutorial courses available when signing in here:October 7, 2021 at 12:33 pm #66275
I found the paper https://dl.optuma.com/public/files/MarketAnalyst8-Scripting.pdf and the link is working so all good.
Thanks for your response.
- You must be logged in to reply to this topic.