combine 2 indicators for 3 EMA crossover

merc2226

Member
VIP
Hello, my strategy is a basic ema cross but with Emma's stacked in the direction of the trade.

9 ema above 13 ema above 100 ema then go long, if they are all stacked on the short side, then go short.

can someone combine these 2 scripts that would then produce the arrow when the above lines up. Now the arrow and trade zone happens with a 9 and 100 cross over, it is missing the ema stacked part with the third ema.

Thank you

Screenshot 2024-11-24 at 10.47.18 AM.png

#
# Trade Lines
# v1.0 by @mark.917
#

# Trade Lines will plot lines with and optional cloud showing where you entered your
# position and the location of your stop loss and profit target.
#
# To use, your code will need to set "your_buy_signal" or "your_sell_signal" to true.
# The profit target and stop loss are based on an ATR multplier. You may modify this
# to be whatever you would like.

declare upper;

#######################
# YOUR CODE STARTS HERE
#######################

# sample using moving average crossover for signals
Input FastMaLength = 5;
Input SlowMaLength = 50;

def FastMA = MovingAverage(AverageType.EXPONENTIAL, close, FastMaLength);
def SlowMA = MovingAverage(AverageType.EXPONENTIAL, close, SlowMaLength);

plot fastMAPlot = FastMA;
fastMAPlot.SetDefaultColor(GetColor(1));

plot slowMAPlot = SlowMA;
slowMAPlot.SetDefaultColor(GetColor(2));

def buy_signal = FastMA crosses above SlowMA;
def sell_signal = FastMA crosses below SlowMA;

###################
# BEGIN TRADE LINES
###################

input show_trade_zone = yes;
input calc_mode = {default fixed, atr}; #hint mode: Select fixed values or atr values for target and stop levels.
input ATRTargetMultiple = 2.5;
input ATRStopMultiple = 1.5;
input FixedTarget = 1.50;
input FixedStop = .75;

def atr = ATR(14, AverageType.EXPONENTIAL);

def target;
def stop;
switch (calc_mode) {
case atr:
target = atr * ATRTargetMultiple;
stop = atr * ATRStopMultiple;
case fixed:
target = FixedTarget;
stop = FixedStop;
}

def long_signal = if buy_signal then 1 else 0;
def long_target = if long_signal == 1 then target else long_target[1];
def long_stop = if long_signal == 1 then stop else long_stop[1];
def long_entry = if long_signal == 1 then open else if (high[1] > long_entry[1] + long_target or low[1] < long_entry[1] - long_stop) then Double.NaN else long_entry[1];
def long_exit = if long_entry > 0 then 0 else 1;

plot long_pt = if show_trade_zone and !long_exit then long_entry + long_target else Double.NaN;
long_pt.SetDefaultColor(Color.GREEN);
plot long_ep = if show_trade_zone and !long_exit then long_entry else Double.NaN;
long_ep.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
long_ep.SetDefaultColor(Color.WHITE);
plot long_sl = if show_trade_zone and !long_exit then long_ep - long_stop else Double.NaN;
long_sl.SetDefaultColor(Color.RED);

#AddCloud(if show_trade_zone then long_pt else Double.NaN, long_ep, Color.GREEN);
#AddCloud(if show_trade_zone then long_sl else Double.NaN, long_ep, Color.RED);

def short_signal = if sell_signal then 1 else 0;
def short_target = if short_signal == 1 then target else short_target[1];
def short_stop = if short_signal == 1 then stop else short_stop[1];
def short_entry = if short_signal == 1 then open else if (low[1] < short_entry[1] - short_target or high[1] > short_entry[1] + short_stop) then Double.NaN else short_entry[1];
def short_exit = if short_entry > 0 then 0 else 1;

plot short_pt = if show_trade_zone and !short_exit then short_entry - short_target else Double.NaN;
short_pt.SetDefaultColor(Color.GREEN);
plot short_ep = if show_trade_zone and !short_exit then short_entry else Double.NaN;
short_ep.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
short_ep.SetDefaultColor(Color.WHITE);
plot short_sl = if show_trade_zone and !short_exit then short_ep + short_stop else Double.NaN;
short_sl.SetDefaultColor(Color.RED);

#AddCloud(if show_trade_zone then short_pt else Double.NaN, short_ep, Color.GREEN);
#AddCloud(if show_trade_zone then short_sl else Double.NaN, short_ep, Color.RED);

#################
# END TRADE LINES
#################
#AddOrder(OrderType.BUY_AUTO, FastMA crosses above SlowMA[1]);
#AddOrder(OrderType.SELL_AUTO, FastMA crosses below SlowMA[1]);;

--------------------------------------------------------------------------------------------------------------------------------------------------

# Multi-Timeframe ElvisTrend
# Copyright (C) 2023 darkelvis twitter.com/TheOGdarkelvis
# Indicator uses a set of stacked moving averages to identify trend. Stacked low to high should indicate an uptrend, stacked high to low should indicate a downtrend, when moving averages are not stacked there is no trend. Green indicates bullish, red for bearish, and yellow for no trend.

declare lower;

##Settings

input AvgType = averageType.EXPONENTIAL;
input Fast_MA = 8;
input Mid_MA = 13;
input Slow_MA = 21;
input Show_Labels = yes;
input Timeframe = aggregationPeriod.HOUR;

##Calculations

def price = close;
def FastValue = MovingAverage(AvgType, close(period=Timeframe),Fast_MA);
def MidValue = MovingAverage(AvgType, close(period=Timeframe), Mid_MA);
def SlowValue = MovingAverage(AvgType, close(period=Timeframe), Slow_MA);
def bullish = FastValue >= MidValue AND MidValue >= SlowValue;
def bearish = FastValue <= MidValue AND MidValue <= SlowValue;
def no_trend = FastValue >= MidValue and MidValue <= SlowValue or FastValue <= MidValue and MidValue >= SlowValue;

##Label

#AddLabel(Show_Labels, If bullish then "LONG ONLY" else "", if bullish then color.green else color.black);
#AddLabel(Show_Labels, If bearish then "SHORT ONLY" else "", if bearish then color.red else color.black);
#AddLabel(Show_Labels, If no_trend then "SIT ON YOUR HANDS" else "", if no_trend then color.yellow else color.black);

##Background cloud

AddCloud(if bullish then Double.POSITIVE_INFINITY else Double.NaN,if bullish then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if bearish then Double.POSITIVE_INFINITY else Double.NaN,if bearish then Double.NEGATIVE_INFINITY else Double.NaN, Color.PINK);
AddCloud(if no_trend then Double.POSITIVE_INFINITY else Double.NaN,if no_trend then Double.NEGATIVE_INFINITY else Double.NaN, Color.YELLOW);

##Color Candles

AssignPriceColor(if bullish then color.GREEN else if bearish then color.RED else color.yellow);
 
Solution
Hello, my strategy is a basic ema cross but with Emma's stacked in the direction of the trade.

9 ema above 13 ema above 100 ema then go long, if they are all stacked on the short side, then go short.

can someone combine these 2 scripts that would then produce the arrow when the above lines up. Now the arrow and trade zone happens with a 9 and 100 cross over, it is missing the ema stacked part with the third ema.

Thank you

View attachment 23409
#
# Trade Lines
# v1.0 by @mark.917
#

# Trade Lines will plot lines with and optional cloud showing where you entered your
# position and the location of your stop loss and profit target.
#
# To use, your code will need to set "your_buy_signal" or "your_sell_signal" to true.
# The profit...
Hello, my strategy is a basic ema cross but with Emma's stacked in the direction of the trade.

9 ema above 13 ema above 100 ema then go long, if they are all stacked on the short side, then go short.

can someone combine these 2 scripts that would then produce the arrow when the above lines up. Now the arrow and trade zone happens with a 9 and 100 cross over, it is missing the ema stacked part with the third ema.

Thank you

View attachment 23409
#
# Trade Lines
# v1.0 by @mark.917
#

# Trade Lines will plot lines with and optional cloud showing where you entered your
# position and the location of your stop loss and profit target.
#
# To use, your code will need to set "your_buy_signal" or "your_sell_signal" to true.
# The profit target and stop loss are based on an ATR multplier. You may modify this
# to be whatever you would like.

declare upper;

#######################
# YOUR CODE STARTS HERE
#######################

# sample using moving average crossover for signals
Input FastMaLength = 5;
Input SlowMaLength = 50;

def FastMA = MovingAverage(AverageType.EXPONENTIAL, close, FastMaLength);
def SlowMA = MovingAverage(AverageType.EXPONENTIAL, close, SlowMaLength);

plot fastMAPlot = FastMA;
fastMAPlot.SetDefaultColor(GetColor(1));

plot slowMAPlot = SlowMA;
slowMAPlot.SetDefaultColor(GetColor(2));

def buy_signal = FastMA crosses above SlowMA;
def sell_signal = FastMA crosses below SlowMA;

###################
# BEGIN TRADE LINES
###################

input show_trade_zone = yes;
input calc_mode = {default fixed, atr}; #hint mode: Select fixed values or atr values for target and stop levels.
input ATRTargetMultiple = 2.5;
input ATRStopMultiple = 1.5;
input FixedTarget = 1.50;
input FixedStop = .75;

def atr = ATR(14, AverageType.EXPONENTIAL);

def target;
def stop;
switch (calc_mode) {
case atr:
target = atr * ATRTargetMultiple;
stop = atr * ATRStopMultiple;
case fixed:
target = FixedTarget;
stop = FixedStop;
}

def long_signal = if buy_signal then 1 else 0;
def long_target = if long_signal == 1 then target else long_target[1];
def long_stop = if long_signal == 1 then stop else long_stop[1];
def long_entry = if long_signal == 1 then open else if (high[1] > long_entry[1] + long_target or low[1] < long_entry[1] - long_stop) then Double.NaN else long_entry[1];
def long_exit = if long_entry > 0 then 0 else 1;

plot long_pt = if show_trade_zone and !long_exit then long_entry + long_target else Double.NaN;
long_pt.SetDefaultColor(Color.GREEN);
plot long_ep = if show_trade_zone and !long_exit then long_entry else Double.NaN;
long_ep.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
long_ep.SetDefaultColor(Color.WHITE);
plot long_sl = if show_trade_zone and !long_exit then long_ep - long_stop else Double.NaN;
long_sl.SetDefaultColor(Color.RED);

#AddCloud(if show_trade_zone then long_pt else Double.NaN, long_ep, Color.GREEN);
#AddCloud(if show_trade_zone then long_sl else Double.NaN, long_ep, Color.RED);

def short_signal = if sell_signal then 1 else 0;
def short_target = if short_signal == 1 then target else short_target[1];
def short_stop = if short_signal == 1 then stop else short_stop[1];
def short_entry = if short_signal == 1 then open else if (low[1] < short_entry[1] - short_target or high[1] > short_entry[1] + short_stop) then Double.NaN else short_entry[1];
def short_exit = if short_entry > 0 then 0 else 1;

plot short_pt = if show_trade_zone and !short_exit then short_entry - short_target else Double.NaN;
short_pt.SetDefaultColor(Color.GREEN);
plot short_ep = if show_trade_zone and !short_exit then short_entry else Double.NaN;
short_ep.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
short_ep.SetDefaultColor(Color.WHITE);
plot short_sl = if show_trade_zone and !short_exit then short_ep + short_stop else Double.NaN;
short_sl.SetDefaultColor(Color.RED);

#AddCloud(if show_trade_zone then short_pt else Double.NaN, short_ep, Color.GREEN);
#AddCloud(if show_trade_zone then short_sl else Double.NaN, short_ep, Color.RED);

#################
# END TRADE LINES
#################
#AddOrder(OrderType.BUY_AUTO, FastMA crosses above SlowMA[1]);
#AddOrder(OrderType.SELL_AUTO, FastMA crosses below SlowMA[1]);;

--------------------------------------------------------------------------------------------------------------------------------------------------

# Multi-Timeframe ElvisTrend
# Copyright (C) 2023 darkelvis twitter.com/TheOGdarkelvis
# Indicator uses a set of stacked moving averages to identify trend. Stacked low to high should indicate an uptrend, stacked high to low should indicate a downtrend, when moving averages are not stacked there is no trend. Green indicates bullish, red for bearish, and yellow for no trend.

declare lower;

##Settings

input AvgType = averageType.EXPONENTIAL;
input Fast_MA = 8;
input Mid_MA = 13;
input Slow_MA = 21;
input Show_Labels = yes;
input Timeframe = aggregationPeriod.HOUR;

##Calculations

def price = close;
def FastValue = MovingAverage(AvgType, close(period=Timeframe),Fast_MA);
def MidValue = MovingAverage(AvgType, close(period=Timeframe), Mid_MA);
def SlowValue = MovingAverage(AvgType, close(period=Timeframe), Slow_MA);
def bullish = FastValue >= MidValue AND MidValue >= SlowValue;
def bearish = FastValue <= MidValue AND MidValue <= SlowValue;
def no_trend = FastValue >= MidValue and MidValue <= SlowValue or FastValue <= MidValue and MidValue >= SlowValue;

##Label

#AddLabel(Show_Labels, If bullish then "LONG ONLY" else "", if bullish then color.green else color.black);
#AddLabel(Show_Labels, If bearish then "SHORT ONLY" else "", if bearish then color.red else color.black);
#AddLabel(Show_Labels, If no_trend then "SIT ON YOUR HANDS" else "", if no_trend then color.yellow else color.black);

##Background cloud

AddCloud(if bullish then Double.POSITIVE_INFINITY else Double.NaN,if bullish then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if bearish then Double.POSITIVE_INFINITY else Double.NaN,if bearish then Double.NEGATIVE_INFINITY else Double.NaN, Color.PINK);
AddCloud(if no_trend then Double.POSITIVE_INFINITY else Double.NaN,if no_trend then Double.NEGATIVE_INFINITY else Double.NaN, Color.YELLOW);

##Color Candles

AssignPriceColor(if bullish then color.GREEN else if bearish then color.RED else color.yellow);

not sure what '2' scripts you are talking about.
you mentioned averages, then post a really long code that you don't even talk about?

i replaced your 2 average codes with 3, and set them as exponential.

added these lines to send signals to your code.
def buy_signal = buy1;
def sell_signal = sell1;

i didn't touch anything after that


Code:
#combine_avgs_atr_
#https://usethinkscript.com/threads/combine-2-indicators.20043/
#combine 2 indicators
# Trade Lines
# v1.0 by @mark.917
#

# Trade Lines will plot lines with and optional cloud showing where you entered your
# position and the location of your stop loss and profit target.
#
# To use, your code will need to set "your_buy_signal" or "your_sell_signal" to true.
# The profit target and stop loss are based on an ATR multplier. You may modify this
# to be whatever you would like.

declare upper;

#######################
# YOUR CODE STARTS HERE

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

input avg1_type = AverageType.exponential;
input avg1_length = 9;
def avg1 = MovingAverage(avg1_type, data, avg1_length );

input avg2_type = AverageType.exponential;
input avg2_length = 13;
def avg2 = MovingAverage(avg2_type, data, avg2_length );

input avg3_type = AverageType.exponential;
input avg3_length = 100;
def avg3 = MovingAverage(avg3_type, data, avg3_length );

input show_lines = yes;
plot zavg1 = if show_lines then avg1 else na;
plot zavg2 = if show_lines then avg2 else na;
plot zavg3 = if show_lines then avg3 else na;

zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();

zavg2.SetDefaultColor(Color.yellow);
zavg2.setlineweight(1);
zavg2.hidebubble();

zavg3.SetDefaultColor(Color.magenta);
zavg3.setlineweight(1);
zavg3.hidebubble();


def up = avg1 > avg2 and avg2 > avg3;
def dwn = avg1 < avg2 and avg2 < avg3;

def buy1 = up and !up[1];
def sell1 = dwn and !dwn[1];


addlabel(1, "  ", color.black);

addlabel(1,
(if avg1_type == AverageType.Simple then "SMA"
 else if avg1_type == AverageType.exponential then "EMA"
 else if avg1_type == AverageType.hull then "HULL"
 else if avg1_type == AverageType.weighted then "WT"
 else if avg1_type == AverageType.wilders then "WILD"
 else "---") + avg1_length
, color.cyan);

addlabel(1,
(if avg2_type == AverageType.Simple then "SMA"
 else if avg2_type == AverageType.exponential then "EMA"
 else if avg2_type == AverageType.hull then "HULL"
 else if avg2_type == AverageType.weighted then "WT"
 else if avg2_type == AverageType.wilders then "WILD"
 else "---") + avg2_length
, color.yellow);

addlabel(1,
(if avg3_type == AverageType.Simple then "SMA"
 else if avg3_type == AverageType.exponential then "EMA"
 else if avg3_type == AverageType.hull then "HULL"
 else if avg3_type == AverageType.weighted then "WT"
 else if avg3_type == AverageType.wilders then "WILD"
 else "---") + avg3_length
, color.magenta);

addlabel(1, "  ", color.black);


#######################

# sample using moving average crossover for signals
#Input FastMaLength = 5;
#Input SlowMaLength = 50;
#def FastMA = MovingAverage(AverageType.EXPONENTIAL, close, FastMaLength);
#def SlowMA = MovingAverage(AverageType.EXPONENTIAL, close, SlowMaLength);
#plot fastMAPlot = FastMA;
#fastMAPlot.SetDefaultColor(GetColor(1));
#plot slowMAPlot = SlowMA;
#slowMAPlot.SetDefaultColor(GetColor(2));
#def buy_signal = FastMA crosses above SlowMA;
#def sell_signal = FastMA crosses below SlowMA;

###################
# BEGIN TRADE LINES


def buy_signal = buy1;
def sell_signal = sell1;




###################

input show_trade_zone = yes;
input calc_mode = {default fixed, atr}; #hint mode: Select fixed values or atr values for target and stop levels.
input ATRTargetMultiple = 2.5;
input ATRStopMultiple = 1.5;
input FixedTarget = 1.50;
input FixedStop = .75;

def atr = ATR(14, AverageType.EXPONENTIAL);

def target;
def stop;
switch (calc_mode) {
case atr:
target = atr * ATRTargetMultiple;
stop = atr * ATRStopMultiple;
case fixed:
target = FixedTarget;
stop = FixedStop;
}

def long_signal = if buy_signal then 1 else 0;
def long_target = if long_signal == 1 then target else long_target[1];
def long_stop = if long_signal == 1 then stop else long_stop[1];
def long_entry = if long_signal == 1 then open else if (high[1] > long_entry[1] + long_target or low[1] < long_entry[1] - long_stop) then Double.NaN else long_entry[1];
def long_exit = if long_entry > 0 then 0 else 1;

plot long_pt = if show_trade_zone and !long_exit then long_entry + long_target else Double.NaN;
long_pt.SetDefaultColor(Color.GREEN);
plot long_ep = if show_trade_zone and !long_exit then long_entry else Double.NaN;
long_ep.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
long_ep.SetDefaultColor(Color.WHITE);
plot long_sl = if show_trade_zone and !long_exit then long_ep - long_stop else Double.NaN;
long_sl.SetDefaultColor(Color.RED);

#AddCloud(if show_trade_zone then long_pt else Double.NaN, long_ep, Color.GREEN);
#AddCloud(if show_trade_zone then long_sl else Double.NaN, long_ep, Color.RED);

def short_signal = if sell_signal then 1 else 0;
def short_target = if short_signal == 1 then target else short_target[1];
def short_stop = if short_signal == 1 then stop else short_stop[1];
def short_entry = if short_signal == 1 then open else if (low[1] < short_entry[1] - short_target or high[1] > short_entry[1] + short_stop) then Double.NaN else short_entry[1];
def short_exit = if short_entry > 0 then 0 else 1;

plot short_pt = if show_trade_zone and !short_exit then short_entry - short_target else Double.NaN;
short_pt.SetDefaultColor(Color.GREEN);
plot short_ep = if show_trade_zone and !short_exit then short_entry else Double.NaN;
short_ep.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
short_ep.SetDefaultColor(Color.WHITE);
plot short_sl = if show_trade_zone and !short_exit then short_ep + short_stop else Double.NaN;
short_sl.SetDefaultColor(Color.RED);

#AddCloud(if show_trade_zone then short_pt else Double.NaN, short_ep, Color.GREEN);
#AddCloud(if show_trade_zone then short_sl else Double.NaN, short_ep, Color.RED);

#################
# END TRADE LINES
#################
#AddOrder(OrderType.BUY_AUTO, FastMA crosses above SlowMA[1]);
#AddOrder(OrderType.SELL_AUTO, FastMA crosses below SlowMA[1]);;



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


# Multi-Timeframe ElvisTrend
# Copyright (C) 2023 darkelvis twitter.com/TheOGdarkelvis
# Indicator uses a set of stacked moving averages to identify trend. Stacked low to high should indicate an uptrend, stacked high to low should indicate a downtrend, when moving averages are not stacked there is no trend. Green indicates bullish, red for bearish, and yellow for no trend.

#declare lower;

##Settings

input AvgType = averageType.EXPONENTIAL;
input Fast_MA = 8;
input Mid_MA = 13;
input Slow_MA = 21;
input Show_Labels = yes;
input Timeframe = aggregationPeriod.HOUR;

##Calculations

def price = close;
def FastValue = MovingAverage(AvgType, close(period=Timeframe),Fast_MA);
def MidValue = MovingAverage(AvgType, close(period=Timeframe), Mid_MA);
def SlowValue = MovingAverage(AvgType, close(period=Timeframe), Slow_MA);
def bullish = FastValue >= MidValue AND MidValue >= SlowValue;
def bearish = FastValue <= MidValue AND MidValue <= SlowValue;
def no_trend = FastValue >= MidValue and MidValue <= SlowValue or FastValue <= MidValue and MidValue >= SlowValue;

##Label

#AddLabel(Show_Labels, If bullish then "LONG ONLY" else "", if bullish then color.green else color.black);
#AddLabel(Show_Labels, If bearish then "SHORT ONLY" else "", if bearish then color.red else color.black);
#AddLabel(Show_Labels, If no_trend then "SIT ON YOUR HANDS" else "", if no_trend then color.yellow else color.black);

##Background cloud

AddCloud(if bullish then Double.POSITIVE_INFINITY else Double.NaN,if bullish then Double.NEGATIVE_INFINITY else Double.NaN, Color.LIGHT_GREEN);
AddCloud(if bearish then Double.POSITIVE_INFINITY else Double.NaN,if bearish then Double.NEGATIVE_INFINITY else Double.NaN, Color.PINK);
AddCloud(if no_trend then Double.POSITIVE_INFINITY else Double.NaN,if no_trend then Double.NEGATIVE_INFINITY else Double.NaN, Color.YELLOW);

##Color Candles

AssignPriceColor(if bullish then color.GREEN else if bearish then color.RED else color.yellow);
#
 

Attachments

  • img1.JPG
    img1.JPG
    51.5 KB · Views: 69
Solution

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

I didn't explain this well enough, I'm sorry.

This is a 2 ema cross over, what i'm looking for is a 3 ema crossover.

A trade is opened when the 5 ema, is above the 21 ema which is above the 50 ema after the candle closes.

the same is true on the short side just below the emas and stacked.

A trade is only opened after the 5 and 50 ema cross and the above is true, it doesn't produce a signal every time they become stacked.

Can you help me with this?


#
# Trade Lines
# v1.0 by @mark.917
#

# Trade Lines will plot lines with and optional cloud showing where you entered your
# position and the location of your stop loss and profit target.
#
# To use, your code will need to set "your_buy_signal" or "your_sell_signal" to true.
# The profit target and stop loss are based on an ATR multplier. You may modify this
# to be whatever you would like.

declare upper;

#######################
# YOUR CODE STARTS HERE
#######################

# sample using moving average crossover for signals
Input FastMaLength = 5;
Input SlowMaLength = 50;

def FastMA = MovingAverage(AverageType.EXPONENTIAL, close, FastMaLength);
def SlowMA = MovingAverage(AverageType.EXPONENTIAL, close, SlowMaLength);

plot fastMAPlot = FastMA;
fastMAPlot.SetDefaultColor(GetColor(1));

plot slowMAPlot = SlowMA;
slowMAPlot.SetDefaultColor(GetColor(2));

def buy_signal = FastMA crosses above SlowMA;
def sell_signal = FastMA crosses below SlowMA;

###################
# BEGIN TRADE LINES
###################

input show_trade_zone = yes;
input calc_mode = {default fixed, atr}; #hint mode: Select fixed values or atr values for target and stop levels.
input ATRTargetMultiple = 2.5;
input ATRStopMultiple = 1.5;
input FixedTarget = 1.50;
input FixedStop = .75;

def atr = ATR(14, AverageType.EXPONENTIAL);

def target;
def stop;
switch (calc_mode) {
case atr:
target = atr * ATRTargetMultiple;
stop = atr * ATRStopMultiple;
case fixed:
target = FixedTarget;
stop = FixedStop;
}

def long_signal = if buy_signal then 1 else 0;
def long_target = if long_signal == 1 then target else long_target[1];
def long_stop = if long_signal == 1 then stop else long_stop[1];
def long_entry = if long_signal == 1 then open else if (high[1] > long_entry[1] + long_target or low[1] < long_entry[1] - long_stop) then Double.NaN else long_entry[1];
def long_exit = if long_entry > 0 then 0 else 1;

plot long_pt = if show_trade_zone and !long_exit then long_entry + long_target else Double.NaN;
long_pt.SetDefaultColor(Color.GREEN);
plot long_ep = if show_trade_zone and !long_exit then long_entry else Double.NaN;
long_ep.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
long_ep.SetDefaultColor(Color.WHITE);
plot long_sl = if show_trade_zone and !long_exit then long_ep - long_stop else Double.NaN;
long_sl.SetDefaultColor(Color.RED);

#AddCloud(if show_trade_zone then long_pt else Double.NaN, long_ep, Color.GREEN);
#AddCloud(if show_trade_zone then long_sl else Double.NaN, long_ep, Color.RED);

def short_signal = if sell_signal then 1 else 0;
def short_target = if short_signal == 1 then target else short_target[1];
def short_stop = if short_signal == 1 then stop else short_stop[1];
def short_entry = if short_signal == 1 then open else if (low[1] < short_entry[1] - short_target or high[1] > short_entry[1] + short_stop) then Double.NaN else short_entry[1];
def short_exit = if short_entry > 0 then 0 else 1;

plot short_pt = if show_trade_zone and !short_exit then short_entry - short_target else Double.NaN;
short_pt.SetDefaultColor(Color.GREEN);
plot short_ep = if show_trade_zone and !short_exit then short_entry else Double.NaN;
short_ep.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
short_ep.SetDefaultColor(Color.WHITE);
plot short_sl = if show_trade_zone and !short_exit then short_ep + short_stop else Double.NaN;
short_sl.SetDefaultColor(Color.RED);

AddCloud(if show_trade_zone then short_pt else Double.NaN, short_ep, Color.GREEN);
AddCloud(if show_trade_zone then short_sl else Double.NaN, short_ep, Color.RED);

#################
# END TRADE LINES
#################
#AddOrder(OrderType.BUY_AUTO, FastMA crosses above SlowMA[1]);
#AddOrder(OrderType.SELL_AUTO, FastMA crosses below SlowMA[1]);;
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
331 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