Hello,
Can you help me please?
...
Could you show us the code snippet how you filled the trends[] array?
In the first block of message.
UpTrends[UpTrendsCount] = trend;
its in white loop.
Here is the full code
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
//---
if(Bars>totalBars)
{
totalBars=Bars;
bool found=false;
int shift=2;
while(!found)
{
if(High[1]<=High[shift] && High[1]>=Low[shift])
{
int lowest_index_on_range=iLowest(NULL,PERIOD_CURRENT,MODE_LOW,shift,0);
UpTrend* trend=new UpTrend(Time[lowest_index_on_range],Time[1]);
if(trend.isSuitable() && !trend.hasSameLow(UpTrends))
{
int UpTrendsCount=ArraySize(UpTrends);
ArrayResize(UpTrends, UpTrendsCount+1);
UpTrends[UpTrendsCount] = trend;
trend.drawTrendLine();
}
delete trend;
}
if(shift>800)
break;
shift++;
}
}
}
Why does that surprise you? | |
| UpTrends[UpTrendsCount] = trend; trend.drawTrendLine(); } delete trend; if(trends[i].low_bar.time==low_bar.time) |
Why does that surprise you? | |
| UpTrends[UpTrendsCount] = trend; trend.drawTrendLine(); } delete trend; |
Thank you for answer.
If i dont delete pointer it gives this message in journal
2017.01.03 15:30:39.599 2016.03.15 16:00:00 main EURUSD,H1: 13267 objects of type UpTrend left
2017.01.03 15:30:39.583 2016.03.15 16:00:00 main EURUSD,H1: 13267 undeleted objects left
how can i pass this?
Thank you for answer.
If i dont delete pointer it gives this message in journal
2017.01.03 15:30:39.599 2016.03.15 16:00:00 main EURUSD,H1: 13267 objects of type UpTrend left
2017.01.03 15:30:39.583 2016.03.15 16:00:00 main EURUSD,H1: 13267 undeleted objects left
how can i pass this?
You have to delete the pointers inside OnDeinit().
Or eventually when you really don't need it any more.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
Can you help me please?
We define the array as
UpTrend* UpTrends[];
And the code of function call
if(trend.isSuitable() && !trend.hasSameLow(UpTrends))
{
int UpTrendsCount=ArraySize(UpTrends);
ArrayResize(UpTrends, UpTrendsCount+1);
UpTrends[UpTrendsCount] = trend;
trend.drawTrendLine();
}
delete trend;
I am getting invalid pointer access on red line.
bool UpTrend::hasSameLow(UpTrend *&trends[])
{
int count=ArraySize(trends);
for(int i=0; i<count; i++)
{
Print(count); //it writes 1
Print(i); // it writes 0
if(trends[i].low_bar.time==low_bar.time)
{
return true;
}
}
return false;
}