Following on from this thread here are details for charts posted on our Twitter account. Comment in the Tweet and we’ll post the details here.

For example, to calculate the average drawdown for the members of an index, as per this Tweet: https://twitter.com/Optuma/status/1471137257969135621?s=20

This was calculated using the Drawdown Percent function DDP() in the custom Market Breadth module, with the Breadth Action set to Average.

By default, the DDP() function will calculate distance from the 1 year high.

Once calculated, the data can be viewed in the Breadth Data tool below the price chart:

Hii Sir,

It seems ismember is not working on this any reason.

Regards,
Deepak

Hi Deepak,

The ISMEMBER() function only works with true/false conditions, not when calculating averages.

```//Define pivots;
#\$Bars=10;
H1=PIVOT(MIN=\$Bars, TYPE=High, IGNOREUNCONFIRMED=True);
L1=PIVOT(MIN=\$Bars, TYPE=Low, IGNOREUNCONFIRMED=True);
//Get pivot values;
H2=VALUEWHEN(HIGH(), H1);
L2=VALUEWHEN(LOW(),L1);
//When did the pivots occur?;
\$TH1=TIMESINCESIGNAL(H1, UNIT=Bars);
\$TL1=TIMESINCESIGNAL(L1, UNIT=Bars);
//Close crosses previous pivot level with a new high/low since the pivot;
(CLOSE() CrossesAbove H2 and CLOSE() > HIGHESTHIGH(BARS=\$TL1)) or
(CLOSE() CrossesBelow L2 and CLOSE() < LOWESTLOW(BARS=\$TL1))```

Can you post the script for the slope of the linear regression.

If you type ‘linear’ in the script editor window then all suggestions will pop up, including LRSLOPE():

VIX-Indices-Curve.owb (45.3 KB)

Day of the Week formulas: https://twitter.com/Optuma/status/1520384472356560896

The DAYOFWEEK() function assigns a value to each week day, with Sundays assigned a 1, Mondays = 2, etc. As such, to mark all Fridays on a chart use DAYOFWEEK()==6 in a Show Bar. This will show all Fridays with a fall greater than 3%:

```DAYOFWEEK()==6 and
CHANGE()<-3```

The Days Down DD() function counts the consecutive bars a value (the close by default) has been lower (Days Up DU() does the opposite).

On a weekly timeframe DD()==5 will signal when there have been 5 consecutive weekly lower closes, which was used in the signal test.

For 5 consecutive lower highs use DD(HIGH())==5

The Days Down tool can be used on a chart (currently 6 weeks for the SPX):

To calculate how long ago the close was at the latest low (or high) - and the dates they occured: https://twitter.com/Optuma/status/1537704403205079040

Worst Change Since:

```//Display as Date in Watchlist;
//Get the last 1D ROC change %;
D1=LAST(ROC(BARS=1));
//Get the BarDate when the 1D ROC was less than D1;
BARDATE(ROC(BARS=1)<D1, UNIT=Days)```

Lowest Close Since:

```//Display as Date in Watchlist;
//Get the last close price;
D1=LAST(CLOSE());
//Get the BarDate when the Close was less than D1;
BARDATE(CLOSE()<D1)```

Weeks Since Low

```//Get the last close price;
D1=LAST(CLOSE());
//Get the time since the Close was less than D1;
TIMESINCESIGNAL(CLOSE()<D1, Unit=Weeks)```

To find the high dates instead, change the < to >. Sample weekly watchlist attached that can be saved as a layout and applied to any other lists.

WorstBest-Dates.owb (94.8 KB)

Hi Optuma team,

can you publish the script for the Twitter chart “ATH Drawdown” (https://twitter.com/Optuma/status/1539727679586443265)?

As always many thanks for your excellent support.

Best wishes,
Thomas

Hi Thomas - use the Drawdown tool set to 100 year lookback (the all-time high calculation is wrong and is being fixed).

https://help.optuma.com/kb/faq.php?id=1237

Hi Darren,

The story goes on. Can you publish the scripts for your two interesting Twitter charts here?

Many thanks for your great inspirations and support.

Best wishes,
Thomas

Hi Thomas,

The pre-Covid high values were defined using the HIGHESTHIGH function between January 1st and March 13th 2020, and getting the percent difference from the latest close:

```V1=HIGHESTHIGH(RANGE=Range, RANGESTART=2020-01-01, RANGEEND=2020-03-13);
DIFFPCT(CLOSE(), V1)/100```

The custom bar colours use this:

```V1=HIGHESTHIGH(RANGE=Range, RANGESTART=2020-01-01, RANGEEND=2020-03-13);
CLOSE()>V1```

To count the days since any value was that high (eg closing price, RIC, RSI, Volume, etc) change the D1 function here, as required:

```D1=RIC();
D2=LAST(D1);
TIMESINCESIGNAL(D1>D2, Unit=Bars)```

Hi Darren,

Would you please be so kind again to explain how you created this chart?

Am I right that I need the “Column Chart” feature in the Professional and Enterprise edition of Optuma to create your chart?

But anyway, please just explain how you created the chart with all the necessary scripts.

I use the following script in a watchlist to calculate the maximum drawdown:

```Line1 = DDP(Week(PERIODAMOUNT=1), BACKTYPE=Weeks, LOOKBACKBARS=52, DEFAULT=Maximum) ;
Line2 = Line1 / 100 ;
Line2```

With this script I get the maximum drawdown for the SPX of -24.52%, in your chart you have for the maximum drawdown a value of -23.69%.
What is the reason for this difference?

Best wishes,
Thomas

Hi Darren,

I have figured out how you have calculated the maximum intra-year drawdowns. You calculate the percentage difference between the closing price of the previous year and the lowest low of the next year.

OK so far so good, but this is not the “real” maximum intra-year drawdown. A better naming would be helpful e.g. maximum drawdown between the closing price of the previous year and the lowest low of the next year.

Best wishes,
Thomas

Hi Thomas,

It has been created using a Show View below a yearly price chart, and the price chart ‘view’ hidden in the Structure Panel.

The Show View formula set to display as a histogram is simply CHANGE() for the columns (as the chart is a yearly timeframe it will calculate yearly change).

Max intra-year low is a Show Plot for the blue line:

```//Current low;
V1 = LOW();
//Prev close;
V2 = CLOSE()[1];
//Percent calc;
DIFFPCT(V1,V2)```

This is different from the DDP() function which uses the 52 week high whereas this calculates from the close of the previous year.

A workbook for the SPX attached, which includes Show Bar formulas for the labels.

IntraYear-Lows.owb (19.2 KB)

1 Like

Hi Darren,

The story goes on and on. You have again published on Twitter a great chart about the % SPX stocks 20EMA > 50EMA.

Would it be possible to publish here the scripts using this analysis?

I know of course I need the Optuma Breadth Module to calculate the % SPX stocks, but I have it.

Many thanks and best wishes,
Thomas

Hi Thomas,

This is the breadth calculation, set to Percent:

`MA(BARS=20, CALC=Close, STYLE=Exponential) > MA(BARS=50, CALC=Close, STYLE=Exponential)`

The Signal Test formula for when the breadth crosses above 33 after crossing 20:

```V1=GETDATA(CODE=[BREADTHSYMBOL]:Market Breadth);
R1=V1 CrossesAbove 33;
R2=V1 CrossesAbove 20;
SIGNALAFTER(R2,R1)```

Hi Darren,

This time making it short: "Can you publish here in the forum the scripts for the chart and backtest of your Twitter analysis about “\$SPX losing 2% on a Monday following a 1% loss on a Friday”?

As always really many thanks for your exceptional good support and ideas.

Best wishes,
Thomas