#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// Written by TradersUltimateEdge
#// Code provided open source, feel free to use it for any purpose except resale
#indicator("TUE ADX/MACD Confluence V1.0", overlay=true)
# Converted by Sam4Cok@Samer800 - 07/2023
# MTF option added by Sam4Cok@Samer800
input useChartTimeframe = {Default "Yes", "No"};
input manualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input showSignals = yes; # "Show BUY/SELL Signals")
input showCandleColors = yes; # "Show Candle Colors")
input adxLength = 14; #, title="ADX Length")
input adxSmoothing = 10; #, title="ADX Smoothing")
input macdSource = close; #, title="MACD Source")
input macdFastLength = 12; #, title="MACD Fast Length")
input macdSlowLength = 26; #, title="MACD Slow Length")
input macdSignalLength = 9; #, title="MACD Signal Length")
def l; def c; def h; def macdSrc;
Switch (useChartTimeframe) {
Case "Yes" :
macdSrc = macdSource;
l = low;
c = close;
h = high;
Case "No" :
macdSrc = close(Period=manualTimeframe);;
l = low(Period=manualTimeframe);
c = close(Period=manualTimeframe);
h = high(Period=manualTimeframe);
}
#// ADX AND MACD CALC
def hiDiff = h - h[1];
def loDiff = l[1] - l;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def ATR = WildersAverage(TrueRange(h, c, l), adxLength);
def diplus = 100 * WildersAverage(plusDM, adxLength) / ATR;
def diminus = 100 * WildersAverage(minusDM, adxLength) / ATR;
def DX = if (diplus + diminus > 0) then 100 * AbsValue(diplus - diminus) / (diplus + diminus) else 0;
def ADX = WildersAverage(DX, adxSmoothing);
def macdline = ExpAverage(macdSrc, macdfastLength) - ExpAverage(macdSrc, macdslowLength);
def signalline = ExpAverage(macdline, macdsignalLength);
#//TRADE CALC
def longcheck = diplus > diminus and macdline > signalline;
def shortcheck = diminus > diplus and signalline > macdline;
def trade;
#//Open from nothing
if trade[1] == 0 and longcheck {
trade = 1;
} else
if trade[1] == 0 and shortcheck {
trade = -1;
} else
if trade[1] == 1 and shortcheck {
trade = -1;
} else
if trade[1] == -1 and longcheck {
trade = 1;
} else {
trade = trade[1];
}
#/PLOT
def colors = if longcheck then 1 else if shortcheck then -1 else 0;
AssignPriceColor(if !showcandlecolors then Color.CURRENT else
if colors>0 then Color.GREEN else
if colors<0 then Color.RED else Color.GRAY);
AddChartBubble(trade[1] != 1 and trade == 1 and showsignals,low, "BUY", color.green, no);
AddChartBubble(trade[1] != -1 and trade == -1 and showsignals, high, "SELL", color.red, yes);
#-- END OF CODE