Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Conditional Scanner - MetaTrader 4 Script | Forex Indicator Download - MT4/MT5 Resources - MetaTrader 5 Resources

author EAcpu | 5 reads | 0 comments |

Condition Scanner - indicator for MetaTrader 4

Condition Scanner - indicator for MetaTrader 4

status scanner (cs)

Demo scanner features:

Code common to all scans:

The specific code of PP (Power Pro) strategy:

The specific code for the MAX (moving average crossover) strategy:

Code whose id starts with csXXXX:

How do I code for the new condition:

I decide on the policy identifier (eg PB for pinbars).

I set up the window as per "Demo Scanner's Features" above, removing any existing indicators.

If my new scans depend on chart indicators, I build them using csXXXX_0.mq4 as the schema. I remember "save as..." csPB_0.mq4. I applied a custom indicator to the chart on the left.

If I need a separate window indicator, I'll build that as well. I remember "save as..." csPB_1.mq4. I apply this to the left hand chart.

I build custom indicators instead of using standard indicators so that I can reference them elsewhere using iCustom functions. This way, if I change my mind about the basic parameters of my strategy (e.g. moving average method), I only have to change my custom indicator. If I were using standard indicators, I would have to change them and then dig into the internals of the code to accommodate my changes in ideas.

I take csXXXX_Chart.mq4, replace all instances of "XXXX" with my strategy identifier "PB", and save the code as csPB_Chart.mq4. It doesn't compile yet because there's still some "include" code that needs to be written.

The "include" code is now provided.

If the condition I want to test is very simple, I just use the "include" file csXXXX_GetBarFlag.mqh, write what I want and then "save as..." csPB_GetBarFlag.mqh. But if coding is tricky, I would go back to the csPB_Chart.mq4 I created earlier and comment out what now reads "#include lines of code and then build the code I want directly in the csPB_Chart.mq4 file. When I had it clean, I moved/pasted the conditional lookup code into the "include" file 'csPB_GetBarFlag.mqh' and uncommented the #include statement in the 'csPB_Chart.mq4 file.

The "csPB_Chart.mq4" file can now be compiled and applied to the left chart.

At this point, I saved the template for the chart on the left as csPB-CHART.tpl. It contains custom indicators on any chart, separate window custom indicators, and result plots applied to the current chart

I loaded the file "csXXXX_Panel.mq4", replaced all instances of "XXXX" with "PB" and then "save as..." "csPB_Panel.mq4". The last file is compiled and applied to the chart on the right. It may run a little slowly when first applied, but it won't use too many resources while running.

I stored csPB_panel.tpl as a template for the chart on the right.

Then I usually store the csPB as a configuration file.

Note : When building custom indicators and referencing them using iCustom functions, I take care that the names are exactly correct. You will not receive a warning if iCustom references a non-existent metric.

Notes : There may be a bug that when first loading a panel indicator produces results that are inconsistent with the results shown on the specific chart. I found that if I change the timescale on the panel window (thereby forcing a recalculation) everything works correctly. If anyone can guide me to solve this problem I would be very grateful.

Note : In your own developed...GetBarFlag.mqh code you can return any integer to the calling program for display. As the code shows, zero means "no results" and causes a gray wing to be displayed indicating which bar was tested. Returning a negative integer will result in a red display, while returning a positive integer will result in a green display.

Some aspects of the software:

The code is written as an indicator so that when the panel is displayed and you want to see a specific currency pair and time frame, you simply select that currency pair from the Market Watch window, drag and drop it to the current chart space and change the time frame to suit. Templates take care of the rest.

To reduce computer overload, I did two things.

First, when working with time series arrays, I mostly return only 200 bars.

Secondly, the panel display software does not test the user's situation every time. It uses a timer mechanism and tests bar[0] only when bar[0] forms 90%, otherwise it tests bar[1]. If bar[1] has focus (i.e. bar[0] formation rate is less than 90%), test once and calculate the time to switch to bar[0]. For each subsequent tick that appears before the transition time is reached, nothing happens. I'm not 100% sure yet that I've coded it correctly, but it seems to work just fine.


Attachment download

📎 code_11135.zip

Source: MQL5 #11135

Verification code Refresh