This is more difficult than I thought. DanL in Futures channel shared a book "The SImple Strategy" by Markus Heitkoetter and Mark Hodge. Spent a few hours putting the codes together to do what the book asks. However, I could not get the cloud (my own idea) to show a straight line like ORB. Wanted to show a cloud or a Plot or a horizontal line for a trade triggered and two more lines. One for stop loss and One for target profit. Seen this in another indicator. But could not get it into this indicator, this code. Can someone help ?
#~~~~~~~~~~~~~~~~~~~~~~~DanL in Futures shared the book
#~~~~~~~~~~~ by Markus Heitkoetter and Mark Hodge
#`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~ ADR = Average Daily Range 7 days average
#~~~~~~~~~~~~~~~~~~~~~ High less Low of each day for 7 prior days
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def highDaysAgo1 = high(period = AggregationPeriod.DAY)[1];
def lowDaysAgo1 = low(period = AggregationPeriod.DAY)[1];
def highDaysAgo2 = high(period = AggregationPeriod.DAY)[2];
def lowDaysAgo2 = low(period = AggregationPeriod.DAY)[2];
def highDaysAgo3 = high(period = AggregationPeriod.DAY)[3];
def lowDaysAgo3 = low(period = AggregationPeriod.DAY)[3];
def highDaysAgo4 = high(period = AggregationPeriod.DAY)[4];
def lowDaysAgo4 = low(period = AggregationPeriod.DAY)[4];
def highDaysAgo5 = high(period = AggregationPeriod.DAY)[5];
def lowDaysAgo5 = low(period = AggregationPeriod.DAY)[5];
def highDaysAgo6 = high(period = AggregationPeriod.DAY)[6];
def lowDaysAgo6 = low(period = AggregationPeriod.DAY)[6];
def highDaysAgo7 = high(period = AggregationPeriod.DAY)[7];
def lowDaysAgo7 = low(period = AggregationPeriod.DAY)[7];
Def SumOfDifference = ((highDaysAgo1 - lowDaysAgo1)+
(highDaysAgo2 - lowDaysAgo2)+
(highDaysAgo3 - lowDaysAgo3)+
(highDaysAgo4 - lowDaysAgo4)+
(highDaysAgo5 - lowDaysAgo5)+
(highDaysAgo6 - lowDaysAgo6)+
(highDaysAgo7 - lowDaysAgo7));
Def ADR = round(SumOfDifference / 7, 1);
#~~~~~~~~~~~~~~~~~~~~~~~ Bollinger Bands
input length = 20;
input num_devs = 2.0;
input bollinger_price = close;
input Upper_band_price = close;
input Lower_band_price = close;
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~ BOLLINGER BANDS and first condition
#~~~~~~~~~~~~~~~~~~~~~~~~~~~MACD ABOVE ZERO and below
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;
def MACDdiff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;
plot Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
def ADR_LONG= MACDdiff > 0 and MACDdiff > Avg and (BBconditionUP_1 or BBconditionUP_2 ) ;
def ADR_SHORT= MACDdiff < 0 and MACDdiff < Avg and (BBconditionDOWN_1 or BBconditionDOWN_2 ) ;
#~~~~~~~~~~~~~~~~~~~~~~~~ Define Stop Loss and Profit Targets
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Def LongStopLoss = close - ADR*.1;
Def LongProfit = close + ADR *.2;
Def ShortStopLoss = close + ADR*.1;
Def ShortProfit = close - ADR *.2;
#~~~~~~~~~~~~~~~~~~~~ show bubble at trade trigger location
AddChartBubble(ADR_LONG, high, "SS+", Color.dark_Green, yes);
AddChartBubble(ADR_SHORT, high, "SS-", Color.light_RED, yes);
#AddCloud(ADR_LONG, LongStopLoss, Color.LIGHT_RED, Color.LIGHT_RED);
#AddCloud(close, ShortStopLoss, Color.yellow, Color.yellow);
def nan = Double.NaN;
#~~~~~~~~~~~~~~~ failed attempt to plot stop loss
plot LongStopLoss1 = if ADR_LONG then close - ADR*.1 else nan;
plot ShortStopLoss1 = if ADR_SHORT then close + ADR*.1 else nan;
AddLabel(1, " ", Color.Blue);
#show Average Daily Range amount at 10%
AddLabel(1, "ADR 10%= " + ADR/10, Color.yellow);
#show info when trade is triggered Long or Short
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AddLabel(1, if ADR_LONG then "In "+close + " SL= " + LongStopLoss + "/ T= "+ LongProfit else if ADR_SHORT then "In "+ADR_SHORT + " SL= " + ShortStopLoss + "/ T= "+ ShortProfit else "No SS Trade", if ADR_LONG then Color.green else if ADR_SHORT then Color.light_red else Color.gray );
AddLabel(1, " ", Color.Blue);
#~~~~~~~~~~~~~~~~~~~~~~~DanL in Futures shared the book
#~~~~~~~~~~~ by Markus Heitkoetter and Mark Hodge
#`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~ ADR = Average Daily Range 7 days average
#~~~~~~~~~~~~~~~~~~~~~ High less Low of each day for 7 prior days
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def highDaysAgo1 = high(period = AggregationPeriod.DAY)[1];
def lowDaysAgo1 = low(period = AggregationPeriod.DAY)[1];
def highDaysAgo2 = high(period = AggregationPeriod.DAY)[2];
def lowDaysAgo2 = low(period = AggregationPeriod.DAY)[2];
def highDaysAgo3 = high(period = AggregationPeriod.DAY)[3];
def lowDaysAgo3 = low(period = AggregationPeriod.DAY)[3];
def highDaysAgo4 = high(period = AggregationPeriod.DAY)[4];
def lowDaysAgo4 = low(period = AggregationPeriod.DAY)[4];
def highDaysAgo5 = high(period = AggregationPeriod.DAY)[5];
def lowDaysAgo5 = low(period = AggregationPeriod.DAY)[5];
def highDaysAgo6 = high(period = AggregationPeriod.DAY)[6];
def lowDaysAgo6 = low(period = AggregationPeriod.DAY)[6];
def highDaysAgo7 = high(period = AggregationPeriod.DAY)[7];
def lowDaysAgo7 = low(period = AggregationPeriod.DAY)[7];
Def SumOfDifference = ((highDaysAgo1 - lowDaysAgo1)+
(highDaysAgo2 - lowDaysAgo2)+
(highDaysAgo3 - lowDaysAgo3)+
(highDaysAgo4 - lowDaysAgo4)+
(highDaysAgo5 - lowDaysAgo5)+
(highDaysAgo6 - lowDaysAgo6)+
(highDaysAgo7 - lowDaysAgo7));
Def ADR = round(SumOfDifference / 7, 1);
#~~~~~~~~~~~~~~~~~~~~~~~ Bollinger Bands
Code:
~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input length = 20;
input num_devs = 2.0;
input bollinger_price = close;
input Upper_band_price = close;
input Lower_band_price = close;
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~ BOLLINGER BANDS and first condition
Code:
~~~~~~~~~~~~~~~~~~~
def BBUPPer = Average(bollinger_price, length) + num_devs * stdev(bollinger_price, length);
def BBconditionUP_1 = Upper_band_price crosses above BBUPPer[1]
;
# and high[-1] >= BBUPPer;
def BBconditionUP_2 = Upper_band_price equals BBUPPer[1]
;
#and high[-1] >= BBUPPer;
def BBLower = Average(bollinger_price, length) - num_devs * stdev(bollinger_price, length);
def BBconditionDOWN_1 = Lower_band_price crosses below BBLower[1]
;
# and low[-1] <= BBLower;
def BBconditionDOWN_2 = Lower_band_price equals BBLower[1]
;
#and low[-1] <= BBLower;
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;
def MACDdiff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;
plot Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;
def ADR_LONG= MACDdiff > 0 and MACDdiff > Avg and (BBconditionUP_1 or BBconditionUP_2 ) ;
def ADR_SHORT= MACDdiff < 0 and MACDdiff < Avg and (BBconditionDOWN_1 or BBconditionDOWN_2 ) ;
#~~~~~~~~~~~~~~~~~~~~~~~~ Define Stop Loss and Profit Targets
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Def LongStopLoss = close - ADR*.1;
Def LongProfit = close + ADR *.2;
Def ShortStopLoss = close + ADR*.1;
Def ShortProfit = close - ADR *.2;
#~~~~~~~~~~~~~~~~~~~~ show bubble at trade trigger location
AddChartBubble(ADR_LONG, high, "SS+", Color.dark_Green, yes);
AddChartBubble(ADR_SHORT, high, "SS-", Color.light_RED, yes);
#AddCloud(ADR_LONG, LongStopLoss, Color.LIGHT_RED, Color.LIGHT_RED);
#AddCloud(close, ShortStopLoss, Color.yellow, Color.yellow);
def nan = Double.NaN;
#~~~~~~~~~~~~~~~ failed attempt to plot stop loss
plot LongStopLoss1 = if ADR_LONG then close - ADR*.1 else nan;
plot ShortStopLoss1 = if ADR_SHORT then close + ADR*.1 else nan;
AddLabel(1, " ", Color.Blue);
#show Average Daily Range amount at 10%
AddLabel(1, "ADR 10%= " + ADR/10, Color.yellow);
#show info when trade is triggered Long or Short
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
AddLabel(1, if ADR_LONG then "In "+close + " SL= " + LongStopLoss + "/ T= "+ LongProfit else if ADR_SHORT then "In "+ADR_SHORT + " SL= " + ShortStopLoss + "/ T= "+ ShortProfit else "No SS Trade", if ADR_LONG then Color.green else if ADR_SHORT then Color.light_red else Color.gray );
AddLabel(1, " ", Color.Blue);