Help needed in Writeif for Exploration

Hello i need help with Writeif Function which i am using as below:

StartCond=DateNum()!=Ref(DateNum(),-1); 		//Day Start
StartPoint=BarsSince(StartCond); 				//Barssince Day Start
PdayEndPoint=StartPoint+1; 						//Previous Day Close Bar

Obar_Close=Ref(Close,-StartPoint); 				  // Close Price of Opening Bar
PdayObar_Close=Ref(Obar_Close,-PdayEndPoint); 	  // Close Price of Previous Day Opening Bar
Pday_Trend=Pday_Close>PdayObar_Close;			  // Check if current day Close of Opening Bar > Pday Close

// in Exploration: show Up if "Previous day close">close of Previous day "Open Bar Close"
AddTextColumn(WriteIf(Pday_Trend,"UP","DOWN"),"YDAY TREND");

I am getting wrong output in Writeif even though the condition is correct as shown by values below

![image|690x384](upload://glgTly7bCe8jto7FF9wm6zKje7S.png)

Your assumption is not correct.

  1. Function WriteIf works perfectly fine and Writeif output is correct according to what documentation is telling you. Reading (entire documentation from top to bottom) is important:

    Please note that WriteIf returns just single string representing current SelectedValue of the EXPRESSION

    Selected Value in analysis is at last bar of set range .

  2. For what you want to do you have to use different function and the solution to your request is here.

1 Like

HI @ Fxshrat, I understand that output is correct as writeif will reference the last bar and give the condition as per last bar. how do i make it reference to particular day bar when Trade Occurred?

@George-The-Trader,

What version of AmiBroker are you using?

Do you have valid AmiBroker License?