Login Page - Create Account

Support Board


Date/Time: Fri, 29 Mar 2024 08:00:55 +0000



[User Discussion] - Divergence Line Drawing

View Count: 5036

[2015-02-13 05:58:32]
CustomIndicators - Posts: 126
Making a divergence indicator, I'm having a little trouble getting the lines to draw.

There are persistent variables correctly holding DateTime data, and persistent variables correctly holding indicator values. I know this, as one of the other drawings, is using the variables to draw correctly.

/* ********************** START OF CODE ********************** */
// These persistent variables have been correctly filled in another part of the code.

float& peakOne = sc.PersistVars->f1;
SCDateTime& peakOneDT = sc.PersistVars->scdt1;
float& peakTwo = sc.PersistVars->f2;
SCDateTime& peakTwoDT = sc.PersistVars->scdt2;

s_UseTool Divergence;

Divergence.Clear();
Divergence.ChartNumber = 1;
Divergence.AddMethod = UTAM_ADD_OR_ADJUST;
Divergence.LineNumber = 852739;
Divergence.DrawingType = DRAWING_LINE;
Divergence.Color = RGB(0,255,0); // Red,Green,Blue
Divergence.LineWidth = 1;
Divergence.BeginDateTime = peakTwoDT;
Divergence.BeginValue = peakTwo;
Divergence.EndDateTime = peakOneDT;
Divergence.EndValue = peakOne;

// Just so I know for sure that the peakOne and peakTwo have the correct values, I had them show up in the log.
// They both correctly showed up in the log.
// The same was done for the SCDateTime pers vars, and they also came up with the correct DateTimes.

SCString BufferPOne;
BufferPOne.Format("Peak 1: %f", peakOne);
sc.AddMessageToLog(BufferPOne, 0);

SCString BufferPTwo;
BufferPTwo.Format("Peak 2: %f", peakTwo);
sc.AddMessageToLog(BufferPTwo, 0);

sc.UseTool(Divergence);

// So far, the code doesn't show any lines.
/* ********************** END OF CODE ********************** */

Any ideas as to how I can get this to work properly?
[2015-02-13 19:32:51]
CustomIndicators - Posts: 126
Am I doing something wrong here? Its the only place I can think of:

Divergence.BeginDateTime = peakTwoDT;
Divergence.EndDateTime = peakOneDT;
[2015-02-13 19:44:54]
Sierra Chart Engineering - Posts: 104368
Nothing obviously wrong.

This does not need to be set:

Divergence.LineNumber = 852739;

It will be automatically set. But this is not the problem.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2015-02-13 19:51:55]
CustomIndicators - Posts: 126
Hmmm, alright. Is there anything I can give you, that may help you see the problem?
[2015-02-13 22:14:11]
CustomIndicators - Posts: 126
Another little update on this, I've tried the following, and it was also unsuccessful.

//Divergence.BeginDateTime = peakTwoDT;
Divergence.BeginIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber,peakTwoDT);
Divergence.BeginValue = peakTwo;
//Divergence.EndDateTime = peakOneDT;
Divergence.EndIndex = sc.GetContainingIndexForSCDateTime(sc.ChartNumber,peakOneDT);
Divergence.EndValue = peakOne;
[2015-02-23 16:25:24]
CustomIndicators - Posts: 126
Could it be that DRAWING_LINE can only be used on subgraphs, and not persistent variables?
[2015-11-11 09:20:19]
User13668 - Posts: 291
User123,

Was the purpose of this Divergence Line Drawing to automatically spot divergence between price data and a study output displayed in another region on the chart?

Did you ever get it sorted?
[2015-11-11 18:28:08]
CustomIndicators - Posts: 126
User13668,

Yes, that was the purpose, and yes, I did get it sorted. It works good for the most part. The only problem is that on occasion, it will miss-draw a line starting/ending point if the datetimes are matching on multiple candles in a row.
[2015-11-11 20:03:42]
User13668 - Posts: 291
Would you mind sharing it?

Thanks in anticipation.
[2015-11-11 20:34:11]
CustomIndicators - Posts: 126
Sure, I don't see why not. Just a heads up, its based on the Stochastic Momentum Indicator's SMI line.

It won't backfill drawings, so if you want to see what happened before, just replay the chart to fill them in.

I've got Divergences in here, colored Blue.
I've got Continuations in here, colored Yellow.

I placed options in the settings that will allow you to adjust the SMI line.

White lines that flicker on and off are Continuations that haven't locked yet.

Turquoise lines that flicker on and off are Divergences that haven't locked yet.

A secondary mark that will tell you if they are locked or not locked yet, is the arrows that appear. Big arrows haven't locked yet. When it locks, they become smaller.

If you would like me to change the oscillator over to one of your preference, let me know. I'm perfectly happy to take the 5 minutes it takes to code it. This can be anything from your personal oscillator line, to one of the existing studies such as the MACD. I can pull arrays from any other indicator for this purpose.

When adding the custom study, you will notice that there is an indicator, and a bot in the DLL. Don't trust the bot. It isn't finished, and will just lose you money. To be safe, I coded for the bot to force simulation mode when placed onto the chart, but by changing the setting: "Simulation Mode On" from 0 to 1, it will become active. I recommend not using the bot. It simply doesn't have a good exit strategy yet.

If you have an exit in mind that you think would work well, we can work with each other in private to try it out. I find that using continuations and divergences together can make wonderful bot entry points. Just gotta find the right combination. If we get it working, we can share it.

PS: Sorry about the name of the study. I'm in a room all alone every day coding bots, and simply need some entertainment.
attachmentDiveCunt.dll - Attached On 2015-11-11 20:34:03 UTC - Size: 298 KB - 638 views
[2015-11-11 21:15:18]
User13668 - Posts: 291
Thanks for that and the detailed guide.

I will have a play with it and come back if I need you to change the oscillator.

I have no intention of using it for automatic trading.
[2015-11-11 21:21:42]
CustomIndicators - Posts: 126
Sounds good man. Good luck, and happy trading!
[2015-11-15 09:02:54]
Futures Operator - Posts: 239
Hi User123, thank you for sharing this, been looking for something like for some time, its excellent!

Some questions:

Any way to adjust how it identifies the swing points to check for divergences on? Sometimes it does not identify the swings I am looking for divergences on, on the MACD, ie I am looking at a bearish divergence, and it draws the bullish convergence before it, and the bearish convergence after it, but missed the bearish divergence in between, pic attached. What is the logic used?

Any chance you could post a version for a MACD histogram on default settings, and a MACD 3/10 oscillator? (settings attached)

Possible to produce an alert signal in SC on the divergence, ie play sound alert?

Would it be much work to allow formatting/customization of the arrows/lines, ie color, hide/show convergences, etc?

Thanks, any help appreciated!
imageDiveCunt Missed Divergence.png / V - Attached On 2015-11-15 08:59:47 UTC - Size: 22 KB - 899 views
Attachment Deleted.
imageMACD 3-10 OSC.png / V - Attached On 2015-11-15 09:01:10 UTC - Size: 12.49 KB - 758 views
[2015-11-15 16:41:34]
CustomIndicators - Posts: 126
Futures Operator,

The way this algo identifies swing points, is this. I'll give the example of locked swing points.

Lets say there are 4 candles. 3, 2, 1, and 0.
0 is the live candle.
1 is the last locked candle, etc.

For a Peak:
if 3 < 2 and 2 > 1

For a Valley:
if 3 > 2 and 2 < 1

Do you prefer a different method of identifying swing points?

I'm not at my trading office right now due to it being the weekend, so I can't look at my code to be sure at the moment. I believe the divergences are something like this:

Lets say, we are keeping track of 2 Peaks, and 2 Valleys.
Peak1 is the last locked peak.
Peak2 is the second locked peak back.

Valley1 is the last locked valley
Valley2 is the second locked peak back.



--- Divergences:

Price chart:
if Peak2 > Peak1

Oscillator:
if Peak2 < Peak1

------------------

Price chart:
if Peak2 < Peak1

Oscillator:
if Peak2 > Peak1


Does that make sense? I hope I'm writing this correctly.


For the MACD version, which line would you want to be used for the divergence/convergence lines?

Yes, customization of the arrows/lines for colors and show/hide could be easily put in.

I'm sorry about the miss-draw. The reason for this is that the candles in that area have the same timestamp down to the second. You are using a tiny tick chart, so this will happen. I tried to fix it when I was working on this study. No luck. Perhaps I'll give it another shot one of these days.
[2018-03-07 08:23:57]
User7817001 - Posts: 96
good day, this thread is the closest I have found for what I am looking for, the divergence study, based on slopes, does not work, how do I load the dll and try this study, thank you ahead of time
[2018-03-08 15:32:06]
User7817001 - Posts: 96
was afraid to run the .dll, should I be?
[2018-03-08 20:00:01]
CustomIndicators - Posts: 126
The DLL is safe, don't worry. I don't have the source code for this anymore. If you want to add it to a chart, you drop the DLL into C:/SierraChart/Data/ on your computer. At least, thats where my SC is installed to.

Open a chart up -> Right click the chart -> Studies -> Add Custom Study -> Press the + to the left of this DLL, and select the study. Add it to the chart.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account