Author Topic: Help with BCFL custom Scans & Coding  (Read 2553 times)

0 Members and 2 Guests are viewing this topic.

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: Help with BCFL custom Scans & Coding
« Reply #75 on: 18/07/2019, 02:29:28 PM »
It looks like a bug has cropped back in to IsDefined(), it looks like it is crashing when events that have not happened (so there is no data to process). Currently talking to the developers about it and what can be done about it as well.

As for the variance MOV - we do not have it as a present MOV option within the MOV function. It is a bit more complicated than that and does not really necessarily need a period setting as it reacts based off a given volatility ratio of a stock.

This will get the same result as the hardcoded indicator with this:

{ Variable Moving Avg }
Check_CMO := CMO(C, 9);
New_CMO := Check_CMO / 100;
Final_CMO := if(New_CMO < 0, -1 * New_CMO, New_CMO);
VMA := (Final_CMO * C) + (1 - Final_CMO) * PREV;
VMA;

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: Help with BCFL custom Scans & Coding
« Reply #76 on: 29/07/2019, 12:23:38 PM »
Ok moving on, there is a TradingView indicator called a variable moving average that I would like to implement as a stand alone indicator and as the basis for other indicators.
I have sifted through and added the required syntax punctuation etc. but there is one embedded Pine reference that I'm struggling with at this point; the nz built in function as follows from Pine script language reference manual:
nz
Replaces NaN values with zeros (or given value) in a series.
nz(x, y) → integer
nz(x, y) → float
nz(x, y) → color
nz(x, y) → bool
nz(x, y) → series[integer]
nz(x, y) → series[bool]
nz(x, y) → series[color]
nz(x, y) → series
nz(x) → color
nz(x) → bool
nz(x) → integer
nz(x) → float
nz(x) → series[integer]
nz(x) → series[bool]
nz(x) → series[color]
nz(x) → series
EXAMPLE
nz(sma(close, 100))
RETURNS
Two args version: returns x if it's a valid (not NaN) number, otherwise y
One arg version: returns x if it's a valid (not NaN) number, otherwise 0
ARGUMENTS
x (series) Series of values to process.
y (float) Value that will be inserted instead of all NaN values in x series.


Original TradingView script:

src=close
len2 = input(10, title = "VMA 2 Length")
std2 = input(true, title = "Show Trend Direction")
bc2 = input(false, title = "Color bars based on Trend")
showVMA2 = input(true, title="Show VMA 2?")
k2 = 1.0/len2
pdm2 = max((src - src[1]), 0)
mdm2 = max((src[1] - src), 0)
pdmS2 = ((1 - k2)*nz(pdmS2[1]) + k2*pdm2)
mdmS2 = ((1 - k2)*nz(mdmS2[1]) + k2*mdm2)
s2 = pdmS2 + mdmS2
pdi2 = pdmS2/s2
mdi2 = mdmS2/s2
pdiS2 = ((1 - k2)*nz(pdiS2[1]) + k2*pdi2)
mdiS2 = ((1 - k2)*nz(mdiS2[1]) + k2*mdi2)
d2 = abs(pdiS2 - mdiS2)
s12 = pdiS2 + mdiS2
iS2 = ((1 - k2)*nz(iS2[1]) + k2*d2/s12)
hhv2 = highest(iS2, len2)
llv2 = lowest(iS2, len2)
d12 = hhv2 - llv2
vI2 = (iS2 - llv2)/d12
vma2 = (1 - k2*vI2)*nz(vma2[1]) + k2*vI2*src
//vam line colour
vmaL2=(vma2 > vma2[1]) ? lime : (vma2<vma2[1]) ? red : (vma2==vma2[1]) ? white : red
plot(showVMA2 and vma2 ? vma2 : na, color=std2 ? vmaL2 : aqua, style=line, linewidth=2, transp=0, title="VMA-1")


My efforts to convert script to BCFL:

{--------------- Variable Moving Average ---------------}
src:=close;
len := 10;
k := 1.0/len;
pdm := max((src - src,-1), 0);
mdm := max((src,-1 - src), 0);
pdmS := ((1 - k)*nz(pdmS,-1) + k*pdm);
mdmS := ((1 - k)*nz(mdmS,-1) + k*mdm);
s := pdmS + mdmS;
pdi := pdmS/s;
mdi := mdmS/s;
pdiS := ((1 - k)*nz(pdiS,-1) + k*pdi);
mdiS := ((1 - k)*nz(mdiS,-1) + k*mdi);
d := abs(pdiS - mdiS);
s1 := pdiS + mdiS;
iS := ((1 - k)*nz(iS,-1) + k*d/s1);
hhv := highest(iS, len);
llv := lowest(iS, len);
d1 := hhv - llv;
vI := (iS - llv)/d1;
vma := (1 - k*vI)*nz(vma,-1) + k*vI*src;
vma;

Take your time no hurry.
« Last Edit: 03/08/2019, 11:31:32 AM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: Help with BCFL custom Scans & Coding
« Reply #77 on: 30/07/2019, 11:47:50 AM »
Hey John,

Can you please post an attachment of what that indicator should look like for comparison purposes as well?

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: Help with BCFL custom Scans & Coding
« Reply #78 on: 01/08/2019, 03:49:53 PM »
Image attached in above post.

Re the IsDefined() bug; when I look at the scan criteria settings there is an option for Time Frame > Type, the drop down box lists three options, if Specific Period selected and last 34 day date range chosen, and the scan trigger is for an event like a cross(x,y) would this produce the same results as the IsDefined() code?
Granted the the date range would have to be continually adjusted for the 34 day period so prefer to be using the BCFL code that would be more a running 34 day period if this is correct.
« Last Edit: 01/08/2019, 04:01:40 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: Help with BCFL custom Scans & Coding
« Reply #79 on: 01/08/2019, 04:18:39 PM »
Period is strictly how many bars the scan should be applied on based on the data mode and period type. A Period type of 5 with Data Mode Day and Period Type Day will mean it will scan over the last 5 bars of every chart provided to the scan.

Key point is that it's totally seperate to what a scan actually looks for, it is just extending the processing and lookback time of the criteria.

I have a file that will extend RSI and fix IsDefined for you sitting on my computer that I was given late yesterday. I just need to squeeze out the time to test it properly before I am happy to give you the fix in advance (I'll probably call you directly when it's ready), which will be widly distributed with the next full release of Beyond Charts.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: Help with BCFL custom Scans & Coding
« Reply #80 on: 05/08/2019, 06:55:27 PM »
Ok then back to RSI's and MACD's,
I have found a couple of oscillators that sync well with the MACD short, not perfect they all seem to lag and want to cycle downward mid trend making them very frustrating to configure, thus the focus on the RSI to handle the MACD longer trend cycles.

I note the system SIROC trends well with price action over prolonged trend periods, the only oscillator I have found to do similar is the RSI III with Wilder and ROC in the formula.
 
I do have another RSI on my to do list for BCFL, and have been searching the Metastock websites for something similar with no luck just yet.

The indicator is from Incredible Charts and I believe is one of the better RSI's out there, formula is not available on the I.C. website so will post an image for comments.
Called the 'Smoothed RSI' with Wilder smoothing (see image), it stays high with a trending stock.

I think when combined with the MACD histogram set it might produce competitive indicators.
Would it be possible to incorporate the Smoothed RSI with Wilder smoothing into the new work being done with the BCFL RSI release, or even better for coding off, recommend a similar RSI code?
Thanks.


« Last Edit: 06/08/2019, 02:00:41 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: Help with BCFL custom Scans & Coding
« Reply #81 on: 06/08/2019, 03:45:45 PM »
Hi John,

I am happy with the fixes. I will contact you directly this afternoon via email about starting to hand these to you as a once off as they are relevant to what you are doing, until the next Beyond Charts release goes wider.

To give a preview, this is what a formula will look like. The RSI has an optional DATA ARRAY parameter. So RSI(14) will still work, but the RSI will be applied on a data array (like the MACD in this example) if it is given one.

{ ---- MACD1 ---- }
MACD1:= mov(C, 260, E) - mov(C, 120, E);
MACD1sig := mov(MACD1, 90, E);
MACD1hist := (MACD1sig - MACD1);

{ ---- RSI (MACD Histogram) ---- }
RSIM_out := RSI(MACD1hist, 14);

{ ---- MACD1hist  crosses above 50 mid line ---- }
RSIM_X := cross(RSIM_out, 50);

{ ---- Output to Scan Engine ---- }
{RSIM_out;}
{RSIM_out output is to compare with MACD with RSI applied from indicators panel}
RSIM_X;

For the Welles Wilder smoothing - Welles Wilder smoothing which can be found in the indicators panel and applied on top of the BCFL output.

As for the previous VMA - it looks like it is filling in the blanks for data series, which BCFL does not support.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: Help with BCFL custom Scans & Coding
« Reply #82 on: 08/08/2019, 12:04:34 AM »
Firstly the RSI with Wilder's Smoothing, I have attempted to do the indicator overlay onto the standard RSI the result is not nearly as clean as the I.C. one. So I tried to code it up in BCFL the result also isn't nearly as similar. Could there be additional code elements to this one? I would very much like to have this one in BC/FL code.
See attached image and my attempt code, lower panel is the code below:

{ RSI with Wilders Smoothing }
RSI_M:= rsi( 14 );
WSMA:= wilders(RSI_M, 14);
WSMA

Secondly; Re the Variable MA, I did find a similar one called Adaptive Zone Indicator in metastock code as shown in the top panel of attached chart. So will go with this for now:

{Adaptive Zones Indicator #1}
Per1:=Input("lookback",10,100,60);
Perc1:=Input("percent uband",.800,.999,.950);
Perc2:=Input("percent lband",1.01,1.2,1.05);
UB:=Ref((HHV(P,Per1)*Perc1),-1);
LB:=Ref((LLV(P,Per1)*Perc2),-1);
MB:=Ref((UB+LB)*.5,-1);
UB;
MB;
LB;

Thirdly; I wasn't expecting any action on the RSI until after next sw iteration delivered next year, so will be good to get that RSIMh nutted out after all the recent indicator code experimenting Iv'e been doing I still rely on the MACD and RSI overlay set as the default indicator reference. Is it just me that sees the RSIM potential?
« Last Edit: 08/08/2019, 12:21:05 AM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: Help with BCFL custom Scans & Coding
« Reply #83 on: 09/08/2019, 03:07:52 PM »
IF there is more too it, unfortunately we will not be able to replicate without knowing exactly how it is calculated - which could be IP that is not publicly accessible.

Saying that, the general shape comparison does look better using a smooth RSI of a MACD from the quick look I have had.

As for the potential query. Investors go through discovery and fine tuning at different times, the level of interest at any given time for an area can be subjective. We are always happy to try assist where we can, but our core systems with perhaps a tweak or two are generally fine for most. At some point execution has to be the focus to make the ROI of your time learning & researching worthwhile, where people settle at is different for all.


Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: Help with BCFL custom Scans & Coding
« Reply #84 on: 10/08/2019, 11:34:37 AM »
Re post 'happy with the fixes';
To condense the RSI formula you had posted to present syntax works:

MACDH3 := FMLVAR("MACD3","MACDH3");
RSIM3_out := RSI(MACDH3, 14);
RSIM3_X50 := cross(RSIM3_out, 50);
RSIM3_X50;

But when I add the Quick Reference Relative Strength Index syntax as displayed:
SYNTAX                    rsi(DATA ARRAY, PERIODS )
EXAMPLE                  rsi( 21 ), rsi(OPEN, 21)

as follows:
MACDH3 := FMLVAR("MACD3","MACDH3");
RSIM3_out := RSI(5),RSI(MACDH3, 14);
RSIM3_X50 := cross(RSIM3_out, 50);
RSIM3_X50;

produces this:
-> There is no function defined. Please define your function with valid arguments
Not sure why the BCFL QR doesn't work, it would be a treat to have RSI double smoothing, if that was the intention.

Which leads me to ask why there are no inbuilt smoothings for the system RSI unlike other indicators tha have a selection of 5 or so, where the Wilders Smoothing could be applied better than I have done in my attempt to code it off the system RSI. Just one more tweak please?
« Last Edit: 12/08/2019, 09:44:11 AM by JohnR »

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: Help with BCFL custom Scans & Coding
« Reply #85 on: 12/08/2019, 10:47:57 AM »
A question in regards to cleaning out watch lists; would there be a suitable code sequence to delete (as opposed to add to) from watch lists stocks that have exceeded there 'use by' date?
Manually deleting stocks could be a slow process, although do-able once a filter is set up.
It might require an addition to the right click select action to delete from 'selected watch list'  after bulk selecting from a scan window.

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: Help with BCFL custom Scans & Coding
« Reply #86 on: 12/08/2019, 04:46:59 PM »
Re post 'happy with the fixes';
To condense the RSI formula you had posted to present syntax works:

MACDH3 := FMLVAR("MACD3","MACDH3");
RSIM3_out := RSI(MACDH3, 14);
RSIM3_X50 := cross(RSIM3_out, 50);
RSIM3_X50;

But when I add the Quick Reference Relative Strength Index syntax as displayed:
SYNTAX                    rsi(DATA ARRAY, PERIODS )
EXAMPLE                  rsi( 21 ), rsi(OPEN, 21)

as follows:
MACDH3 := FMLVAR("MACD3","MACDH3");
RSIM3_out := RSI(5),RSI(MACDH3, 14);
RSIM3_X50 := cross(RSIM3_out, 50);
RSIM3_X50;

produces this:
-> There is no function defined. Please define your function with valid arguments
Not sure why the BCFL QR doesn't work, it would be a treat to have RSI double smoothing, if that was the intention.

Which leads me to ask why there are no inbuilt smoothings for the system RSI unlike other indicators tha have a selection of 5 or so, where the Wilders Smoothing could be applied better than I have done in my attempt to code it off the system RSI. Just one more tweak please?

2 Seperate examples. I'll feed that back to the developers to make it clearer. Per my post you can use RSI(14) or RSI(C, 14), so that formulas that currently will be using RSI(14) or RSI(21) do not break. There is no reason to use RSI(5),RSI(MACDH3, 14); as RSI() is a function call in itself. 

Not all indicators have smoothing, only 4 to 5 of them do depending how you look at the seperate bollinger band functions and none of those have Wilders available as an option inside BCFL itself, so it would be totally new functionality instead of a tweak.

I do believe the expanded RSI(data array, period) syntax has an issue being directly embedded in to another function like Wilders at the moment.

Although Wilders smoothing is similar to the result of an (2*n-1) EMA and is commonly used as the input to the calculation instead of smoothing the end product. For 5 days of wilder you can use a 9 day EMA on the inputs to the RSI itself to achieve wilder smoothing.

A question in regards to cleaning out watch lists; would there be a suitable code sequence to delete (as opposed to add to) from watch lists stocks that have exceeded there 'use by' date?
Manually deleting stocks could be a slow process, although do-able once a filter is set up.
It might require an addition to the right click select action to delete from 'selected watch list'  after bulk selecting from a scan window.

It is best to send technical issues like this to support@sharewealthsystems.com so we can easily track the amount that come through to an area - it contributes to the prioritisation of the next release.

You can delete stocks from a data sheet by highlighting the rows (SHIFT for a block or use ALT to click individual rows) then hitting the delete key on the keyboard which is quicker than a right click menu option once you are used to it.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: Help with BCFL custom Scans & Coding
« Reply #87 on: 16/08/2019, 12:25:41 AM »
Quote
Not all indicators have smoothing, only 4 to 5 of them do depending how you look at the seperate bollinger band functions

Bollinger Band functions is something I wasn't expecting in relation to indicator smoothings, could you elaborate on how the BB apply to the indicators with the optional smoothing?
Thanks.

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: Help with BCFL custom Scans & Coding
« Reply #88 on: 16/08/2019, 04:23:30 PM »
Bollinger Bands consist of 2 functions: top band and bottom band. These are some of the few that use smoothing as part of the parameters.

bbandbot(<DATA ARRAY>, <PERIOD> , <SMOOTHING>, <DEVIATIONS>)
bbandtop(<DATA ARRAY>, <PERIOD> , <SMOOTHING>, <DEVIATIONS>)

Only a few BCFL functions have in-built smoothing options as part of their calculation.