SuperTrend CCI ATR Trend for ThinkorSwim

T

tomsk

Well-known member
VIP
There was a request yesterday from @blakecmathis to add buy/sell signals on the following study which essentially is a combined study of SuperTrend together with CCI ATR Trend. That study originated from a user called DTEK on 8.10.2019 and was based on Mobius original work several years ago.

https://tos.mx/dDZh6eC
It looked really promising (as most strudies from Mobius are). However after working through the details, it appeared that the embedded logic was a bit complex and confusing. Hence I cleaned up the code, modified the logic, rewrote portions of the underlying engine, added state transitions, implemented buy/sell signals and arrows as well as gave it a new coloring structure.

Since the previous study did not have a name, as a placeholder I'm tagging this study as "Supertrend ATR CCI Trend". Here then is version 2.0 of the code.
Enjoy it folks!

Code:
# SuperTrend CCI ATR Trend
# tomsk
# 11.18.2019

# V1.0 - 08.10.2019 - dtek  - Initial release of SuperTrend CCI ATR Trend
# V2.0 - 11.18.2019 - tomsk - Modified the logic, cleaned up code for consistency

# SUPERTREND BY MOBIUS AND CCI ATR TREND COMBINED INTO ONE CHART INDICATOR,
# BOTH IN AGREEMENT IS A VERY POWERFUL SIGNAL IF TRENDING. VERY GOOD AT CATCHING
# REVERSALS. WORKS WELL ON 1 AND 5 MIN CHARTS. PLOT IS THE COMBINATION LOWEST
# FOR UPTREND AND HIGHEST OF THE DOWNTREND. DOTS COLORED IF BOTH IN AGREEMENT
# OR GREY IF NOT -  08/10/2019 DTEK

# Supertrend, extracted from Mobius original code

input ST_Atr_Mult = 1.0;    # was .70
input ST_nATR = 4;
input ST_AvgType = AverageType.HULL;

def ATR = MovingAverage(ST_AvgType, TrueRange(high, close, low), ST_nATR);
def UP = HL2 + (ST_Atr_Mult* ATR);
def DN = HL2 + (-ST_Atr_Mult * ATR);
def ST = if close < ST[1] then UP else DN;

# CCI_ATR measures distance from the mean. Calculates a trend
# line based on that distance using ATR as the locator for the line.
# Credit goes to Mobius for the underlying logic

input lengthCCI = 50;      # Was 20
input lengthATR = 21;      # Was 4
input AtrFactor = 1.0;     # Was 0.7

def ATRCCI = Average(TrueRange(high, close, low), lengthATR) * AtrFactor;
def price = close + low + high;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0
          then 0
          else (price - Average(price, lengthCCI)) / linDev / 0.015;

def MT1 = if CCI > 0
          then Max(MT1[1], HL2 - ATRCCI)
          else Min(MT1[1], HL2 + ATRCCI);

# Alignment of Supertrend and CCI ATR indicators

def Pos_State = close > ST and close > MT1;
def Neg_State = close < ST and close < MT1;

# Combined Signal Approach - Supertrend and ATR CCI

plot CSA = MT1;
CSA.AssignValueColor(if Pos_State then Color.CYAN
                     else if Neg_State then Color.MAGENTA
                     else Color.YELLOW);

# Buy/Sell Signals using state transitions

def BuySignal = (!Pos_State[1] and Pos_State);
def SellSignal = !Neg_State[1] and Neg_State;

# Buy/Sell Arrows

plot BuySignalArrow = if BuySignal then 0.995 * MT1 else Double.NaN;
BuySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignalArrow.SetDefaultColor(Color.CYAN);
BuySignalArrow.SetLineWeight(5);

plot SellSignalArrow = if SellSignal then 1.005 * MT1 else Double.NaN;
SellSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignalArrow.SetDefaultColor(Color.PINK);
SellSignalArrow.SetLineWeight(5);

# Candle Colors

AssignPriceColor(if Pos_State then Color.GREEN
                 else if Neg_State then Color.RED
                 else Color.YELLOW);
# End SuperTrend CCI ATR Trend
 
horserider

horserider

Well-known member
VIP
Seems Trend Magic does essentially the same with simpler code. Also has a MTF version.
 
T

tomsk

Well-known member
VIP
Seems Trend Magic does essentially the same with simpler code. Also has a MTF version.

I looked at that MTF study - for sure it has the CCI ATR base code - the version I posted includes Mobius SuperTrend as well, and thus is a combined study with CCI ATR. That was a follow up for the poster who requested that enhancement
 
H

HighBredCloud

Well-known member
VIP
@tomsk Anyway to add buy and sell chart bubbles like the Mobius ATR SuperTrend you enhanced? By the way...does this one repaint? Or is it in line with the Mobius ATR SuperTrend that you enhanced few weeks ago?
 
T

tomsk

Well-known member
VIP
Folks, given that stocks ebb in and out from time to time, there was an excellent idea on another thread where the request was just to display the current trend and ignore past historical up/down trends. This not only helps one have an instant insight into what the current trend is but also simplifies the display, is cleaner and reduces screen "clutter".

Using that approach, here is version 2.1 of the SuperTrend CCI ATR Trend study, I used this opportunity to redesign the state transition engine and tested this on uptrending stocks like AAPL as well as downtrending stocks like X. It works both on daily as well as intraday

Have fun with this!

Code:
# SuperTrend CCI ATR Trend
# tomsk
# 1.17.2020

# V1.0 - 08.10.2019 - dtek  - Initial release of SuperTrend CCI ATR Trend
# V2.0 - 11.18.2019 - tomsk - Modified the logic, cleaned up code for consistency
# V2.1 - 01.17.2020 - tomsk - Enhanced state transition engine to only display latest trend

# SUPERTREND BY MOBIUS AND CCI ATR TREND COMBINED INTO ONE CHART INDICATOR, 
# BOTH IN AGREEMENT IS A VERY POWERFUL SIGNAL IF TRENDING. VERY GOOD AT CATCHING 
# REVERSALS. WORKS WELL ON 1 AND 5 MIN CHARTS. PLOT IS THE COMBINATION LOWEST 
# FOR UPTREND AND HIGHEST OF THE DOWNTREND. DOTS COLORED IF BOTH IN AGREEMENT 
# OR GREY IF NOT -  08/10/2019 DTEK

# Supertrend, extracted from Mobius original code

input ST_Atr_Mult = 1.0;    # was .70
input ST_nATR = 4; 
input ST_AvgType = AverageType.HULL; 

def ATR = MovingAverage(ST_AvgType, TrueRange(high, close, low), ST_nATR); 
def UP = HL2 + (ST_Atr_Mult* ATR); 
def DN = HL2 + (-ST_Atr_Mult * ATR); 
def ST = if close < ST[1] then UP else DN; 

# CCI_ATR measures distance from the mean. Calculates a trend
# line based on that distance using ATR as the locator for the line.
# Credit goes to Mobius for the underlying logic

input lengthCCI = 50;      # Was 20
input lengthATR = 21;      # Was 4
input AtrFactor = 1.0;     # Was 0.7

def bar = barNumber();
def StateUp = 1;
def StateDn = 2;
def ATRCCI = Average(TrueRange(high, close, low), lengthATR) * AtrFactor;
def price = close + low + high;
def linDev = LinDev(price, lengthCCI);
def CCI = if linDev == 0 
          then 0 
          else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
          then Max(MT1[1], HL2 - ATRCCI)
          else Min(MT1[1], HL2 + ATRCCI);

# Alignment of Supertrend and CCI ATR indicators
def State = if close > ST and close > MT1 then StateUp
            else if close < ST and close < MT1 then StateDn
            else State[1];
def newState = HighestAll(if State <> State[1] then bar else 0);

# Combined Signal Approach - Supertrend and ATR CCI

plot CSA = if bar >= newState then MT1 else Double.NaN;
CSA.AssignValueColor(if bar >= newState 
                     then if State == StateUp then Color.CYAN
                          else if State == StateDn then Color.YELLOW
                          else Color.CURRENT
                     else Color.CURRENT);
# Buy/Sell Arrows
plot BuySignalArrow = if bar >= newState and State == StateUp and State[1] <> StateUp then 0.995 * MT1 else Double.NaN;
BuySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignalArrow.SetDefaultColor(Color.CYAN);
BuySignalArrow.SetLineWeight(5);

plot SellSignalArrow = if bar >= newState and State == StateDn and State[1] <> StateDn then 1.005 * MT1 else Double.NaN;
SellSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignalArrow.SetDefaultColor(Color.YELLOW);
SellSignalArrow.SetLineWeight(5);

# Candle Colors
AssignPriceColor(if bar >= newState
                 then if State == StateUp then Color.GREEN 
                      else if State == StateDn then Color.RED 
                      else Color.YELLOW
                 else Color.CURRENT);

# End SuperTrend CCI ATR Trend
 
A

Alex

Member
VIP
@tomsk Hey, I've recently ran a little back test using the indicator and I was pretty digging it, is there a way to possibly display buy / sell signals in the form of labels?
 
dougn

dougn

Member
2019 Donor
For some reason I am not able to scan with this study. If anyone has a fix for that please post the changes needed. Thx!
 
T

Thomas

Active member
VIP
Watching Hahn-Tech, and other areas, I cannot figure out how to simplify this column,.....HELP......alerting me to being "Too complex,"
 
Last edited by a moderator:
J

JerryR

New member
TOMSK, I'm not able to get the study to work. Any chance you can post an update? Thank you.
 
T

thebewb

Member
SPXtrader is charging $1k for this indicator...

Code:
# SPXTrader Scalper Strategy + indicator -> Z model Multi Timeframe

input tradeSize = 1;
def ShortTermATRFactor = 1.0;
def ATRPeriod = 4;
def MAType = AverageType.HULL;
def Channel_Length = 10;
def Average_Length = 21;
input aggPeriod = aggregationPeriod.FIVE_MIN;

input MTF = AggregationPeriod.THIRTY_MIN ;
input Entry_Mode = {default "Aggressive", "Conservative", "NonRepaintAggressive", "NonRepaintConservative"};
def S_R_TickThreshold = 6; # Not used anymore
input Use_Wider_Stops = Yes;
input S_R_PercentThreshold = 50;
input RTH_Only = No;
input TradeExitAlerts = No;

input colorBars = Yes;
input Show_Mode_Lines = Yes;
input Show_Labels = yes;
input usePresetColors = yes;
input UpColor = {"MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", default "GREEN", "GRAY", "WHITE", "YELLOW", "DARK_GRAY", "DARK_GREEN", "DARK_ORANGE", "DARK_RED", "LIGHT_GREEN", "LIGHT_ORANGE", "LIGHT_RED" };
input DownColor = { "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", default "RED", "GREEN", "GRAY", "WHITE", "YELLOW", "DARK_GRAY", "DARK_GREEN", "DARK_ORANGE",  "DARK_RED", "LIGHT_GREEN", "LIGHT_ORANGE", "LIGHT_RED"};
input NeutralColor = { "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE", default "YELLOW", "DARK_GRAY", "DARK_GREEN", "DARK_ORANGE", "DARK_RED", "LIGHT_GREEN", "LIGHT_ORANGE", "LIGHT_RED"};


def currentAggregationPeriod = aggperiod;

# Enforces that currentAggregationPeriod must be less than MTF and likely divisible
def aggregationPeriodFactor = currentAggregationPeriod / MTF;


# avoid 30 mins of open and 90 mins of close

input skipWindowStart1 = 0000;
input skipWindowEnd1 = 0700;

input skipWindowStart2 = 1455;
input skipWindowEnd2 = 1830;

def aggregationPeriodHigh = high(period = MTF);
def aggregationPeriodLow = low(period = MTF);
def aggregationPeriodClose = close(period = MTF);
def aggregationPeriodOpen = open(period = MTF);

# Outside windows
def timeframeOutWindow1 = (SecondsTillTime(skipWindowStart1) > 0 or SecondsTillTime(skipWindowEnd1) < 0);
def timeframeOutWindow2 = (SecondsTillTime(skipWindowStart2) > 0 or SecondsTillTime(skipWindowEnd2) < 0);

def StateUp = 1;
def StateDn = 2;


# Current Period
def tr =  TrueRange(high, close, low);
def ATR = MovingAverage(MAType, tr, ATRPeriod);
def UP = HL2 + (ShortTermATRFactor * ATR);
def DN = HL2 + (-ShortTermATRFactor * ATR);
def Trend = if close < Trend[1] then UP else DN;
plot ST = Trend;
def ltTrend = Trend;

# Aggregation Period

def agTR = TrueRange(aggregationPeriodHigh, aggregationPeriodClose, aggregationPeriodLow);
def aggregationPeriodATR = MovingAverage(MAType, agTR, ATRPeriod);
def agHL2 = hl2(GetSymbol(), MTF);
def aggregationPeriodUP = hl2(GetSymbol(), MTF) + (ShortTermATRFactor * ATR);
def aggregationPeriodDN = hl2(GetSymbol(), MTF) + (-ShortTermATRFactor * ATR);
def aggregationPeriodTrend = if aggregationPeriodClose < aggregationPeriodTrend[1] then aggregationPeriodUP else aggregationPeriodDN;

plot agtRp = aggregationperiodtrend;
def ZLength = 50;
def ZLengthATR = 21;
def ZDivider = 0.15;

def bar = BarNumber();  #check if we need this for mtf

#BarNumber for aggregated timeframe
def apBar = bar * aggregationPeriodFactor;

def ZATR = Average(TrueRange(high, close, low), ZLengthATR) * ShortTermATRFactor;
def price = close + low + high;
def linDev = LinDev(price, ZLength);


# aggregation Period calculations
def aggregationPeriodZATR = Average(TrueRange(aggregationPeriodHigh, aggregationPeriodClose, aggregationPeriodLow), ZLengthATR) * ShortTermATRFactor;
def aggregationPeriodPrice = aggregationPeriodClose + aggregationPeriodLow + aggregationPeriodHigh;
def aggregationPeriodLinDev = LinDev(aggregationPeriodPrice, ZLength);

def agLinDev = aggregationPeriodLinDev;
def agPrice = aggregationPeriodPrice;
def agZATR = aggregationPeriodZATR;

def ZAG = if linDev == 0
          then 0
          else (price - Average(price, ZLength)) / linDev / ZDivider;
def ZLevel = if ZAG > 0
          then Max(ZLevel[1], HL2 - ZATR)
          else Min(ZLevel[1], HL2 + ZATR);


#plot LTFZLevel = Zlevel;

#plot zlPlot  = ZLevel;
# aggregationPeriod calculations
def aggregationPeriodZAG = if aggregationPeriodLinDev == 0
          then 0
          else (aggregationPeriodPrice - Average(aggregationPeriodPrice, ZLength)) / aggregationPeriodLinDev / ZDivider;
def aggregationPeriodZLevel = if aggregationPeriodZAG > 0
          then Max(aggregationPeriodZLevel[1], hl2(GetSymbol(), MTF) - aggregationPeriodZATR)
          else Min(aggregationPeriodZLevel[1], hl2(GetSymbol(), MTF) + aggregationPeriodZATR);



# Normal Period

def State = if close > Trend and close > ZLevel then StateUp
            else if close < Trend and close < ZLevel then StateDn
            else State[1];
def newState = HighestAll(if State <> State[1] then bar else 0);


# Aggregation Period

def agClose = aggregationPeriodClose;
def agTrend = aggregationPeriodTrend;
#plot agZlevel = aggregationPeriodZLevel;

def ZLevelBand=3;

# TODO: added (GetAggregationPeriod() / 1000)
def secondsPassed = SecondsFromTime(0000) + (GetAggregationPeriod() / 1000);
def secondsSinceHTFClose = secondsPassed % (MTF / 1000); # MTF is in millis
plot barsSinceHTFClose = secondsSinceHTFClose / (GetAggregationPeriod() / 1000);
def canChangeHTFState = barsSinceHTFClose == 0;


def aggregationPeriodState;

switch (Entry_Mode) {
case Aggressive:
    aggregationPeriodState = if aggregationPeriodClose > aggregationPeriodTrend and aggregationPeriodClose > aggregationPeriodZLevel then StateUp
            else if aggregationPeriodClose < aggregationPeriodTrend and aggregationPeriodClose < aggregationPeriodZLevel then StateDn
            else aggregationPeriodState[1];
    case Conservative:
    aggregationPeriodState = if aggregationPeriodClose > aggregationPeriodTrend and aggregationPeriodClose > aggregationPeriodZLevel then StateUp
            else if aggregationPeriodClose < aggregationPeriodTrend and aggregationPeriodClose < aggregationPeriodZLevel then StateDn
            else aggregationPeriodState[1];
    case NonRepaintAggressive:
    aggregationPeriodState = if aggregationPeriodClose > aggregationPeriodTrend and aggregationPeriodClose > aggregationPeriodZLevel and canChangeHTFState  then StateUp
            else if aggregationPeriodClose < aggregationPeriodTrend and aggregationPeriodClose < aggregationPeriodZLevel and canChangeHTFState then StateDn
            else aggregationPeriodState[1];
    case NonRepaintConservative:
    aggregationPeriodState = if aggregationPeriodClose > aggregationPeriodTrend and aggregationPeriodClose > aggregationPeriodZLevel and canChangeHTFState  then StateUp
            else if aggregationPeriodClose < aggregationPeriodTrend and aggregationPeriodClose < aggregationPeriodZLevel and canChangeHTFState then StateDn
            else aggregationPeriodState[1];
}


def aggregationPeriodNewState = HighestAll(if aggregationPeriodState <> aggregationPeriodState[1] then apBar else 0); #TODO check if bar causes issues with MTF

def prevAgState = aggregationPeriodState[1];
def highTFState = aggregationPeriodState;
def highTFNewState = aggregationPeriodNewState;

AddLabel(Show_Labels, if State == 1 then "LTF: Up" else "LTF: Down",  if State == 1 then   GetColor(UpColor) else GetColor(DownColor) );
AddLabel(Show_Labels, if aggregationPeriodState == 1 then "HTF: Up" else "HTF: Down",  if aggregationPeriodState == 1 then  if usePresetColors then Color.GREEN else GetColor(UpColor) else  if usePresetColors then Color.RED else GetColor(DownColor) );
AddLabel(Show_Labels, "Mode: " + Entry_Mode, Color.YELLOW);


# Normal Timeframe
#plot TrendLine = if bar >= newState then ZLevel else Double.NaN;
plot TrendLine = if Show_Mode_Lines then ZLevel else Double.Nan;
#TrendLine.AssignValueColor(if bar >= newState
#                     then if State == StateUp then Color.CYAN
#                          else if State == StateDn then Color.YELLOW
#                          else Color.CURRENT
#                     else Color.CURRENT);
TrendLine.AssignValueColor(if State == StateUp then Color.GREEN
                          else if State == StateDn then Color.RED
                          else Color.CURRENT);
TrendLine.SetLineWeight(1);

# Aggregated Timeframe
#plot aggregatedTimeframeTrendLine = if apBar >= aggregationPeriodNewState then ZLevel else Double.NaN;

#plot HTFLevel = aggregationPeriodZLevel;
plot HTF_TrendLine = if Show_Mode_Lines then aggregationPeriodZLevel else Double.Nan;

#aggregatedTimeframeTrendLine.AssignValueColor(if apBar >= aggregationPeriodNewState
#                     then if aggregationPeriodState == StateUp then  if usePresetColors #then Color.GREEN else GetColor(upColor)
#                          else if aggregationPeriodState == StateDn then  if #usePresetColors then Color.RED else GetColor(downColor)
#                          else Color.CURRENT
#                     else Color.CURRENT);

HTF_TrendLine.AssignValueColor(
                            if aggregationPeriodState == StateUp then Color.GREEN
                            else if aggregationPeriodState == StateDn then  Color.RED
                            else Color.BLUE);
HTF_TrendLine.SetLineWeight(2);

#AssignBackgroundColor( if aggregationPeriodState == StateUp then Color.DARK_GREEN
#                            else Color.DARK_RED);

#VWAP
def cap = GetAggregationPeriod();
def yyyyMmDd = GetYYYYMMDD();
def periodIndx = yyyyMmDd;
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def vwPrice = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(vwPrice), 0));

def VWAP = vwPrice;
def UpperBand = vwPrice + 2.0 * deviation;
def LowerBand = vwPrice  - 2.0 * deviation;

def UpperBandFirst = vwPrice +  deviation;
def LowerBandFirst = vwPrice - deviation;

# Relation to ADD
input relatedSecurity = "$ADD";
def relatedSecurityUpT = 2000;
def relatedSecurityDownT = -2000;
def relatedSecurityPrice = Fundamental(FundamentalType.CLOSE, relatedSecurity);


def RTHTimeCondition =  RegularTradingStart(GetYYYYMMDD())  < GetTime() and RegularTradingEnd(GetYYYYMMDD()) > GetTime();


# if outside RTH, ignore this condition
def rsBuyCondition = if RTHTimeCondition then relatedSecurityPrice > relatedSecurityDownT else yes;
def rsShortCondition =  if RTHTimeCondition then relatedSecurityPrice < relatedSecurityUpT else yes;


# Buy/Sell Arrows

def RTH_Only_Condition = if RTH_Only then RTHTimeCondition else yes;



def vwapStdDevConditionBuyNew = close < UpperBand[1] -  ((UpperBand[1] - UpperBandFirst[1]) * S_R_PercentThreshold/100);
def vwapStdDevConditionShorNew = close > LowerBand[1] + ((LowerBandFirst[1] - LowerBand[1]) * S_R_PercentThreshold/100);

def vwapStdDevConditionBuy = close + (S_R_TickThreshold * TickSize()) < UpperBand[1];
def vwapStdDevConditionShort = close - (S_R_TickThreshold * TickSize()) > LowerBand[1];

def vwapConditionBuy = close  < VWAP[1];
def vwapConditionShort = close > VWAP[1];


def vwapClosingThresholdConditionBuyOrShort = yes; # (close >  VWAP[1] - (S_R_TickThreshold * TickSize())) OR (close <  VWAP[1] + (S_R_TickThreshold * TickSize()));
def priceBandWidth = close * 0.0005;
def vwapCloseCondition = close < AbsValue(VWAP - priceBandWidth)  or close > AbsValue(VWAP + priceBandWidth);

#TODO check performance with this
def refBarCondition = yes ; #AbsValue(close - ZLevel) <= 4; # deviation * S_R_PercentThreshold/100; #refBarDistanceThreshold;
def refBarConditionCons = AbsValue(close - ZLevel) <= 16 * TickSize(); # deviation * S_R_PercentThreshold/100;

def secondsFromMidnight = SecondsFromTime(0000);
def thirtyMinCondition = yes; #secondsPassed % 1800 == 0;

def StateUpCondition = State == StateUp;
def StateDOwnCondition = State == StateDn;
def agStateUpCondition = aggregationPeriodState == StateUp;
def agStateDnCondition = aggregationPeriodState == StateDn;


def stateChangeToUpCondition = (State[1] <> StateUp) or (aggregationPeriodState[1] <> StateUp);
def stateChangeToDnCondition = State[1] <> StateDn or (aggregationPeriodState[1] <> StateDn);


def buyCondition;
def sellCondition;


def ZModelBuyAgg =  RTH_Only_Condition and refBarCondition and vwapClosingThresholdConditionBuyOrShort and vwapStdDevConditionBuyNew and timeframeOutWindow1 and timeframeOutWindow2 and  StateUpCondition and agStateUpCondition and stateChangeToUpCondition and rsBuyCondition ;

def ZModelShortAgg =  RTH_Only_Condition and refBarCondition and vwapClosingThresholdConditionBuyOrShort and vwapStdDevConditionShorNew and timeframeOutWindow1 and timeframeOutWindow2 and StateDOwnCondition and agStateDnCondition and stateChangeToDnCondition and rsShortCondition ;

def PModelBuy = StateUpCondition and agStateUpCondition and low <= ZLevel and close > ZLevel and absvalue(close - ZLevel) <=1 and  timeframeOutWindow1 and timeframeOutWindow2 and open > ZLevel;

def PModelShort = StateDownCondition and agStateDnCondition and high >= ZLevel and close < ZLevel and absvalue(close - ZLevel) <=1 and  timeframeOutWindow1 and timeframeOutWindow2 and open < ZLevel ;


def ZModelBuyCons = RTH_Only_Condition and vwapConditionBuy and timeframeOutWindow1 and timeframeOutWindow2 and  StateUpCondition and agStateUpCondition and stateChangeToUpCondition and refBarCondition;

def ZModelShortCons = RTH_Only_Condition and vwapConditionShort and timeframeOutWindow1 and timeframeOutWindow2 and StateDOwnCondition and agStateDnCondition and stateChangeToDnCondition and refBarCondition;

switch (Entry_Mode) {
case Aggressive:
    buyCondition = vwapCloseCondition and thirtyMinCondition and vwapClosingThresholdConditionBuyOrShort and vwapStdDevConditionBuyNew and timeframeOutWindow1 and timeframeOutWindow2 and  StateUpCondition and thirtyMinCondition and agStateUpCondition and stateChangeToUpCondition;
    sellCondition =  vwapCloseCondition and vwapClosingThresholdConditionBuyOrShort and vwapStdDevConditionShorNew and timeframeOutWindow1 and timeframeOutWindow2 and StateDOwnCondition and agStateDnCondition and stateChangeToDnCondition;
case Conservative:
    buyCondition = vwapCloseCondition and vwapConditionBuy and timeframeOutWindow1 and timeframeOutWindow2 and  StateUpCondition and agStateUpCondition and stateChangeToUpCondition;
    sellCondition = vwapCloseCondition and vwapConditionShort and timeframeOutWindow1 and timeframeOutWindow2 and StateDOwnCondition and agStateDnCondition and stateChangeToDnCondition;
case NonRepaintAggressive:
    buyCondition = ZModelBuyAgg; # or PModelBuy ;
    sellCondition = ZModelShortAgg; # or PModelShort;
case NonRepaintConservative:
    buyCondition = ZModelBuyAgg and refBarConditionCons;
    sellCondition = ZModelShortAgg and refBarConditionCons;
}



plot BuySignalArrow = if buyCondition then 0.998 * ZLevel else Double.NaN;
BuySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignalArrow.SetDefaultColor(Color.CYAN);
BuySignalArrow.SetLineWeight(5);




plot SellSignalArrow = if sellCondition then 1.002 * ZLevel else Double.NaN;
SellSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignalArrow.SetDefaultColor(Color.YELLOW);
SellSignalArrow.SetLineWeight(5);

AssignPriceColor( if colorBars and State == StateUp then  if usePresetColors then Color.GREEN else GetColor(UpColor)
                      else if colorBars and  State == StateDn then  if usePresetColors then Color.RED else GetColor(DownColor)
                      else Color.CURRENT
                );


#def shortExitCondition1 = (State == StateUp and State[1] <> StateUp) or  (aggregationPeriodState == StateUp and aggregationPeriodState[1] <> StateUp);

#def buyExitCondition1 = (State == StateDn and State[1] <> StateDn) or (aggregationPeriodState == StateDn and aggregationPeriodState[1] <> StateDn);


# Remove vwapCloseCondition
def barWidth = absvalue(open - close);
def barWidthCondition = barWidth < 0.0015 * close;  # bar is less than 0.15% of close
def widerStopBuyExit = if Use_Wider_Stops and barWidthCondition then low > ZLevel else yes;
def widerStopShortExit = if Use_Wider_Stops and barWidthCondition then  high < ZLevel else yes;

def shortExitCondition1 = State == StateUp and widerStopBuyExit and vwapCloseCondition;
def buyExitCondition1 = State == StateDn and widerStopShortExit and vwapCloseCondition;



# Long side trade
AddOrder(OrderType.BUY_TO_OPEN, buyCondition, open[-1], tradeSize, Color.CYAN, Color.YELLOW);
Alert(buyCondition, ”Scalper MTF Buy alert”, Alert.BAR, Sound.Ding);

# Long side trade exit
AddOrder(OrderType.SELL_TO_CLOSE, buyExitCondition1, open[-1], tradeSize, Color.CYAN, Color.YELLOW);
Alert(TradeExitAlerts and buyExitCondition1, ”Scalper MTF Long Exit alert”, Alert.BAR, Sound.Ding);

# Short side trade
AddOrder(OrderType.SELL_TO_OPEN, sellCondition, open[-1], tradeSize, Color.CYAN, Color.PINK);
Alert(sellCondition, ”Scalper MTF Short alert”, Alert.BAR, Sound.Ding);


# Short side trade exit
AddOrder(OrderType.BUY_TO_CLOSE, shortExitCondition1, open[-1], tradeSize, Color.CYAN, Color.PINK);
Alert(TradeExitAlerts and shortExitCondition1, ”Scalper MTF Short Exit alert”, Alert.BAR, Sound.Ding);


# close all position EOD
def startOffset = 2;
def endOffset = 2;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD());
def firstBarOfDay = if
    (beforeStart[1+startOffset] == 1 and beforeStart[startOffset] == 0) or
    (isRollover[startOffset] and beforeStart[startOffset] == 0)
    then 1
    else 0;
def lastBarOfDay = if
    (afterEnd[-1-endOffset] == 1 and afterEnd[endOffset] == 0) or
    (isRollover[-1-endOffset] and firstBarOfDay[-1-endOffset])
    then 1
    else 0;

AddOrder(OrderType.SELL_TO_CLOSE, lastBarOfDay[-1], Open[-1], 1);
AddOrder(OrderType.BUY_TO_CLOSE, lastBarOfDay[-1], Open[-1], 1);

I hope everyone sees the similarities here... this guy uses state up and state dn variable he has the same comments as @tomsk in there.... Total fraud... I would hope Ben helps shed light on this fraud but who knows nowadays... please message me with any questions.
 
Last edited by a moderator:
T

thebewb

Member
And there we go... Ben removed me from his VIP discord for posting this.
 
BenTen

BenTen

Administrative
Staff
VIP
@thebewb I didn't remove you from our Discord for trying to expose someone. If you look above, your "expose" is still up there for everybody to see. You may want to reevaluate the way you behave in our Discord channel. Several members have reported your poor behavior today.
 
T

thebewb

Member
Ben seemed very defensive when I wanted to post this.... Its too bad that he seems to be caught up in this guys web. Ben I paid $175 for VIP... I will be requesting a refund through the proper channels... I will get it back one way or another...
 
BenTen

BenTen

Administrative
Staff
VIP
Some context for those who are not aware.

@thebewb claimed that someone on Twitter is stealing the codebase that @tomsk provided in this thread and tried to resell it for $1k.

I suggested that he should post his proof directly within this thread to shed light. During our conversation in Discord, @thebewb's behaviour was rather odd. He then assumed that I'm "getting a payout from that guy..."

"That guy" here is the person @thebewb was trying to expose.

I had no idea why he's handling himself so poorly. Earlier today, we had to halt our Discord channel for a short while because @thebewb was calling another member a "moron."

Ben I paid $175 for VIP... I will be requesting a refund through the proper channels... I will get it back one way or another...



No you didn't!
 
T

thebewb

Member
The fact ben is commenting is telling.... He keeps acting like I am spouting nonsense when the proof is in the code.
 
BenTen

BenTen

Administrative
Staff
VIP
@thebewb You need to go back to comment #12 and #14. I clearly stated the reason why we banned you from our Discord. It has nothing to do with the code you posted. All the names calling you did today, the odd messages you sent to others, and the false claims you made against me are what you got booted.
 
T

thebewb

Member
Ben doesnt care at all about the newb traders... he is more than happy to let SPXtrader fleece people for $1k a pop...I dont know why but just ask yourself.... Why was Ben so against me sharing this script?
 
BenTen

BenTen

Administrative
Staff
VIP
@thebewb You clearly still don't understand. The script you posted is still available in message #10. The fact that you have made multiple false claims about me made me doubt your credibility. But anyway, this conversation ends here. I will let everyone be the judge of that.
 
MattATM

MattATM

Active member
VIP
The fact ben is commenting is telling.... He keeps acting like I am spouting nonsense when the proof is in the code.
Sir, Ben definitely deserves the $100 donations we give for the costs of up keeping this website.

Is it possible you have him confused for someone else? Who is selling code for $1000... The easiest way to stop some of those behaviors is to get search results. For example I applied a normalization the other day on here that anyone can use. Some character like Johnathan from Simpler Trading could give it an odd name and resell it but that's life.

On one side I can never own simple mathematics but on the other side some works are proprietary. For example we don't pay someone with a patent for chairs everytime we sit down...

IDK?
 
T

Thomas

Active member
VIP
@thebewb You don't need any of this really, learn price patterns and candles, what volume is telling you, and opening with 2 minute chart, or position trade.
 

Similar threads

Top