Recognize And Exploit Uptrends and Downtrends

Best Binary Options Brokers 2020:
  • Binarium
    Binarium

    The Best Binary Options Broker 2020!
    Perfect For Beginners!
    Free Demo Account!
    Free Trading Education!
    Sign-up Bonus!

  • Binomo
    Binomo

    Trustful Broker!

Uptrend, Ranging or Downtrend?

Many have heard “buy the low, sell the high” , “trade with trend”.

The problem is I don’t know the current price is a Higher High or a Lower Low for the NEXT period, only to the past period.
If we following the trend we enter to late , maybe missing 30% of the trend beginning and we exit to late losing 50% or our profit. Here, in a trending market we need to Sell the LL and buy the HH. Sadly no pullback to Fibo level, sometimes the price just fly, like in today it was manipulation Monday. Then maybe turn to a Fibo level to hit the SL or it fly 300 pip without any pullback then a pause and other 300-400 pip, so counter trend , pending orders are useless. The perfect exit point it is still a HH or a LL, but in counter direction.

On a ranging market, just simply Sell the HH and Buy the LL. It is very-very profitable, until the market goes to trending. then a huge loss.

Here is an EUR/USD H4 chart zoom out.
Applied EMA or SMA to (H+L)/2, then other one to H and other one to L. So we see a band, where if is crossing, then the trend is over.

I would say it started trending when the price went trough the EMA band and bigger is the distance from the price to the closest EMA then closer is the turning point, until that is trending. If the price is below EMA band, then is an downtrend if is above, then is an uptrend.

Here is a chart:

Has uptrend turned to downtrend without ranging and has with ranging too

There is another:

So it can’t even say after X candles must be a turning point or a pullback or after X range.

The billionaire question is what to do on a new LL? – buy it or sell it? – same with HH

Best Binary Options Brokers 2020:
  • Binarium
    Binarium

    The Best Binary Options Broker 2020!
    Perfect For Beginners!
    Free Demo Account!
    Free Trading Education!
    Sign-up Bonus!

  • Binomo
    Binomo

    Trustful Broker!

Many system works, but they work or in trending market or in ranging market.

I would like to make an indicator / system, where it shows 3 states: uptrend, ranging, downtrend for the past.
Also I would like to have some prediction of “maybe is a change now”. For this MACD and Stochastic are the best candidates as I know, but I can’t use it properly: or no signal (way to late) or fake signals.

Coding uptrends and downtrends

This topic contains 1 reply, has 2 voices, and was last updated by Nicolas 2 years, 9 months ago.

In prorealtime charts you can set the system to colour code when a Moving Average is in an uptrend and when it is in a downtrend.

If you want to use this in a automated strategy, e.g. you create an indicator which is the 50day moving average basis closing prices.

then you want to code the system such that it can identify if the 50MA is an uptrend or a downtrend.

what i cant find is how you write this in code.

Recognize And Exploit Uptrends and Downtrends

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

stocktrends / stocktrends / indicators.py /

Users who have contributed to this file

import numpy as np
import pandas as pd
# import ray.dataframe as pd
class Instrument :
def __init__ ( self , df ):
self . odf = df
self . df = df
self . _validate_df ()
ohlc =
UPTREND_CONTINUAL = 0
UPTREND_REVERSAL = 1
DOWNTREND_CONTINUAL = 2
DOWNTREND_REVERSAL = 3
def _validate_df ( self ):
if not self . ohlc . issubset ( self . df . columns ):
raise ValueError ( ‘DataFrame should have OHLC <> columns’ . format ( self . ohlc ))
class Renko ( Instrument ):
PERIOD_CLOSE = 1
PRICE_MOVEMENT = 2
TREND_CHANGE_DIFF = 2
brick_size = 1
chart_type = PERIOD_CLOSE
def get_ohlc_data ( self ):
if self . chart_type == self . PERIOD_CLOSE :
self . period_close_bricks ()
else :
self . price_movement_bricks ()
return self . cdf
def price_movement_bricks ( self ):
pass
def period_close_bricks ( self ):
brick_size = self . brick_size
columns = [ ‘date’ , ‘open’ , ‘high’ , ‘low’ , ‘close’ ]
self . df = self . df [ columns ]
self . cdf = pd . DataFrame (
columns = columns ,
data = [],
)
self . cdf . loc [ 0 ] = self . df . loc [ 0 ]
close = self . df . loc [ 0 ][ ‘close’ ] // brick_size * brick_size
self . cdf . loc [ 0 , 1 :] = [ close – brick_size , close , close – brick_size , close ]
self . cdf [ ‘uptrend’ ] = True
columns = [ ‘date’ , ‘open’ , ‘high’ , ‘low’ , ‘close’ , ‘uptrend’ ]
for index , row in self . df . iterrows ():
close = row [ ‘close’ ]
date = row [ ‘date’ ]
row_p1 = self . cdf . iloc [ – 1 ]
uptrend = row_p1 [ ‘uptrend’ ]
close_p1 = row_p1 [ ‘close’ ]
bricks = int (( close – close_p1 ) / brick_size )
data = []
if uptrend and bricks >= 1 :
for i in range ( bricks ):
r = [ date , close_p1 , close_p1 + brick_size , close_p1 , close_p1 + brick_size , uptrend ]
data . append ( r )
close_p1 += brick_size
elif uptrend and bricks – 2 :
uptrend = not uptrend
bricks += 1
close_p1 -= brick_size
for i in range ( abs ( bricks )):
r = [ date , close_p1 , close_p1 , close_p1 – brick_size , close_p1 – brick_size , uptrend ]
data . append ( r )
close_p1 -= brick_size
elif not uptrend and bricks – 1 :
for i in range ( abs ( bricks )):
r = [ date , close_p1 , close_p1 , close_p1 – brick_size , close_p1 – brick_size , uptrend ]
data . append ( r )
close_p1 -= brick_size
elif not uptrend and bricks >= 2 :
uptrend = not uptrend
bricks -= 1
close_p1 += brick_size
for i in range ( abs ( bricks )):
r = [ date , close_p1 , close_p1 + brick_size , close_p1 , close_p1 + brick_size , uptrend ]
data . append ( r )
close_p1 += brick_size
else :
continue
sdf = pd . DataFrame ( data = data , columns = columns )
self . cdf = pd . concat ([ self . cdf , sdf ])
self . cdf . reset_index ( inplace = True , drop = True )
return self . cdf
def shift_bricks ( self ):
shift = self . df [ ‘close’ ]. iloc [ – 1 ] – self . bdf [ ‘close’ ]. iloc [ – 1 ]
if abs ( shift ) self . brick_size :
return
step = shift // self . brick_size
self . bdf [[ ‘open’ , ‘close’ ]] += step * self . brick_size
class LineBreak ( Instrument ):
line_number = 3
def uptrend_reversal ( self , close ):
lows = [ self . cdf . iloc [ i ][ ‘low’ ] for i in range ( – 1 , – self . line_number – 1 , – 1 )]
least = min ( lows )
return close least
def downtrend_reversal ( self , close ):
highs = [ self . cdf . iloc [ i ][ ‘high’ ] for i in range ( – 1 , – self . line_number – 1 , – 1 )]
highest = max ( highs )
return close > highest
def get_ohlc_data ( self ):
columns = [ ‘date’ , ‘open’ , ‘high’ , ‘low’ , ‘close’ ]
self . df = self . df [ columns ]
self . cdf = pd . DataFrame ( columns = columns , data = [])
for i in range ( self . line_number ):
self . cdf . loc [ i ] = self . df . loc [ i ]
self . cdf [ ‘uptrend’ ] = True
columns = [ ‘date’ , ‘open’ , ‘high’ , ‘low’ , ‘close’ , ‘uptrend’ ]
for index , row in self . df . iterrows ():
close = row [ ‘close’ ]
row_p1 = self . cdf . iloc [ – 1 ]
uptrend = row_p1 [ ‘uptrend’ ]
open_p1 = row_p1 [ ‘open’ ]
close_p1 = row_p1 [ ‘close’ ]
if uptrend and close > close_p1 :
r = [ close_p1 , close , close_p1 , close ]
elif uptrend and self . uptrend_reversal ( close ):
uptrend = not uptrend
r = [ open_p1 , open_p1 , close , close ]
elif not uptrend and close close_p1 :
r = [ close_p1 , close_p1 , close , close ]
elif not uptrend and self . downtrend_reversal ( close ):
uptrend = not uptrend
r = [ open_p1 , close , open_p1 , close ]
else :
continue
sdf = pd . DataFrame ( data = [[ row [ ‘date’ ]] + r + [ uptrend ]], columns = columns )
self . cdf = pd . concat ([ self . cdf , sdf ])
self . cdf . reset_index ( inplace = True )
return self . cdf
class PnF ( Instrument ):
box_size = 2
reversal_size = 3
@ property
def brick_size ( self ):
return self . box_size
def get_state ( self , uptrend_p1 , bricks ):
state = None
if uptrend_p1 and bricks > 0 :
state = self . UPTREND_CONTINUAL
elif uptrend_p1 and bricks * – 1 >= self . reversal_size :
state = self . UPTREND_REVERSAL
elif not uptrend_p1 and bricks 0 :
state = self . DOWNTREND_CONTINUAL
elif not uptrend_p1 and bricks >= self . reversal_size :
state = self . DOWNTREND_REVERSAL
return state
def roundit ( self , x , base = 5 ):
return int ( base * round ( float ( x ) / base ))
def get_ohlc_data ( self , source = ‘close’ ):
source = source . lower ()
box_size = self . box_size
data = self . df . itertuples ()
uptrend_p1 = True
if source == ‘close’ :
open_ = self . df . ix [ 0 ][ ‘open’ ]
close = self . roundit ( open_ , base = self . box_size )
pnf_data = [[ 0 , 0 , 0 , 0 , close , True ]]
else :
low = self . df . ix [ 0 ][ ‘low’ ]
open_ = self . roundit ( low , base = self . box_size )
pnf_data = [[ 0 , 0 , open_ , open_ , open_ , True ]]
for row in data :
date = row . date
close = row . close
open_p1 = pnf_data [ – 1 ][ 1 ]
high_p1 = pnf_data [ – 1 ][ 2 ]
low_p1 = pnf_data [ – 1 ][ 3 ]
close_p1 = pnf_data [ – 1 ][ 4 ]
if source == ‘close’ :
bricks = int (( close – close_p1 ) / box_size )
elif source == ‘hl’ :
if uptrend_p1 :
bricks = int (( row . high – high_p1 ) / box_size )
else :
bricks = int (( row . low – low_p1 ) / box_size )
state = self . get_state ( uptrend_p1 , bricks )
if state is None :
continue
day_data = []
if state == self . UPTREND_CONTINUAL :
for i in range ( bricks ):
r = [ date , close_p1 , close_p1 + box_size , close_p1 , close_p1 + box_size , uptrend_p1 ]
day_data . append ( r )
close_p1 += box_size
elif state == self . UPTREND_REVERSAL :
uptrend_p1 = not uptrend_p1
bricks += 1
close_p1 -= box_size
for i in range ( abs ( bricks )):
r = [ date , close_p1 , close_p1 , close_p1 – box_size , close_p1 – box_size , uptrend_p1 ]
day_data . append ( r )
close_p1 -= box_size
elif state == self . DOWNTREND_CONTINUAL :
for i in range ( abs ( bricks )):
r = [ date , close_p1 , close_p1 , close_p1 – box_size , close_p1 – box_size , uptrend_p1 ]
day_data . append ( r )
close_p1 -= box_size
elif state == self . DOWNTREND_REVERSAL :
uptrend_p1 = not uptrend_p1
bricks -= 1
close_p1 += box_size
for i in range ( abs ( bricks )):
r = [ date , close_p1 , close_p1 + box_size , close_p1 , close_p1 + box_size , uptrend_p1 ]
day_data . append ( r )
close_p1 += box_size
pnf_data . extend ( day_data )
self . cdf = pd . DataFrame ( pnf_data [ 1 :])
self . cdf . columns = [ ‘date’ , ‘open’ , ‘high’ , ‘low’ , ‘close’ , ‘uptrend’ ]
return self . cdf
def get_bar_ohlc_data ( self , source = ‘close’ ):
df = self . get_ohlc_data ( source = source )
df [ ‘trend_change’ ] = df [ ‘uptrend’ ]. ne ( df [ ‘uptrend’ ]. shift (). bfill ()). astype ( int )
df [ ‘trend_change_-1’ ] = df [ ‘trend_change’ ]. shift ( – 1 )
start = df . iloc [ 0 ]. values
df = df [( df [ ‘trend_change’ ] == 1 ) | ( df [ ‘trend_change_-1’ ] == 1 )]
data = np . vstack ([ start , df . values ])
df = pd . DataFrame ( data )
df . columns = [ ‘date’ , ‘open’ , ‘high’ , ‘low’ , ‘close’ , ‘uptrend’ , ‘tc’ , ‘tc1’ ]
bopen = df [[ ‘date’ , ‘open’ ]][ df . index % 2 == 0 ]
bclose = df [[ ‘date’ , ‘close’ ]][ df . index % 2 == 1 ]
bopen . reset_index ( inplace = True , drop = True )
bclose . reset_index ( inplace = True , drop = True )
bopen [ ‘close’ ] = bclose [ ‘close’ ]
df = bopen
df [ ‘high’ ] = df [[ ‘open’ , ‘close’ ]]. max ( axis = 1 )
df [ ‘low’ ] = df [[ ‘open’ , ‘close’ ]]. min ( axis = 1 )
df . dropna ( inplace = True )
df [[ ‘open’ , ‘close’ ]] = df [[ ‘open’ , ‘close’ ]]. astype ( float )
return df
  • © 2020 GitHub, Inc.
  • Terms
  • Privacy
  • Security
  • Status
  • Help

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

How to describe an uptrend/downtrend in stock or market?

Atul Suri, Trader & Investor explains how one can identify the uptrend or downtrend in a stock or market.

Q: How would you describe the stock or a market that is in an uptrend versus the downtrend? What marks out that clear directional move for it?

A: For this I will have to go back to the father of modern technical analysis, Charles Dow. He came up with the Dow Theory and this is the first attempt and I would say a very successful attempt which is even valid today of defining a trend. So, how he defines a trend is that when a stock is moving up, how we would say it is in an uptrend; a stock makes a move up, every stock or every market corrects, so it moves down. However, the next move surpasses the previous high and again it corrects. The next move again surpasses the previous high. So, essentially you say a market or a stock is in an uptrend.

If the market makes new highs – it’s like climbing steps; if you are blindfolded and every step you take is a higher step so you know that you are climbing upstairs that means a trend is up and you are blindfolded but your next step is lower and lower and lower, so that is the inverse.

So, the moment the market starts making newer lows you know that you are in a downtrend. so, that in all its simplicity is what Charles Dow came out with the Dow Theory and that is what define trends and that holds very true because when you look at the bigger moves in the market they are all – one of the underlying principles is higher tops and higher bottoms and in an uptrend lower tops and lower bottoms in a downtrend and it is as simple as that.

Best Binary Options Brokers 2020:
  • Binarium
    Binarium

    The Best Binary Options Broker 2020!
    Perfect For Beginners!
    Free Demo Account!
    Free Trading Education!
    Sign-up Bonus!

  • Binomo
    Binomo

    Trustful Broker!

Like this post? Please share to your friends:
Binary Options Wiki
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: