View difference between Paste ID: vgWN6zP2 and fwSgM68w
SHOW: | | - or go back to the newest paste.
1
input  int        InpFastEMA                     = 12;
2
input  int        InpSlowEMA                     = 26;
3
input  int        InpSignalSMA                   = 9;
4
5
6
#include <indicator_template_setup.mqh>
7
8
void start()
9
{  
10
   double lot = 0.1;            // so 1 pip = 1 dollar
11
	if(Volume[0] != 1) return;   // only trade on candle beginning
12
	pipValue = get_pip_value();  // get pip value
13
14
	//
15
	// PUT YOUR CODE BELOW HERE:
16
	//
17
	int    signal  = 0;
18
	double indic   = get_MACD(0, 1, InpFastEMA, InpSlowEMA, InpSignalSMA);
19
	
20
	if(indic > 0) signal = +1;
21
	if(indic < 0) signal = -1;		
22
		
23
   	//
24
   	// execute indicator signal		
25
	if(signal == +1)                         // indicator returned BUY (+1)
26
	{                                        // ... so ...
27
		close_orders(-1);                     // close all SELL (-1) orders
28-
		trade       (+1);                     // and go LONG (+1)
28+
		if(open_trades() == 0)                // and if there are no trades open
29
		   trade       (+1);                  // go LONG (+1) 
30
	}
31
	if(signal == -1)                         // indicator returned SELL (-1)
32
	{                                        // ... so ...
33-
		trade       (-1);                     // and go SHORT (-1)
33+
34
		if(open_trades() == 0)                // and if there are no trades open
35
		   trade       (-1);                  // go SHORT (-1) 
36
	}
37
}
38
39
/*
40
	Modes:
41
		0 == ExtMacdBuffer named '"MACD"', of type DRAW_HISTOGRAM
42
		1 == ExtSignalBuffer named '"Signal"', of type DRAW_LINE
43
*/
44
double get_MACD (int which_mode, int which_bar = 1, int InpFastEMA = 12, int InpSlowEMA = 26, int InpSignalSMA = 9)
45
{
46
	return iCustom(Symbol(), 0, "MACD", InpFastEMA, InpSlowEMA, InpSignalSMA, which_mode, which_bar);
47
}