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

0 Members and 1 Guest are viewing this topic.

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 189
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #30 on: 08/05/2019, 11:53:31 AM »
Fantastic that you have a process to work to - at least this will get the work a line in the sand initially. I think it definitely is important.

Quote
... I need to work out what percentage of trade allocation $ to retain in a stock whilst in trend as MACD3 trades out of cycle, as a base holding. I note SPA3 Trader system sells 100% upon signal triggers, I question this if the trend is measured and indicated as strongly intact. I would like to retain a base amount in the holding.

In this scenario you may wish to take it as we call a lighten signal - or a 33% reduction in the position size. It takes some off the table and usually we do not do it for more than once per trade. Could be the midway point you are looking at here.

Quote
Q. re the BCFL Money Flow: Just setting one up, BCFL doesn't like what I have coded is there a specific setup of moving averages I need to use in place of the MFI(100) line?

{ ---- Money Flow Index ---- }
 MFI( 21 )
MFIsig := MOV(MFI, 50, S)


Thanks.
[edit] I think I may have asnwered the MFI line by plugging in the same line as the AT-RTS and changing to MFI:
{ ---- Money Flow Index ---- }
{ MFI( 14 ); original from BCFL library}

MFI_1 := MOV(MFI(1), 21, S);
MA_MFI := MOV(MFI_1, 50, S);

Depends what you are trying to replicate or achieve with this question so bare with me on this one. Also I am not sure where the MFI 100 you mentioned comes in?

MFI() is the same as the indicator panel in BCFL, so if you are replicating a moving average of the MFI what you had initially looks correct to me. BCFL editor might be companing about that lack of designated output and semi-colons though, so it should look like this if you wanty to see how the indicator calculation looks on the chart:

MFIsig := MOV(MFI(21), 50, S);
MFIsig;

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #31 on: 08/05/2019, 01:48:54 PM »
Thanks, the Money Flow saved no problems.
Re the Money Flow;  I was looking for an additional qualifier to aid in weeding out junk stocks. It also fits to the RSI of the MACD Histogram panel without distortion.

Over at Incredible Charts I use the Twiggs Money Flow (TMF) and Twiggs Momentum Oscillator (TMO) their proprietary indicators, so looking for something similar here. Although I might try to implement the Metastock (TMF) code.

TMF (Proprietary see footnote *) http://www.incrediblecharts.com/indicators/twiggs_money_flow.php?clientID=228052&app_productcode=101&ic_a_id=1_25_25_0
TMO (Proprietary) http://www.incrediblecharts.com/indicators/twiggs_momentum_oscillator.php?clientID=228052&app_productcode=101&ic_a_id=1_25_25_0

* Twiggs Money Flow is a proprietary indicator. Readers are permitted to explain/describe Twiggs Money Flow on other websites/publications and/or to include/reproduce the formula in other software provided that they display a hyperlink to this web page.

For reference I include the Metastock (TMF) formula:
periods:=Input("TMF periods",1,100,21);
TRH:=Max(Ref(C,-1),H);
TRL:=Min(Ref(C,-1),L);
TR:=TRH-TRL;
ADV:=((C-TRL)-(TRH-C))/If(TR=0,999999,TR)*V;
If(Wilders(V,periods)=0,0,Wilders(ADV,periods)/Wilders(V,periods))

Q1. Could you recommend an indicator or series that could weed out the non performing junk stocks?
Have added this to some scans for volume, not sure how effective it is at this stage:
AND MOV(CLOSE,21,S) * MOV(VOLUME,21,S) >= 50000;

Q2. Also having problems with getting the TMF to code correctly for use in lower code, if you could point me in the right direction, I assume it's an indicator script without an output?. I'm tempted to think it needs a MOV(ADV,,) type line? but when I tried this it didn't want to save.

Once that is achieved I would like next to code for a TMF >=0 and less then 15, or any number of indexed levels. Is the index level built into the indicator formula or do you need to build one seperately?
(I guess this question covers any indicator that could be referenced to an index level like; RSI (of MACD) and MACD itself, ultimately to code for a crossing above a line level like 20 or 50 for buys and downward 50 80 or 90 for sells. I know the cross() script but does it apply to index levels also?
« Last Edit: 09/05/2019, 01:55:54 PM by JohnR »

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #32 on: 08/05/2019, 06:54:00 PM »
Ok here's a problem I've had all along where the MACD above and below zero qualifier is ignored by the scan:

{ ---- Parameters ---- }
MACD1_DN := MACD1<0 and MACD1<MACD1sig;
MACD2_UP := MACD2<0 and MACD2<MACD2sig and MACD2 > REF(MACD2,-1);
MACDhist_converge := MACD2hist > REF(MACD2hist,-1) and MACD1hist < REF(MACD1hist,-1);

{ ---- Scan triggers ---- }
SCAN_TRIG_BUY := MACD1_DN and MACD2_UP and MACDhist_converge and MOV(CLOSE,21,S) * MOV(VOLUME,21,S) >= 50000;

{ ---- Alert Signals ---- }
Alert_BUY_MACD_hist := Alert (SCAN_TRIG_BUY, 1);

{ ---- Output to Scan Engine ---- }
Alert_BUY_MACD_hist;
SCAN_TRIG_BUY;


I noted in the third post the M9<0 was placed in the lower Alert lines, not sure why though, as it forms part of the MACD state qualifying parameters:

M9:= Mov(MACD(),100,E);
X:=Cross(Mov(C,50,E),Mov(C,30,E));
Alert1 := Alert( M9<0 AND Cross(MACD(),M9),5); { Alert() Holds signal TRUE for 5 bars or whatever number you choose}
Output := X AND Alert1;
Output;

Once I get the last few posts sorted, it should be all I need to do go forward with the tr-MACD scan and alerts on charts. I have done dozens of formulas already but most seem to be over signalling or incorrectly signalling (ignoring the >0 <0 part), and pulling in too many junk stocks, the TMF should sort the latter out though.
And having eyeballed 100's of scan result charts now, I can identify that the RSI of the MACD histogram panel does the better read for cleaner entries most of the time over the direct read of the MACD histogram, but there are always areas that go saw toothed, which I think some MACD histogram smoothing and RSI smoothing might help with in the display of the indicators.

Thanks.
« Last Edit: 09/05/2019, 02:09:02 PM by JohnR »

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #33 on: 09/05/2019, 02:38:46 PM »
The RSI of the MACD histogram; would this be correct for a crossing of the 20 index level:

{ ---- Macd 2 Medium ---- }
MACD1:= mov(C, 100, E) - mov(C, 50, E);
MACD1sig := mov(MACD1, 30, E);
MACD1hist := (MACD1 - MACD1sig);
{-------------------------------------}

{ 100 - [100 / (1 + Avg Gain / Avg Loss ] }
{ Avg Gain = Avg of all up periods for calc }
{ Avg Loss = Avg of all down periods for calc (in positive cont) }

periods := 5;
{Change C for what the RSI is to be based on if not the close }
change:= ROC(MACD1hist,1,$);
Gain :=Sum(If(change>0,change,0),periods);
Loss :=Sum(If(change<0,Abs(change),0),periods);
AvgCalc := Gain / Loss;
RSIM_out := 100-(100/(1+AvgCalc));
RSIM_out;

{ ---- Formula ---- }
RSIM_X20 := RSIM_out cross(RSIM_out,1, 20);

{ ---- Alerts ---- }
ALERT_RSIM_x20 := alert(RSIM_X20);

{ ---- Output to Scan Engine ---- }
ALERT_RSIM_x20;
RSIM_X20;

Outout -> RSIM_OUT is unrecognised


Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 189
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #34 on: 09/05/2019, 03:07:59 PM »
Q1. Could you recommend an indicator or series that could weed out the non performing junk stocks?
Have added this to some scans for volume, not sure how effective it is at this stage:
AND MOV(CLOSE,21,S) * MOV(VOLUME,21,S) >= 50000;

That formula calculation is definitely how to set a liquidity benchmark requirement.

It is part of SPA3 criteria for RSC parameters to be met.  Section 9.5 of the reference manual goes in to more detail: https://documentation.beyondcharts.com/SPA3_REF.php

The RSC formula for comparing a stock to the index is provided in the Sample Formula section of the Formula Explorer, which can be imported to your formula with this line:

RSC_Comp := FML("Relative Strength Comparison");

Then to convert it in to a moving average:

RSC_MOV := MOV(RSC_Comp, 30, E);

Then to acheieve a similar effect to the SPA3 Trader system built in to your scans, you just need to compare the position of the RSC to the RSC MOV. Section 9.5.3 goes in to more detail as to why this in particular is useful for finding currently outperforming stocks.

Q2. Also having problems with getting the TMF to code correctly for use in lower code, if you could point me in the right direction, I assume it's an indicator script without an output?. I'm tempted to think it needs a MOV(ADV,,) type line? but when I tried this it didn't want to save.

The way it is setup is designed to be used on its own with the IF statement working out the only output. It can get a bit messy and I personally, am not a fan of inputs (still work though), but I would defintely change the last line to this:

TMF := If(Wilders(V,periods)=0,0,Wilders(ADV,periods)/Wilders(V,periods));

Then the calculation can be referenced easier. It does work as-is in its own formula.

Once that is achieved I would like next to code for a TMF >=0 and less then 15, or any number of indexed levels. Is the index level built into the indicator formula or do you need to build one seperately?

(I guess this question covers any indicator that could be referenced to an index level like; RSI (of MACD) and MACD itself, ultimately to code for a crossing above a line level like 20 or 50 for buys and downward 50 80 or 90 for sells. I know the cross() script but does it apply to index levels also?
[/quote]

Plot TMF as an output on to a chart and work this one out. It is a good habit to get in to, to know what is actually happening with the indicator. In this case it seems to osscilate above and under 0.

So depending on what you are looking for - you can always check if say TMF > 0 or <-0.5 depending what you are interested in.

Ok here's a problem I've had all along where the MACD above and below zero qualifier is ignored by the scan:

{ ---- Parameters ---- }
MACD1_DN := MACD1<0 and MACD1<MACD1sig;
MACD2_UP := MACD2<0 and MACD2<MACD2sig and MACD2 > REF(MACD2,-1);
MACDhist_converge := MACD2hist > REF(MACD2hist,-1) and MACD1hist < REF(MACD1hist,-1);

{ ---- Scan triggers ---- }
SCAN_TRIG_BUY := MACD1_DN and MACD2_UP and MACDhist_converge and MOV(CLOSE,21,S) * MOV(VOLUME,21,S) >= 50000;

{ ---- Alert Signals ---- }
Alert_BUY_MACD_hist := Alert (SCAN_TRIG_BUY, 1);

{ ---- Output to Scan Engine ---- }
Alert_BUY_MACD_hist;
SCAN_TRIG_BUY;

You have 2 outputs here - best to keep it to 1 for scans so it's clear what you are searching for. In this case, have you dragged this formula on to a chart to check what it is doing and ensure it lines up to what you are expecting?

Remember if you put MACD1; or MACD1_DN; on their own line in the output at the end - you can see on the chart what that calculation is actually doing. If you get a few lines, right click the chart background -> panel -> add.

Then drag one of the lines in to their own empty panel - makes it easier to read and understand what each calculation is actually producing. If you are not sure to do this let me know and I can produce a quick video about it by COB tomorrow.

Quote
{ ---- Formula ---- }
RSIM_X20 := RSIM_out cross(RSIM_out,1, 20);

{ ---- Alerts ---- }
ALERT_RSIM_x20 := alert(RSIM_X20);

{ ---- Output to Scan Engine ---- }
ALERT_RSIM_x20;
RSIM_X20;

Stay RSIM_out is not defined ie. BCFL does not understand.

Also the cross function is cross(some indicator, some other indicator) checking if A has gone above B for a certain bar. So if you wanted to see if it moved above a value of 20 it would look like this:

RSIM_X20 := cross(RSIM_out, 20);

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #35 on: 09/05/2019, 10:52:59 PM »
Just something you mentioned about setting up the TMF as an indicator, were you referring to an actual indicator like the Money Flow in the Indicators list or was that a BCFL alert signal output insert or overlay?
I would like to have the TMF as an actual indicator if that can be done.

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 189
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #36 on: 10/05/2019, 03:45:15 PM »
Hi John,

As an indicator, but the indicator is the formula itself. Have a look at the BCFL editor video:

https://beyondcharts.com/education/tutorme.php?s=bcfl

You'll see the default for any formula (like the original TMF, if you saved it as its own stand alone formula) is a line in its own panel when plotted on the chart. You can change this to other styles which is shown in the 2nd half of that video, but its the general idea of what I meant.

The TMF you have as provided, in its own formula, will work once you click OK to the period input it will ask you as you drag it from the formula explorer (where you drag it from is what you call it when you save it) on to a chart.

Where this change comes in:

TMF := If(Wilders(V,periods)=0,0,Wilders(ADV,periods)/Wilders(V,periods));

Is if you wanted to put the indicator as part of another formula and be able to use the calculation as part of something else.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #37 on: 10/05/2019, 06:22:20 PM »
Got it thanks, even included a signal line :)

{ ---- Twiggs Money Flow ---- }
periods:=Input("TMF periods",1,100,21);
TRH:=Max(Ref(C,-1),H);
TRL:=Min(Ref(C,-1),L);
TR:=TRH-TRL;
ADV:=((C-TRL)-(TRH-C))/If(TR=0,999999,TR)*V;
TMF := If(Wilders(V,periods)=0,0,Wilders(ADV,periods)/Wilders(V,periods));
ADV_out := ADV >0 and ADV < 0.5;

{ ---- Signal Line ---- }
TMFsig := mov(TMF, 50, E);

{ ---- Output ---- }
TMF;
TMFsig;
« Last Edit: 10/05/2019, 06:40:40 PM by JohnR »

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #38 on: 10/05/2019, 08:40:36 PM »
Had mixed results with the RSI of MACD1 histogram crossing up over 50 line, using the provided additional code:
When RSIM_out is turn on you can see what the triggers are reporting; why is the RSIM not plotting like the RSI of the panel of the MACD histogram above it, and within the 100 index?
 
{ ---- MACD1 ---- }
MACD1:= mov(C, 260, E) - mov(C, 120, E);
MACD1sig := mov(MACD1, 90, E);
MACD1hist := (MACD1 - MACD1sig);

{ ---- RSI (MACD Histogram) ---- }
{ 100 - [100 / (1 + Avg Gain / Avg Loss ] }
{ Avg Gain = Avg of all up periods for calc }
{ Avg Loss = Avg of all down periods for calc (in positive cont) }

periods := 5;
{Change C for what the RSI is to be based on if not the close }
change:= ROC(MACD1hist,1,$);
Gain :=Sum(If(change>0,change,0),periods);
Loss :=Sum(If(change<0,Abs(change),0),periods);
AvgCalc := Gain / Loss;
RSIM_out := 100-(100/(1+AvgCalc));

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

{ ---- Alerts ---- }
ALERT_RSIM_X := alert(RSIM_X,1);

{ ---- Output to Scan Engine ---- }
ALERT_RSIM_X;
RSIM_out;

« Last Edit: 12/05/2019, 07:40:11 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 189
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #39 on: 13/05/2019, 05:11:41 PM »
This is where the BCFL 'version of an RSI' is starting to show I think. The re-computation using the raw language just is not as good compared to the in-built RSI calculation at handling the values the RSI needs.

I have raised a change off the back of this to the development team, asking to expand the RSI function capabilities in BCFL to include custom data sets (not just the close data as it is now). Due to the development work that's prioritised I am unable to give a timeline of when this will come in to Beyond Charts.

Below is the best fit I can get right now, changing the smoothing over to wilders instead of a raw sum so it stays within the 0 to 100 bounds and matches the movements of the RSI of the MACDH. Also the MACD1hist had to be flipped around, so the data values where positive and negative in the right places compared to the hard coded indicator we are basing it off.

It seems to struggle most tracking the acension of increasing negative values within the wilder smoothing itself. I'll have another look at this tomorrow and see if there is any further improvements we can make on this end - but otherwise it may be the closest fit available for the time being.

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

{ ---- RSI (MACD Histogram) ---- }
{ 100 - [100 / (1 + Avg Gain / Avg Loss ] }
{ Avg Gain = Avg of all up periods for calc }
{ Avg Loss = Avg of all down periods for calc (in positive cont) }

{Change C for what the RSI is to be based on if not the close }
periods := 14;
change:= ROC(MACD1hist,1,$);
Gain :=Wilders(If(change>0,change,0),periods);
Loss :=Wilders(if(change<0,abs(change),0),periods);
AvgCalc := Gain / Loss;
RSIM_out := 100-(100/(1+AvgCalc));

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

{ ---- Output to Scan Engine ---- }
RSIM_out;

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #40 on: 14/05/2019, 03:15:49 PM »
Ok thanks for the effort, I wouldn't know where to start with this.
I was left wondering why BCFL RSI raw code is not available to users (does that apply to most BCFL indicators?), I understand proprietary being locked but common garden variety ones not.
Note how TradingView deal with this in that they reference locked indicators like rma(see image).

I have tried a few different open source Metastock ones also without any success. So you efforts are my best source.

The RSI is what I'm focusing on currently as it doesn't whipsaw as severely and frequently as the raw MACD histograms so the RSI acts as a whipsaw filter, and will make a much cleaner signaling and scanning system, even better with algo-smoothings for each indicator used (when implemented).

To test the worthiness of the RSI MACD histogram (RSIMh) combination I have gone back to Pine to finish what I started there a few months ago and are proceeding to code the key triggers to display on charts and is quite straight forward for this, but cannot do scans for RSIMh's in TradingView.

BTW no hurry here, I need time to draft up the triggers and signal codes and index of terms anyway.
And your efforts are respectfully appreciated :)
« Last Edit: 15/05/2019, 10:18:48 AM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 189
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #41 on: 15/05/2019, 03:24:57 PM »
The BCFL raw code is not in BCFL, really. The functions like SUM(data array, # of bars) or MOV(data array, # of bars, type of smoothing) are all coded in to Beyond Charts+ using C# which the rest of the software is programmed in. So there is a degree of limitations in BCFL of what is possible based on what is programmed in to be manipulated via BCFL.

Now the RSI that is achiveable via BCFL compared to C# mainly is limited because there are no loops in BCFL. The formula is run over each individual bar in full instead of running only a small portion of the code in one area before moving on. BCFL also lacks an ability to change multiple variables when one condition is met. Both of these would take significant time to address. Now a raw RSI largely can be done - as long as you don't have these great big rises like the MACDH can have from an all time low to a new peak.

This is because when you average out based on a small number of periods, eventually the average loss over the periods is going to hit 0 since a loss has not happened for quite some time.

But it can be solved by just taking the previous value and pushing it along. This makes the volatility of the RSI sharper (well, is one of the reasons) and may over a long period cause one or two false cross overs compared to the hard coded indicator as the dips are longer from the top of the range - but until we expand the BCFL function capability (for RSI) this is likely the most that's possible using the BCFL language.

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

{ ---- RSI (MACD Histogram) ---- }
{ 100 - [100 / (1 + Avg Gain / Avg Loss ] }
{ Avg Gain = Avg of all up periods for calc }
{ Avg Loss = Avg of all down periods for calc (in positive cont) }

{Change C for what the RSI is to be based on if not the close }
{ RSI primer }

period := 14;
currentValue := MACD1hist;
previousValue := REF(MACD1hist, -1);

change := currentValue - previousValue;

Gain := if(cum(1) > period, sum(If(change>0, change, 0), period), 0);
Loss := if(cum(1) > period, sum(If(change<0, abs(change), 0), period), 0);

Avg_Gain := Gain / period;
Avg_Loss := Loss / period;

Avg_Change := if(Avg_Loss > 0, Avg_Gain / Avg_Loss, PREV);

{ Calc RSI }
RSIM_out := 100-(100/(1+Avg_Change));

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

{ ---- Output to Scan Engine ---- }
{RSIM_out}

RSIM_X;

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #42 on: 18/05/2019, 12:00:24 PM »
Quote
BCFL also lacks an ability to change multiple variables when one condition is met.
Point taken, don't quite understand this, no doubt will come back to bite me later on.

Re:
Quote
Ok here's a problem I've had all along where the MACD above and below zero qualifier is ignored by the scan:
Quote
You have 2 outputs here - best to keep it to 1 for scans so it's clear what you are searching for. In this case, have you dragged this formula on to a chart to check what it is doing and ensure it lines up to what you are expecting?
Remember if you put MACD1; or MACD1_DN; on their own line in the output at the end - you can see on the chart what that calculation is actually doing. If you get a few lines, right click the chart background -> panel -> add.
Then drag one of the lines in to their own empty panel - makes it easier to read and understand what each calculation is actually producing. If you are not sure to do this let me know and I can produce a quick video about it by COB tomorrow.

The MACD 260,120-90 is completely ignored by the scan, returning results that  are based on something? but not the MACD1 criteria.

[edit]
Having done some testing I found is what I thought was being ignored is in fact to do with the code, so when I reversed the criteria it scans correctly for what I was expecting:

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

{ ---- MACD1 is above signal line and above zero ---- }
MACD1_UP := MACD1sig >= MACD1 and MACD1 <0;


{ ---- Output to Scan Engine ---- }
MACD1_UP;

 returns the opposite of what is coded where the MACD1 Main is greater than the MACD1 Signal and MACD1 is greater than zero line :confused: everything is upside down!
Added the MACD code as an indicator and sure enough every things upside down:

[edit]
Found the problem: reversing the 260 with the 120 fixed this upside downess. No wonder the MACD scans weren't producing results as expected.
{ ---- MACD1 Indicator---- }
MACD1:= mov(C, 120, E) - mov(C, 260, E);
MACD1sig := mov(MACD1, 90, E);
MACD1hist := (MACD1 - MACD1sig);
MACD1;
MACD1sig;
MACD1hist;
« Last Edit: 19/05/2019, 11:52:49 AM by JohnR »

Offline JohnR

  • Jr. Member
  • **
  • Posts: 36
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #43 on: 19/05/2019, 03:37:24 PM »
Re the Relative Strength Comparison;

Quote
The RSC formula for comparing a stock to the index is provided in the Sample Formula section of the Formula Explorer, which can be imported to your formula with this line:
RSC_Comp := FML("Relative Strength Comparison");

Then to convert it in to a moving average:
RSC_MOV := MOV(RSC_Comp, 30, E);

Then to achieve a similar effect to the SPA3 Trader system built in to your scans, you just need to compare the position of the RSC to the RSC MOV. Section 9.5.3 goes in to more detail as to why this in particular is useful for finding currently outperforming stocks.

There are two versions of the RSC; one from your earlier post and one from the BCFL Sample Formula list, question is which one to use:

RSC 1:
{ Description:  This Script can be used to compare the price movement of a stock with another stock, sector, or index}
{ RSC INDEX EXAMPLE }

COMPARISON:= Security(INDEX,C);
RSC:= (C/COMPARISON)*1000000;
RSC;

RSC_MOV := MOV(RSC, 150, W);
RSC_MOV;


RSC 2:
RSC_Comp := FML("Relative Strength Comparison");
RSC_Comp;

RSC_MOV := MOV(RSC_Comp, 150, W);
RSC_MOV;


Both these work ok as indicators.

When I use the system Indicator for RSC it auto selects the Industry Sector to the current stock in the chart, and displays the name of the industry sector.

When I tried an index code like $XEJ in place of the 'INDEX' in line 1 of the sample code; BCFL complains about -> Identifier $XEJ is not defined. Although when the INDEX is left as is, the System Indicator compared to the BCFL code indicator looks the same when I go through the stock scan list, so I assume it is auto selecting the correct industry for the stock and I don't have to add in the sector code manually? This must have something to do with BCFL not integrated into C# program as you mentioned before.

So; when I use RSC in a custom BCFL coded scan for selection criteria filter, am I simply comparing the RSC; with the RSC_MOV; to find out performing stocks? like this:

RSC_filter := RSC > RSC_MOV;

What I might do is use a Moving Average Envelope to reduce 'ranging' RSC comparisons that move up and down across the MA that will trigger.
I note there is no BCFL Library list entry for Envelope Trading Bands, so will need to create the code for an indicator from raw MetaStock source code for a Moving Average x% offset:

Raw MaetaStock formula for trading bands (changed the 10% to /100):
Band_upper := Mov(C, 150,S) +10/100;
Band_lower := Mov(C, 150,S) - 10/100;
Mov_S := Mov(C,150,S);

Band_upper;
Band_lower;
Mov_S;


This plots over the price ok, but not the RSC. had to take out the /100 to get it to work on RSC and drop the 10 to 7 for the fit I was looking for and to match the System Envelope of 5% over the RSC:

The Envelope inclusion:
RSC_Comp := FML("Relative Strength Comparison");
RSC_Comp;

RSC_MOV_W := MOV(RSC_Comp, 150, W);
RSC_MOV_W;

RSC_MOV_S := MOV(RSC_Comp, 150, S);
RSC_MOV_S;

Band_upper := Mov(RSC_Comp, 150, S) + 7;
Band_lower := Mov(RSC_Comp, 150, S) - 7;
Band_upper;
Band_lower;


I think this will do, And I'm slightly impressed with myself, although it consumed most of my day!




« Last Edit: 19/05/2019, 03:53:01 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 189
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #44 on: 21/05/2019, 04:10:26 PM »
There is definitely a few ways to do RSC. The FML("Relative Strength Comparison") is a reference to grabbing the output (or calculation result) from the Relative Strength Comparison formula under the sample formula group section. This is found in the left hand side Formula Explorer panel.. You can right click and edit this sample formula name and you'll see the formula it is made up of, which is the 1st example you asked about. So they are both the same.

To expand the focus on why you may do one approach or the other. The sample formula is a pre-configured, uneditable bit of formula. You may want to use the longer format if you are looking at stocks from XASX, XNAS or XNYS (depending on what is available) to compare against an individual stocks sector, dynamically:

COMPARISON:= Security(SECTOR,C);
RSC:= (C/COMPARISON)*1000000;
RSC;

If you wanted to plug in a code directly it needs to look like below. The hardcoded approach means, well in this example, everything will be compared to the energy sector even if they are not part of it.

COMPARISON:= Security("$XEJ.XASX",C);
RSC:= (C/COMPARISON)*1000000;
RSC_MOV := MOV(RSC, 105, E);

This is all possible as we extended the ability of the Security function to dynamically grab relevant sector and indexes for comparison, when possible, using the keywords INDEX or SECTOR. Otherwise you would have to save 10 different formulas (essentially) with only the index code reference in the Security function being different and set up 10 different scans to accomodate them all.

You can see this work in practice by dragging the sample formula Relative Strength Comparison on to a blank chart from the Formula Explorer panel and then applying the RSC indicator from the indicators panel (parameters set to Comparison: Auto & Level: Market). They will both be the same.

This post is mainly a confirmation of what you have already worked out it seems!