Stocks & Commodities Magazine - Traders' Tips

For the past couple of years we have been participating in the Traders’ Tips section of Stocks & Commodities magazine (www.traders.com) where we include scripting formulas for tools and indicators discussed in the article.

The attached workbook can be downloaded and opened in your copy of Optuma with examples of charts with the formulas, and new ones will be added to this thread as new articles are published.

Here’s the Stochastic Distance Indicator from the June 2023 edition which can be used in a Show View tool:

```//Stochastic Distance by Vitali Apirine - Stocks & Commodities June 2023;
\$LBPeriod=200;
\$Period=40;
\$Pds=3;
Dist1 = ABS(CLOSE()-CLOSE(OFFSET=\$Period));
D1=(Dist1-LOWESTLOW(Dist1, BARS=\$LBPeriod)) / (HIGHESTHIGH(Dist1, BARS=\$LBPeriod) - LOWESTLOW(Dist1, BARS=\$LBPeriod));
DD1=IF(CLOSE()>CLOSE(OFFSET=\$Period),D1, IF(CLOSE()<CLOSE(OFFSET=\$Period),D1*-1,0));
MA(DD1, STYLE=Exponential, BARS=\$Pds)*100```

This is BRILLIANT! Non-programming users would welcome additional resources like this one!

August 2023 - Donchian Channels

Attached is a workbook containing a study based on 20 day Donchian Channels used in the August 2023 edition. The DC Regime column shows Long when the upper line is higher, and stays long until a lower lower line occurs, using this SWITCH() function:
```U1=DONCH(INCURBAR=True, DEFAULT=UpperLine, BARS=20) IsUp;
D1=DONCH(INCURBAR=True, DEFAULT=LowerLine, BARS=20) IsDown;
SWITCH(U1,D1)```
This is also used for the Show Bar arrows, custom bar colours, and Analysis Tile.

The Regime Date column shows the date of the switch (change the Column Type to Date):

```U1=DONCH(INCURBAR=True, DEFAULT=UpperLine, BARS=20) IsUp;
D1=DONCH(INCURBAR=True, DEFAULT=LowerLine, BARS=20) IsDown;
V3=SWITCH(U1,D1) ChangeTo 1;
V4=SWITCH(U1,D1) ChangeTo 0;
V5 = BARDATE(V3);
V6 = BARDATE(V4);
IF(V5>V6,V5,V6)```

The Regime Days column counts the number of days:

```U1=DONCH(INCURBAR=True, DEFAULT=UpperLine, BARS=20) IsUp;
D1=DONCH(INCURBAR=True, DEFAULT=LowerLine, BARS=20) IsDown;
V3=SWITCH(U1,D1) ChangeTo 1;
V4=SWITCH(U1,D1) ChangeTo 0;
V5 = BARDATE(V3);
V6 = BARDATE(V4);
IF(V5>V6,TIMESINCESIGNAL(V3),TIMESINCESIGNAL(V4))+1```

The Above Centreline column tells us if the last price is above the midpoint of the 20 day high / low range:

`CLOSE()>DONCH(INCURBAR=True, DEFAULT=CentreLine, BARS=20)`

In this example, the Nasdaq 100 Index \$NDX has been long since March 17th 2023, which is currently 78 trading days. S&P500 is 35 days, and in the list of stocks \$META has been long for 150 days - since December 1st last year. By contrast, Consumer Staples \$XLP has been in a short regime since May 18th (35 days):

Donchian-Channels-Aug-23.owb (97.8 KB)