berodney
New member
Has anyone wrote a strategy in thinkscript like below (or something similar)?
Note: This can be used for any timeframe, but I like to look at 1m and 5m charts.
Pop pull back candle over candle – Strong igniting bar at least 3 times the size of a normal bar, followed by a resting bar closing in the top 33% of the igniting bar (the pull back), entry when it looks like it will break the high of the pull back bar.
Conditions:
-Stock trending up
-Previous Candle has to have a range 33.33% larger than average (upward)
-1,2 or 3 pull back candles (need to stay in the top 50% of pop candle
-Buy condition when stock price passes the high of previous pull back candle and smi > smiavg and vol > 10,000
-Sell condition when stock price passes the high of the pop candle or smi < smiavg
Example
I know this is kind of a crazy ask and I'm not that good with coding in thinkscript (or in general) so any help would be appreciated.
---------------------------------------------------------------------------------------------------------------------------------------------------------------
This is what I have so far:
Thanks to redit user Mobius_ts for the starting point
Current Issues/changes:
-Instead of the buy and sell be on the Open/close of the candle change it so it would show when the condition is met
Currently just showing buy and sell on the same candle once the first condition is met
-Need to add alerts for buy and sell
CODE:
# Conditions:
#-Stock trending up
#-Previous Candle has to have a range 33.33% larger than average (upward)
#-1,2 or 3 pull back candles (need to stay in the top 50% of pop candle
#-Buy condition when stock price passes the high of previous pull back candle
#-Sell condition when stock price passes the high of the pop candle
input length = 10;
def TR = TrueRange(high, close, low);
def ATR = Average(TR, length);
def cond_1 = TR >= ATR * 1.33;
def cond_1_High = if(cond_1, high, cond_1_High[1]);
def cond_1_HL2 = if(cond_1, HL2, cond_1_HL2[1]);
def cond_2 = high < cond_1_High and low > cond_1_HL2;
def cond_2_High = if(cond_1[1] and cond_2, high, cond_2_High[1]);
###################
#
# SMI
#
###################
input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;
input alerts = yes;
def min_low = lowest(low, percentKLength);
def max_high = highest(high, percentKLength);
def rel_diff = close - (max_high + min_low)/2;
def diff = max_high - min_low;
def avgrel = expaverage(expaverage(rel_diff, percentDLength), percentDLength);
def avgdiff = expaverage(expaverage(diff, percentDLength), percentDLength);
def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
def AvgSMI = expaverage(smi, percentDLength);
###################
#
# Buying/Selling Conditions
#
###################
def vol = volume >= 10000;
def smi2 = smi >= avgsmi;
def smi3 = smi <= avgsmi;
addOrder(OrderType.BUY_TO_OPEN, cond_1[2] and cond_2[1]and vol and smi2 and close crosses above cond_2_High, cond_2_high);
addOrder(OrderType.SELL_TO_CLOSE, close crosses above cond_1_High or smi3, cond_1_High);
Note: This can be used for any timeframe, but I like to look at 1m and 5m charts.
Pop pull back candle over candle – Strong igniting bar at least 3 times the size of a normal bar, followed by a resting bar closing in the top 33% of the igniting bar (the pull back), entry when it looks like it will break the high of the pull back bar.
Conditions:
-Stock trending up
-Previous Candle has to have a range 33.33% larger than average (upward)
-1,2 or 3 pull back candles (need to stay in the top 50% of pop candle
-Buy condition when stock price passes the high of previous pull back candle and smi > smiavg and vol > 10,000
-Sell condition when stock price passes the high of the pop candle or smi < smiavg
Example
I know this is kind of a crazy ask and I'm not that good with coding in thinkscript (or in general) so any help would be appreciated.
---------------------------------------------------------------------------------------------------------------------------------------------------------------
This is what I have so far:
Thanks to redit user Mobius_ts for the starting point
Current Issues/changes:
-Instead of the buy and sell be on the Open/close of the candle change it so it would show when the condition is met
Currently just showing buy and sell on the same candle once the first condition is met
-Need to add alerts for buy and sell
CODE:
# Conditions:
#-Stock trending up
#-Previous Candle has to have a range 33.33% larger than average (upward)
#-1,2 or 3 pull back candles (need to stay in the top 50% of pop candle
#-Buy condition when stock price passes the high of previous pull back candle
#-Sell condition when stock price passes the high of the pop candle
input length = 10;
def TR = TrueRange(high, close, low);
def ATR = Average(TR, length);
def cond_1 = TR >= ATR * 1.33;
def cond_1_High = if(cond_1, high, cond_1_High[1]);
def cond_1_HL2 = if(cond_1, HL2, cond_1_HL2[1]);
def cond_2 = high < cond_1_High and low > cond_1_HL2;
def cond_2_High = if(cond_1[1] and cond_2, high, cond_2_High[1]);
###################
#
# SMI
#
###################
input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;
input alerts = yes;
def min_low = lowest(low, percentKLength);
def max_high = highest(high, percentKLength);
def rel_diff = close - (max_high + min_low)/2;
def diff = max_high - min_low;
def avgrel = expaverage(expaverage(rel_diff, percentDLength), percentDLength);
def avgdiff = expaverage(expaverage(diff, percentDLength), percentDLength);
def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
def AvgSMI = expaverage(smi, percentDLength);
###################
#
# Buying/Selling Conditions
#
###################
def vol = volume >= 10000;
def smi2 = smi >= avgsmi;
def smi3 = smi <= avgsmi;
addOrder(OrderType.BUY_TO_OPEN, cond_1[2] and cond_2[1]and vol and smi2 and close crosses above cond_2_High, cond_2_high);
addOrder(OrderType.SELL_TO_CLOSE, close crosses above cond_1_High or smi3, cond_1_High);
Last edited: