NexusFi: Find Your Edge


Home Menu

 





Delta Bar Type For Multicharts.


Discussion in EasyLanguage Programming

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




 
Search this Thread
  #1 (permalink)
 PainlessTrader 
Yuma, Az
 
Experience: Advanced
Posts: 7 since Dec 2022
Thanks Given: 2
Thanks Received: 8

This needs a real programmer to fix. This is a bar type for Delta Bars in Multicharts. From the Custom Resolutions Editor - I was trying to get Delta bars for Multicharts like in Ninja Trader. I'm sure this would be useful for many people if we get it to work.



#define TRACE
using System;
using System.Runtime.InteropServices;
using CustomResolutionsTypes;
using System.Diagnostics;

namespace DeltaBars
{
[ComVisible(true)]
[Guid("55915203-40eb-40d5-b5da-c826b08e090a")]
[ClassInterface(ClassInterfaceType.None)]
[CustomResolutionPluginAttribute(RuleOHLC = true)]
public class Plugin : ICustomResolutionPlugin, ICustomPluginFormatParams, ICustomResolutionStyles
{
#region Fields
private long m_Volume = 0;
private long m_UpVolume = 0;
private long m_DownVolume = 0;
private double m_PointValue = 0.0001;
private long m_MinMovement = 1;
private long m_TrendDeltaThreshold = 1000; // Threshold for continuing trend
private long m_TrendReversalThreshold = 500; // Threshold for trend reversal
private long m_CumulativeDelta = 0; // Tracks upVolume - downVolume
private long m_PeakDelta = 0; // Tracks highest/lowest delta in current trend
private bool m_IsBullishTrend = true; // Tracks current trend direction
#endregion

#region Ctor
public Plugin()
{
}
#endregion

#region ICustomResolutionPlugin
public string Name
{
get { return "Delta Bars"; }
}

public string Guid
{
get { return "2df36d33-92f6-4549-953e-30fa3de4efaf"; }
}

public string Description
{
get { return "Bars based on cumulative delta with trend continuation and reversal thresholds."; }
}

public string Vendor
{
get { return "PainlessTrader"; }
}

public void Init(IBaseOptions baseOptions, IParams customParams)
{
if (baseOptions != null)
{
m_PointValue = baseOptions.PointValue;
m_MinMovement = baseOptions.MinMovement;
}

// Safely retrieve parameters from IParams
try
{
if (customParams != null)
{
// Attempt to access parameters by name
// Replace 'GetParamByName' with the actual method if different (check MultiCharts SDK)
object trendDeltaValue = customParams.GetParamByName?.Invoke("Trend Delta")?.Value;
object trendReversalValue = customParams.GetParamByName?.Invoke("Trend Reversal")?.Value;

if (trendDeltaValue != null)
{
m_TrendDeltaThreshold = Convert.ToInt64(trendDeltaValue);
}
if (trendReversalValue != null)
{
m_TrendReversalThreshold = Convert.ToInt64(trendReversalValue);
}
}
}
catch (Exception ex)
{
Trace.TraceError($"Error reading custom parameters: {ex.Message}");
// Keep default values if parameters are invalid
}

Trace.TraceInformation($"Init {Name}: PointValue={m_PointValue}, MinMovement={m_MinMovement}, TrendDelta={m_TrendDeltaThreshold}, TrendReversal={m_TrendReversalThreshold}");
}

public void OnData(ICustomBar Bar, long time_in_ticks, int tickId, double open, double high, double low, double close, long volumeAdded, long upVolumeAdded, long downVolumeAdded, ECustomBarTrendType trend, bool isBarClose)
{
// Accumulate volumes
m_Volume += volumeAdded;
m_UpVolume += upVolumeAdded;
m_DownVolume += downVolumeAdded;
m_CumulativeDelta = m_UpVolume - m_DownVolume;

// Determine trend direction
bool currentIsBullish = m_CumulativeDelta >= 0;

// Update trend and peak delta
if (m_IsBullishTrend)
{
// Bullish trend: track highest delta
if (m_CumulativeDelta > m_PeakDelta)
{
m_PeakDelta = m_CumulativeDelta;
}
// Check for trend reversal (delta drops significantly)
if (m_CumulativeDelta <= m_PeakDelta - m_TrendReversalThreshold)
{
Bar.CloseBar();
Reset();
m_IsBullishTrend = false; // Switch to bearish
m_PeakDelta = m_CumulativeDelta; // Set new peak for bearish trend
Trace.TraceInformation($"Bar closed: Reversal from bullish, Delta={m_CumulativeDelta}");
return;
}
// Check for trend continuation
if (m_CumulativeDelta >= m_TrendDeltaThreshold)
{
Bar.CloseBar();
Reset();
m_PeakDelta = 0; // Reset peak for new bar in same trend
Trace.TraceInformation($"Bar closed: Bullish continuation, Delta={m_CumulativeDelta}");
return;
}
}
else
{
// Bearish trend: track lowest delta
if (m_CumulativeDelta < m_PeakDelta)
{
m_PeakDelta = m_CumulativeDelta;
}
// Check for trend reversal (delta rises significantly)
if (m_CumulativeDelta >= m_PeakDelta + m_TrendReversalThreshold)
{
Bar.CloseBar();
Reset();
m_IsBullishTrend = true; // Switch to bullish
m_PeakDelta = m_CumulativeDelta; // Set new peak for bullish trend
Trace.TraceInformation($"Bar closed: Reversal from bearish, Delta={m_CumulativeDelta}");
return;
}
// Check for trend continuation
if (m_CumulativeDelta <= -m_TrendDeltaThreshold)
{
Bar.CloseBar();
Reset();
m_PeakDelta = 0; // Reset peak for new bar in same trend
Trace.TraceInformation($"Bar closed: Bearish continuation, Delta={m_CumulativeDelta}");
return;
}
}

// Update bar if not closing
Bar.UpdateBar(time_in_ticks, tickId, open, high, low, close, m_Volume, m_UpVolume, m_DownVolume, trend, true, false);
}

public void Reset()
{
m_Volume = 0;
m_UpVolume = 0;
m_DownVolume = 0;
m_CumulativeDelta = 0;
}
#endregion

#region ICustomPluginFormatParams
public void FormatParams(IParams customParams, IPriceScale priceScale, out string formattedParams)
{
formattedParams = $"{Name} (TrendDelta={m_TrendDeltaThreshold}, Reversal={m_TrendReversalThreshold})";
}
#endregion

#region ICustomResolutionStyles
public int StyleCount
{
get { return m_Styles.Length; }
}

public EStyleType GetStyle(int Idx)
{
return m_Styles[Idx];
}

private EStyleType[] m_Styles = new EStyleType[] { EStyleType.OHLC, EStyleType.Candlestick };
#endregion
}
}


Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
Memorandum Watch: How the 60-Day MOU Framework Makes May …
Prediction Markets & Event Contracts
Thursday May 28: GDP + Core PCE + Jobless Claims All at …
Traders Hideout
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
Netherlands & Germany Surge as World Cup Field Narro …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
196 thanks
Sober Journey With S&P
27 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
BERN ALGOS algo trading journal
8 thanks
  #2 (permalink)
 
Fi's Avatar
 Fi 
NexusFi
 


PainlessTrader View Post
This needs a real programmer to fix.

@PainlessTrader,

The foundation here is solid - you have the right interfaces implemented and the delta accumulation logic makes sense. A few things to check:

1. Parameter Access Issue
The syntax for accessing custom parameters looks incorrect:
 
Code
customParams.GetParamByName?.Invoke("Trend Delta")?.Value
The IParams interface in MultiCharts SDK typically uses a different accessor pattern. Check the pre-built custom resolution plugins that ship with MultiCharts (Range Bars, Renko, etc.) - they show the correct way to retrieve parameter values. These templates are in your MultiCharts installation folder under the Custom Resolutions samples.

2. Missing Parameter Definition Interface
To expose "Trend Delta" and "Trend Reversal" in the Custom Resolutions Manager UI, you likely need to implement an additional interface that defines these parameters. The pre-built samples show how to register custom parameters so users can modify them.

3. Your Logic Looks Sound
The approach of tracking cumulative delta (upVolume - downVolume) and closing bars when thresholds are crossed is correct. The trend continuation vs reversal threshold distinction is a nice touch.

Next Steps
  • Open one of the working pre-built plugins in Visual Studio and compare the Init() method
  • Check how they access IParams - this is likely where the issue lives
  • Add debug output to confirm your code is being called at all

If you post the specific error messages from the Output Window when loading the plugin, that would help narrow down the issue.

-- Fi
"The best debugging starts with the simplest working example."


Learn more about Fi AI trading companion
IMPORTANT: I can make mistakes! Always verify data before relying on it.

Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.

Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.
Reply With Quote
  #3 (permalink)
juan
Madrid, Espaņa
 
Posts: 3 since Jan 2011
Thanks Given: 0
Thanks Received: 1



PainlessTrader View Post
This needs a real programmer to fix. This is a bar type for Delta Bars in Multicharts. From the Custom Resolutions Editor - I was trying to get Delta bars for Multicharts like in Ninja Trader. I'm sure this would be useful for many people if we get it to work.



#define TRACE
using System;
using System.Runtime.InteropServices;
using CustomResolutionsTypes;
using System.Diagnostics;

namespace DeltaBars
{
[ComVisible(true)]
[Guid("55915203-40eb-40d5-b5da-c826b08e090a")]
[ClassInterface(ClassInterfaceType.None)]
[CustomResolutionPluginAttribute(RuleOHLC = true)]
public class Plugin : ICustomResolutionPlugin, ICustomPluginFormatParams, ICustomResolutionStyles
{
#region Fields
private long m_Volume = 0;
private long m_UpVolume = 0;
private long m_DownVolume = 0;
private double m_PointValue = 0.0001;
private long m_MinMovement = 1;
private long m_TrendDeltaThreshold = 1000; // Threshold for continuing trend
private long m_TrendReversalThreshold = 500; // Threshold for trend reversal
private long m_CumulativeDelta = 0; // Tracks upVolume - downVolume
private long m_PeakDelta = 0; // Tracks highest/lowest delta in current trend
private bool m_IsBullishTrend = true; // Tracks current trend direction
#endregion

#region Ctor
public Plugin()
{
}
#endregion

#region ICustomResolutionPlugin
public string Name
{
get { return "Delta Bars"; }
}

public string Guid
{
get { return "2df36d33-92f6-4549-953e-30fa3de4efaf"; }
}

public string Description
{
get { return "Bars based on cumulative delta with trend continuation and reversal thresholds."; }
}

public string Vendor
{
get { return "PainlessTrader"; }
}

public void Init(IBaseOptions baseOptions, IParams customParams)
{
if (baseOptions != null)
{
m_PointValue = baseOptions.PointValue;
m_MinMovement = baseOptions.MinMovement;
}

// Safely retrieve parameters from IParams
try
{
if (customParams != null)
{
// Attempt to access parameters by name
// Replace 'GetParamByName' with the actual method if different (check MultiCharts SDK)
object trendDeltaValue = customParams.GetParamByName?.Invoke("Trend Delta")?.Value;
object trendReversalValue = customParams.GetParamByName?.Invoke("Trend Reversal")?.Value;

if (trendDeltaValue != null)
{
m_TrendDeltaThreshold = Convert.ToInt64(trendDeltaValue);
}
if (trendReversalValue != null)
{
m_TrendReversalThreshold = Convert.ToInt64(trendReversalValue);
}
}
}
catch (Exception ex)
{
Trace.TraceError($"Error reading custom parameters: {ex.Message}");
// Keep default values if parameters are invalid
}

Trace.TraceInformation($"Init {Name}: PointValue={m_PointValue}, MinMovement={m_MinMovement}, TrendDelta={m_TrendDeltaThreshold}, TrendReversal={m_TrendReversalThreshold}");
}

public void OnData(ICustomBar Bar, long time_in_ticks, int tickId, double open, double high, double low, double close, long volumeAdded, long upVolumeAdded, long downVolumeAdded, ECustomBarTrendType trend, bool isBarClose)
{
// Accumulate volumes
m_Volume += volumeAdded;
m_UpVolume += upVolumeAdded;
m_DownVolume += downVolumeAdded;
m_CumulativeDelta = m_UpVolume - m_DownVolume;

// Determine trend direction
bool currentIsBullish = m_CumulativeDelta >= 0;

// Update trend and peak delta
if (m_IsBullishTrend)
{
// Bullish trend: track highest delta
if (m_CumulativeDelta > m_PeakDelta)
{
m_PeakDelta = m_CumulativeDelta;
}
// Check for trend reversal (delta drops significantly)
if (m_CumulativeDelta <= m_PeakDelta - m_TrendReversalThreshold)
{
Bar.CloseBar();
Reset();
m_IsBullishTrend = false; // Switch to bearish
m_PeakDelta = m_CumulativeDelta; // Set new peak for bearish trend
Trace.TraceInformation($"Bar closed: Reversal from bullish, Delta={m_CumulativeDelta}");
return;
}
// Check for trend continuation
if (m_CumulativeDelta >= m_TrendDeltaThreshold)
{
Bar.CloseBar();
Reset();
m_PeakDelta = 0; // Reset peak for new bar in same trend
Trace.TraceInformation($"Bar closed: Bullish continuation, Delta={m_CumulativeDelta}");
return;
}
}
else
{
// Bearish trend: track lowest delta
if (m_CumulativeDelta < m_PeakDelta)
{
m_PeakDelta = m_CumulativeDelta;
}
// Check for trend reversal (delta rises significantly)
if (m_CumulativeDelta >= m_PeakDelta + m_TrendReversalThreshold)
{
Bar.CloseBar();
Reset();
m_IsBullishTrend = true; // Switch to bullish
m_PeakDelta = m_CumulativeDelta; // Set new peak for bullish trend
Trace.TraceInformation($"Bar closed: Reversal from bearish, Delta={m_CumulativeDelta}");
return;
}
// Check for trend continuation
if (m_CumulativeDelta <= -m_TrendDeltaThreshold)
{
Bar.CloseBar();
Reset();
m_PeakDelta = 0; // Reset peak for new bar in same trend
Trace.TraceInformation($"Bar closed: Bearish continuation, Delta={m_CumulativeDelta}");
return;
}
}

// Update bar if not closing
Bar.UpdateBar(time_in_ticks, tickId, open, high, low, close, m_Volume, m_UpVolume, m_DownVolume, trend, true, false);
}

public void Reset()
{
m_Volume = 0;
m_UpVolume = 0;
m_DownVolume = 0;
m_CumulativeDelta = 0;
}
#endregion

#region ICustomPluginFormatParams
public void FormatParams(IParams customParams, IPriceScale priceScale, out string formattedParams)
{
formattedParams = $"{Name} (TrendDelta={m_TrendDeltaThreshold}, Reversal={m_TrendReversalThreshold})";
}
#endregion

#region ICustomResolutionStyles
public int StyleCount
{
get { return m_Styles.Length; }
}

public EStyleType GetStyle(int Idx)
{
return m_Styles[Idx];
}

private EStyleType[] m_Styles = new EStyleType[] { EStyleType.OHLC, EStyleType.Candlestick };
#endregion
}
}

Hi, did you get anywhere with this?
I'm interested.
Thanks


Reply With Quote
Thanked by:




Last Updated on January 8, 2026


© 2026 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 - Downloads - Top
no new posts