Price Bands not printing correctly at end of chart - Sierra Chart Programming | futures io social day trading
futures io futures trading


Price Bands not printing correctly at end of chart
Updated: Views / Replies:314 / 4
Created: by vdhoek Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

Price Bands not printing correctly at end of chart

  #1 (permalink)
Trading Apprentice
Grand Rapids MI / USA
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Infinity Futures
Favorite Futures: Futures ES CL GC
 
Posts: 4 since Nov 2014
Thanks: 2 given, 1 received

Price Bands not printing correctly at end of chart

I have begun to delve into the world of programming with a bit of fear and trepidation. My goal has been to put together a custom indicator called “Price Bands” that will always maintain an equal distance between the top and bottom bands throughout, with price always in between. What will make the bands begin to move up or down is if price tries to break through one of the bands. If it breaks to the downside, both the top and bottom bands will begin to drop maintaining an equal distance in between. Price always stays in between the bands.

I have been able to take the simple Donchian channel study and modify it to fit what I want it to do, and my “Price Bands” work perfectly as the chart is loaded or refreshed. However, at the very end of the chart, as it adds more bars, the indicator does not maintain the equal distance. In fact, the indicators start to mimic the movement of price (Look at my two examples, one that is correct, the other incorrect).

(Sorry, I was going to post two pictures here showing what was happening, one working correctly, one incorrectly, but I guess I am supposed to have posted more posts to this site before being allowed to post any pictures. I didn't know that. Sorry! If anyone can give still give any advice, that would be appreciated.)

I have tried everything I could think of, but to no avail. It seems like when I turn “sc.FreeDLL = 0”, that makes it work better, but even then, not all the time. I am at a loss. Is there anyone who could give me some pointers on what I must do to make it perform correctly? I have included two different versions of code I have tried in attempt to solve the problem. Both work on a refresh, but not as new bars are added. I would greatly appreciate any help you could give me… Dan


First attempt:

 
Code
// The top of every source code file must include this line
#include "sierrachart.h"

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies. 
SCDLLName("Price Bands DLL")

float Lowest = FLT_MAX;
float Highest = -FLT_MAX;
int BarIndex;
	
	
SCSFExport scsf_PriceBands(SCStudyInterfaceRef sc)
{
	SCSubgraphRef HighestHigh = sc.Subgraph[0];
	SCSubgraphRef LowestLow = sc.Subgraph[1];
	SCSubgraphRef Midline = sc.Subgraph[2];
	SCInputRef Length = sc.Input[3];
	
	
	if (sc.SetDefaults)
	{
		sc.GraphName = "Price Bands";
		// During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. 
		// When development is completed, set it to 0 to improve performance.
		sc.FreeDLL = 0;
		sc.GraphRegion = 0;
		sc.AutoLoop = true;

		HighestHigh.Name= "Highest High";
		HighestHigh.DrawStyle=  DRAWSTYLE_LINE;
		HighestHigh.PrimaryColor = RGB(255,206,206);
		HighestHigh.LineWidth = 48;
		HighestHigh.DrawZeros= true;
		HighestHigh.GraphicalDisplacement= 1;

		LowestLow.Name = "Lowest Low";
		LowestLow.DrawStyle=  DRAWSTYLE_LINE;
		LowestLow.PrimaryColor = RGB(183,255,183);
		LowestLow.LineWidth = 48;
		LowestLow.DrawZeros= true;
		LowestLow.GraphicalDisplacement= 1;

		Midline.Name = "Mid Line";
		Midline.DrawStyle=  DRAWSTYLE_LINE;
		Midline.PrimaryColor = RGB(232,232,232);
		Midline.LineWidth = 56;
		Midline.DrawZeros= true;
		Midline.GraphicalDisplacement= 1;

		Length.Name = "Band Width in Ticks";
		Length.SetInt(48);
		Length.SetIntLimits(1, MAX_STUDY_LENGTH);

		return;
	}
	
	float BandWidth = Length.GetInt() * sc.TickSize;
	float VertOffsetTop = sc.TickSize * (HighestHigh.LineWidth / 16.0f);
	float VertOffsetBot = sc.TickSize * (LowestLow.LineWidth / 16.0f);
	
	
	BarIndex = sc.Index - 1;
		
	if(sc.High[BarIndex] > Highest)
	{	
		Highest = sc.High[BarIndex];
		Lowest = Highest - BandWidth;
	}
	
	if(sc.Low[BarIndex] < Lowest)
	{	
		Lowest = sc.Low[BarIndex];
		Highest = Lowest + BandWidth;
	}
	
	HighestHigh[sc.Index] = Highest - VertOffsetTop;
	LowestLow[sc.Index] = Lowest + VertOffsetBot;
	Midline[sc.Index] = (Highest + Lowest) / 2.0f;
	
	//Following lines added for debugging, as needed
	//SCString Buffer;	
	//Buffer.Format("%d -- %f -- %f -- %f -- %f", sc.Index, sc.High[sc.Index], sc.Low[sc.Index], Highest, Lowest);
	//sc.AddMessageToLog(Buffer,1);
}


Second attempt:

 
Code
// The top of every source code file must include this line
#include "sierrachart.h"

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies. 
SCDLLName("Price Bands DLL")

float Lowest = FLT_MAX;
float Highest = -FLT_MAX;
int BarIndex;
	
	
SCSFExport scsf_PriceBands(SCStudyInterfaceRef sc)
{
	SCSubgraphRef HighestHigh = sc.Subgraph[0];
	SCSubgraphRef LowestLow = sc.Subgraph[1];
	SCSubgraphRef Midline = sc.Subgraph[2];
	SCInputRef Width = sc.Input[3];
	
	
	if (sc.SetDefaults)
	{
		sc.GraphName = "Price Bands";
		// During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart. 
		// When development is completed, set it to 0 to improve performance.
		sc.FreeDLL = 0;
		sc.GraphRegion = 0;
		sc.AutoLoop = true;

		HighestHigh.Name= "Highest High";
		HighestHigh.DrawStyle=  DRAWSTYLE_LINE;
		HighestHigh.PrimaryColor = RGB(255,206,206);
		HighestHigh.LineWidth = 48;
		HighestHigh.DrawZeros= true;
		HighestHigh.GraphicalDisplacement= 1;

		LowestLow.Name = "Lowest Low";
		LowestLow.DrawStyle=  DRAWSTYLE_LINE;
		LowestLow.PrimaryColor = RGB(183,255,183);
		LowestLow.LineWidth = 48;
		LowestLow.DrawZeros= true;
		LowestLow.GraphicalDisplacement= 1;

		Midline.Name = "Mid Line";
		Midline.DrawStyle=  DRAWSTYLE_LINE;
		Midline.PrimaryColor = RGB(232,232,232);
		Midline.LineWidth = 56;
		Midline.DrawZeros= true;
		Midline.GraphicalDisplacement= 1;

		Width.Name = "Band Width in Ticks";
		Width.SetInt(48);
		Width.SetIntLimits(1, MAX_STUDY_LENGTH);

		return;
	}
	
	float BandWidth = Width.GetInt() * sc.TickSize;
	float VertOffsetTop = sc.TickSize * (HighestHigh.LineWidth / 16.0f);
	float VertOffsetBot = sc.TickSize * (LowestLow.LineWidth / 16.0f);
	
		
	for(BarIndex = sc.Index - 1; BarIndex <= sc.Index; BarIndex++)
	{		
		if(sc.BaseDataIn[SC_HIGH][BarIndex] > Highest)
		{	
			Highest = sc.BaseDataIn[SC_HIGH][BarIndex];
			Lowest = Highest - BandWidth;
		}
	
		if(sc.BaseDataIn[SC_LOW][BarIndex] < Lowest)
		{	
			Lowest = sc.BaseDataIn[SC_LOW][BarIndex];
			Highest = Lowest + BandWidth;
		}
	}
	
	HighestHigh[sc.Index] = Highest - VertOffsetTop;
	LowestLow[sc.Index] = Lowest + VertOffsetBot;
	Midline[sc.Index] = (Highest + Lowest) / 2.0f;
	
	//Following lines added for debugging, as needed
	//SCString Buffer;	
	//Buffer.Format("%d -- %f -- %f -- %f -- %f", sc.Index, sc.High[sc.Index], sc.Low[sc.Index], Highest, Lowest);
	//sc.AddMessageToLog(Buffer,1);
}

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Trading Apprentice
Grand Rapids MI / USA
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Infinity Futures
Favorite Futures: Futures ES CL GC
 
Posts: 4 since Nov 2014
Thanks: 2 given, 1 received

Problem solved???? Comments still welcome...


Not sure. I may have solved my own problem. Both code examples work, though the first is simpler. But they seem to work only if I have one occurrence of the study in a chartbook. I'm not sure if by defining and using a global variable that when there is more than one occurrence of the study within the same chartbook but on different time frames, that the global variable information gets muddled between the two charts that the indicator is trying to print on??? Is that possible? Or does the global variable still maintain its independence from other occurrences that may be found in a chartbook. Any thoughts from a more experience programmer? Thanks in advance!

Reply With Quote
 
  #4 (permalink)
Elite Member
England
 
Futures Experience: Advanced
Platform: SierraChart
 
Posts: 58 since Jul 2009
Thanks: 5 given, 57 received

Hi

I have just got round to looking at your code. I don't know how it works by putting global variables outside of the routine. In ACSIL there is a way of defining persistent variables. I have fixed your code by using them. The way I do it is to load the variables with your minimum and maximum values in the set defaults block. Then, every time the routine is run, Highest and Lowest are loaded with the persistent variables. Just before exiting from the code, you then load the vairables with the current values of Highest and Lowest.

I have tested it and it works. There may be neater solutions, and there are alternatives that work, but this is how I do it. See the revised code below.

Hope this helps.

// The top of every source code file must include this line
#include "sierrachart.h"

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("Price Bands DLL")

int BarIndex;


SCSFExport scsf_PriceBands(SCStudyInterfaceRef sc)
{
SCSubgraphRef HighestHigh = sc.Subgraph[0];
SCSubgraphRef LowestLow = sc.Subgraph[1];
SCSubgraphRef Midline = sc.Subgraph[2];
SCInputRef Width = sc.Input[3];

if (sc.SetDefaults)
{
sc.GraphName = "Price Bands";
// During development set this flag to 1, so the DLL can be rebuilt without restarting Sierra Chart.
// When development is completed, set it to 0 to improve performance.
sc.FreeDLL = 0;
sc.GraphRegion = 0;
sc.AutoLoop = true;

HighestHigh.Name= "Highest High";
HighestHigh.DrawStyle= DRAWSTYLE_LINE;
HighestHigh.PrimaryColor = RGB(255,206,206);
HighestHigh.LineWidth = 48;
HighestHigh.DrawZeros= true;
HighestHigh.GraphicalDisplacement= 1;

LowestLow.Name = "Lowest Low";
LowestLow.DrawStyle= DRAWSTYLE_LINE;
LowestLow.PrimaryColor = RGB(183,255,183);
LowestLow.LineWidth = 48;
LowestLow.DrawZeros= true;
LowestLow.GraphicalDisplacement= 1;

Midline.Name = "Mid Line";
Midline.DrawStyle= DRAWSTYLE_LINE;
Midline.PrimaryColor = RGB(232,232,232);
Midline.LineWidth = 56;
Midline.DrawZeros= true;
Midline.GraphicalDisplacement= 1;

Width.Name = "Band Width in Ticks";
Width.SetInt(48);
Width.SetIntLimits(1, MAX_STUDY_LENGTH);

sc.PersistVars->f1 = FLT_MAX;
sc.PersistVars->f2 = -FLT_MAX;

return;
}

float BandWidth = Width.GetInt() * sc.TickSize;
float VertOffsetTop = sc.TickSize * (HighestHigh.LineWidth / 16.0f);
float VertOffsetBot = sc.TickSize * (LowestLow.LineWidth / 16.0f);

float Highest = sc.PersistVars->f1;
float Lowest = sc.PersistVars->f2;

for(BarIndex = sc.Index - 1; BarIndex <= sc.Index; BarIndex++)
{
if(sc.BaseDataIn[SC_HIGH][BarIndex] > Highest)
{
Highest = sc.BaseDataIn[SC_HIGH][BarIndex];
Lowest = Highest - BandWidth;
}

if(sc.BaseDataIn[SC_LOW][BarIndex] < Lowest)
{
Lowest = sc.BaseDataIn[SC_LOW][BarIndex];
Highest = Lowest + BandWidth;
}
}

HighestHigh[sc.Index] = Highest - VertOffsetTop;
LowestLow[sc.Index] = Lowest + VertOffsetBot;
Midline[sc.Index] = (Highest + Lowest) / 2.0f;

sc.PersistVars->f1 = Highest;
sc.PersistVars->f2 = Lowest;


//Following lines added for debugging, as needed
//SCString Buffer;
//Buffer.Format("%d -- %f -- %f -- %f -- %f", sc.Index, sc.High[sc.Index], sc.Low[sc.Index], Highest, Lowest);
//sc.AddMessageToLog(Buffer,1);
}

Reply With Quote
The following user says Thank You to swandro for this post:
 
  #5 (permalink)
Trading Apprentice
Grand Rapids MI / USA
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Infinity Futures
Favorite Futures: Futures ES CL GC
 
Posts: 4 since Nov 2014
Thanks: 2 given, 1 received

Thank you swandro!!!

Yes! It works! Thank you swandro! I didn't realize there was such a thing as "persistent variables" that would carry values across iterations. I thought global variables were the key, but they kept giving me problems, so I learned something here. So, again, thank you!

I had seen an indicator like this used elsewhere and really grew to like it because of how it helps me to see when price is consolidating or is trending. I have also now added a second price band to overlay the first. The outer bands I "ignore", but the mid -band, I made just three points wide, with color based on slope--blue if going up and red if going down. It is clean, simple, and sweet.

Reply With Quote
The following user says Thank You to vdhoek for this post:

Reply



futures io > > > > > Price Bands not printing correctly at end of chart

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Price Action with Bollinger Bands Saroj The Elite Circle 36 March 18th, 2012 08:12 AM
Sierra Chart VWAP Bands with StdDev Big Mike Sierra Chart 21 December 28th, 2011 12:29 AM
price oscillator bands (works on some charts, but not on others) khmodel NinjaTrader Programming 2 December 9th, 2011 04:04 PM
Why Europe's Central Bank May End Up Printing Money Quick Summary News and Current Events 0 November 17th, 2011 09:50 PM
Printing Price that a signal fires at on the chart mainstream NinjaTrader Programming 5 December 13th, 2010 12:04 PM


All times are GMT -4. The time now is 10:21 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-10 in 0.11 seconds with 19 queries on phoenix via your IP 54.221.73.186