Last active
April 2, 2018 15:19
-
-
Save trAve3113r/b23e12907ead008b53537c546c43e1d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Notes on the InsidePinBar setup | |
| # inverted__hammer indicates upward price rejection | |
| # bullish/bearish hammer indicate downward price rejection | |
| # *** how do we trade swing_points ??? entry,stop_loss & take_profit *** | |
| # *** rejection of bearish_trend setup *** | |
| # stop_loss --> 1 pip below hammer_pin_bar's 'low' OR (entry - 10 to 20 pips) | |
| # entry -- > 'high' of the hammer_pin_bar ('buy' order) | |
| # take_profit -- > entry + (2*stop_loss) :: won't the 3 next bars swallow up this margin? | |
| # i.e if take_profit < high of the 3rd bar after the swing_point | |
| # since take_profit is simply twice the swing_point's length | |
| # => take_profit = entry + 2*(3rd_candlestick_high - stop_loss) ??? *** food for thought *** | |
| # argument :: if take_profit is too tight you won't get the best reward viz risk | |
| # or :: take_profit to be computed similar to an inside_pin_bar's trend reversal (** more sensible **) | |
| # or :: use key levels, i.e, resistance and support | |
| # ***** what if stop_loss is set at entry + 1 pip such that we neve make a loss ??? ***** | |
| # bullish_hammer :: (bearish bars to the left & bullish bars to the right?? ideally) | |
| # *** rejection of bullish_trend setup *** | |
| # entry --> 'low' of the hammer_pin_bar ('sell' order) | |
| # stop_loss > 1 pip + 'high' of the hammer_pin_bar | |
| # take_profit --> entry - (2*stop_loss) | |
| # bearish_inverted_hammer :: (bullish bars to the left and bearish bars to the right?? ideally) | |
| # these hammer bars are also swing_points viz. the last 10 previous bars (since 10 bars make a trend) | |
| # bolster swing_point strategy with EMA for range_bound markets where < 10 bars stick to the trend (*** more risky ***) | |
| # 'minima' for the 'lows' of the last 10 bars == hammer_bar_low | |
| # 'maxima' for the 'highs' of the last 10 bars == inverted_hammer_low | |
| # A general “rule of thumb” is that: | |
| # the pin bar tail be two/thirds the total pin bar length or more and, | |
| # the rest of the pin bar should be one/third the total pin bar length or less. | |
| # *ANY* candlestick (bullish or bearish) that fully engulfs the next candlestick constitutes an inside_bar setup | |
| # we can have an inside_bar setup where both the mother_bar and inside_bar are bearish candlesticks | |
| # **inside_pin_bar** i a much higher probability setup than a regular inside_bar setup | |
| # ---> first check for is_inside_pin :: else use_inside_bar | |
| def is_inside_bar(self,dfz): | |
| tail = dfz.tail(2).tolist() | |
| mb_low,mb_high = tail['low'][-1],tail['high'][-1] | |
| ib_low_,ib_high = tail['low'][0],tail['high'][0] | |
| if (mb_hgh > ib_high) and (mb_low < ib_low): | |
| return True | |
| else: | |
| return False | |
| def inside_bar_setup(self,dfz): | |
| if self.is_inside_pin() == True: | |
| # can be traded during a weak trend | |
| return 1 | |
| elif self.is_inside_bar(): | |
| # only trade in a strongly trending market | |
| return 2 | |
| else: | |
| return 0 | |
| # NB: Identify strong and weak trend in the 'trend()' func/algo | |
| # if the next 1,2 or 3 bars to the right of the inside_pin/bar are contained within the mother_bar | |
| # ---> this is a strong trend continuation signal ::: incoporate this in bearish_breakout & bullish_breakout | |
| # the additional inside_bars/pin will not be exclusively bearish or bullish | |
| # watch for a breakout viz the last inside_pin/bar :: either upward or downward | |
| # focus on the ** daily ** chart to avoid false breaks | |
| # always watchout for pin_bar reversal patterns within the next 3 bars | |
| # during an up_trend a bearish_hammer is a strong trend continuation signal(the perfect inside_pin) | |
| # bearish_inverted_hammer is a strong continuation signal for a down_trend(the perfect inside_pin) | |
| # *** incorporate pin_bar continuation signals to bolster trend computation, i.e, if less than 10 bars conform | |
| # *** unrealted factoid:: for up_trend ,analyze the 'lows' of the candlesticks & vice versa for a down_trend *** | |
| def higher_and_higher(self,lst): | |
| return np.all(np.diff(lst) > 0) | |
| def lower_and_lower(self,lst): | |
| return np.all(np.diff(lst) < 0) | |
| def is_strong_up_trend(self,dfz): | |
| data = dfz.tail(10).tolist() | |
| lst1 = data['high'] | |
| lst2 = data['low'] | |
| higher_highs = self.higher_and_higher(lst1) | |
| higher_lows = self.higher_and_higher(lst2) | |
| if higher_highs is True and higher_lows is True: | |
| return True | |
| elif higher_highs is False and higher_lows is True: | |
| return False | |
| else: | |
| return None | |
| def is_strong_down_trend(self,dfz): | |
| data = dfz.tail(10).tolist() | |
| lst1 = data['high'] | |
| lst2 = data['low'] | |
| lower_highs = self.lower_and_lower(lst1) | |
| lower_lows = self.lower_and_lower(lst2) | |
| if lower_highs is True and lower_lows is True: | |
| return True | |
| elif lower_highs is False and lower_lows is True: | |
| return False | |
| else: | |
| return None | |
| def is_consolidation(self,dfz): | |
| up_trend = self.is_strong_uptrend(dfz) | |
| down_trend = self.is_strong_downtrend(dfz) | |
| if up_trend is None and down_trend is None: | |
| return True | |
| else: | |
| return False | |
| def generic_swing_point(self,dfz): | |
| """ maxima or minima of ANY candlestick """ | |
| # minima_swing_point | |
| # maxima_swing_point | |
| pass | |
| def bearish_reversal_signal(self,dfz): | |
| """ signifies reversal of a down_trend """ | |
| tail = dfz.tail(1).tolist() | |
| o,h,l,c = tail['open'][-1],tail['high'][-1],tail['low'][-1],tail['close'][-1] | |
| bullish_hammer = w.is_bullish_hammer(o,h,l,c) | |
| bearish_hammer = w.is_bearish_hammer(o,h,l,c) | |
| down_trend = self.is_strong_downtrend(dfz) | |
| # minima = dfz['low'].tail(10).min(axis=1) | |
| #if l == minima and (bullish_hammer is True or bearish_hammer is True): | |
| if down_trend is True and bullish_hammer is True: | |
| # insert 'Setup' data :: watch for confirmation signal | |
| return True | |
| else: | |
| pass | |
| def bullish_reversal_signal(self,dfz): | |
| tail = dfz.tail(1).tolist() | |
| o,h,l,c = tail['open'][-1],tail['high'][-1],tail['low'][-1],tail['close'][-1] | |
| bullish_inv_hammer = w.is_bullish_inv_hammer(o,h,l,c) | |
| bearish_inv_hammer = w.is_bearish_inv_hammer(o,h,l,c) | |
| maxima = dfz['high'].tail(10).max(axis=1) | |
| if h == maxima and (bullish_inv_hammer is True or bearish_inv_hammer is True): | |
| return True: | |
| else: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment