Author Topic: FORMULA & INDICATOR SHARED LIBRARY  (Read 241 times)

0 Members and 1 Guest are viewing this topic.

Offline JohnR

  • Newbie
  • *
  • Posts: 5
FORMULA & INDICATOR SHARED LIBRARY
« on: 06/03/2019, 12:01:10 PM »
The perfect place to share any working scan and indicator formula with the SWS community.

Offline JohnR

  • Newbie
  • *
  • Posts: 5
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #1 on: 06/03/2019, 12:13:08 PM »
MACD 100,50,30 crossover help please.

I'm completely 'fresh off the boat' when it comes to SWS/Metastock language.
My current competency is with Pine for TradingView (limited but functional) where the Pine language is "self evident", I'm finding the SWS formula language a bit cryptic.

So any help with my first attempt greatly appreciated.
MACD (100,50) main crossing the Signal (30) scan for crossing up over signal line.

What I have so far, and is copied directly off a metastock web page and adjusted for the macd settings:
{New Indicator} M9:= Mov(MACD(),100,E); X:=Cross(Mov(C,50 {opt1},E),Mov(C,30 {opt2},E)); X AND Alert( M9<0 AND Cross(MACD(),M9),5); { Alert() Holds signal TRUE for 5 bars or whatever number you choose}

Output:
-> There is 1 unassigned output. The unassigned output will have priority over all assigned outputs
-> There is 1 unassigned output. The unassigned output will have priority over all assigned outputs
-> There is 1 unassigned output. The unassigned output will have priority over all assigned outputs

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 160
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #2 on: 06/03/2019, 05:12:36 PM »
Hi John,

An unassigned output is a line of BCFL that does not have a 'variable' container or a name for the calculation.

It is more of a warning message than an error, as the formula will still save. It is saying that the BCFL engine has found an unassigned output and this will have priority over an assigned outputs it may find.

This is so 1 line formulas like "C > REF(C, -1)" (check if close is higher than yesterdays) for example will still operate which can be common in the metastock programs, due to limited character allowances.

An assigned output version of your formula would look like this:

{New Indicator}
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;

The key difference is the name of the calculation is on its own line. The important of this is it allows you to plot more than 1 calculation on to the chart, in case you wanted to see how a specific one was working. This is useful for indicators with more than 1 calculation or if you want to test your formula to ensure it's doing what you think it is.

For instance, to see what composes the output, you would have this instead:

{New Indicator}
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;
{ Testing the output contents }
X;
Alert1;

--

I hope this makes sense and let me know if you would like any more clarification.

Offline JohnR

  • Newbie
  • *
  • Posts: 5
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #3 on: 09/03/2019, 03:20:44 PM »
Hi Campbell, good to have the brains trust of the whole operation on board here :thumb:
Firstly; are there any manuals for SWS BCFL that you can direct me to?

I found this Metastock primer website, will this be worth reading?
https://www.metastock.com/customer/resources/formulas/primer.aspx

I put the MACD Histogram script into the editor :
{ MACD Histogram }
MACD_Hist := macd(100) -mov(macd(50),30,E);
MCAD_Hist


Output:
-> MACD function has invalid number of arguments

What does the 'E' do in the above  :confused:


Maybe I should explain and graphically show you what I want to do with the MACD and histograms signals; primarily for forward scanning of the Investor ATR-TS and Spa3 SIROC entry signals, and forward of the exit signals, and to eliminate (false or low momentum / high risk) system signals leading to over-trading costs and draw downs.

Primarily to validate system entry and exit strategies against the MACD 120,260-90 and 50,100-30 states; to rule out the system very fast buy sell signals (they are about 3 days apart) when the MACD lines and histogram are signaling "high risk" when compared to zero line, and when the MACD.main has crossed its signal line.

I have found that the MACD setting of 120,260-90 as measured on the histogram finds its peak level that very closely corresponds to the MACD 50,100 main crossing the 30 signal line (or when the histogram drops below zero line by a bar or two).
Also there exists a zone of pre-warning that momentum is dropping off prior to the MACD 50,100 crossing, when the histogram also falls bellow the most recent dip prior to a high level, and measured/visualised by drawing a line from the recent high dip extending horizontally, any histogram pips that fall below the line have high percentage chance of leading to the histogram falling below zero leading into higher risk.

This MACD 50,100-30 histogram falling and then crossing zero; correlates to the MACD 120,260-90 losing momentum. The same can be said of the rising momentum of the MACD combination.

There are four basic states for each of the two MACD's: Main greater than Signal and Main less than Signal;  occurring above zero and below zero. And these four states generally reflect bullish and bearish momentum surprisingly accurately.

Any shallow MACD 50,100-30 histogram levels around the zero line indicate low momentum that then can be assessed against the MACD 120,260 main being above or below its 90 signal line for risk assessment.

A third faster MACD can then be used to also qualify the MACD 100,50-30 histogram signals earlier, like a MACD 12,50-25.
And to avoid line clutter on the chart I have found it best to use the histograms only overlaid onto each other:


Having eyeballed the system triggers on the chart for entry and exits and correlated against the two MACD's; there could be written a formula set to qualify those entries as high risk and low risk, maybe as bright yellow symbols or candle background colour on the chart, maybe to scan the market to enter positive results into a watch list for monitoring to optimize entry and exit strategies prior to system triggers.

« Last Edit: 10/03/2019, 10:49:06 AM by JohnR »

Offline JohnR

  • Newbie
  • *
  • Posts: 5
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #4 on: 10/03/2019, 06:19:13 PM »
Have TradingView Pine code trend candle colour based on the 50,100-30 with additional fast MACD as an entry exit stinger (aqua / fuchsia).
I can't imagine trying to setup a scan in SWS BCFL for something similar, too many variables to consider given each MACD has 8 states and each histogram has four.
Best approach is to eyeball it! might have another go later though for the fast MACS stinger early entry and exit chart signals.

Image is chart in Trading View (30 minute time frame, MACD's are set with WMA's, outmacd2 = 50,100-90)
Pine candle full colour:

M1a = outmacd2 > 0 and outmacd2 > outsignal2 and outmacd2 > outmacd2[1]
M1b = outmacd2 > 0 and outmacd2 > outsignal2 and outmacd2 < outmacd2[1]
M2a = outmacd2 > 0 and outmacd2 < outsignal2 and outmacd2 > outmacd2 [1]
M2b = outmacd2 > 0 and outmacd2 < outsignal2 and outmacd2 < outmacd2[1]

M3a = outmacd2 < 0 and outmacd2 < outsignal2 and outmacd2 > outmacd2[1]
M3b = outmacd2 < 0 and outmacd2 < outsignal2 and outmacd2 < outmacd2[1]
M4a = outmacd2 < 0 and outmacd2 > outsignal2 and outmacd2 > outmacd2[1]
M4b = outmacd2 < 0 and outmacd2 > outsignal2 and outmacd2 < outmacd2[1]

SH1b = outHist3 > 0 and outHist3 < outHist3[1]
SH2b = outHist3 <= 0 and outHist3 > outHist3[1]

bc=input(true, title="Color bars based on MACD 2 Trend")
barmacd2col = outmacd2<0 and SH2b ? aqua : M2b and SH2b ? aqua : SH1b ? fuchsia :
    M1a ? green : M1b ? red : M2a ? #00cc00 : M2b ? red : M3a ? gray : M3b ? red : M4a ? white : M4b ? red : yellow
barcolor(bc ? barmacd2col : na)
« Last Edit: 10/03/2019, 06:25:48 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 160
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #5 on: 12/03/2019, 05:15:16 PM »
Hi Campbell, good to have the brains trust of the whole operation on board here :thumb:
Firstly; are there any manuals for SWS BCFL that you can direct me to?

I found this Metastock primer website, will this be worth reading?
https://www.metastock.com/customer/resources/formulas/primer.aspx

Thanks! Brains trust maybe not, but I am happy to help and if anyone else has any questions about what they are doing, please feel free to chip in.

This is usually the one we point people towards. While the user interface that you see in Beyond Charts is not the same, the language is. For anyone who wants to know how to 'get around' the formula editor, have a look under Home -> TutorMe for the time being.

Quote

I put the MACD Histogram script into the editor :
{ MACD Histogram }
MACD_Hist := macd(100) -mov(macd(50),30,E);
MCAD_Hist


Output:
-> MACD function has invalid number of arguments

What does the 'E' do in the above  :confused:

The output is because the MACD() function is pre-set and does not take a number in the parentheses. It's part of a generic error, usually to say you have not formatted a function correctly. When this comes up, use the quick reference panel from the right hand side BCFL Library to see what the editor is expecting.

A traditional MACD uses a 26 EMA - 12 EMA, that is how the '14' discussed around MACD comes up. You would need to quickly build your own MACD then push that calculation through to the rest of the formula to achieve the 50 MACD for instance:

My_MACD := MOV(C, 100, E) - MOV(C, 50, E);
MACD_Hist := My_MACD - mov(My_MACD,30,E);
MACD_Hist;

The 'E' refers to Exponential. There are others like W for Weighted and S for Simple.

Quote
Maybe I should explain and graphically show you what I want to do with the MACD and histograms signals; primarily for forward scanning of the Investor ATR-TS and Spa3 SIROC entry signals, and forward of the exit signals, and to eliminate (false or low momentum / high risk) system signals leading to over-trading costs and draw downs.

Primarily to validate system entry and exit strategies against the MACD 120,260-90 and 50,100-30 states; to rule out the system very fast buy sell signals (they are about 3 days apart) when the MACD lines and histogram are signaling "high risk" when compared to zero line, and when the MACD.main has crossed its signal line.

I have found that the MACD setting of 120,260-90 as measured on the histogram finds its peak level that very closely corresponds to the MACD 50,100 main crossing the 30 signal line (or when the histogram drops below zero line by a bar or two).
Also there exists a zone of pre-warning that momentum is dropping off prior to the MACD 50,100 crossing, when the histogram also falls bellow the most recent dip prior to a high level, and measured/visualised by drawing a line from the recent high dip extending horizontally, any histogram pips that fall below the line have high percentage chance of leading to the histogram falling below zero leading into higher risk.

This MACD 50,100-30 histogram falling and then crossing zero; correlates to the MACD 120,260-90 losing momentum. The same can be said of the rising momentum of the MACD combination.

There are four basic states for each of the two MACD's: Main greater than Signal and Main less than Signal;  occurring above zero and below zero. And these four states generally reflect bullish and bearish momentum surprisingly accurately.

Any shallow MACD 50,100-30 histogram levels around the zero line indicate low momentum that then can be assessed against the MACD 120,260 main being above or below its 90 signal line for risk assessment.

A third faster MACD can then be used to also qualify the MACD 100,50-30 histogram signals earlier, like a MACD 12,50-25.
And to avoid line clutter on the chart I have found it best to use the histograms only overlaid onto each other:


Having eyeballed the system triggers on the chart for entry and exits and correlated against the two MACD's; there could be written a formula set to qualify those entries as high risk and low risk, maybe as bright yellow symbols or candle background colour on the chart, maybe to scan the market to enter positive results into a watch list for monitoring to optimize entry and exit strategies prior to system triggers.


With regards to SPA3 Investor, there has been many discussions on this forum I believe about changes and modifications and how they affect investment plans. I have also talked about it lots over the phone and by email, I am sure the rest of the team have as well, but it comes down to the rule of unitended consequences. Small changes can have big affects to portfolio outcomes over a large sample of trades, some will come off worse while some will improve the system. When we do our research, not enough over the years have 'moved the needle' enough to warrant an integrated change in SPA3.

That is as much as I will say around that for now. You can always take entries and exits and do a bit of a manual backtest to see the outcomes yourself in Excel and decide if you are on to something that you believes will improve, by the sounds of it you are confident in that regard. As long as you have confidence to execute in the market and you are not taking hours a day to make decisions or with subjective criteria, that is the main goal.

Now I'll talk more on the BCFL side of things. SPA3 is not involved or integrated in to BCFL, but you can run BCFL scans over the SPA3 Investor watch lists provided in Beyond Charts for results of which ones do hit the mark and take on actions as appropriate.

Unfortunately the images came across a bit small. Feel free to send them in to support or try and re-upload them here if you wish, but the general idea I believe is that you can take the code I provided above and perhaps plot out 2 histograms and the moving averages can also be put in to their own variables for output on top of this.

MACD1 := MOV(C, 100, E) - MOV(C, 50, E);
MACD2 := MOV(C, 260, E) - MOV(C, 120, E);
MACD1_Signal := mov(MACD1,30,E);
MACD2_Signal := mov(MACD2,90,E);
MACD_Hist := MACD1 - mov(My_MACD,30,E);
MACD_Hist2 := MACD2 - mov(My_MACD,90,E);
MACD_Hist;
MACD_Hist2;

Naming wise it is a bit ungamely and probably can be refined by sectioning out the histograms correctly. You could also split the 2 MACDs in to seperate formulas and then in a 3rd formula call them with the FML() function to assign to their own variables (the left hand side of := is the variable name) for output. It just depends how you prefer to store formula calculations, what is 'readable' to you, which normally comes along with exposure to BCFL.

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 160
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #6 on: 12/03/2019, 05:30:47 PM »
Have TradingView Pine code trend candle colour based on the 50,100-30 with additional fast MACD as an entry exit stinger (aqua / fuchsia).
I can't imagine trying to setup a scan in SWS BCFL for something similar, too many variables to consider given each MACD has 8 states and each histogram has four.
Best approach is to eyeball it! might have another go later though for the fast MACS stinger early entry and exit chart signals.

Image is chart in Trading View (30 minute time frame, MACD's are set with WMA's, outmacd2 = 50,100-90)
Pine candle full colour:

M1a = outmacd2 > 0 and outmacd2 > outsignal2 and outmacd2 > outmacd2[1]
M1b = outmacd2 > 0 and outmacd2 > outsignal2 and outmacd2 < outmacd2[1]
M2a = outmacd2 > 0 and outmacd2 < outsignal2 and outmacd2 > outmacd2 [1]
M2b = outmacd2 > 0 and outmacd2 < outsignal2 and outmacd2 < outmacd2[1]

M3a = outmacd2 < 0 and outmacd2 < outsignal2 and outmacd2 > outmacd2[1]
M3b = outmacd2 < 0 and outmacd2 < outsignal2 and outmacd2 < outmacd2[1]
M4a = outmacd2 < 0 and outmacd2 > outsignal2 and outmacd2 > outmacd2[1]
M4b = outmacd2 < 0 and outmacd2 > outsignal2 and outmacd2 < outmacd2[1]

SH1b = outHist3 > 0 and outHist3 < outHist3[1]
SH2b = outHist3 <= 0 and outHist3 > outHist3[1]

bc=input(true, title="Color bars based on MACD 2 Trend")
barmacd2col = outmacd2<0 and SH2b ? aqua : M2b and SH2b ? aqua : SH1b ? fuchsia :
    M1a ? green : M1b ? red : M2a ? #00cc00 : M2b ? red : M3a ? gray : M3b ? red : M4a ? white : M4b ? red : yellow
barcolor(bc ? barmacd2col : na)

This is a bit of a step up in BCFL technical ability and comprehension of all the moving parts, it is not possible right now in 1 single formula. You would need to utalise BCFL Highlights and set up all the indicator variations in one formula, which each variation having their own variable.

So something like:
{Indicator Formula}
Instance_1 := ...;
Instance_2 := ...;

Then assuming none of the criteria overlap or conflict, you can use the Formula Variable Call function from the BCFL Library ( FMLVAR("Indicator Formula", "Instance_1") in the editor for example ) to tell BCFL to look at that formula, grab the specific indicator and do the checks on that. Using the BCFL highlight capabilities to dictate what colour the highlight changes to when the criteria is met.

So it will be work to setup, but not something I see as expressly unachiveable.

BCFL Highlights: https://beyondcharts.com/education/tutorme.php?s=latest
BCFL Library: https://education.beyondcharts.com/tutorme.php?s=bcfl

Offline JohnR

  • Newbie
  • *
  • Posts: 5
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #7 on: 13/03/2019, 12:25:52 AM »
Looks like I've more reading to do re the BCF Language.

And as my Spa3 Trader scans watch list grows and stocks remain in Spa3 conditions and MACD parameters, the scan results should optimise recurring signal entries & exits, at least in relation to the MACD 100 crossings. This might save having to review every stock in the watch list, something I definitely want to get away from having to do every night, in three chart programs!
This MACD system is hard to back test for having only visual parameters and nothing in code for programming at this time.

I might add the way I picked up Pine scripting was by having plenty of examples to examine and copy, adjust and cut & paste from the TV user base library.
If there were the same for SWS of functioning formulas it would make it much easy to see and understand the process, as I'm still trying to get a MACD working.

ps. not sure why the images were too small, they were saved as 900x600 pixel sized.

« Last Edit: 13/03/2019, 11:42:03 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 160
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #8 on: 14/03/2019, 10:10:04 AM »
Feel free to copy and paste in what you are working on with a description of the next step you are trying to accomplish, we can help unravel it and move you in the right direction.

There is a learning curve with most scripting languages and we can get you to where you need to be.