Plot Shapes for specified BAR/DATE

I am taking an input from USER using following code:

Barsno=Param( "Bars", 244, 1, 6100 );
DateBack = Ref(DateTime(), -Barsno );

I am able to get the date in exploration using:

I wish to plot a shape say a HOLLOW STAR at the start date:
Say,

How can I get a condition that I can use in following code:
StartDate = Cross(DateNum(),DateBack) ;
(This is something wrong)
StartDate = (DateNum()=DateBack) ;

shapeStartDate=IIf(StartDate,shapeHollowStar,shapeNone);

You have been a forum member for ages yet you haven't used 'Code Tags'!

You will find that members will choose to ignore your post!

Apologies. Since this was more of a small part of the bigger code, I put it in open post. The code would look something like this:

``````Barsno=Param( "Bars", 244, 1, 6100 );
DateBack = Ref(DateTime(), -Barsno );

//I wish to plot a shape say a HOLLOW STAR at the start date:

//How can I get a condition that I can use in following code:
StartDate = Cross(DateNum(),DateBack) ;
//(This is something wrong)
StartDate = (DateNum()=DateBack) ;

shapeStartDate=IIf(StartDate,shapeHollowStar,shapeNone);
``````

Modify to suit:

``````bi = BarIndex();
bi_last = LastValue(bi);

nBars = Param("# Bars Back", 20, 1, 500, 10);
dateBack_bi = bi_last - Min(bi_last, nBars);

startDate = bi == dateBack_bi;

PlotShapes(shapeHollowStar * startDate, colorBlue, 0, Low, -20);
``````

Use Lookup Function
AFL Function Reference - LOOKUP (amibroker.com)

@TrendSurfer it worked out well. Many thanks. The modified code:

``````// Bars in consideration

Barsno=Param( "Bars", 244, 1, 6100 );
Bars4 = Barsno / 4;
Bars4Num = LastValue(Bars4);

bi = BarIndex();
bi_last = LastValue(bi);
dateBack_bi = bi_last - Min(bi_last,Barsno);
startDate = bi == dateBack_bi;

PlotShapes(shapeSquare*startDate, colorBlue, 0, 50, 0);

DateBack = Ref(DateTime(),-Barsno );

``````

@TrendSurfer the code seems to fail where I am taking the input as a date. The code is as follows:

``````                fromdate = StrToDateTime( ParamDate("Start Date", "2020-03-24", 1 ) );
fromdatestr = DateTimetoStr(fromdate);

Barsno = BarsSince( DateTime() <= _DT(fromdatestr));

Bars4 = BarsNum / 4;
Bars4Num = LastValue(Bars4);

bi = BarIndex();
bi_last = LastValue(bi);
dateBack_bi = bi_last - Min(bi_last,Barsno);
startDate = bi == dateBack_bi;

PlotShapes(shapeUpTriangle*startDate, colorBlue, 0, 50, 0);

DateBack = Ref(DateTime(),-Barsno );

``````

While the DateBack as well as barsno is throwing out a correct date & bars in exploration, the Plot function is putting shape at some other date.

What could be wrong in there?

Using Fixed bars the output is RIGHT (Refer the lower pane. Blue traingle comes in right at bar 244

Part 2 - As only one embeded picture is allowed

But, when I am putting it in FROM date format, it throws out a wrong date (Refer the lower pane. While selection of date is for 03/24/2020, the BLUE traingle is shown around August 2022

You just need DateTimeDiff and nothing else.

``````Version(6.20);
fromdate = ParamDate( "Start Date", "2020-03-24", 2 );
startDate = DateTimeDiff(DateTime(),fromdate) == 0;

Plot( C, "Price", colorDefault, styleBar );
PlotShapes( shapeUpTriangle*startDate, colorBlue, 0, L, -20 );
``````
1 Like

Part 1 of 2 : Settings

In the settings, I have changed to new date, the exploration too has accounted for it

Part 2 of 2

But the chart still marks the old date

Have some counters to be updated there?
Would it be prudent to raise the query with 2 alternative full codes at releavant topic
IBD Relative Strength

Param's are cached.

Params are dependent on chart iD.
Chart and Analysis have different chart IDs (always zero in Analysis).
So if you change params in one of those two environments it won't change to same in other one.

Use static variables to apply same value in both ones.

@TrendSurfer That did help as now once I toggle the parameters on both exploration window & chart it is helping out.

@fxshrat will require a bit more links for reading. StaticVarSet can it be accessed through a date variable type? Where will I get to read on this?

Why can't you search the forum for yourself?

@TrendSurfer Thanks. The reading helped in understanding a bit about StaticVar. Will need to do some R&D.

The code seems to return BLANKS where historical data is available for lesser bars as compared to given date. Is there a way to check this wrt some particular scrip, say a benchmark using Foreign function? I tried following code, but the flaw lies in basic BLANKS coming through:

``````               fromdate = ParamDate( "Start Date", "", 2 );
fromdatestr = DateTimetoStr(fromdate);
startDate = DateTimeDiff(DateTime(),fromdate) == 0;
Barsno = BarsSince( DateTime() <= _DT(fromdatestr));

PlotShapes(shapeUpTriangle*startDate, colorBlue, 0, 50, 0);

dt = DateTime();
begindt = BeginValue(dt);
FirstDate = DateTimeToStr(begindt);
FirstBarsno = BarsSince( DateTime() <= _DT(FirstDate));

Barsno=IIf(Barsno>FirstBarsno,FirstBarsno,Barsno);
BarsNum = LastValue(Barsno);

``````

Is there a condition to check whether the filed is blank and include in the IIF function?

The output is as follows:

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