confluence905
New member
I trying to combine the TTM Squeeze and Schaff Trend Cycle (STC) as a trading strategy in TOS but having some trouble getting the bullish signal to align with the TTM squeeze and STC.
Ruby:
#Position
input Shares = 5;
input Gain = 0.03;
#TTM Squeeze parameters
input length = 10;
input nk = 1.5;
input nBB = 2.0;
#MACD, TTM, STC Parameters
input fastLength = 5;
input medLength = 20;
input slowLength = 50;
#STC Parameters
input KPeriod = 10;
input DPeriod = 3;
#Studies
def TTM = TTM_Squeeze(close, length, nk, nBB).histogram;
def squeeze = TTM_Squeeze(close, length, nk, nBB).SqueezeAlert;
def STC = schaffTrendCycle(fastLength, slowLength, KPeriod, DPeriod);
#def MAC = MACD(fastLength, medLength, length);
#Bullish Signals
#def MACBullish = if MAC > MAC[1] and MAC[1] < MAC[2] then 1 else 0;
def STCBullish = if STC < 25 and STC > STC[1] and STC[1] < STC[2] then 1 else 0;
def TTMBullish = if TTM < Squeeze and TTM > TTM[1] and TTM[1] < TTM[2] then 1 else 0;
def Bullish = if STCBullish == 1 and TTMBullish ==1 then 1 else 0;
#Bearish Signals
#def MACBearish = if MAC < MAC[1] and MAC[1] > MAC[2] then 1 else 0;
def STCBearish = if STC > 75 and STC < STC[1] and STC[1] > STC[2] then 1 else 0;
def TTMBearish = if TTM > squeeze and TTM < TTM[1] and TTM[1] >= TTM[2] then 1 else 0;
def Bearish = if STCBearish == 1 then 1 else 0;
#Combined
def BullishSignal = Bullish == 1;
def BearishSignal = Bearish == 1;
#Exit Trade
def exitBullishTrade = if Bearish == 1 then 1 else 0;
def exitBearishTrade = if Bullish == 1 then 1 else 0;
#Execute Bullish Buy and Sell
AddOrder(OrderType.BUY_TO_OPEN, BullishSignal, close, Shares);
AddOrder(OrderType.SELL_TO_CLOSE, high >= EntryPrice() + EntryPrice() * Gain, EntryPrice() + EntryPrice() * Gain, Shares);
AddOrder(OrderType.SELL_TO_CLOSE, exitBullishTrade, close, Shares);
#Execute Bearish Buy and Sell
#AddOrder(OrderType.SELL_TO_OPEN, BearishSignal, close, Shares);
#AddOrder(OrderType.BUY_TO_CLOSE, low <= EntryPrice() - (EntryPrice() * Gain), EntryPrice() - (EntryPrice() * Gain), Shares);
#AddOrder(OrderType.BUY_TO_CLOSE, exitBearishTrade, close, Shares);
Last edited by a moderator: