Show trade signal arrows for today only?

Hey guys,
I've got a quick question.
I want to show trade arrows in my formula only for today.
Please note that I want this to be suitable for any timeframe (less than daily).
What kind of function/algorithm would you recommend to use for such purpose?

// Ugly check for a new day. NewDay == 1 when new day starts
DN 			= LastValue(DateNum());
PrevDN		= StaticVarGet("DateNumber");
NewDay 		= (DN > PrevDN);
StaticVarSet("DateNumber", DN);

Today = Now(6); // current day of the month number

//plotting
if(condition)
{
	if (LongArrows)
	{
		PlotShapes	(Buy	*	shapeUpArrow,	colorWhite,			0,	Low-10);
		PlotShapes	(Sell	*	shapeDownArrow,	colorRed,			0,	High+40);
	}
	if (ShortArrows)
	{
		PlotShapes	(Short	*	shapeDownArrow,	colorWhite,			0,	High+10);
		PlotShapes	(Cover	*	shapeUpArrow,	colorRed,			0,	Low-40);
	}
}

I am not asking for a complete solution, but more for some sort of direction to think about.
Thank you =)

1 Like

Try this one

dn = DateNum();
currentday_cond = dn == LastValue(dn);

//plotting
if(condition)
{	
	if (LongArrows)
	{
		PlotShapes	((Buy AND currentday_cond)	*	shapeUpArrow,	colorWhite,			0,	Low-10);
		PlotShapes	((Sell AND currentday_cond)	*	shapeDownArrow,	colorRed,			0,	High+40);
	}
	if (ShortArrows)
	{
		PlotShapes	((Short AND currentday_cond)	*	shapeDownArrow,	colorWhite,		0,	High+10);
		PlotShapes	((Cover AND currentday_cond)	*	shapeUpArrow,	colorRed,		0,	Low-40);
	}
}

EDIT: your variables "condition" and "LongArrows" as well as "ShortArrows" are unknown. So I kept it in there... Try PlotShapes without them first. Also you should know that PlotShapes has y-offset as 5th argument already. So things like "H+40" and "L-10" as in your code are not required. But I kept it in. It is your code...

2 Likes

Array based solution is the simplest and does not really require if statement

Today = DateNum() == LastValue( DateNum() );

PlotShapes( Today * Buy * ShapeUpArrow, colorWhite, 0, Low - 1 );
4 Likes

Dear @fxshrat and @Tomasz
Thank you so much for this genius solution!
I knew there should be something this elegant =)

looking back at my code ...:man_facepalming:t2: what was I thinking? :sweat_smile:

p.s. I have spent several hours working on this task today and finally decided to ask for help here

"LongArrows" and "ShortArrows" of if statements could be

LongArrows = ParamToggle( "Plot Long arrows", "OFF|ON", 1 );
ShortArrows = ParamToggle( "Plot Short arrows", "OFF|ON", 1 );

AFAICS, there isn't anything wrong with adding such vars to some if statement. It's not my business if one user wants to deactivate some shapes completely.

What is assigned to "condition"? We don't know. It looks as redundant one. But it's not my code....Maybe "condition" makes a call to E.T.... who knows...

(Buy AND currentday_cond)	

etc. solve original question.

1 Like

Thank you @fxshrat This does look nice. Although I've created so many parameters already ^^' And yes, there is one for Long and one for Short arrows toggles.
Recently I am quite excited about the idea of creating UI for better accessibility. That's why I spam conditions everywhere instead of directly linking them to parameters.

What is assigned to "condition"? We don't know. It looks as redundant one. But it's not my code....Maybe "condition" makes a call to E.T. ... who knows...

Ha ha ha :rofl: it was supposed to be "the condition" to check whether it is "today". And if so, then plot all the arrows.
I am still thinking with different approach by default. And was not trying to incorporate the condition array into plotting function, but doing a single value check.
I usually like to do so, because it allows me to place many different things under such condition. For example put a _TRACE or use this condition with a for loop to plot text labels:

for (i = 0; i < BarCount; i++)
{
	if (LongLabels)
	{
		if (Buy[i]) 	PlotText ("Buy " 	+ C[i], i, L[i]-25, colorWhite);
		if (Sell[i]) 	PlotText ("Sell " 	+ C[i], i, H[i]+50, colorWhite);
	}
	if (ShortLabels)
	{
		if (Short[i]) 	PlotText ("Short " 	+ C[i], i, H[i]+20, colorYellow);
		if (Cover[i]) 	PlotText ("Cover "	+ C[i], i, L[i]-55, colorYellow);
	}
}

While I appreciate the beauty of array-based solution. My brain still tends to think of a simple "if" with a single True/False and not an array, I hope I will get to the arrays-way of thinking soon.

1 Like