assemble in one indicator 1-2-3-4-5 minutes MACDs

Tonydl

New member
Hey Y'all
This my is my first ever post on this AMAZING site!!!

Wonder if someone can help.I cannot write code.
Maybe this kind of indicator already exists on the site.Would it be possible to assemble in one indicator 1-2-3-4-5 minutes MACDs ?and have it show an arrow to buy or sell when they all turn at the same time?Thinking of using it mostly for trading futures intraday but people with more experience might be able to suggest pairing it with other indicator/strategy ?
Thank you so much for considering this .
Tony.

I want to make it clear that this would be to use on Thinkorswim.
 
Are you thinking of something like this?

jOEcx4D.png


I threw this together relatively quickly so it may not be what you were thinking of, but I just took five aggregation periods' worth of MACD values going from the current time period (1min) up to 5min, and plotted the classic MACD values as cumulative diffs/values/averages. I also kept the current time period's oscillator plotting just to see it in relation to the overall sum.

Let me know if this is what you were looking for! Side note -- this current image is using fast length=7, slow=13, macd=6 on a Wilders moving average.

Code:
## Five-Timeframe Aggregate MACD for tonydl
## Coded by Chemmy for usethinkscript.com

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
input showline2 = no;
input showline3 = no;
input showline4 = no;
input showline5 = no;

## Aggregations
input agg1 = aggregationPeriod.MIN;
input agg2 = aggregationPeriod.TWO_MIN;
input agg3 = aggregationperiod.Three_min;
input agg4 = aggregationperiod.four_min;
input agg5 = aggregationperiod.five_min;

## Values and Averages
def Value1 = MovingAverage(averageType, close(period=agg1), fastLength) - MovingAverage(averageType, close(period=agg1), slowLength);
def Avg1 = MovingAverage(averageType, Value1, MACDLength);

def Value2 = MovingAverage(averageType, close(period=agg2), fastLength) - MovingAverage(averageType, close(period=agg2), slowLength);
def Avg2 = MovingAverage(averageType, Value1, MACDLength);

def Value3 = MovingAverage(averageType, close(period=agg3), fastLength) - MovingAverage(averageType, close(period=agg3), slowLength);
def Avg3 = MovingAverage(averageType, Value1, MACDLength);

def Value4 = MovingAverage(averageType, close(period=agg4), fastLength) - MovingAverage(averageType, close(period=agg4), slowLength);
def Avg4 = MovingAverage(averageType, Value1, MACDLength);

def Value5 = MovingAverage(averageType, close(period=agg5), fastLength) - MovingAverage(averageType, close(period=agg5), slowLength);
def Avg5 = MovingAverage(averageType, Value1, MACDLength);

## Diffs
plot Diff1 = Value1 - Avg1;
plot Diff2 = Value2 - Avg2;
diff2.sethiding(!showline2);
plot Diff3 = Value3 - Avg3;
diff3.sethiding(!showline3);
plot Diff4 = Value4 - Avg4;
diff4.sethiding(!showline4);
plot Diff5 = Value5 - Avg5;
diff5.sethiding(!showline5);


plot fulldiff = (diff1 + diff2 + diff3 + diff4 + diff5)/5;
plot valavg = (value1 + value2 + value3 + value4 + value5)/5;
plot fullavg = (avg1 + avg2 + avg3 + avg4 + avg5)/5;

plot ZeroLine = 0;
## Signals
plot UpSignal = if fulldiff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if fulldiff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

valavg.SetDefaultColor(GetColor(1));
fullavg.SetDefaultColor(GetColor(8));


Diff1.SetDefaultColor(GetColor(5));
Diff1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff1.SetLineWeight(3);
Diff1.DefineColor("Positive and Up", Color.GREEN);
Diff1.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff1.DefineColor("Negative and Down", Color.RED);
Diff1.DefineColor("Negative and Up", Color.DARK_RED);
Diff1.AssignValueColor(if Diff1 >= 0 then if Diff1 > Diff1[1] then Diff1.color("Positive and Up") else Diff1.color("Positive and Down") else if Diff1 < Diff1[1] then Diff1.color("Negative and Down") else Diff1.color("Negative and Up"));

fulldiff.SetDefaultColor(GetColor(5));
fulldiff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
fulldiff.SetLineWeight(3);
fulldiff.DefineColor("Positive and Up", Color.GREEN);
fulldiff.DefineColor("Positive and Down", Color.DARK_GREEN);
fulldiff.DefineColor("Negative and Down", Color.RED);
fulldiff.DefineColor("Negative and Up", Color.DARK_RED);
fulldiff.AssignValueColor(if fulldiff >= 0 then if fulldiff > fulldiff[1] then fulldiff.color("Positive and Up") else fulldiff.color("Positive and Down") else if fulldiff < fulldiff[1] then fulldiff.color("Negative and Down") else fulldiff.color("Negative and Up"));


ZeroLine.SetDefaultColor(GetColor(0));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(3);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Chemmy
thank you so much for doing this!
I am kind of new at this.
I don't know if I explained myself clearly enough:
I was thinking that when the five time frames's MACDs all turn -up or down-at about the same time
it would be a good indication of a change in momentum area and a good entry point for a trade.
I also envisioned the arrow appearing on the the chart by the candles instead of the lower study
(say... red arrow for a short at around 1:15 and a green arrow for a long at around 2:30-2:35)
I see your Multy MACD crossing the zero line at about that time ,so i guess that could be the signal?
does it make sense or am I thinking of pie in the sky?

Thanks so much.Tony
 
Chemmy
thank you so much for doing this!
I am kind of new at this.
I don't know if I explained myself clearly enough:
I was thinking that when the five time frames's MACDs all turn -up or down-at about the same time
it would be a good indication of a change in momentum area and a good entry point for a trade.
I also envisioned the arrow appearing on the the chart by the candles instead of the lower study
(say... red arrow for a short at around 1:15 and a green arrow for a long at around 2:30-2:35)
I see your Multy MACD crossing the zero line at about that time ,so i guess that could be the signal?
does it make sense or am I thinking of pie in the sky?

Thanks so much.Tony


this plots arrows and a pulse signal,
representing the buy/sell signals, derived from 5 different MACD MTF signals.
when all 5 are up, then buy. all 5 down, sell.

the arrows tend to be placed randomly vertically. i think it is a quirk of using 2nd aggregation data.

the pulse signal is scaled and superimposed on top of the candles.
i used highest, instead of highestall() , so the study wouldn't become complex.
because of this, the signal tends to shift vertically at times...

i started with chemmy code and added to the end of it.


upper

Code:
# macd_mtf_buysell_00e_upper

# https://usethinkscript.com/threads/assemble-in-one-indicator-1-2-3-4-5-minutes-macds.13297/
#mtf macd  5 times
#main chart  arrows

#assemble in one indicator 1-2-3-4-5 minutes MACDs

## Five-Timeframe Aggregate MACD for tonydl
## Coded by Chemmy for usethinkscript.com

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
input showline2 = no;
input showline3 = no;
input showline4 = no;
input showline5 = no;

## Aggregations
input agg1 = AggregationPeriod.MIN;
input agg2 = AggregationPeriod.TWO_MIN;
input agg3 = AggregationPeriod.THREE_MIN;
input agg4 = AggregationPeriod.FOUR_MIN;
input agg5 = AggregationPeriod.FIVE_MIN;

## Values and Averages
def Value1 = MovingAverage(averageType, close(period = agg1), fastLength) - MovingAverage(averageType, close(period = agg1), slowLength);
def Avg1 = MovingAverage(averageType, Value1, MACDLength);

def Value2 = MovingAverage(averageType, close(period = agg2), fastLength) - MovingAverage(averageType, close(period = agg2), slowLength);
def Avg2 = MovingAverage(averageType, Value1, MACDLength);

def Value3 = MovingAverage(averageType, close(period = agg3), fastLength) - MovingAverage(averageType, close(period = agg3), slowLength);
def Avg3 = MovingAverage(averageType, Value1, MACDLength);

def Value4 = MovingAverage(averageType, close(period = agg4), fastLength) - MovingAverage(averageType, close(period = agg4), slowLength);
def Avg4 = MovingAverage(averageType, Value1, MACDLength);

def Value5 = MovingAverage(averageType, close(period = agg5), fastLength) - MovingAverage(averageType, close(period = agg5), slowLength);
def Avg5 = MovingAverage(averageType, Value1, MACDLength);

## Diffs
def Diff1 = Value1 - Avg1;
def Diff2 = Value2 - Avg2;
def Diff3 = Value3 - Avg3;
def Diff4 = Value4 - Avg4;
def Diff5 = Value5 - Avg5;

#Diff1.SetHiding(!showline2);
#Diff2.SetHiding(!showline2);
#Diff3.SetHiding(!showline3);
#Diff4.SetHiding(!showline4);
#Diff5.SetHiding(!showline5);

def fulldiff = (Diff1 + Diff2 + Diff3 + Diff4 + Diff5) / 5;
def valavg = (Value1 + Value2 + Value3 + Value4 + Value5) / 5;
def fullavg = (Avg1 + Avg2 + Avg3 + Avg4 + Avg5) / 5;

def ZeroLine = 0;
## Signals
def UpSignal = if fulldiff crosses above ZeroLine then ZeroLine else Double.NaN;
def DownSignal = if fulldiff crosses below ZeroLine then ZeroLine else Double.NaN;

#UpSignal.SetHiding(!showBreakoutSignals);
#DownSignal.SetHiding(!showBreakoutSignals);
#valavg.SetDefaultColor(GetColor(1));
#fullavg.SetDefaultColor(GetColor(8));


#Diff1.SetDefaultColor(GetColor(5));
#Diff1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Diff1.SetLineWeight(3);
#Diff1.DefineColor("Positive and Up", Color.GREEN);
#Diff1.DefineColor("Positive and Down", Color.DARK_GREEN);
#Diff1.DefineColor("Negative and Down", Color.RED);
#Diff1.DefineColor("Negative and Up", Color.DARK_RED);
#Diff1.AssignValueColor(if Diff1 >= 0 then if Diff1 > Diff1[1] then Diff1.Color("Positive and Up") else Diff1.Color("Positive and Down") else if Diff1 < Diff1[1] then Diff1.Color("Negative and Down") else Diff1.Color("Negative and Up"));

#fulldiff.SetDefaultColor(GetColor(5));
#fulldiff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#fulldiff.SetLineWeight(3);
#fulldiff.DefineColor("Positive and Up", Color.GREEN);
#fulldiff.DefineColor("Positive and Down", Color.DARK_GREEN);
#fulldiff.DefineColor("Negative and Down", Color.RED);
#fulldiff.DefineColor("Negative and Up", Color.DARK_RED);
#fulldiff.AssignValueColor(if fulldiff >= 0 then if fulldiff > fulldiff[1] then fulldiff.Color("Positive and Up") else fulldiff.Color("Positive and Down") else if fulldiff < fulldiff[1] then fulldiff.Color("Negative and Down") else fulldiff.Color("Negative and Up"));


#ZeroLine.SetDefaultColor(GetColor(0));
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#UpSignal.SetLineWeight(3);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#DownSignal.SetLineWeight(3);


#-------------------------------------------


def na = double.nan;
def bn = barnumber();


input back = 1;
def m1 = if value1 > value1[back] then 1
 else if value1 < value1[back] then -1
 else 0;
def m2 = if value2 > value2[back] then 1
 else if value2 < value2[back] then -1
 else 0;
def m3 = if value3 > value3[back] then 1
 else if value3 < value3[back] then -1
 else 0;
def m4 = if value4 > value4[back] then 1
 else if value4 < value4[back] then -1
 else 0;
def m5 = if value5 > value5[back] then 1
 else if value5 < value5[back] then -1
 else 0;


input exit = 3;
#def longclose = (m1 + m2 + m3 + m4 + m5 <= exit);
#def shortclose = (m1 + m2 + m3 + m4 + m5 >= -exit);
#def longopen = (m1 + m2 + m3 + m4 + m5 == 5);
#def shortopen = (m1 + m2 + m3 + m4 + m5 == -5);


# def longopen = (longopen[1] != 5) and (m1 + m2 + m3 + m4 + m5 == 5);

def msum = (m1 + m2 + m3 + m4 + m5);

def longclose = (msum[1] > exit) and (msum <= exit);
def shortclose = (msum[1] < -exit) and (msum >= -exit);
def longopen = (msum[1] != 5) and (msum == 5);
def shortopen = (msum[1] != -5) and (msum == -5);


# save a buy price level
# use to tell if in trade, >0
# compare value to close to see if trade is stopped for loss
# compare value to close to see if trade is stopped for gain

def longbuy = if bn == 1 then 0
else if longclose then 0
else if shortopen then 0
else if close < longbuy[1] * 0.999  then 0
else if close > (longbuy[1] * 1.02) then 0
else if longopen then close
else longbuy[1];

def shortbuy = if bn == 1 then 0
else if shortclose then 0
else if longopen then 0
else if close > shortbuy[1] * 1.001 then 0
else if close < (shortbuy[1] * 0.98 ) then 0
else if shortopen then close
else shortbuy[1];


def long = if bn == 1 then 0
else if longclose then 0
else if longopen then 1
else long[1];

def short = if bn == 1 then 0
else if shortclose then 0
else if shortopen then 1
else short[1];


# avg the long n short trades..  stretch them out ,  remove all the small blips
def trade = if bn ==1 then 0
 else if long then 1
 else if short then -1
 else trade[1];



#--------------------------------

# lower plots

#plot zm1 = m1;
#plot zm2 = m2+2.2;
#plot zm3 = m3+4.4;
#plot zm4 = m4+6.6;
#plot zm5 = m5+8.8;

#plot r = 0;


#plot y1 = longopen+12;
#plot y2 = longclose+10;
#plot y3 = shortopen+8;
#plot y4 = shortclose+6;
#y1.SetDefaultColor(Color.green);
#y2.SetDefaultColor(Color.cyan);
#y3.SetDefaultColor(Color.red);
#y4.SetDefaultColor(Color.yellow);

#plot k = 14;
#k.SetDefaultColor(Color.white);
#k.setlineweight(3);


input vertlines = no;
addverticalline(vertlines and longopen, "-" , color.green);
addverticalline(vertlines and longclose, "-" , color.red);
addverticalline(vertlines and shortopen, "-" , color.cyan);
addverticalline(vertlines and shortclose, "-" , color.yellow);


#plot b = if longbuy > 0 then longbuy else na;
#plot s = if shortbuy > 0 then shortbuy else na;

#plot z1 = value1;
#plot z2 = value2;
#plot z3 = value3;
#plot z4 = value4;
#plot z5 = value5;


addchartbubble(0, -6,
msum + "\n" +
long + " L\n" +
short + " S\n" +

longopen + " LO\n" +
longclose + " LC\n" +
shortopen + " SO\n" +
shortclose + " SC\n" 
, color.yellow, yes);


#plot zl = long+18;
#plot zs = short+16;
#zl.SetDefaultColor(Color.green);
#zs.SetDefaultColor(Color.red);


#plot t = trade+2;
#t.SetDefaultColor(Color.cyan);

#plot u = 2;
#u.SetDefaultColor(Color.white);
#u.setlineweight(2);


#--------------------------

# upper plots


# arrows don't line up?  maybe a 2nd agg quirk
plot long_enter = if trade == 1 and trade[1] != 1 then low else na;
long_enter.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
long_enter.SetDefaultColor(Color.green);
long_enter.setlineweight(3);
long_enter.hidebubble();

plot long_exit = if trade != 1 and trade[1] == 1 then high else na;
long_exit.SetPaintingStrategy(PaintingStrategy.ARROW_down);
long_exit.SetDefaultColor(Color.red);
long_exit.setlineweight(3);
long_exit.hidebubble();

#------------------------------

def n =1000;
def h = highest(high, n);
def l = lowest(low, n);
def rng = h-l;
def mid = l + (rng/2);


# plot a pulse signal , representing the buy/sell trade signal
# scale and super impose on top of candles
# used highest, instead of highestall() , so study wouldn't become complex. 
# len of 1000  causes signal to shift vertically at times
input show_trade_pulse_signal = yes;
plot zt = if show_trade_pulse_signal then (mid + (trade * (rng/8))) else na;
zt.AssignValueColor(if trade > 0 then color.green else color.red);
zt.setlineweight(2);

#

upper and lower studies
15kcWQx.jpg



=================================
=================================



lower study , for testing

bottom , cyan pulse signal, is buy/sell signal
top green line is long
top red line is short


Code:
# macd_mtf_buysell_00d_lower

# https://usethinkscript.com/threads/assemble-in-one-indicator-1-2-3-4-5-minutes-macds.13297/
#mtf macd  5 times
#main chart  arrows

#Chemmy
## Five-Timeframe Aggregate MACD for tonydl
## Coded by Chemmy for usethinkscript.com

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
input showline2 = no;
input showline3 = no;
input showline4 = no;
input showline5 = no;

## Aggregations
input agg1 = AggregationPeriod.MIN;
input agg2 = AggregationPeriod.TWO_MIN;
input agg3 = AggregationPeriod.THREE_MIN;
input agg4 = AggregationPeriod.FOUR_MIN;
input agg5 = AggregationPeriod.FIVE_MIN;

## Values and Averages
def Value1 = MovingAverage(averageType, close(period = agg1), fastLength) - MovingAverage(averageType, close(period = agg1), slowLength);
def Avg1 = MovingAverage(averageType, Value1, MACDLength);

def Value2 = MovingAverage(averageType, close(period = agg2), fastLength) - MovingAverage(averageType, close(period = agg2), slowLength);
def Avg2 = MovingAverage(averageType, Value1, MACDLength);

def Value3 = MovingAverage(averageType, close(period = agg3), fastLength) - MovingAverage(averageType, close(period = agg3), slowLength);
def Avg3 = MovingAverage(averageType, Value1, MACDLength);

def Value4 = MovingAverage(averageType, close(period = agg4), fastLength) - MovingAverage(averageType, close(period = agg4), slowLength);
def Avg4 = MovingAverage(averageType, Value1, MACDLength);

def Value5 = MovingAverage(averageType, close(period = agg5), fastLength) - MovingAverage(averageType, close(period = agg5), slowLength);
def Avg5 = MovingAverage(averageType, Value1, MACDLength);

## Diffs
def Diff1 = Value1 - Avg1;
def Diff2 = Value2 - Avg2;
def Diff3 = Value3 - Avg3;
def Diff4 = Value4 - Avg4;
def Diff5 = Value5 - Avg5;

#Diff1.SetHiding(!showline2);
#Diff2.SetHiding(!showline2);
#Diff3.SetHiding(!showline3);
#Diff4.SetHiding(!showline4);
#Diff5.SetHiding(!showline5);

def fulldiff = (Diff1 + Diff2 + Diff3 + Diff4 + Diff5) / 5;
def valavg = (Value1 + Value2 + Value3 + Value4 + Value5) / 5;
def fullavg = (Avg1 + Avg2 + Avg3 + Avg4 + Avg5) / 5;

def ZeroLine = 0;
## Signals
def UpSignal = if fulldiff crosses above ZeroLine then ZeroLine else Double.NaN;
def DownSignal = if fulldiff crosses below ZeroLine then ZeroLine else Double.NaN;

#UpSignal.SetHiding(!showBreakoutSignals);
#DownSignal.SetHiding(!showBreakoutSignals);
#valavg.SetDefaultColor(GetColor(1));
#fullavg.SetDefaultColor(GetColor(8));


#Diff1.SetDefaultColor(GetColor(5));
#Diff1.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Diff1.SetLineWeight(3);
#Diff1.DefineColor("Positive and Up", Color.GREEN);
#Diff1.DefineColor("Positive and Down", Color.DARK_GREEN);
#Diff1.DefineColor("Negative and Down", Color.RED);
#Diff1.DefineColor("Negative and Up", Color.DARK_RED);
#Diff1.AssignValueColor(if Diff1 >= 0 then if Diff1 > Diff1[1] then Diff1.Color("Positive and Up") else Diff1.Color("Positive and Down") else if Diff1 < Diff1[1] then Diff1.Color("Negative and Down") else Diff1.Color("Negative and Up"));

#fulldiff.SetDefaultColor(GetColor(5));
#fulldiff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#fulldiff.SetLineWeight(3);
#fulldiff.DefineColor("Positive and Up", Color.GREEN);
#fulldiff.DefineColor("Positive and Down", Color.DARK_GREEN);
#fulldiff.DefineColor("Negative and Down", Color.RED);
#fulldiff.DefineColor("Negative and Up", Color.DARK_RED);
#fulldiff.AssignValueColor(if fulldiff >= 0 then if fulldiff > fulldiff[1] then fulldiff.Color("Positive and Up") else fulldiff.Color("Positive and Down") else if fulldiff < fulldiff[1] then fulldiff.Color("Negative and Down") else fulldiff.Color("Negative and Up"));


#ZeroLine.SetDefaultColor(GetColor(0));
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#UpSignal.SetLineWeight(3);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#DownSignal.SetLineWeight(3);

#------------------------

def na = double.nan;
def bn = barnumber();

input back = 1;
def m1 = if value1 > value1[back] then 1
 else if value1 < value1[back] then -1
 else 0;
def m2 = if value2 > value2[back] then 1
 else if value2 < value2[back] then -1
 else 0;
def m3 = if value3 > value3[back] then 1
 else if value3 < value3[back] then -1
 else 0;
def m4 = if value4 > value4[back] then 1
 else if value4 < value4[back] then -1
 else 0;
def m5 = if value5 > value5[back] then 1
 else if value5 < value5[back] then -1
 else 0;


input exit = 3;
#def longclose = (m1 + m2 + m3 + m4 + m5 <= exit);
#def shortclose = (m1 + m2 + m3 + m4 + m5 >= -exit);
#def longopen = (m1 + m2 + m3 + m4 + m5 == 5);
#def shortopen = (m1 + m2 + m3 + m4 + m5 == -5);


# def longopen = (longopen[1] != 5) and (m1 + m2 + m3 + m4 + m5 == 5);

def msum = (m1 + m2 + m3 + m4 + m5);

def longclose = (msum[1] > exit) and (msum <= exit);
def shortclose = (msum[1] < -exit) and (msum >= -exit);
def longopen = (msum[1] != 5) and (msum == 5);
def shortopen = (msum[1] != -5) and (msum == -5);


# save a buy price level
# use to tell if in trade, >0
# compare value to close to see if trade is stopped for loss
# compare value to close to see if trade is stopped for gain

def longbuy = if bn == 1 then 0
else if longclose then 0
else if shortopen then 0
else if close < longbuy[1] * 0.999  then 0
else if close > (longbuy[1] * 1.02) then 0
else if longopen then close
else longbuy[1];

def shortbuy = if bn == 1 then 0
else if shortclose then 0
else if longopen then 0
else if close > shortbuy[1] * 1.001 then 0
else if close < (shortbuy[1] * 0.98 ) then 0
else if shortopen then close
else shortbuy[1];


def long = if bn == 1 then 0
else if longclose then 0
else if longopen then 1
else long[1];

def short = if bn == 1 then 0
else if shortclose then 0
else if shortopen then 1
else short[1];


# avg the long n short trades..  stretch them out ,  remove all the small blips
def trade = if bn ==1 then 0
 else if long then 1
 else if short then -1
 else trade[1];



#--------------------------------

# lower plots

#plot zm1 = m1;
#plot zm2 = m2+2.2;
#plot zm3 = m3+4.4;
#plot zm4 = m4+6.6;
#plot zm5 = m5+8.8;
plot r = 0;


plot y1 = longopen+12;
plot y2 = longclose+10;
plot y3 = shortopen+8;
plot y4 = shortclose+6;
y1.SetDefaultColor(Color.green);
y2.SetDefaultColor(Color.cyan);
y3.SetDefaultColor(Color.red);
y4.SetDefaultColor(Color.yellow);

plot k = 14;
k.SetDefaultColor(Color.white);
k.setlineweight(3);


input vertlines = no;
addverticalline(vertlines and longopen, "-" , color.green);
addverticalline(vertlines and longclose, "-" , color.red);
addverticalline(vertlines and shortopen, "-" , color.cyan);
addverticalline(vertlines and shortclose, "-" , color.yellow);


#plot b = if longbuy > 0 then longbuy else na;
#plot s = if shortbuy > 0 then shortbuy else na;

#plot z1 = value1;
#plot z2 = value2;
#plot z3 = value3;
#plot z4 = value4;
#plot z5 = value5;


addchartbubble(0, -6,
msum + "\n" +
long + " L\n" +
short + " S\n" +

longopen + " LO\n" +
longclose + " LC\n" +
shortopen + " SO\n" +
shortclose + " SC\n" 
, color.yellow, yes);


plot zl = long+18;
plot zs = short+16;
zl.SetDefaultColor(Color.green);
zs.SetDefaultColor(Color.red);

plot t = trade+2;
t.SetDefaultColor(Color.cyan);

plot u = 2;
u.SetDefaultColor(Color.white);
u.setlineweight(2);
#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
482 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top