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:
AddColumn(DateBack, "FromDate", formatDateTime );
I wish to plot a shape say a HOLLOW STAR at the start date:
Say,
AddColumn(DateNum(),"Num");
AddColumn(DateNum()-Barsno,"Num-Back");
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);
@pushkan ,
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 );
AddColumn(DateBack, "FromDate", formatDateTime );
//I wish to plot a shape say a HOLLOW STAR at the start date:
AddColumn(DateNum(),"Num");
AddColumn(DateNum()-Barsno,"Num-Back");
//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);
@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
pushkan
October 10, 2022, 4:15am
10
Part 1 of 2 : Settings
In the settings, I have changed to new date, the exploration too has accounted for it
pushkan
October 10, 2022, 4:19am
11
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
Senior please advise
fxshrat
October 10, 2022, 7:01am
13
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.
pushkan
October 10, 2022, 11:16am
14
@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?
Originally all Param…() functions have been implemented for use in chart panes only!
They are dependent on ChartID.
ChartID return value in all analysis windows is zero (always).
Still if you want to use same parameters (that have been set in chart pane) in analysis window too then you may store them to static variables.
Example for Param() function:
...
uniqueID = "";// uniqueID-> some unique name (which may include chartID)
if ( Status( "action" ) == actionIndicator ) { // if in chart pa…
pushkan
October 11, 2022, 8:17am
16
@TrendSurfer Thanks. The reading helped in understanding a bit about StaticVar. Will need to do some R&D.
pushkan
November 1, 2022, 9:35am
17
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:
system
Closed
February 9, 2023, 9:35am
18
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.