Indicator does not generate alert when price crosses VPOC

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

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: 161
Joined: 20 Nov 2014
Has thanked: 43 times
Been thanked: 21 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: 22
Joined: 28 Nov 2015
Has thanked: 5 times
Been thanked: 1 time

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 15 Mar 2019

darob wrote: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: 161
Joined: 20 Nov 2014
Has thanked: 43 times
Been thanked: 21 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: 22
Joined: 28 Nov 2015
Has thanked: 5 times
Been thanked: 1 time

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: 8960
Joined: 25 Aug 2011
Has thanked: 1240 times
Been thanked: 2885 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: 22
Joined: 28 Nov 2015
Has thanked: 5 times
Been thanked: 1 time

Re: Indicator does not generate alert when price crosses VPOC

Postby Abhi » 20 Mar 2019

Henry MultiСharts wrote: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) Not downloaded yet

darob
Posts: 161
Joined: 20 Nov 2014
Has thanked: 43 times
Been thanked: 21 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
Screen Shot 2019-03-22 at 10.29.24 AM.png (11.04 KiB) Viewed 6 times


Return to “MultiCharts .NET”