Anchored Vwap, But YYYYMMDD input separated


Category:
0
0

Hello again, trying to figure out if I can create separate year, month and day inputs for the ‘GetYYYMMDD’ function, to appear in the Edit Studies / Customization window.  Ideas to have 3 input fields.   Just for ease of use purposes.   Hoping you can point me in the right direction.  Put Code and picture below.   Thanks Again

 

#input anchorDate = 20191111;
#input anchorTime = 0930;

#def postAnchorDate = if GetYYYYMMDD() >= anchorDate then 1 else 0;
#def postAnchorTime = if SecondsFromTime(anchorTime) >= 0 then 1 else 0;

#plot anchoredVWAP = TotalSum(if postAnchorDate and postAnchorTime then ((high+low+close)/3)*(volume) else 0)/TotalSum(if postAnchorDate and postAnchorTime then volume else 0);

#anchoredVWAP.setStyle(Curve.Firm);
#anchoredVWAP.SetLineWeight(3);
#anchoredVWAP.SetDefaultColor(Color.Cyan);

Attachments:
Marked as spam
Posted by (Questions: 11, Answers: 15)
Asked on September 29, 2020 6:24 pm
257 views
0
Private answer

I am not sure if this is possible to do on Thinkorswim. But if it is, even the time it takes me to research the possible solutions will far exceed the brief 15 minutes I allow for free solutions in the Q&A forum.

I can tell you it's not possible to do it using the code you provided. You would need to copy the entire code from the built-in version provided by Thinkorswim. Then you would need to learn exactly what this section of code is doing:

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case MONTH:
periodIndx = roundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

...and once you learned what makes that section of code do what it does you would then need to experiment with various methods of using a date/time for the timeFrame input instead of the fixed values of Day, Week, Month that are provided. This is not for the faint of heart. This is job for a seasoned professional.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on September 30, 2020 11:48 am