NexusFi: Find Your Edge


Home Menu

 





Delta Reversal Bars Coding Help


Discussion in Sierra Chart

Updated
    1. trending_up 2,949 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Delta Reversal Bars Coding Help

  #1 (permalink)
Luda Chris
Buffalo, NY
 
Posts: 8 since May 2021
Thanks Given: 12
Thanks Received: 6

I'm trying to code a custom chart bar study using the Sierra provided CustomChartBars_Example. I've compiled and tried the volume example and it looks like that works like it should.

My goal is to create a bar type that prints a new bar after delta has reversed from it's min/max value by x amount. I use a 1-10 point and figure on regular candles and I'd like the same idea applied to delta instead. The problem is I'm not sure on the logic (or anything code related), right now it's just printing new bars instantly for the most part. My DeltaReversalInput is set default to 250, but changing it doesn't do anything, new bars just print instantly.

I'm assuming the problem is on a new bar print the min and max are 0, so any delta move in the right direction is going to just make a new bar. Any help is greatly appreciated!


 
Code
		
		SCInputRef DeltaReversalInput = ChartBarInterface.GetInput(0);
		const uint64_t CurrentBarAskVol = (uint64_t)ChartBarInterface.GetChartBarValue(SC_ASKVOL, ChartBarInterface.CurrentBarIndex);
		const uint64_t CurrentBarBidVol = (uint64_t)ChartBarInterface.GetChartBarValue(SC_BIDVOL, ChartBarInterface.CurrentBarIndex);
		const uint64_t minDelta = (uint64_t)ChartBarInterface.GetChartBarValue(SC_ASKBID_DIFF_LOW, ChartBarInterface.CurrentBarIndex);
		const uint64_t maxDelta = (uint64_t)ChartBarInterface.GetChartBarValue(SC_ASKBID_DIFF_HIGH, ChartBarInterface.CurrentBarIndex);
		int direction = GetRangeBarDirection(ChartBarInterface, ChartBarInterface.CurrentBarIndex);
		float& r_BarHigh = ChartBarInterface.GetChartBarValue(SC_HIGH, ChartBarInterface.CurrentBarIndex);
		float& r_BarLow = ChartBarInterface.GetChartBarValue(SC_LOW, ChartBarInterface.CurrentBarIndex);
		float& r_BarOpen = ChartBarInterface.GetChartBarValue(SC_OPEN, ChartBarInterface.CurrentBarIndex);
		float& r_BarLast = ChartBarInterface.GetChartBarValue(SC_LAST, ChartBarInterface.CurrentBarIndex);
		
		if (direction == 1)// Up
		{
			ChartBarInterface.NewRecordToInsert.High = r_BarHigh;
			ChartBarInterface.NewRecordToInsert.Close = r_BarLast;
			
			if (CurrentBarAskVol-CurrentBarBidVol < (maxDelta - DeltaReversalInput.GetInt()))
			{
				ChartBarInterface.StartNewBarFlag = 1;
				return;
			}
			
		}
		else// Down
		{			

			ChartBarInterface.NewRecordToInsert.Low = r_BarLow;
			ChartBarInterface.NewRecordToInsert.Close = r_BarLast;
			
			if (CurrentBarAskVol-CurrentBarBidVol > (minDelta + DeltaReversalInput.GetInt()))
			
			{
				ChartBarInterface.StartNewBarFlag = 1;
				return;
			}

 
Code
SCSFExport scsf_CustomChartBarsExample(SCStudyInterfaceRef sc)
{
	SCInputRef Input_DeltaReversal = sc.Input[0];

	if (sc.SetDefaults)
	{
		// Set the configuration and defaults
		sc.GraphRegion = 0;
		sc.GraphName = "Delta Reversal Bars";
		sc.UsesCustomChartBarFunction = 1;

		// This function is called from another thread.
		sc.fp_ACSCustomChartBarFunction = CustomChartBarBuildingFunction;

		sc.AutoLoop = 0;//Always use manual looping.

		//sc.MaintainAdditionalChartDataArrays = 1;
		//sc.AllocateAndNameRenkoChartBarArrays = 1;

		Input_DeltaReversal.Name = "Delta Reversal Amount";
		Input_DeltaReversal.SetInt(250);
		Input_DeltaReversal.SetIntLimits(250, INT_MAX);

		return;
	}


	int& r_ChartDataReloadedFlag = sc.GetPersistentInt(CUSTOM_CHART_BAR_RELOAD_FLAG_KEY);

	if (r_ChartDataReloadedFlag == 0)
	{
		sc.FlagToReloadChartData = true;
		r_ChartDataReloadedFlag = 1;
	}

	// It is necessary for the study function which creates custom chart bars to detect changes with its own input settings and flag to reload data.

	const int DeltaReversal = Input_DeltaReversal.GetInt();

	int& r_PriorDeltaReversal = sc.GetPersistentInt(1);

	if (r_PriorDeltaReversal!= 0 && r_PriorDeltaReversal != DeltaReversal)
		sc.FlagToReloadChartData = true;

	r_PriorDeltaReversal= DeltaReversal;

	// Set the graph name for this custom bar type.
	if (sc.IsFullRecalculation)
		sc.GraphName.Format("Custom Chart Bar Volume = %d", DeltaReversal);
}

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
 
  #2 (permalink)
Nobreceara
Dublin Ireland
 
Posts: 4 since Feb 2022
Thanks Given: 1
Thanks Received: 3

Hi,

Did you manage to figure out the issue?

I'm going to take a look soon on this.

regards,

Nobre

Reply With Quote
Thanked by:
  #3 (permalink)
Luda Chris
Buffalo, NY
 
Posts: 8 since May 2021
Thanks Given: 12
Thanks Received: 6



Nobreceara View Post
Hi,

Did you manage to figure out the issue?

I'm going to take a look soon on this.

regards,

Nobre

Thanks for the response, the project has been put on the backburner, it's above my skillset at the moment. Instead I've modified the cumulative delta bars study with a new option to reset on alert condition. This has allowed me to reset the cumulative delta to 0 automatically from specific events from other subgraphs. This is kind of on the same page as my original idea but the bar type would be very cool to study.


The delta reversal bar type ideally would take a "max" input for the absolute value of the difference between the ask volume and the bid volume, say 200, and then a second input for the reversal amount, let's say 100.

Min/Max Absolute Value = 200
Reversal amount = 100

Then a bar would print until the delta is either 200 or -200, at which point the min/max threshold would be hit. After that any further delta movement would make a new min/max until ultimately delta reverses and falls away from the min/max.

For an example let's say the bar's delta rises steadily with no major reversing to 378 for a max, and then starts to fall again.

Once delta reverses the reversal amount of 100 from it's max of 378 to 278, then a new bar prints.

Reply With Quote




Last Updated on April 20, 2022


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts