I've gained a lot from this website in the shadows and figured I'd share this strategy I'm working on for opinions and/or suggestions.
This uses the halftrend indicator with added deviation bands I coded in. The conditions are fairly simple.
On the 5min 180day test it gets 1270 trades, a 2.3 profit factor and a pretty sweet equity curve that you should be able to see in the screenshot below.
This is a trend following strategy.
-----------
Click for image----------
Settings In use:
Price: Low
Amplitude: 20
Num dev dn: -4
num dev up: 4
stop mult: 0.5
-------------------------
Here's the strategy code:
#Trender
input Price = High;
input Amplitude = 25;
input Num_Dev_Dn = -17;
input Num_Dev_up = 17;
def lowpricei;
def highpricei;
def lowma;
def highma;
def barindex = BarNumber();
def nexttrend;
def maxlowprice;
def trend;
def minhighprice;
def up;
def down;
def halftrend;
lowpricei = Lowest(low, Amplitude);
highpricei = Highest(high, Amplitude);
lowma = Average(low, Amplitude);
highma = Average(high, Amplitude);
if barindex > Amplitude and
nexttrend[1] == 1
{
maxlowprice = Max(lowpricei, maxlowprice[1]);
trend = if highma < maxlowprice[1] and close < low[1]
then 1
else trend[1];
nexttrend = if highma < maxlowprice[1] and close < low[1]
then 0
else nexttrend[1];
minhighprice = if highma < maxlowprice[1] and close < low[1]
then highpricei
else minhighprice[1];
}
else if nexttrend[1] == 0
{
minhighprice = Min(highpricei, minhighprice[1]);
trend = if lowma > minhighprice[1] and close > high[1]
then 0
else trend[1];
nexttrend = if lowma > minhighprice[1] and close > high[1]
then 1
else nexttrend[1];
maxlowprice = if lowma > minhighprice[1] and close > high[1]
then lowpricei
else maxlowprice[1];
}
else
{
maxlowprice = maxlowprice[1];
trend = trend[1];
nexttrend = nexttrend[1];
minhighprice = minhighprice[1];
}
if trend == 0
{
up = if trend[1] <> 0
then down[1]
else Max(maxlowprice[1], up[1]);
down = 0;
}
else if trend[1] <> 1
{
down = up[1];
up = 0;# up[1] este era el error
}
else if trend == 1
{
down = Min(minhighprice, down[1]);
up = up[1];
}
else
{
up = up[1];
down = down[1];
}
if up > 0
{
halftrend = up;
}
else
{
halftrend = down;
}
plot MidLine = halftrend;
plot LowerBand = halftrend + Num_Dev_Dn;
plot UpperBand = halftrend + Num_Dev_up;
Midline.SetStyle(Curve.Firm);
midline.AssignValueColor(if up > 0 then color.Cyan else color.Red);
Midline.SetLineWeight(2);
AddOrder(OrderType.BUY_auto, Price crosses above midline and up, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");
AddOrder(OrderType.SELL_auto, Price crosses below lowerband, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");
AddOrder(OrderType.SELL_auto,Price crosses below midline and down, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");
AddOrder(OrderType.BUY_auto,Price crosses above upperband, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");
#STOP LOSS ATR
input stop_mult = 2.5;
def stopb = EntryPrice() - ATR() * stop_mult;
AddOrder(OrderType.SELL_to_close, CLOSE <= stopb, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = stopb);
def stops = EntryPrice() + ATR() * stop_mult;
AddOrder(OrderType.BUY_to_close, CLOSE >= stops, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = stops);