The exploration changes (I think) the stock quotation

Good afternoon,

I'm really sorry to bother you because what's happening to me is really weird and I don't know if someone is going to know how to help me, but I had to try.

I'm using an exploration what it looks is that the explorer changes de quotation of the stocks.

I enclose a screen video where you can see that the current close (Cierre actual) for CC is 40,04. It gets updates to 40,8 and when I explore it two times it changes back to 40,04.

It's a daily system. I enclose as well the system code.

If anyone has a hint where I should look or what is wrong, I'd be very glad!

Thanks and have a good sunday!



/* PART 1 - VARIABLES
*/


Margin 				= 0; 			// 1 = 50% margin, 0 = cash
PositionsHeld 		= OPTIMIZE("Positions", 10,5,20,1);;			// Maximum number of simultaneously open positions	
OwnCapital 			= 100000; 		// Initial capital

AllocationPercent = IIf(Margin==1,(1/PositionsHeld)*200,(1/PositionsHeld)*100); 


/* PART 2 - BACKTESTER SETTINGS
*/

SetBacktestMode(backtestRegularRaw);					 // Backtest mode - raw used so that Amibroker doesn't automatically filter out excessive signals
SetPositionSize(AllocationPercent, spsPercentOfEquity);  // Allocation per position, using the allocationpercent variable calculated in part 1
SetOption("InitialEquity",OwnCapital);					 // Initial capital, using OwnCapital variable from part 1
SetOption("AllowSameBarExit",False);					 // Disable same bar exit as the strategy exits at open of the following day
SetOption("AccountMargin",IIf(Margin==1,50,100));		 // Margin - using the Margin switch from part 1
SetOption("maxopenpositions",PositionsHeld);			 // Maximum number of simultaneously open positions	using the variable from part 1
SetOption("UsePrevBarEquityForPosSizing",True);			 // Equity value as of close of previous bar is used to calculate position size
SetOption("usecustombacktestproc", True);				 //	CBT needs to be enabled to handle the limit order entries - part 8 of the code	 
SetTradeDelays(0,1,0,0); 								 // Sell delay set to 1 to allow for exiting the positions at the open of the following day
RoundLotSize = 1;										 // Round the share quantity to whole numbers


/* PART 3 - PRICE CHANNEL FILTER 
*/

ChannelHigh 		= HHV(H,50);	// Channel high variable - taking the highest high value of N days
ChannelLow 			= LLV(L,10);	// Channel low variable - taking the lowest low value of N days

ChannelBOwindow 	= 5; 						// Channel breakout window - how many bars since channel breakout are we still looking to enter
ChannelBreakout 	= C > Ref(ChannelHigh,-1);	// Definition of channel breakout - price CLOSES above the channel high

Diff = (ChannelHigh - ChannelLow) / 4;	// Difference between channel high and low, divided by X
BuyZone = ChannelLow + (Diff * 2);		// Buyzone - used to filter out non-trending stocks that do not show sufficient momentum, using Diff multiplied by X





/* PART 4 - BUY SETUP AND RANKING
*/
FechaInicio=10000 * (2021 - 1900) + 100 * 12 + 31;
BuySetup= 	ROC(C,1) < - 2										// Closing price decreased by at least 2 percent
			AND C > BuyZone										// Closing price is in the BuyZone 
			AND BarsSince(ChannelBreakout) < ChannelBOwindow	// Channel breakout took place within the specified time window prior to the signal
			AND Close > 1 		;								// Check if closing price is greater than 5; this is to filter out stocks that are too cheap to control the trading commissions
			//AND IIf(DateNum()<Fechainicio,valida_y_dentro,IIF( InWatchListName("S&P 500"), 1  , 0 ));	// Pertenece al Ć­ndice		
PositionScore =	-Ref(ROC(C,5),-1) ; // Signal ranking - greater the decrease in the closing price, the better; using previous bar's value as entering following day with limit order



/* PART 5 - LIMIT PRICE AND EXIT SETUP
*/

ATRvariable 	= ATR(5);	// ATR used in calculation of the limit price and a stop-loss
ATRMultiple 	= 1; 		// Multiple of ATR used in calculation of the limit price

LimitPrice = IIf(Ref(BuySetup,-1),Ref(L,-1)-(Ref(ATRvariable,-1) * ATRMultiple),Null);	// If BuySetup at previous bar, set the limit price calculated from low of the previous bar, using ATR and its multiple, if no BuySetup set to null

ExitSignal = C > O;			// Sell signal definition - signal generated on first up bar following the entry



/* PART 6 - BUY LIMIT FILL
*/


Buy	= Ref(BuySetup,-1); 				// Buy signal gets activated if a valid BuySetup got generated at the previous bar
BuyPrice = Close; 			// Buyprice provisionally set to either bar's open on our limit price (which ever is lower) - however we do not yet know if the limit price actually gets filled (handled via CBT)

LimitBuy = Buy AND Low < LimitPrice; 	// Final limit buy simulation - valid buy signal at previous bar and low of the current bar lower than our limit price; however not taking the maximum open position count into the account (handled via CBT)
LimitBuy = ExRem(LimitBuy,ExitSignal); 	// LimitBuy var restated using ExRem - this filters out excessive LimitBuy signals after the first one has been taken



/* PART 7 - STOP-LOSS AND EXIT
*/

ATRatEntry = ValueWhen(LimitBuy,Ref(ATRvariable,-1));	// Take the ATR's value at the point of LimitBuy (as of previous bar's close) to be used to calculate the stop-loss
StopLoss = ValueWhen(LimitBuy,BuyPrice) - ATRatEntry;	// Set the stop-loss price at the point of LimitBuy - deduct the ATRatEntry from the buyprice

Sell = ExitSignal ; 	
SellPrice = Close; 					// Sellprice set to open, as trades are closed at the open of the following day


bars = 3; // exit after 10 bars



/* PART 9 - EXPLORER CODE
*/

Nombre=FullName();// aƱadido por EJ




Filter = BuySetup;
AddTextColumn(Nombre,"Nombre",1.2);// aƱadido por EJ

AddTextColumn( GetFnData( "Alias" ), "ISIN");



AddColumn(Ref(C,-1),"Cierre Anterior",1.2);
AddColumn(C,"Cierre Actual",1.2);
AddColumn(ROC(C,1),"Cambio",1.2);


AddColumn(L-(ATRvariable * ATRMultiple),"Precio LĆ­mite",1.2);
AddColumn(L-(ATRvariable * ATRMultiple) - ATRvariable,"Stop Loss",1.2);
AddColumn(ATR(5)/(L-(ATRvariable * ATRMultiple) - ATRvariable)*100,"% Stop Loss",1.2);// aƱadido por EJ
AddColumn(((C-(L-(ATRvariable * ATRMultiple)))/C)*100,"Distancia Entrada",1.2);// aƱadido por EJ



if ( Status( "action" ) == actionExplore ) SetSortColumns(-2,7); // sort for Exploration only
if ( Status( "action" ) == actionBacktest ) SetSortColumns(-5 ); // sort for Backtest only




Are you sure the code you posted is the code you are running in the video? I tried running an Exploration against a single symbol, CC, and did not get any output for 20-May-2022 even though my closing price on that date is the same as shown in your video.

Does this problem occur if you run the Exploration against a single symbol instead of an (unknown to us) watchlist of symbols?

1 Like

I changed the code to make it easier but the same problems happens to me.

What makes it weirder is that I have two PC's and in one PC it's working properly and in the other happens what I showed in the video. Then, I guess there is no problem in the code but in other place. I checked the settings and everything is the same.

I'm running out of ideas :thinking:

Answering your question. It happens the same for just one single stock or watchlist. By the way, I'm using Russell 300

Well, if it only happens on one of your two systems, then there's not much point in anyone looking at your code. :slight_smile:

That leaves the data and your settings. You can eliminate the Analysis Settings by saving an AmiBroker Project File (.apx) on one machine and then running that file on the other machine. Data issues can be painful to track down -- good luck!

1 Like

@vegeta, in your video you are using a 3rd party data plugin (that actually refreshes data during the exploration).
Are the settings/server connection the same on the 2 machines?
Do you have any alternative data source (like free Yahoo data) to double check?

2 Likes

I used the same apx in the second computer and works properly.

What I don't understand is how an exploration can change the data

Same settings/server connection. In fact, I only found this behaviour with this explorer.

If I stop the download of the quotes, the same happens. What I mean. now the quote is correct. Then I disconnect the connection so it doesn't update the quotes, I explore and it changes the quote.

I addition, I can say that during last week that I've been testing this system it didn't happen. If I explore for other dates it works properly. It only happens for last friday :roll_eyes:

I made another video. You can see that the plugin is paused (it doesn't update the quotation).

The close is 40.8 and after the exploration the close is 40.04. It has no sense at all

Even though your data plugin claims to be "paused", I think that is the most likely culprit here. Here's another thread that you might want to read through: Exploration giving different results when it is run successive times - #6 by NorgateData

3 Likes

Exploration (or any other AFL code used in any way) CANNOT physically change quotation data if it doesn't use direct write access to database (via OLE) or AddToComposite() function (that exists for the exact purpose of creating composites and writing data to them).

If you are using DATA PLUGIN - it is data plugin that OWNS the data and changes it.

1 Like

You're right. I made a copy of the Data Base in Local and it started working properly.

Thanks a lot!

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