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

0 Members and 1 Guest are viewing this topic.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #15 on: 19/04/2019, 02:57:40 PM »
Ok have a working script to filter for MACD Weekly and MACD Daily scans" thanks.
Not sure of the logic behind having two separate scripts for a. stock filter, and b. graphic signal, as the one script seems to do both presently (graphic symbols saved as overlay F key with additional technical indicators).

Filter scan for weekly data MACD 100 (about equal to a MACD 260 Daily data):

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

{Macd 2 Medium 50, 24-18}
MACD2:= mov(C, 50, E) - mov(C, 24, E);
MACD2sig := mov(MACD2, 18, E);
MACD2hist := (MACD2-MACD2sig);

MACD3:= mov(C, 12, E) - mov(C, 26, E);
MACD3sig := mov(MACD3, 9, E);
MACD3hist := (MACD3-MACD3sig);


{Alert: Macd Medium Main crosses signal line, M1 histogram rising x nos bars }
MACD2_xUP := Cross(MACD2sig, MACD2)
AND (MACD1hist>REF(MACD1hist,-2)
AND MOV(CLOSE,21,S) * MOV(VOLUME,21,S) >= 50000);

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

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


And Daily data MACD 260:

{------------------------------------------------}
{Macd 1 Long 260,120-90}
MACD1:= mov(C, 260, W) - mov(C, 120, W);
MACD1sig := mov(MACD1, 90, W);
MACD1hist := (MACD1-MACD1sig);

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


{Alert: Macd Medium Main crosses signal line, M1 histogram rising x nos bars }
MACD2_xUP := Cross(MACD2sig, MACD2)
AND (MACD1hist>REF(MACD1hist,-2)
AND MOV(CLOSE,21,S) * MOV(VOLUME,21,S) >= 50000);

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

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



But when I attempt a fast MACD "turning up by 2 bars or so from running down" (below zero) script to run on the above MACD scan results watch list, nothing seems to work:
(I take it the MACD greater than MACD 1 bar back means the indicator is rising no falling) as the MACD index is greater as it falls lower than zero and above zero?
I'll be using this indicator / histogram turning state quite a lot so would like to know how the code should read.

{------------------------------------------------}
MACD3:= mov(C, 12, E) - mov(C, 50, E);
MACD3sig := mov(MACD3, 25, E);
MACD3hist := (MACD3sig-MACD3);

MACD3_UP:= (MACD3 <0 AND MACD3 > REF(MACD3,-1) AND (MACD3,-1 < REF(MACD3,-2)));

{Alert: Macd Fast turning up, hold x nos of bars }
Alert_MACD3 := Alert (MACD3_UP, 3);

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


OUTPUT= -> There is no function defined. Please define your function with valid arguments


Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #16 on: 23/04/2019, 02:43:38 PM »
The logic is that for an "indicator" type script, you will always get a new number day to day. IE. 7, 10 or 15 depending on what the indicator is.

When scanning for results, the scan gives a result for anything that provides a result for 1 (or greater!). So by scanning for an indicator, results of 0.63 will not show up, even if you want them. By changing a scan formula to give you a 1 (for yes) or 0 (for no), it is much easier to understand why results come up.

If there is a lot going on, it may not be inherently useful if you decide to look at it in 6 months or in 1 years time. Anything that checks for a cross, or asks if two conditions are true, returns a 1 or 0 and is instantly ready to be used for scanning. The way you have the top 2 formulas are suitable for scanning because of this.

When plotted on a chart, 1 or 0 is only really useful if you understand what that 1 or 0 represents as an indicator on a given chart.

Re: the script.

The error is because of the MACD3_UP line, there is thing part: MACD3,-1 < REF(MACD3,-2); that is throwing BCFL in to a spin. It can see the ,-1 and it cannot find the function this corrolates to. Commas are only used within the paranteheses for functions in order to split parameters such as with MOV or REF. I assume by context you were trying to use a REF here.

as the MACD index is greater as it falls lower than zero and above zero?
- Not 100% sure how to interpret this but I think you are going for a U shape where it goes below 0, declines but then comes back up above 0? Right now I can't see any condition that looks at if the value is above 0 - only below it.

In full - this line, assuming you were after a REF, is doing this:

MACD3_UP:= MACD3 < 0 [1] AND MACD3 > REF(MACD3,-1) [2] AND (REF(MACD3,-1) < REF(MACD3,-2))[3];

[1] MACD3 (most recent bar) is less than 0
[2] MACD3 (most recent bar) is greater than the previous bar
[3] MACD3 on the previous bar, is less than the value 2 bars ago.

When all 3 of these conditions line up, it will return 1 for yes otherwise 0 for no.

If you are going for a below 0 but then above 0 and I assumed correctly. Either REF(MACD3, -2) or REF(MACD3, -1) should cross under 0 OR < 0 depending on what you are after specifically, then the current bar > 0. Posting or linking to a clear example of when this has happened on a chart can help for me to get a better idea of your goals. Possibly zoom in before copying and saving the chart in case it uploads too small again.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #17 on: 23/04/2019, 11:44:17 PM »
Spent the entire long weekend trying to get a number of scripts working like the proverbial 100 monkeys on typewriters, to achieve nothing that works.
So I will have to post here the couple of things I want to do with the now working MACD's.

I'm finding saving graphics as a separate script to function keys cumbersome to implement with limited F keys already mostly mapped, and the MACD's I have setup already needing to be applied to each scan type, when the "alert :=" parts are taken out it doesn't work as a scan only script. It only works as a complete script, but without the graphics part configured. I don't want to complicate your responses so i'll come back to this later on when other things are working.


Firstly; yes 'U' trigger for scanning and for chart graphics.
 
Actually, the turning of the MACD histogram is the indicator I want to initially apply the script to for scanning selected watch lists for, as the histogram mostly starts rising prior to the MACD.main, but the line of script can be adapted for lots of others indicators I might develop. It's one of those base functionality scripts that define a trigger that can be re-used in others.

The simple turning script in Pine as follows, in this case to plot a single histogram bar a unique colour, or place a graphic symbol on the chart in later plot= or plotshape= code:
Hist_TurnUp_Col = outHist3<0 and outHist3 > outHist3[1] and outHist3[1] < outHist3[2]
Hist_TurnDn_Col = outHist3>0 and outHist3 < outHist3[1] and outHist3[1] > outHist3[2]

This should work in most scripting languages, with a bit of variation.
Can I get both directions working in the one BCFL script, or would that result in a 1 and 0 result?

Secondly; for some reason I'm unable to combine two MACD's into one line trigger line; but this works for the previous REF(MACD2hist-2) code, but completely ignores the (MACD1 >=0) or (MACD1 > MACDsig) type qualifier as follows:
Works:
MACD2_xUP := Cross(MACD2sig, MACD2)
AND (MACD1hist>REF(MACD1hist,-2)
AND MOV(CLOSE,21,S) * MOV(VOLUME,21,S) >= 50000);


Doesn't work:
MACD_BUY := (MACD1 >= MACD1sig) AND cross(MACD3, MACD3sig);
and
MACD_BUY := (MACD1 >= 0) AND cross(MACD3, MACD3sig);


« Last Edit: 24/04/2019, 01:03:55 AM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #18 on: 24/04/2019, 05:22:10 PM »
Re: Graphics. It may get some getting used to, but the key point to keep in mind is not everything you do in a formula needs a graphical version necessarily. If you are building a custom indicator you cannot achieve from the preset varients, then that is when it would be appropriate. Otherwise you could reasonably give it a miss for now. Concentrate on seeing and scanning over the information you wish to see and scan over.

If you have Overlays that already do the job, use those.

For the U shape, it may be better to lay out the exact criteria you want it to do in terms of steps and then work towards building the blocks to ensure all those checks are met. From the attached screenshot, I have some impression that it may not necessarily be a 3 consecutive bar affair but I could still be wrong. From the lines provided, you definitely could replicate this in BCFL, assuming that outHist3 is defined (the MACD?) earlier.

It would come in a 1 or 0 result, or a boolean, as BCFL will be checking to see if all 3 checks are met or not and give a result based on that.

With the works / doesn't work if the variables (MACD1, MACD1sig, MACD3, MACD3sig) exist in the formula and are defined it all checks out. If you are definitely seeing error messages I will need the full context of the formula you are using it in.

Just remember that you can plot individiaul variables out to a chart to see what is happening, comment code with '{ }' on the start and end of the line to temporarily take it out of action. A bit of debugging to understand what BCFL is doing can make it easier to manipulate to what you are after.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #19 on: 25/04/2019, 03:46:29 PM »
A lot of de-bugging going on here.
Ok, finally got the two macd's in the one script working by putting the cross() bit first then adding onto with others with 'AND'. I still can't get the MACD1 (260,120-90) reading as a line but does work with histogram being greater than histogram -1. But I still need to work this macd set to hone in on what produces better scan results, so far not happy.

The turning of the line or histogram bit of code as follows:

{ MACD2 Histogram Turning up from moving down }
{------------------------------------------------}
{--- Macd 2 Medium ---}

MACD2:= mov(C, 50, E) - mov(C, 100, E);
MACD2sig := mov(MACD2, 30, E);
MACD2hist := (MACD2 - MACD2sig);

{------------------------------------------------}
MACD2hist_TUP := MACD2hist<0 AND MACD2hist > MACD2hist,-1 AND MACD2hist,-1 < MACD2hist,-2;
{BELOW WORKS IN PINE SCRIPT:                                                                                                         }
{MACD2hist_TUP = MACD2hist <0 and MACD2hist > MACD2hist[1] and MACD2hist[1] < MACD2hist[2]}

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

{ ---Alert signal holds signal TRUE for x nos bars---}

Alert_MACD2hist_TUP := Alert (MACD2hist_TUP,1);

{ ---Testing the output contents (not sure why this is done)---}
Alert_MACD2hist_TUP;

Output -> There is no function defined. Please define your function with valid arguments

This would be a useful bit of base script I will use for various indicators.
Have tried variations of parenthesis() with no luck.
See image of intention for output (first lime bar is result of same Pine formula, but second cluster easier to see:

« Last Edit: 25/04/2019, 05:30:10 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #20 on: 26/04/2019, 03:27:51 PM »
That script shares the issue explained a couple of posts back:

"The error is because of the MACD3_UP line, there is thing part: MACD3,-1 < REF(MACD3,-2); that is throwing BCFL in to a spin. It can see the ,-1 and it cannot find the function this corrolates to. Commas are only used within the paranteheses for functions in order to split parameters such as with MOV or REF. I assume by context you were trying to use a REF here."

In this formula it is this line:

MACD2hist_TUP := MACD2hist<0 AND MACD2hist > MACD2hist,-1 AND MACD2hist,-1 < MACD2hist,-2;

BCFL has no idea what "MACD2hist,-1" actually means. If you want to grab the prior value (ie. 1 or 2 bars) ago it should look like this using the REF() function:

MACD2hist_TUP := MACD2hist<0 AND MACD2hist > REF(MACD2hist,-1) AND REF(MACD2hist,-1) < REF(MACD2hist,-2);

This is how I would save it to get what you are after, in case it helps. I output MACD2hist when testing along with the end product, so I can see what BCFL is calculating along the way to the desired final logic. Then I comment it out in the end.

Also since you are sending the alert out to just 1 bar - it does not strictly need to be included:

{ MACD2 Histogram Turning up from moving down }
{------------------------------------------------}
{--- Macd 2 Medium ---}

MACD2:= mov(C, 50, E) - mov(C, 100, E);
MACD2sig := mov(MACD2, 30, E);
MACD2hist := (MACD2 - MACD2sig);

{ Criteria Checks }
MACD_Less_0 := MACD2hist<0;
MACD_Higher_1_Bar_Ago := MACD2hist > REF(MACD2hist,-1);
MACD_2BarsAgo_Higher_1BarAgo := REF(MACD2hist,-1) < REF(MACD2hist,-2);

{ Bringing it all Together }
MACD2hist_TUP := MACD_Less_0 AND MACD_Higher_1_Bar_Ago AND MACD_2BarsAgo_Higher_1BarAgo;

{ --- Output to Chart / Scan Engine --- }
{ MACD2hist; }

MACD2hist_TUP;

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #21 on: 29/04/2019, 03:23:35 PM »
Ok have a few working SYSTEM scan results.
ASX 300, Period:200d, Period Type:Day, (Data Mode:Day)
The Benchmark scan result is the SIROC 21:8 same settings as above (except for data mode = no setting).

Now if I got the coding correct and the scan correct the following results are for the following MACD systems:
MACD-0 = two MACD's: Long 260.120-90 and Short 100,50-30

1) (orange) MACD-0 = MACD Main Turning (MACD.Main turns up from down)
2) (blue)  MACD-0 = MACD Histograms turning (Histogram turning up from down)
3) (lime) MACD-0 = MACD Crossing system (main crossing signal line)

I could end up doing dozens of MACD scans for the tri-macd setup I've been using, and for the combinations of two MACD's allowed for the system scans.
Not sure how to proceed at this point, it all looks so visually simple and convincing on my chart setups.

I think instead of an absolute MACD tri-setup system for buy and sell long and short, I need to focus more on a complimentary setup to just filter out SPA3 Trader excessive signals especially in overbought and oversold scenarios, where I can visually identify a resistance level not being broken and where the MACD 100 histogram is clearly descending from a high turning point to a lower trough and then making lower lows and losing momentum (although by that time the SIROC is or is about to trigger a sell anyway, but from the looks of it a few bars later then the MACD histigram, it's the few bars that the MACD histogram rescues the trade), and where I believe, the SIROC starts producing multiple buy sell signals as the SIROC bounces in overbought territory and starts producing loss trades in addition to excessive trade fees.

At this point I'm struggling with the correct 3 MACD histogram coding to implement the above statement.
BTW Is there a way to produce, and overlay on other, scan results an equity curve (key components) of the results?
Scan results as follows:

Bench Mark SIROC 21:8

MACD System 1), 2) and 3).


« Last Edit: 29/04/2019, 05:59:06 PM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #22 on: 30/04/2019, 11:20:30 AM »
At this point - I would not be looking at the system results for benchmarking with too much emphasis. Not all trades are equal with SPA3 money management. Just over 1/3 of the last 200 days have been in a high market risk environment, with 124 in low market risk. Depending on your investment plan from there would dictate which trades are not taken.

There is no way to produce an equity curve of results within Beyond Charts. You may need to export and do any further work in Excel becuase there is no portfolio charting software inside Beyond Charts itself. This can be done by CTRL + A on the trades tab so they are all highlighted -> Home tab at the top -> Export -> CSV or XLS depending on preference.

Regardless, as you are intending to work side by side with SPA3, now that you have the MACDs entry and exit criteria defined is to work out the overall process flow. You will have at least 2 scans - one for SPA3 signals and one for the MACD system(s), I expect. I work well with bullet point lists, as it helps break down big ideas in to the smaller steps then you can tackle each one off like a shopping list.

For instance I would start off with are you looking for SPA3 signals first, or are you interested only in the SPA3 trades that meet your criteria? Once you have done one scan over a length of time, use the watch list button at the top of the scan results to overwrite an existing watch list that fuels the other scan depending which way you go.

Just starting off this exercise will help you define the process of how you are going to approach this to do what you are looking to do. This will help the realistic trades come out to you as a combined methodology rather than independant systems which may help you judge the viability of the extra steps.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #23 on: 01/05/2019, 10:55:11 PM »
Agreed about the system results.
have been looking at this from different angles to see what might eventuate to a complimentary system of Tri-MACD related scans that will find (in trend or very early in trend) stocks that the system hasn't signalled for yet, [edit] and find triggers for entries 'in trend' by the MACD 12,50-25 short period histogram turning up.

The ATR Trailing Stop found in the indicator list, but not in the BCFL list; is this able to be coded up in BCFL for scanning? it would make another good way to get into a stock in early trend phases.
Also the RSI of the MACD histograms in the lower panel; is this able to be coded for in BCFL?

Looking at the MACD 260,120-90 (that I find excellent for identifying trending stocks), I have converted this into two moving averages, one a moving average of the first, to be a near equivalent to the long term set MACD 260 as follows:
{------------------------------------------------}
MA1 := MOV(CLOSE, 60, W);
MA1sig := MOV(MA1, 90, W);
{------------------------------------------------}

SCAN_TRIG := cross(MA1, MA1sig);
{------------------------------------------------}

{ ---Alert signal holds signal TRUE for x nos bars---}
Alert_BUYMAX := Alert (SCAN_TRIG,1);
Alert_BUYMAX;
{------------------------------------------------}

Above comes close to the MACD 260 on most stocks, and works well at finding initial crossings at or near the current period price support level similar to the MACD 260 rising to a crossing of signal line, and I want to stress these two points; I prefer to jump into stocks in the initial phase of what is indicated to be an early trend, than to go into stocks in upper mature trends in the hope they continue upwards. I identify these upper mature trend stocks by the level of MACD 100,50-30 histogram in combination the MACD 260 histogram levels; a dropping MACD 100 histogram from high indicates the longer term will also start losing momentum.  A minor percentage of stocks will keep going up but even these at some point will become 'overly' overbought to the point of retracing anywhere up to 50%.

The other point is that I can't accept anywhere near the system draw down amounts (from multiple stocks) beyond $800, especially when I read the MACD mid and long histograms being very high levels and losing momentum, (although sometimes you can't help taking draw-downs because the stock moves very quickly against you).

Once the early stage stocks are identified it becomes a matter of using the short and mid term MACD (or system SIROC signals if they kick in) to pyramid into and lighten out of.

Following charts are of the first two stocks found with the Moving Average scan of ASX All Ordinaries (499 stocks) and are a good example of what I like the look of:

[edit]
Have back dated scans for MA (above), although some of the scans look promising, a greater proportion fail the MA crossing up completely without any price momentum to carry them up. So the qualifier will have to include a momentum strength indicator like the MACD above zero or above an numerical indexed level, and or above signal. Might just add I'm yet to find anything to perform as well as the system does when the SPA3 Trader finds stocks in early trend phase (looking back over the chart).
« Last Edit: 03/05/2019, 10:41:39 AM by JohnR »

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #24 on: 03/05/2019, 02:15:07 PM »
Hi John,

The RSI in the indicators list and inbuilt in to BCFL are based on the close price. When deviating away from the close, it does become tricky to do in BCFL because there is no way to say "skip" for when calculating over a lookback / previous period. It is "A" form of RSI.

{ RSI }

{ 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 := 14;
{Change C for what the RSI is to be based on if not the close }
change:= ROC(C,1,$);
Gain :=Sum(If(change>0,change,0),periods);
Loss :=Sum(If(change<0,Abs(change),0),periods);
AvgCalc := Gain / Loss;

{ Output }
output := 100-(100/(1+AvgCalc));
output;

As for the vanilla ATR TS indicator, again, you can plug in a form of it in to BCFL. This is one I have on hand:

{ Trailing_Stop }
atrper := 14;
up_atrfact:= 3;
dn_atrfact := 3;
up_loss:=up_atrfact*ATR(atrper);
dn_loss:=dn_atrfact*ATR(atrper);
trail:=
If(L>PREV AND Ref(L,-1)>PREV,
Max(PREV,L-dn_loss),
If(L<PREV AND Ref(L,-1)<PREV,
Min(PREV,L+up_loss),
If(L>PREV,L-dn_loss,L+up_loss)));
trail;

For the rest - it sounds like you are struggling to find what criteria you want to identify stocks with still. Scans are great for finding stocks that meet 1 or more set of criteria, given that they all occur on a given bar.

This can extend in to a MACD crossing over another indicator and has risen in value for 2 consecutive bars. Now that you have largely the indicators you want defined - it really is just about writing down what exactly you want to have happened when you open a chart from a scan. Computers and BCFL are only as smart as the instructions they are given to execute, or possible to be executed in a given area.

So if the MOV is not doing it for you. Try and concentrate on defining how you want the MACD itself to work for you.

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #25 on: 03/05/2019, 06:21:13 PM »
Exactly that, I 'am' struggling to execute in code the specific idea, looking at charts and seeing the potential helps direct my efforts but actually implementing a structural approach is like asking me to re-invent what you have already done with the SIROC system.
And if I manage to re-invent the wheel you already have, after many hours on the computer, this still doesn't help when deploying and managing real capital into a non-system that falls outside the strict Beyond Charts and Trade Master system of which I can only act on system signals. Something I was unaware of when I bought into the software.
So with that realisation is where I'm currently struggling to implement any optimization I might come up with. I think it best I do complimentary code work within system at this point in time. And when satisfied move on to a stand alone system, if I find it necessary.

I'm getting used to system signals and operation, but still have nagging issues with it, this is my main focus now. Maybe the issues will fade once I gain confidence they will make some money, and I become more complacent with them.

Setting up the MA code in prior post with the ATR-TS is helping define the tradeable zone of the trend where I could employ the MACD3 fast to trigger on the turnings, although in strong trends this also fails more often. And I take it this is the reason why SWS have used the SIROC.
I have a number of fast clean cycle MACD's in pine that could be used like the CCI Schaff MACD, Hull MACD, Normalized MACD. Havn't tried to convert Pine script to BCFL yet.


*Thanks for the code in prev. post. I will spend the weekend tinkering.
Have sufficient code in the collection now, I might do more reading to connect with the more advanced Metastock type formula.

[edit] Re the RSI of the MACD; I've already mentioned this to the help desk people, could you note my interest and request to add a smoothing options to the MACD histogram for the charts; so that the chart indicator is in sync with the BCFL alert symbols and the chart MACD+Signal when using smoothings.

Also I would like to add an RSI smoothing option to the request, as I would like to smooth the RSI of the MACD histogram to remove choppiness of the shorter term one.

Thanks.
« Last Edit: 06/05/2019, 12:03:09 AM by JohnR »

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #26 on: 04/05/2019, 11:56:47 AM »
Just realised something in BCFL that will save a lot of time when doing scan studies for indicators that you then have to then setup the indicators for each time you adjust the formula and re-run the scan;
you can drag and drop the formula onto a preset indicator chart saved as an overlay.
And here i was re-creating the base chart indicators every time! A very DOH! moment.  ::)
« Last Edit: 04/05/2019, 12:12:30 PM by JohnR »

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #27 on: 05/05/2019, 01:48:35 PM »
The ATR-TS works well at scanning. If I use the 'Simple' for smoothing (as I have with the chart indicator), where would you place the 'S'?
The RSI of the MACD I will have to do more work with.

I might spend more time trying to get better quality stock selections in the scan results; so moving on with configuring Beyond Charts scanning options and adding criteria to BCFL or preferably to add Parameters in the Parameter Editor linked to the Scan Profiles.

As the SPA3 system uses Parameter profiles, and they are already set-up I've copied the parameters values to my own Parameter profile.
The question is how do you link to the parameter profiles from BCFL Scan Profile as there seems to be no item to select from?

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

Offline Campbell Sinclair

  • Support & Administration
  • Administrator
  • *****
  • Posts: 211
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #28 on: 07/05/2019, 11:40:46 AM »
Hi John,

Quote
Exactly that, I 'am' struggling to execute in code the specific idea, looking at charts and seeing the potential helps direct my efforts but actually implementing a structural approach is like asking me to re-invent what you have already done with the SIROC system.
And if I manage to re-invent the wheel you already have, after many hours on the computer, this still doesn't help when deploying and managing real capital into a non-system that falls outside the strict Beyond Charts and Trade Master system of which I can only act on system signals. Something I was unaware of when I bought into the software.
So with that realisation is where I'm currently struggling to implement any optimization I might come up with. I think it best I do complimentary code work within system at this point in time. And when satisfied move on to a stand alone system, if I find it necessary.

Looking at your most recent post, I was out of the office yesterday, I think this is still something you need to do as much as you think it is re-inventing the wheel. BCFL does NOT have SPA3 indicators built in to it and definitely not the signals.

SPA3 Parameters deal with the settings for how the indicators used in conjunction with the SIROC look like for finding SPA3 system signals. So that is why BCFL has no room for them - as without knowing what to look for, having a set of settings for different indicators does not help a BCFL formula with its objective. It has no idea what to do with this data. This is very similar with a BCFL scan, you need to define somewhere what to look for and the why (in your head, on a piece of paper, as a comment) to be able to purpose the data that comes out of the BCFL scan as actionable information in some way.

As you are trying to interface with SPA3, any BCFL formulas or BCFL scans will be best utalised to act as a filter before the fact or after the fact around the SPA3 methodologies entry or exit signals. You cannot get around this right now in a with the tools and, thought needs to be made on what your scanning ojective is and then how the process look around that. If you cannot define this or do not put thought in to it - then it is the same as navigating a ship without a map to me. It is working without the objective in mind.

It seems to me that you have a manual process outlined - so putting it in to BCFL should be more so about how to optimise alerts to tell you that this manual process may be occuring. A best fit implementation, with the tools at hand, perhaps is another angle to consider it from.

Without any processes of how you expect the whole overall to work with these points in mind - then you can start thinking about how money real world works with the system. I definitely do not and no one here at SWS want you to put cash in to signals that you are not confident in. Without processes and belief, you cannot be objective with your market participation.

You can enter non-system trades in to TradeMaster via the Act On Menu -> New Buy as well which you may want to take a look into.

As for simple smoothing on the trailing stop, it would look as so. Where the ATR period setting was is now in the moving average of the ATR:

{ Trailing_Stop SIMPLE SMOOTHING }
ATR_smoother := MOV(ATR(1), 14, S);
up_atrfact:= 3;
dn_atrfact := 3;
up_loss:=up_atrfact*ATR_smoother;
dn_loss:=dn_atrfact*ATR_smoother;
trail:=
If(L>PREV AND Ref(L,-1)>PREV,
Max(PREV,L-dn_loss),
If(L<PREV AND Ref(L,-1)<PREV,
Min(PREV,L+up_loss),
If(L>PREV,L-dn_loss,L+up_loss)));
trail;

Offline JohnR

  • Jr. Member
  • **
  • Posts: 54
Re: FORMULA & INDICATOR SHARED LIBRARY
« Reply #29 on: 07/05/2019, 02:24:58 PM »
Thanks for sorting out the ATR code with smoothing;
I like the ATR-TS for getting into stocks early; this is a primary driver ATM for code time, and combined with the posted MA code seems to work even better at finding early trenders than the MACD set, or at least before they kick in with any certainty as the MACD 100 warbles about for weeks until the MACD 260 finds certainty. So the MA I set up to reflect the MACD 260 does an excellent job here.

Yes I need to focus, and time will be needed to think it through.
Having given the predicament some thought I see the following as current goals:

Goal 1. Find quality early stocks that could potentially fit the "system scanned" parameters of stocks that will be triggered in a few days/weeks time. Early entries that can be traded in and out of by MACD3 Short histogram timing.
Goal 1 Indicators for code to find stocks: (MA 65,W with Signal of the MA), (ATR-TS, S), (Money Flow Indicator MFI 100 or 60 with Simple signal line). Back up will be the MACD1 260 with complimentary MACD 100.

Goal 2. Work within system for stocks already holding or recently holding (still in primary trend) through the SPA3 triggers to "graphically signal for" clean exits that occur on the MACD3 short histogram or similar cyclic indicator (if one exists in BCFL).
Goal 2. Indicators: Set up a MACD3 histogram code for alert graphic symbol to overlay on the main chart set up I use. Could do entries also but if you don't hold the stock then you are outside the system so it would have to be a separate watch-list based for scanned potential entries of recent holdings that remain within my MA or MACD 1 Long term trend (this shows potential to work well as I frequently see the system trade back in a few days later anyway on the same stock many times in some trends; exactly what I would like to eliminate).

Goal 3. Exit Sell "graphic Sell signals" for stocks already bought, that might outperform system ones, by simply using an overlay of the code to give graphic signals. In addition to short term 'in trend' signals identify long term trend phase out locations by long term indicators.
Goal 3. Indicators for code: (MACD3 Short histogram) and  (MACD2 medium histogram) for top turning identification, and finally MACD3, ATR-ST and MA crossings for stop loss, as well as SPA3 signal stops, sell all end of trend get out signals.

Next step will be to set up a portfolio (that you mentioned) and watch-list for these trades. 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.


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);

would this be correct?
« Last Edit: 07/05/2019, 11:55:55 PM by JohnR »