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

0 Members and 1 Guest are viewing this topic.

Offline JohnR

  • Newbie
  • *
  • Posts: 10
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: 10
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: 167
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: 10
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: 10
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: 167
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: 167
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: 10
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: 167
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.

Offline JohnR

  • Newbie
  • *
  • Posts: 10
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #9 on: 25/03/2019, 10:08:32 PM »
Ok thanks.
Understood about "the rule of unintended consequences."
I need to set this up and review the results to make any decision. If anything it will aid decision making, reducing any uncertainty with system signals that I have observed.

Here's the first attempt at MACD2 (50,100-30) for testing; would like signal symbol on chart as well as being able to use in a filter scan.

The following script executed but did not trigger any alerts and did not place any symbols on charts, so there must be something wrong or missing. Is there a plot function/routine I'm not aware of?

with the comment line: { Alert() Holds signal TRUE for 5 bars or whatever number you choose}, I'm not sure what this means, does it refer to the scan will return codes up to 5 days after trigger?

{------------------------------------------------}
{Macd Medium (50,100-30) formula}
MACD2 := mov(C, 100, E) - mov(C, 50, E);
MACD2sig := mov(C, 30, E);

MACD2hist := (MACD2 - MACD2sig);
MACD2hist;

{------------------------------------------------}
{Alert: Macd Medium Main crosses signal line below zero}
MACD2_X_1a:= Cross(MACD2, MACD2sig);

AlertMACD2_1a := Alert( MACD2 <=0 and Cross(MACD2, MACD2sig),5); { Alert() Holds signal TRUE for 5 bars or whatever number you choose}
OutputMACD2_1a := MACD2_X_1a AND AlertMACD2_1a;
{ Testing the output contents }
MACD2_X_1a;
AlertMACD2_1a;

{------------------------------------------------}

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 167
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #10 on: 26/03/2019, 02:29:45 PM »
The comment refers to the Alert(logic check, days to sustain) function the formula you found uses. So when the logic check is found positive, it will stay positive for the given amount of bars ahead of it regardless if it is still true or false.

In this case, it is 5 bars. Using the term bars as it is dependant if you are using a daily or weekly chart if it is 5 days or 5 weeks.

The scan outputs positive results, so if you output the number 1, you will get a list back of everything you are scanning over. In your formula, there are a few reasons why you never hit results which are in the numbered list below.

My preference here would be to keep the histogram as its own formula that you can plot on to the chart, then have a 2nd formula purely for scans. This way it is easier to see on sight what is intended to be pushed back out, otherwise BCFL will give a result for a positive histogram which goes against the logic later on (MACD2 <= 0).

Also I prefer my formulas to scans to have only one output - 1 scan for 1 output, so I know exactly the result I am looking for.

  • Histogram - It is constantly in the negatives as you are taking away the result of a 30 bar EMA of the close rather than the MACD.
  • MACD2_X_1a - This output never hits because of the same hiccup - the signal line calculation is a 30 EMA of the close, not a 30 day EMA of the MACD. The 2 are way to far apart to ever cross.
  • AlertMACD2_1a - uses the above output, so it was never going to return an alert unless the above does.

Formula 1 - Pretty much fine as was with the signal line tweak
{Macd Medium (50,100-30) formula}
MACD2 := mov(C, 100, E) - mov(C, 50, E);
MACD2sig := mov(MACD2, 30, E);

MACD2hist := (MACD2 - MACD2sig);
MACD2hist;


Formula 2
{Macd Medium (50,100-30) formula}
MACD2 := mov(C, 100, E) - mov(C, 50, E);
MACD2sig := mov(MACD2, 30, E);

{Alert: Macd Medium Main crosses signal line below zero}
MACD2_X_1a := Cross(MACD2, MACD2sig);

AlertMACD2_1a := Alert( MACD2 <=0 and MACD2_X_1a, 5); { Alert() Holds signal TRUE for 5 bars or whatever number you choose}
{CS Note: The above will give positive for the bar where histogram < 0, when the cross occurs and for the 4 bars after)

{ Testing the output contents }
AlertMACD2_1a;

Offline JohnR

  • Newbie
  • *
  • Posts: 10
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #11 on: 27/03/2019, 12:17:48 PM »
OK that got it working! although the crossing is in both direction up and down for the one symbol and colour, and also for above zero.
So just looking at the symbols on chart scripts at this point;

I take it there will need to be another script to get a red Symbol for SELL for when the Main crosses below the Signal line; Alert(MACD2 <=0 leading into separate scripts for the above and below zero MACD cross states; one for crosses up <0 & >0 representing BUY, and one for crosses down <0 & >0 representing SELL?

or 4 different scripts with colour symbols one for each of the 4 states below zero and above zero.
A limitation of not being able to assign multiple symbols and or colours to differing states of a single indicator script plotting onto the chart, compared to Pine or QuoteTracker PaintBar scripts do/did so well.

Now looking at the system script (MACD Crossover to enter a long trade) I see that:
A := MACD();
B := MOV(A, 9, E);
CROSS(A, B)

 cross A,B would infer a crossing of A to above B as the way the computer differentiates the cross direction? conversely CROSS (B,A) would be the downward cross?
Yet I can't see the difference with the one I authored: MACD2_X_1a := Cross(MACD2, MACD2sig) where I get all crosses <0 & >0 plotting onto the chart. Or is there something else missing in the script?

Formula 2
Yes I was wondering about the duplication of code within the brackets, I actually took that code out and replaced it with CROSS(MACD2_X_1a), but got bad output. I see now from your example how to do this: Alert(MACD2 <=0 and MACD2_X_1a, 5)
« Last Edit: 27/03/2019, 01:55:46 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 167
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #12 on: 27/03/2019, 03:52:01 PM »
Every formula will have the same colour and symbol, if it is happening on downward crosses it would likely be due to the alert part of the formula as it is extending the signal for an extra 4 days after the criteria is hit. Cross(A, B) only flags when A crosses above B. That should answer your question at the end as well.

To differentiate, you may wish to use a system (https://education.beyondcharts.com/tutorme.php?s=bcfl , ~2mins 20) where you would need another script with the differences you are after. You can right click in the long entry / long exit boxes to customise the appearances on the chart.

It depends on the intentions, as using a system will make it easier to scan as you can choose which alerts you are looking for instead of creating 4 different scans as you would have to for a formula.

Offline JohnR

  • Newbie
  • *
  • Posts: 10
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #13 on: 14/04/2019, 02:11:40 PM »
OK I will get to the system formula later once I get the intended alerts and scanning correct, as the 'systems' are slightly more complex.

Just to clarify the intention:
a) signal for MACD 100 crossing Signal with the following qualifier;
b) MACD(260) is greater than MACD(260) 2 bars back hold signal for 5 bars.

This will get some early potential trender's into the watch list.

I take it there will need to be two scripts; one for the graphic alerts plotted onto charts and setup as an 'overlay', and one for the actual filter screener with qualifiers?

When the above is working I will then add other screener qualifiers for value and volume, and or one of the system indicators like RSC ranking and ROC(126), ATRVe (15) to pull into the scan more 'system' like stocks.
What would be good here would be something that leads into the ATR-TS Investor signal prior to it happening (SIROC?) from my observance the MACD(100) crossing its signal line with MACD(260) rising for more than a few bars does a pretty good job for the 5 to 15 bars prior to the ATR-TS signal.

So with that in mind; that is the MACD plan for now.

Formula as it is now (not saving):
{------------------------------------------------}
{Macd 1 Long 260,120-90}
M1:= mov(C, 260, W) - mov(C, 120, W);
M1sig := mov(M1, 90, W);
M1hist := (M1-M1sig)

{Macd 2 Medium 100, 50-30}
M2:= mov(C, 100, E) - mov(C, 50, E);
M2sig := mov(M2, 30, E);

{Alert: Macd Medium Main crosses signal line, M1 histogram rising x nos bars }
M2_xUP := Cross(M2sig, M2) and (M1hist>M1hist-2);

{ Alert signal holds signal TRUE for 5 bars or whatever number you choose}
Alert_M2 := Alert (M2_xUP, 5);

{ Testing the output contents }
Alert_M2;
{------------------------------------------------}


Output -> Identifier M2 is not defined

I've been over this a few times and can't see why the M2 is not defined. The "M2_xUP := Cross(M2sig, M2)" part works by itself giving the correct cross over direction.

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 167
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #14 on: 15/04/2019, 02:29:13 PM »
I would definitely do it that way - have one script for the chart and another for finding the signal to be used in scans.

In terms of the intention, with M2_xUP to be clear, as code is now you are asking if the 100 day MACD signal has gone above the 100 day MACD and that the M1histogram is higher than itself -2.

So to look for a value bars ago, use the REF() function. REF(<something>, -1) grabs the value of "something" a singe bar back. Something is not valid or tangible, just an example. Below is how it should look for looking 2 bars back:

{Alert: Macd Medium Main crosses signal line, M1 histogram rising x nos bars }
M2_xUP := Cross(M2sig, M2) and (M1hist>REF(M1hist,-2));

Now with the script as a whole - this is one of those scripting issues where a "clear" error is not apparent until you have run in to it 1 or 2 times then you will understand the logic behind it. By saying "M2" is not defined - it is saying it has found M2 but it does not know what to do with it. It's a total unknown.

The cause in this instance is with M1hist - it needs a semi colon on the end:

M1hist := (M1-M1sig) to M1hist := (M1-M1sig);

This says M1hist has ended, so it is free to assume  that M2 will be a variable name.