MACD histogram Scan With consecutive bars


Category:
0
0

I want to build a scan that has these parameters time,how many consecutive bars,positive to negative negative to positive.

Marked as spam
Posted by (Questions: 2, Answers: 6)
Asked on November 20, 2017 1:20 pm
865 views
0

Time parameter, already built into the scan engine. Positive to negative cross of the zero line and vise versa, already been done (it’s littered throughout the website). Not to mention you can already do this using standard tools of Thinkorswim that require not code whatsoever. You will need to explain how you want to scan for “consecutive bars”. Consecutive bars of what? How may consecutive bars (of what) do you want to scan for?

( at November 20, 2017 10:32 pm)
0
Private answer

for instance i want the scan to show only when there has been a crossover (positive to negative or negative to positive) with 4 or more consecutive bars(as in 4 positive consecutive or 4 negative Depends on you preference on how many consecutive bars)  too catch early cross overs. using MACD of course.How do i learn the script i would really like to learn i already have background programming knowledge.

Marked as spam
Posted by (Questions: 2, Answers: 6)
Answered on November 21, 2017 12:55 pm
0

It would have been very easy if you have provided a screenshot. Let me see if I understand correctly. You want to scan for Histogram crossing below zero line. But you want to make sure the histogram has been above the zero line for 4 or more consecutive bars. Is that right? Unless you are providing a screenshot please be sure to post your response as a question instead of a new answer.

If you have a programming background, then you can probably learn Thinkscript on your own just be viewing the language reference: http://tlc.thinkorswim.com/center/reference/thinkScript/

And be sure to check out the tutorials published by Thinkorswim. They have Basic and Advanced: http://tlc.thinkorswim.com/center/howToTos/tutorials/Basic.html

( at November 21, 2017 1:56 pm)
0
Private answer

Here is an example. after running the scan this would be one that would show up

With parameters

negative to positive with  4 positive consecutive bars

Attachments:
Marked as spam
Posted by (Questions: 2, Answers: 6)
Answered on November 21, 2017 2:43 pm
0
Private answer

Ok, very good thing I persisted until we got this clarification.

From your last response dated 11/21/17: So you want the rule to be “Find a MACD Histogram crossing above zero line, then alert once we get four consecutive positive bars AFTER that cross”

I am going to take the code straight from Thinkorswim. The built in study named “MACDHistogramCrossover”. This does almost everything we need. You are requesting a scan so we don’t need to plot anything other than the signal. So we’ll strip out all the style statements and provide two options for the scan. One for cross below and one for cross above.

Having completed those steps. All that is left is to shift the plot scan statement to look for a cross of the Histogram occurring 4 bars ago. Then check that we have been on the same side of the zero line since that cross occurred.

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input numberOfBars = 4;
Assert(numberOfBars >= 1, "The number of bars parameter must be greater than or equal to 1");
input averageType = AverageType.EXPONENTIAL;
def Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;
def crossAbove = Crosses(Diff, 0, CrossingDirection.ABOVE);
def crossBelow = Crosses(Diff, 0, CrossingDirection.BELOW);
def fourPositiveBars = Lowest(Diff, numberOfBars - 1) >= 0;
def fourNegativeBars = Highest(Diff, numberOfBars - 1) <= 0;
# use this scan for cross above
plot scan = crossAbove[numberOfBars - 1] and fourPositiveBars;
# use this scan for cross below
#plot scan = crossBelow[numberOfBars - 1] and fourNegativeBars;

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on November 21, 2017 3:57 pm
0
Private answer

Yes this is exactly what i am talking about.But i need to know before it has four consecutive bars to keep an eye on.the scan would show only when it just had a cross over with 2 till four consecutive bars.

for instance this showed up with the code you provided.It is very late to take the trade

Attachments:
Marked as spam
Posted by (Questions: 2, Answers: 6)
Answered on November 22, 2017 6:46 am
0
Private answer

i need the scan to be like this.

NZD/CHF just had a negative to positive crossover with

1 bar (The scan would pick it up)

2 consecutive bars (The scan would pick it up)

3 consecutive bars((The scan would pick it up)

4 consecutive bars((The scan would pick it up)

and the same for a positive to negative

 

Sorry for not giving a good explanation

Attachments:
Marked as spam
Posted by (Questions: 2, Answers: 6)
Answered on November 22, 2017 6:56 am
0

There is an input, named numberOfBars. The default setting is 4 bars. You can change that to 1 and it will alert with cross above and one positive bar. Change it to 2 and it will alert with cross above and 2 positive bars.

The line of code that creates that input is:
input numberOfBars = 4;

( at November 22, 2017 7:57 am)
0
Private answer

you my friend are a genius.One more thing it exceeds 4 consecutive bars how would i remove it from the scan.

Marked as spam
Posted by (Questions: 2, Answers: 6)
Answered on November 22, 2017 9:00 am
0

The Number of Bars setting, sets an upper limit to the number of consecutive bars. So with the setting left at the default of 4 bars, you should not see any scan results that have more than 4 consecutive bars.

( at November 22, 2017 9:19 am)
0
Private answer

the results do show more than four consecutive bars

Marked as spam
Posted by (Questions: 2, Answers: 6)
Answered on November 27, 2017 8:26 am
0

Be sure you are using the correct chart settings. I just noticed on some of your screenshots you are working with intraday time frames. Thinkorswim uses a default setting on charts which places them out of alignment with every other tool on the platform. I have notified them and hope they correct it soon. Get all the details here: https://www.hahn-tech.com/ans/hourly-adx-watchlist-not-matching-hourly-chart/

( at November 27, 2017 10:40 am)