Indicator does not generate alert when price crosses VPOC

Questions about MultiCharts .NET and user contributed studies.
Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Indicator does not generate alert when price crosses VPOC

Postby Abhi » 13 Mar 2019

Hi, I am using the below code, the indicator generate should generate alert when the close of the bar crosses below or above the volume profile.

For some reason, alert is never generated, what am I doing wrong here.



using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
[SameAsSymbol(true)]
[UpdateOnEveryTick(true)]
[SkipIdenticalTicks(false)]
public class AG_Test : IndicatorObject
{
public AG_Test(object _ctx):base(_ctx)
{
}
private IPlotObjectStr Vol_POC_VA;
private VariableSeries<Double> VPOCDoubleSeries;

protected override void Create()
{
Vol_POC_VA = AddPlot(new StringPlotAttributes());
VPOCDoubleSeries = new VariableSeries<Double>(this);
}
protected override void StartCalc()
{
//subscribing for profile changes
VolumeProfile.EChanged += VolumeProfileOnEChanged;
}
protected override void CalcBar()
{
// indicator logic
int bn = Bars.FullSymbolData.Current-1;
var vp = VolumeProfile.ItemForBar(bn);
if (vp != null)
{
double VolValue = (double)vp.POC.TotalValue;
VPOCDoubleSeries.Value = VolValue ;
double PriceValue = (double)vp.POCForBar(bn).Dbl;
if ( VolValue > 49999)
{
Vol_POC_VA.Set(string.Format("P={0:n2},V={1:n0}", PriceValue ,VolValue), Color.Yellow);

if ( this.CrossesOver(VPOCDoubleSeries,Bars.Close) || this.CrossesUnder(VPOCDoubleSeries,Bars.Close))
{
Alerts.Alert("Test");
}

}else

{
Vol_POC_VA.Set(string.Format("P={0:n2},V={1:n0}", PriceValue ,VolValue), Color.White);

}

}
}
private void VolumeProfileOnEChanged(bool full)
{
//Recalculate if the profile has been completely changed.
if (full)
this.ExecControl.Recalculate();
}

}
}

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Indicator does not generate alert when price crosses VPOC

Postby darob » 15 Mar 2019

if ( this.CrossesOver(VPOCDoubleSeries,Bars.Close) || this.CrossesUnder(VPOCDoubleSeries,Bars.Close))
{

Hi, I may be all wet, but is Bars.Close just the last traded price when UpdateEveryTick is set to true, and therefore never crossed?

Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 15 Mar 2019

if ( this.CrossesOver(VPOCDoubleSeries,Bars.Close) || this.CrossesUnder(VPOCDoubleSeries,Bars.Close))
{

Hi, I may be all wet, but is Bars.Close just the last traded price when UpdateEveryTick is set to true, and therefore never crossed?

Thanks Darob for the suggesstion, I ticked off that option, didn't work.

Henry, Svetlana anyone with any suggestions. please could you help.

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Indicator does not generate alert when price crosses VPOC

Postby darob » 15 Mar 2019

The other thing I'm wondering is if Bars.Close should be first in the expression ie this.CrossesOver(Bars.Close, VPOCDoubleSeries).

Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 15 Mar 2019

tried that also, didn't work.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Henry MultiСharts » 15 Mar 2019

Hello Abhi,

You need to make sure the alerts for the indicator are enabled in the settings:
Indicator: http://www.multicharts.com/trading-soft ... ing_Alerts
If an alert was not generated, then the condition for generating it has not been met.
You will need to add output logic to debug it.

Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 20 Mar 2019

Hello Abhi,

You need to make sure the alerts for the indicator are enabled in the settings:
Indicator: http://www.multicharts.com/trading-soft ... ing_Alerts
If an alert was not generated, then the condition for generating it has not been met.
You will need to add output logic to debug it.
I can assure you Henry that the alert has been setup correctly and the VPOC values are generated correctly as I display them on the status line. every time the close crosses the VPOC value, it never generates an alert. please can you help when you get a chance! not asking you to help immediately. I know you guys are busy.

The latest code


using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
[SameAsSymbol(true)]
[UpdateOnEveryTick(true)]
[SkipIdenticalTicks(false)]
public class AG_Test : IndicatorObject
{
public AG_Test(object _ctx):base(_ctx)
{
}
private IPlotObjectStr Vol_POC_VA;
private VariableSeries<Double> VPOCDoubleSeries;

protected override void Create()
{
Vol_POC_VA = AddPlot(new StringPlotAttributes());
VPOCDoubleSeries = new VariableSeries<Double>(this);
}
protected override void StartCalc()
{
//subscribing for profile changes
VolumeProfile.EChanged += VolumeProfileOnEChanged;
}
protected override void CalcBar()
{
// indicator logic
int bn = Bars.FullSymbolData.Current-1;
var vp = VolumeProfile.ItemForBar(bn);
if (vp != null)
{
double VolValue = (double)vp.POC.TotalValue;
double PriceValue = (double)vp.POCForBar(bn).Dbl;
VPOCDoubleSeries.Value = PriceValue ;
if ( VolValue > 49999)
{
Vol_POC_VA.Set(string.Format("P={0:n2},V={1:n0}", PriceValue ,VolValue), Color.Yellow);

if ( this.CrossesOver(Bars.Close, VPOCDoubleSeries) || this.CrossesUnder(Bars.Close, VPOCDoubleSeries))
{
Alerts.Alert("Test");
}

}else

{
Vol_POC_VA.Set(string.Format("P={0:n2},V={1:n0}", PriceValue ,VolValue), Color.White);

}

}
}
private void VolumeProfileOnEChanged(bool full)
{
//Recalculate if the profile has been completely changed.
if (full)
this.ExecControl.Recalculate();
}

}
}
Attachments
Tradestation.wsp
(171.69 KiB) Downloaded 324 times

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Indicator does not generate alert when price crosses VPOC

Postby darob » 22 Mar 2019

Hi Abhi, I've got one more suggestion (and that's it, promise :wink: ) The indicator recalculates after a profile change, but maybe this isn't frequent enough to fire the alert. You could try adding a time-based recalculation in CalcBar():
Screen Shot 2019-03-22 at 10.29.24 AM.png
(11.04 KiB) Downloaded 1027 times

Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 25 Mar 2019

Hi Darob, I am open to all suggestions, you can give as many as you want, I will be very glad to try out. I tried the above option of recalculating after both 1 and 10 seconds, didn't work.

Just thinking out loud - the crossover and crossunder interfaces take two double series as parameters and compares and when the price crosses above or under should generate an alert. There is no time factor in it.

That's what it does in the moving average indicator, where it takes moving average values for each bar and the close values of each bar as parameters and generates alert when the condition is met.

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Indicator does not generate alert when price crosses VPOC

Postby darob » 25 Mar 2019

Hi Abhi,

I thought I’d suggest it because as a novice and for the practice I built the VA_Min_Max indicator that Multicharts has provided and found it works when first applied to a chart, but when I change instruments on the chart it doesn’t reload unless the status button in the format indicators dialogue is toggled. I found adding the time based recalculation makes it work as I think it’s supposed to.

I’m not sure what the implications are for your purposes when the MC example apparently isn’t working correctly either.

I should probably let the experts take it from here. Thanks for the feedback.

Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 26 Mar 2019

Hi Darob, I was not giving a feedback I was just telling my opinion :) I am no better than you in Multicharts c# coding. I have done easy language coding and c# in ICMarkets but Multicharts .NET has a steep learning curve.

As you said, let's wait for the expert to comment. Like I said earlier, if you have any more suggestions happy to try out.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Henry MultiСharts » 17 Apr 2019

I can assure you Henry that the alert has been setup correctly and the VPOC values are generated correctly as I display them on the status line. every time the close crosses the VPOC value, it never generates an alert. please can you help when you get a chance! not asking you to help immediately. I know you guys are busy.
Abhi, are you able to get the alerts generated for the prebuilt indicators, for example, playback a chart with the ADX indicator applied and alerts enabled in the settings?
What if you add traces to your own code next to the alert generation logic, is the trace added to the output when the alert is supposed to be generated?

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Indicator does not generate alert when price crosses VPOC

Postby darob » 29 Apr 2019

Hi Abhi and Henry. Was this ever solved? When volume profile is enabled I’ve found that alerts involving vp levels don’t always fire when set to bar close, but when set to once per bar they do. Is this by design? (I’m referring only to setups that are valid at bar close.)

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Henry MultiСharts » 15 May 2019

Hi Abhi and Henry. Was this ever solved? When volume profile is enabled I’ve found that alerts involving vp levels don’t always fire when set to bar close, but when set to once per bar they do. Is this by design? (I’m referring only to setups that are valid at bar close.)
Hello darob,

The alert condition needs to be fulfilled on the calculation performed on the bar close for the alert to be triggered.
If that is the case, but the alert is not triggered, please send us the code and the workspace for replicating this behavior on our end.
Detailed instructions/screenshots/video demonstrating the issue will be helpful as well.

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Indicator does not generate alert when price crosses VPOC

Postby darob » 15 May 2019

Hi Henry, I've sent you the code etc. I've also managed to get this to work for my purposes by offsetting the calculation 1 bar so that when the once per bar alert fires I in fact have the close I'm waiting for. Obviously it would be good to understand why this is necessary.

Thanks

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Henry MultiСharts » 17 May 2019

darob,

We were unable to replicate this behavior on our end using the provided data.
If you want to continue the analysis - I would recommend adding Bars.Status value output next to the alert command in your code.
If output shows EBarState.Close, but the alert is not triggered, this is something to look into.

Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 21 Jun 2019

Hi Abhi and Henry. Was this ever solved? When volume profile is enabled I’ve found that alerts involving vp levels don’t always fire when set to bar close, but when set to once per bar they do. Is this by design? (I’m referring only to setups that are valid at bar close.)

Many apologies Darob, completely forgotten to reply. Never worked for me. But I am not looking at the these kind of alerts anymore so I didn't pursue any further.

Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 12 Aug 2019

Hi Henry and Darob, found out a way to generate alert when price crosses volume point of control. I am using the following in the code:-

double PriceValue = (double)vp.POCForBar(bn).Dbl;
if ( (PriceValue - .05 <= Bars.CloseValue) && (Bars.CloseValue <= PriceValue + .05) )
{
Alerts.Alert("Crossed POC");
}

So if the price is within the range of volume POC +/- 0.05, then alert is generated.

I could not make the CrossesOver and CrossesUnder methods work to generate alert.

Thought I would share with you.

Abhi
Posts: 38
Joined: 28 Nov 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 12 Aug 2019

The complete code. Sharing and caring for the Multicharts community :)

Every time the price is near the range of volume POC +/_- 0.05, alert will be generated.

Thanks a lot Henry and Darob for all your inputs on this.

I used your suggestion Darob to recalculate the indicator after every 3 seconds. After session hours, the code does not recalculate as no tick data. so iIused your suggestion to force the code to recalculate.


Complete code below

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
[SameAsSymbol(true)]
[UpdateOnEveryTick(true)]
[SkipIdenticalTicks(false)]
public class AG_Test : IndicatorObject
{
public AG_Test(object _ctx):base(_ctx)
{
}
private IPlotObjectStr Vol_POC_VA;
//private VariableSeries<Double> VPOCDoubleSeries;
//private ISeries<Double> CloseDoubleSeries;
//private EResolution resolution;
//private IPlotObject TestPlot;

protected override void Create()
{
Vol_POC_VA = AddPlot(new StringPlotAttributes());
//VPOCDoubleSeries = new VariableSeries<Double>(this);
//TestPlot = AddPlot(new PlotAttributes("Test", EPlotShapes.Histogram, Color.Yellow,Color.Empty, 0, 0, true));
//CloseDoubleSeries = new ISeries<Double>(this);
}
protected override void StartCalc()
{
//subscribing for profile changes
VolumeProfile.EChanged += VolumeProfileOnEChanged;
//resolution = Bars.Info.Resolution.Type;
}
protected override void CalcBar()
{
// indicator logic
int bn = Bars.FullSymbolData.Current-1;
var vp = VolumeProfile.ItemForBar(bn);
if (vp != null)
{
double VolValue = (double)vp.POC.TotalValue;
double PriceValue = (double)vp.POCForBar(bn).Dbl;
double ValueAreaDifferencePrice = (double)vp.HighVAForBar(bn).Dbl - (double)vp.LowVAForBar(bn).Dbl;
double ValueAreaDifferenceVolume = (double)vp.VAValue;
//double ValueAreaVolume = (double)vp.VAValue ;
//VPOCDoubleSeries.Value = PriceValue ;
//CloseDoubleSeries = Bars.Close;
//TestPlot.Set(0, VPOCDoubleSeries.Value);
if (VolValue > 100000)
//ValueAreaDifferenceVolume > 700000 && ValueAreaDifferencePrice > 0.00 && ValueAreaDifferencePrice < 0.81)
{
Vol_POC_VA.Set(string.Format("POC={0:n2} POCV={1:n0} VAV={2:n0} VAPD={3:n2}", PriceValue,VolValue,ValueAreaDifferenceVolume, ValueAreaDifferencePrice), Color.Yellow);

//if ( DateTime.Now < Convert.ToDateTime("15:00:00 PM") && resolution != EResolution.Day )
//{
//Alerts.Alert("V=" + string.Format("{0:n0}", VolValue) );
//}

if ( DateTime.Now >= Convert.ToDateTime("14:45:00 PM") && (PriceValue - .05 <= Bars.CloseValue) && (Bars.CloseValue <= PriceValue + .05) )
{
Alerts.Alert("Crossed POC");
}

}else

{
Vol_POC_VA.Set(string.Format("POC={0:n2} POCV={1:n0} VAV={2:n0} VAPD={3:n2}", PriceValue,VolValue,ValueAreaDifferenceVolume, ValueAreaDifferencePrice), Color.White);

}

if (Bars.LastBarOnChart)
{
ExecControl.RecalcLastBarAfter(new TimeSpan(0,0,3));
}

}
}


private void VolumeProfileOnEChanged(bool full)
{
//Recalculate if the profile has been completely changed.
if (full)
this.ExecControl.Recalculate();
}

}
}


Return to “MultiCharts .NET”