- MetaTrader 5 Built-in Trading Strategy Tester
- When MetaTrader 5 Web Terminal is indispensable
- Download the MetaTrader 5 mobile app for Android
//+------------------------------------------------------------------+ //| | //| | //| | //+------------------------------------------------------------------+ #property copyright "" #property link "" #property strict #property indicator_chart_window // The number of buffers for calculation, up to 8 #property indicator_buffers 2 // The color for displaying arrows #property indicator_color1 clrLimeGreen // Long signal #property indicator_color2 clrRed // Short signal // Width of the arrows #property indicator_width1 1 // Long signal arrow #property indicator_width2 1 // Short signal arrow /* extern int ArrowDistance = 0; extern bool WaitForCandleClose = true; extern bool ArrowOnTriggerBar = false; extern int Arrow = 117; */ //extern int MarkMinuteGMT = 0; // Buffers for the calculations double Up_Arrow_Buffer[]; // Long buffer for display double Down_Arrow_Buffer[]; // Short buffer for display /* int SignalIndex = 0; int ArrowOffset = 0; */ //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { /*if (WaitForCandleClose) { SignalIndex = 1; } else { SignalIndex = 0; } if (ArrowOnTriggerBar) { ArrowOffset = 0; } else { ArrowOffset = 0; }*/ // SetIndexStyle - sets the new type, style, width and color for a given indicator line // SetIndexBuffer - binds the array variable declared at a global level to the custom indicator pre-defined buffer // SetIndexArrow - sets an arrow symbol for indicators line of the DRAW_ARROW type. SetIndexStyle(0, DRAW_ARROW); SetIndexBuffer(0, Up_Arrow_Buffer); SetIndexArrow(0, 117); // Up arrow SetIndexStyle(1, DRAW_ARROW); SetIndexBuffer(1, Down_Arrow_Buffer); SetIndexArrow(1, 117); // Down arrow //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i; // Bar index int Counted_bars; // Number of counted bars //-------------------------------------------------------------------- Counted_bars = IndicatorCounted(); // Number of counted bars i = Bars - Counted_bars; // Index of the first uncounted if (Counted_bars == 0) i = Bars - 100; while (i >= 0) { double upper_line = iCustom(NULL, PERIOD_CURRENT, "FastTMALine__1", 1, i); double lower_line = iCustom(NULL, PERIOD_CURRENT, "FastTMALine__1", 2, i); if (Close[i] > upper_line) Up_Arrow_Buffer[i] = High[i]; if (Close[i] < lower_line) Down_Arrow_Buffer[i] = Low[i]; i--; } /* if (i == 0) { i = 2; // the newest signal bar is suppose to be at index 2 } while(i >= SignalIndex) // Loop for uncounted bars { if (isUpSwingBar(i)) { Up_Arrow_Buffer[i - ArrowOffset] = Close[i - ArrowOffset]; // - (ArrowDistance * Point); Down_Arrow_Buffer[i - ArrowOffset] = EMPTY_VALUE; } else if (isDownSwingBar(i)) { Down_Arrow_Buffer[i - ArrowOffset] = Close[i - ArrowOffset]; // + (ArrowDistance * Point); Up_Arrow_Buffer[i - ArrowOffset] = EMPTY_VALUE; } else { Up_Arrow_Buffer[i - ArrowOffset] = EMPTY_VALUE; Down_Arrow_Buffer[i - ArrowOffset] = EMPTY_VALUE; } i--; }*/ //---- return(0); } /* bool isUpSwingBar(int i) { //&& TimeMinute(Time[i])==MarkMinuteGMT) { if(true) { return (true); } return (false); } } bool isDownSwingBar(int i) { { if(true) { return (true); } return (false); // } } */ //+------------------------------------------------------------------+
It may be "FastTMALine" instead of "FastTMALine__1" on your PC. If so, correct it.
It may be "FastTMALine" instead of "FastTMALine__1" on your PC. If so, correct it.
Thanks mate, that's fantastic!! Really appreciate that.
It may be "FastTMALine" instead of "FastTMALine__1" on your PC. If so, correct it.
Hi Naguisa,
I'm now struggling to add an alert to this. When I do it just constantly alerts and it's in the loop. Do you know how I could add an alert that just runs once?
Thanks
Mark
MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum #1
You are looking at a signal. Act on a change of signal.
MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum #1
Thanks, William
Look at this sample.
Thanks, Naguisa, that'll come in very handy for other things. Just one final thing, the code in your first reply doesn't wait for the bar to close, is there a quick fix for that?
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 programming forum
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 programming forum
Thanks again, William.
Naguisa, ignore my last comment about the signal appearing before the bar closes.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use