WildTiger99
New member
I have a strategy that is quite simple; basically when close crosses (a moving average), I tell the strat to get long. I then code the script to exit out four bars later (weekly or daily). As I'm viewing the chart, every position exits out the position four bars forward, except the last trade either exits out six bars later (XLE) or doesn't exit out at all for another ticker (OIH).
Basic strat: Close crosses above LRadjEMA, get long. Exit the strat after four bars (Bar_numbers). Using weekly charts. XLE or OIH.
I hope someone is out there able to provide an answer, and many thanks in advance!!
[/CODE]
XLE weekly (image of the XLE weekly w/strat)
Basic strat: Close crosses above LRadjEMA, get long. Exit the strat after four bars (Bar_numbers). Using weekly charts. XLE or OIH.
I hope someone is out there able to provide an answer, and many thanks in advance!!
Code:
[code]
#The Linear Regression-adjusted EMA strategy
#TASC's September 2022 edition of Traders' Tips includes an article by Vitali Apirine titled "The Linear Regression-Adjusted Exponential Moving Average". This script implements the titular indicator presented in this article.
input price = close;
#LRadjEMA
#input price = close;
input length = 50;
input lrLength = 50;
input highLowLength = 50;
input multiplier = 3;
def lr = Inertia(price, lrLength);
def dist = AbsValue(price - lr);
def maxDist = Highest(dist, highLowLength);
def minDist = Lowest(dist, highLowLength);
def multiplier1 = 2 / (length + 1);
def multiplier2 = multiplier * ((dist - minDist) / (maxDist - minDist));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (price - ma[1]), Average(price, length));
plot LRAdjEMA = ma;
LRAdjEMA.SetDefaultColor(GetColor(1));
#condition
def condition = price crosses above LRAdjEMA;
#define entry
def entryPrice = EntryPrice();
def long1 = condition;
#define how to exit the strategy
input exit_type = {default Percentage, Combo, Bar_numbers};
plot exit1;
#count number of bars from long1 entry point
def count = if long1[1] then 1 else count[1] + 1;
input percentage_exit = 1.20;
input percentage_below_entry = .80;
input Bar_numbers = 4;
def a = percentage_below_entry;
switch (exit_type) {
case Percentage:
exit1 = close > ((percentage_exit) * entryPrice);
case Combo:
exit1 = close > ((percentage_exit) * entryPrice) or close is less than entryPrice * a;
case Bar_numbers:
exit1 = count == Bar_numbers;
}
AddOrder(OrderType.BUY_TO_OPEN, long1, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "LRadjEMA_long");
AddOrder(OrderType.SELL_TO_CLOSE, exit1, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LRadjEMA_exit");
XLE weekly (image of the XLE weekly w/strat)
I have a strategy that is quite simple; basically when close crosses (a moving average), I tell the strat to get long. I then code the script to exit out four bars later (weekly or daily). As I'm viewing the chart, every position exits out the position four bars forward, except the last trade either exits out six bars later (XLE) or doesn't exit out at all for another ticker (OIH).
Basic strat: Close crosses above LRadjEMA, get long. Exit the strat after four bars (Bar_numbers). Using weekly charts. XLE or OIH.
I hope someone is out there able to provide an answer, and many thanks in advance!!
[/CODE]Code:[code] #The Linear Regression-adjusted EMA strategy #TASC's September 2022 edition of Traders' Tips includes an article by Vitali Apirine titled "The Linear Regression-Adjusted Exponential Moving Average". This script implements the titular indicator presented in this article. input price = close; #LRadjEMA #input price = close; input length = 50; input lrLength = 50; input highLowLength = 50; input multiplier = 3; def lr = Inertia(price, lrLength); def dist = AbsValue(price - lr); def maxDist = Highest(dist, highLowLength); def minDist = Lowest(dist, highLowLength); def multiplier1 = 2 / (length + 1); def multiplier2 = multiplier * ((dist - minDist) / (maxDist - minDist)); def alpha = multiplier1 * (1 + multiplier2); def ma = CompoundValue(1, ma[1] + alpha * (price - ma[1]), Average(price, length)); plot LRAdjEMA = ma; LRAdjEMA.SetDefaultColor(GetColor(1)); #condition def condition = price crosses above LRAdjEMA; #define entry def entryPrice = EntryPrice(); def long1 = condition; #define how to exit the strategy input exit_type = {default Percentage, Combo, Bar_numbers}; plot exit1; #count number of bars from long1 entry point def count = if long1[1] then 1 else count[1] + 1; input percentage_exit = 1.20; input percentage_below_entry = .80; input Bar_numbers = 4; def a = percentage_below_entry; switch (exit_type) { case Percentage: exit1 = close > ((percentage_exit) * entryPrice); case Combo: exit1 = close > ((percentage_exit) * entryPrice) or close is less than entryPrice * a; case Bar_numbers: exit1 = count == Bar_numbers; } AddOrder(OrderType.BUY_TO_OPEN, long1, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "LRadjEMA_long"); AddOrder(OrderType.SELL_TO_CLOSE, exit1, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "LRadjEMA_exit");
Last edited: