Lesnewby
Member
Can anyone help me add criteria to this strategy so entries and exits are never possible when the MACD signal line is below the MACD average line.
mod edited: misleading stats
. Any help will be much appreciated.
Here is the code:
mod edited: misleading stats
. Any help will be much appreciated.
Here is the code:
Code:
#2022 1202 LJJ_GrnRedFPL
#HA Enter trade on first green bar and exit on first red .
#NEVER ENTER TRADE IF MACD SIGNAL LINE IS BELOW AVERAGE LINE.
#Thanks to Modius, RConner7, Barbaros and Eddielee394.
#start
def haClose = ohlc4;
def haOpen = open;
input AtrMult = .60;#hint AtrMult: Modify to FloatingPL Plot-Original set to 1.00
input nATR = 6;
input AvgType = AverageType.HULL;
input ShowBubbles = NO;
def ATR = ATR("length" = nATR, "average type" = AvgType);
def UP_Band_Basic = HL2 + (AtrMult * ATR);
def LW_Band_Basic = HL2 + (-AtrMult * ATR);
def UP_Band = if ((UP_Band_Basic < UP_Band[1]) or (close[1] > UP_Band[1])) then UP_Band_Basic else UP_Band[1];
def LW_Band = if ((LW_Band_Basic > LW_Band[1]) or (close[1] < LW_Band[1])) then LW_Band_Basic else LW_Band[1];
def ST = if ((ST[1] == UP_Band[1]) and (close < UP_Band)) then UP_Band
else if ((ST[1] == UP_Band[1]) and (close > Up_Band)) then LW_Band
else if ((ST[1] == LW_Band[1]) and (close > LW_Band)) then LW_Band
else if ((ST[1] == LW_Band) and (close < LW_Band)) then UP_Band
else LW_Band;
def Long = if close > ST then ST else Double.NaN;
#Long.AssignValueColor(Color.GREEN);
#Long.SetLineWeight(2);
def Short = if close < ST then ST else Double.NaN;
#Short.AssignValueColor(Color.RED);
#Short.SetLineWeight(3);
def LongTrigger = IsNaN(Long[1]) and !IsNaN(Long);
def ShortTrigger = IsNaN(Short[1]) and !IsNaN(Short);
plot LongDot = if LongTrigger then ST else Double.NaN;
LongDot.SetPaintingStrategy(PaintingStrategy.POINTS);
LongDot.AssignValueColor(Color.GREEN);
LongDot.SetLineWeight(4);
plot ShortDot = if ShortTrigger then ST else Double.NaN;
ShortDot.SetPaintingStrategy(PaintingStrategy.POINTS);
ShortDot.AssignValueColor(Color.RED);
ShortDot.SetLineWeight(4);
AddChartBubble(ShowBubbles and LongTrigger, ST, "B", color.YELLOW, yes);
AddChartBubble(ShowBubbles and ShortTrigger, ST, "S", color.CYAN, yes);
def ha_up = MACD()."Value" crosses above MACD()."Avg" and haClose > haOpen ;
def ha_dn = MACD()."Value" crosses below MACD()."Avg" and haClose < haOpen;
def bto = ha_up ;
def stc = ha_dn ;
addOrder(OrderType.BUY_TO_OPEN, Long , Open, name = "LE");
addOrder(OrderType.Sell_TO_CLOSE, Short, open, name = "LX");
Last edited by a moderator: