SHOW:
|
|
- or go back to the newest paste.
| 1 | void start() | |
| 2 | {
| |
| 3 | double lot = 0.1; // so 1 pip = 1 dollar | |
| 4 | if(Volume[0] != 1) return; // only trade on candle beginning | |
| 5 | pipValue = get_pip_value(); // get pip value | |
| 6 | ||
| 7 | // | |
| 8 | // PUT YOUR CODE BELOW HERE: | |
| 9 | // | |
| 10 | ||
| 11 | - | // exit trades based on signal line <-> buffer |
| 11 | + | // exit trades based on signal line <-> buffer |
| 12 | double macd_histogram = get_MACD(0, 1, InpFastEMA, InpSlowEMA, InpSignalSMA); | |
| 13 | double macd_line = get_MACD(1, 1, InpFastEMA, InpSlowEMA, InpSignalSMA); | |
| 14 | ||
| 15 | if(macd_histogram > macd_line) { close_orders(-1); } // close shorts when histogram is above signal
| |
| 16 | if(macd_histogram < macd_line) { close_orders(+1); } // close longs when histogram is beyond signal
| |
| 17 | ||
| 18 | // enter trades based on a zero-line cross | |
| 19 | - | double macd_histogram_now = get_MACD(0, 1, InpFastEMA, InpSlowEMA, InpSignalSMA); // 1 bar in past; mode is 0 for histogram |
| 19 | + | double macd_histogram_now = get_MACD(0, 1, InpFastEMA, InpSlowEMA, InpSignalSMA); // 1 bar in past; mode is 0 for histogram |
| 20 | double macd_histogram_past = get_MACD(0, 2, InpFastEMA, InpSlowEMA, InpSignalSMA); // 2 bars in past; mode is 0 for histogram | |
| 21 | ||
| 22 | if(macd_histogram_past < 0 && macd_histogram_now > 0) // macd histogram crossed from beyond -> above zero line | |
| 23 | if(open_trades() == 0) // only 1 open trade at a time | |
| 24 | trade (+1); | |
| 25 | ||
| 26 | if(macd_histogram_past > 0 && macd_histogram_now < 0) // macd histogram crossed from above -> beyond zero line | |
| 27 | if(open_trades() == 0) // only 1 open trade at a time | |
| 28 | trade (-1); | |
| 29 | } |