Bobbydigital83
Member
I enjoy this community. Have you ever been on the futures IO and/or TOS chat room? You cannot ask for anything without getting ripped to pieces or mocked because you forgot to cross your "t's." So thank you all for be a whole lot kinder than other forums.
First let me begin by saying, as a suggestion that if someone posts a successful strategy to this community then free lifetime VIP membership should be granted to the person who post/shares it. Include a special icon/badge too and hopefully others would want to contribute as well. Many strategies posted appear successful all over the internet but often end having terrible repaint issues. People posting a successful strategy is very very rare.
So what I have here is simple Volatility Stop Strategy where the entry will not repaint on you. I grabbed the Volatility Stop code from here and played around with it and I am making my contribution. This is for a 100 tick chart on /EMD with the afterhours turned OFF. It can also work on the 1 min but it will whipsaw a little more.
Attached is the view of the chart along with the settings. P&L is set to 1 contract of /EMD.
It has been proving successful during these volatile times so hopefully it plays out nicely for the time being. Thank you!
First let me begin by saying, as a suggestion that if someone posts a successful strategy to this community then free lifetime VIP membership should be granted to the person who post/shares it. Include a special icon/badge too and hopefully others would want to contribute as well. Many strategies posted appear successful all over the internet but often end having terrible repaint issues. People posting a successful strategy is very very rare.
So what I have here is simple Volatility Stop Strategy where the entry will not repaint on you. I grabbed the Volatility Stop code from here and played around with it and I am making my contribution. This is for a 100 tick chart on /EMD with the afterhours turned OFF. It can also work on the 1 min but it will whipsaw a little more.
Attached is the view of the chart along with the settings. P&L is set to 1 contract of /EMD.
It has been proving successful during these volatile times so hopefully it plays out nicely for the time being. Thank you!
Code:
#
input mult = 3.0; #Multiple of Average True Range to use
input length = 10; #Average True Range period
#
# Input to select Close or High/Low for switching:
#
input Style={default Close, HighLow};
def type;
switch(Style){
case Close:
type=1;
case HighLow:
type=0;
}
#
# Set parameters based on switch selection:
#
def uu=if type then close else high;
def ll=if type then close else low;
def na=double.nan;
#
# Calculate average range for volatility:
#
def atr = expaverage(high-low,length);
#
# Calculate initial short and long volatility stop values:
#
def svs =low+ceil(mult*atr/ticksize())*ticksize();
def lvs =high-ceil(mult*atr/ticksize())*ticksize();
#
# Set up the trailing stop logic:
#
rec shortvs=if isnan(shortvs[1]) then svs else if uu>shortvs[1] then svs else min(svs,shortvs[1]);
rec longvs=if isnan(longvs[1]) then lvs else if ll<longvs[1] then lvs else max(lvs,longvs[1]);
#
# Detect if we breached the trailing stop (close or high/low):
#
def longswitch=if uu>=shortvs[1] and uu[1]<shortvs[1] then 1 else 0;
def shortswitch=if ll<=longvs[1] and ll[1]>longvs[1] then 1 else 0;
#
# This logic remembers the direction and changes when needed:
#
rec direction= compoundvalue(1,if isnan(direction[1]) then 0 else
if direction[1]<=0 and longswitch then 1
else if direction[1]>=0 and shortswitch then -1
else direction[1],0);
#
# Set up the two plots. "na" makes the current value disappear
# if we?re trading in the opposite direction:
#
plot short=if direction>0 then na else shortvs;
plot long=if direction<0 then na else longvs;
#addlabel(yes,"Short", if short then color.green else color.red);
#
# Formatting:
#
long.SetDefaultColor(color.magenta);
long.SetStyle(curve.points);
long.SetLineWeight(2);
short.SetDefaultColor(color.red);
short.SetStyle(curve.points);
short.SetLineWeight(2);
#
# Alerts:
#
def alerttrigger= if direction[1]<=0 and longswitch then 1
else if direction[1]>=0 and shortswitch then 1 else 0;
input alerttext="Alert Text";
# BLOCK CODE BELOW
#input UseAlerts = {false, default true};
#input AlertType = {default "BAR", "ONCE", "TICK"};
#def at=AlertType;
#input AlertSound = {"Bell", "Chimes", default "Ding", #"NoSound", "Ring"};
#alert(alerttrigger AND UseAlerts, alerttext, if at==1 then #Alert.ONCE else if at==2 then Alert.TICK else Alert.BAR, #AlertSound);
AddOrder(OrderType.BUY_AUTO,longswitch is true, close[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "LONG");
AddOrder(OrderType.SELL_AUTO, shortswitch is true, close [-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "SHORT");
Last edited: