Plotted BUY signal gone missing during intraday-SCAN

I have an issue which I don't quite know where to start... I created an AFL which I plot in a pane. The result is perfect: the buy/sell signals are plotted on the exact day. In a "visual" way, everything is ok.

Now I wanted to SCAN the chart for these signals. I set the correct intraday-periodicity (e.g. 15min) and click SCAN - no results the "mathematical" way.

The confusing thing is that on a daily basis (daily database), it seems to be working perfect, on an intraday basis (separate database), it does not work as desired.

I wonder if you can tell me if the structure of my AFL contains any logical mistakes or not. I cannot copy/paste the whole AFL, that would be several hundred lines of IP, so I SHORTENED it a lot:

//  ==============================================
//  a VERY simplified version of my AFL structure
//  do not question the rules or logic in this AFL (they make no sense), it's only for DEMONSTRATION purpose of the STRUCTURE.

for (v1 = 1; v1 < BarCount; v1++)
	{
		for (v2 = 1; v2 < BarCount; v2++)
		{
			if (C[v2] > 2)   //
			{
				x0 = rule1[v1];
				y0 = rule2[v1];
				x1 = rule1[v2];
				y1 = rule2[v2];
								
				newTL = LineArray(x0,y0,x1,y1,0,0);
				
				if (bi[v2] > 500))
					{
					Plot(newTL,"",colorRed, styleNoLabel);		
					Buy[v2] = C[v2];   // Point1: arguments are passed successfully through the loops and a BUY is generated
					
					for(s=(v2+1); s < BarCount; s++)
							{
							Sell[s] = C[s];
							Sell = ExRem( sell, buy ); 
							break;
							}
					}
					break;
			}
		}
	} 	

// BUY from Point1 is successfully plotted
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorGreen,layer=0, yposition=Graph0, -20);
PlotShapes(IIf(Sell, shapedownArrow, shapeNone),colorRed,layer=0, yposition=Graph0, -20);

Considering that the values are passed through the loops in a correct way and a BUY is generated and used for plotting, I would assume that they are calculated during the SCAN in the same way?

any help, indication, tip or whatsoever would be much appreciated! Thank you

@TATrader when you post some code (even it is not the actual formula you are using) you should post working code: I mean without syntax errors like this one:

 if (bi[v2] > 500)) # here the is an extra parenthesis

and without undeclared variables (i.e. rules even if they are not the actually ones you use).

What is the bi[ ] array? Is it BarIndex()? In such a case I will first check/debug this to see if it is the cause of your problem.

In any case, if you truly want someone to help you, I suggest to repost your code (ideally the actual formula), so it can be replicated by other users.

1 Like

The code is incorrect on 3 things:

  1. You should NOT call Plot inside BarCount loop
  2. You should NOT call ExRem inside loop (see below)
  3. Double nested loop is rarely ever needed

The code like this is simply wrong:

for( ... )
{
 for(...)
 {
  // inside double nested loop 
  Sell[s] = C[s]; // this is incorrect. Sell is supposed to be BOOLEAN (true/false).     Assigning close is out of place here
   Sell = ExRem( sell, buy ); // This overwrites ENTIRE Sell array
  }
}
1 Like

You are correct, the code could be improved, but especially on point 3), I need the double nested loop.

Maybe I should rewrite my question: if I have a loop where in the end it generates a BUY inside the loop, should this automatically be transferred outside the loop, so a scan will recognize it as a signal?

Anyway, thank you for your help, always much appreciated.

you are right beppe, this particular code snippet contains a syntax error. I cannot post the whole code in here. I have used the debugger and the (original) code is correct, working without any problem. So here the problem is less the syntax, but the logic. E.g. local/global variables could be a problem. Or something similar I have not considered.
Thank you for your help.

It does not need to be "transferred". If you assign a Buy inside loop it is visible outside too as it is just the very same variable visible globally.