List of exit signals of open positions

Hello, I try to learn AFL programming, but I still a beginner :smiley:
I want to get exit signals of open positions.

My code:

	i = BarCount - 1;
		for( sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
				if (sig.IsExit() )
					for( openpos = bo.GetFirstOpenPos(); openpos; openpos = bo.GetNextOpenPos() )
						_TRACE(sig.Symbol + "," + FullName() + "," + (NumToStr(dt[i],formatDateTime)) + "," + (NumToStr(sig.Price,format = 1.2,False)));

My results:


I get some extra signals, which I don't want.

I want exit signals:


Could you help me, please?
Thanks all.

Beginners should not dig into custom backtester because it is too complex for beginners. If you want to see exit signals, no coding is needed at all.
Use "Detailed log" instead as instructed here: How do I debug my formula?

Thanks for your answer. Yes, I know, if I want to only see exit signals I use a Detailed log.
But I want automatically export a list of exit signals to a CSV file. I already have a list of open positions, there are exits left.

Instead of iterating all signals in outer loop and open positions in inner loop, you should have ONE loop, that only iterates open positions and uses FindSignal method to find relevant signal for open position.

Quote from:

Signal FindSignal( long Bar, string Symbol, long Type ) - new in v5.10

where bar is a bar number, type represents type of signal to find: 0 - both entries and exits, 1 - only entries, 2 - only exitsThe method finds for first matching signal that has fPrice != -1 (different than -1). If 0 is used as type, and entry and exit is on the same bar then entry signal will be returned. Note: fPrice = -1 is a special marker meaning that given signal should be ignored.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.