I
itrader
Guest
I keep looking for a way of triggering a function in my code only after a List element is added, but i can't find any info to help me get this done.
I've tried ObservableCollection as below, but the code doesn't trigger
If anybody could help me find the error in my code, I will appreciate
private List<int> ListCountL;
...
ListCountL = new List<int>();
...
if (!LSwDmiAdd && b > 1 && LSwDMI[b-1] - LSwDMI > 0.001 && LSwDMI[b-1] - LSwDMI[b-2] > 0.001)
{
LastLSwDMI.Add(LSwDMI[b-1]);
listCountLL = LastLSwDMI.Count;
ListCountL.Add(listCountLL);
j++;
}
...
if (ListCountL[j-1] > ListCountL[j-2])
{
// Logic triggered after ListCountL increase
}
var colL = new ObservableCollection<int>(ListCountL);
colL.CollectionChanged += (s, e) =>
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
// This code never triggers, but in the previous code it did after
// if (ListCountL[j-1] > ListCountL[j-2])
if (k > 1 && c > 1 && (lowSwBarDiffA <= BarDiff || lowSwBarDiffB <= BarDiff))
{
if (!posDiv && ((LastLSwDMI[k-1] - LastLSwDMI[k-2] > 0.001 && LastLSwDMIprice[k-2] - LastLSwDMIprice[k-1] > TickSize)
|| (LSwDMI[c-1] - LastLSwDMI[k-1] > 0.001 && LastLSwDMIprice[k-1] - LSwDMIprice[c-1] > TickSize)))
posDiv = true;
else
posDiv = false;
}
};
Continue reading...
I've tried ObservableCollection as below, but the code doesn't trigger
If anybody could help me find the error in my code, I will appreciate
private List<int> ListCountL;
...
ListCountL = new List<int>();
...
if (!LSwDmiAdd && b > 1 && LSwDMI[b-1] - LSwDMI > 0.001 && LSwDMI[b-1] - LSwDMI[b-2] > 0.001)
{
LastLSwDMI.Add(LSwDMI[b-1]);
listCountLL = LastLSwDMI.Count;
ListCountL.Add(listCountLL);
j++;
}
...
if (ListCountL[j-1] > ListCountL[j-2])
{
// Logic triggered after ListCountL increase
}
var colL = new ObservableCollection<int>(ListCountL);
colL.CollectionChanged += (s, e) =>
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
// This code never triggers, but in the previous code it did after
// if (ListCountL[j-1] > ListCountL[j-2])
if (k > 1 && c > 1 && (lowSwBarDiffA <= BarDiff || lowSwBarDiffB <= BarDiff))
{
if (!posDiv && ((LastLSwDMI[k-1] - LastLSwDMI[k-2] > 0.001 && LastLSwDMIprice[k-2] - LastLSwDMIprice[k-1] > TickSize)
|| (LSwDMI[c-1] - LastLSwDMI[k-1] > 0.001 && LastLSwDMIprice[k-1] - LSwDMIprice[c-1] > TickSize)))
posDiv = true;
else
posDiv = false;
}
};
Continue reading...