EA from scratch - Part 1 - page 3

 

high_plot_v0.2

This version of high_plot adds a visual change to the histogram using an extra array and extra variable. This allows the code to display the histogram using 2 distinct shades of colour as an immediate visual aid to complement the rising and falling histogram. Light shades of green indicate a rise whereas the darker shades indicate a fall when compared to the previous bar.

Files:
 

low_plot_v0.2

This version of low_plot adds a visual change to the histogram using an extra array and extra variable. This allows the code to display the histogram using 2 distinct shades of colour as an immediate visual aid to complement the rising and falling histogram. Light shades of red indicate a rising low whereas the darker shades indicate a declining low when compared to the previous bar.

Files:
 

high_plot and low_plot together

Placing both high_plot and low_plot on a chart, in this case AUDUSD 1hr, and scanning across both indicators it can be seen that there may be possibilities to trade using the indicators.

What we look for is both buying, selling and holding positons according to the state of the histograms.

Here' are a few simple rules to follow:-

Buying

When both the high_plot and low_plot histograms are shown to be above the zero line in each graph then take a long trade on the close of the bar.

Selling

When both the high_plot and low_plot histograms are shown to be below the zero line in each graph then take a short trade on the close of the bar.

Hold/No trade to enter

Unless either of the above conditions are met then either continue to hold if already in position or do not take a trade until the correct condition of both histograms is seen to be met.

Files:
 

Now I'm confused. To me, the code below should place a red dot above the current bar if the low is less than the previous bar's low. What is wrong with the logic?

while(pos>=0)

{

current_bar_low = Low[pos]; // Get the low price of the current bar

previous_bar_low = Low[pos-1]; // Get the low price of the previous bar

if(current_bar_low < previous_bar_low) // Check for LL

{

ExtMapBuffer2[pos] = High[pos] + Point * 3; // Place a red dot above the bar to indicate a LL

}

pos--;

}

Also, if I used the expression:

if(current_bar_low < previous_bar_low && current_bar high < previous_bar high) ...

Wouldn't that be correct if the bar was making a lower low and lower high?

Files:
 

high_low_plot_v0.2

Here's an indicator which identifies a bar which makes either a higher high and higher low then places a green dot below the bar or lower low and lower high then places a red dot above the bar.

Files:
 

high_low_plot_v0.3

Here's what probably is the last version of the high_low_plot indicator. This version identifies 2 further bar states; inside bars and outside bars. Inside bars are identified with a olive coloured double ended arrowhead and outside bars are identified with an orange double ended arrowhead.

The program code is fully commented so feel free to take a look at it.

 

Based on this indicator I will look to create an EA so we can all learn the basics of making an indicator to then EA together.

 

OK. I see the error.

The error lies in Low[pos-1]. This should read Low[pos+1].

"How the bars indexed in MQL4?

MQL4 indexes the bars from 0 (for the current bar) then 1, 2, 3 etc to the count of the

bars.

So, if you want to work with the current bar you use the index 0.

And the index of the previous bar (of the current bar) is 1."

Quote from Codersguru MQL Course (Thank you coderguru and yes, I still love you (but not like that)

 

Actually, what would be nice it for the indicator to colour each bar according to it's state rather than display a shape. Does anyone know/worked out how that is achieved?

 
Sadly:
Actually, what would be nice it for the indicator to colour each bar according to it's state rather than display a shape. Does anyone know/worked out how that is achieved?

...change the color identifier, from Red to Blue, for example...

#property indicator bar_blue