Escolar Documentos
Profissional Documentos
Cultura Documentos
com/QuantNews_com)
ARTIGOS (HTTPS://WWW.QUANTNEWS.COM/ARTICLES/)
MANCHETES (/FEED_TYPE/HEADLINE/)
PESQUISA (HTTPS://WWW.QUANTNEWS.COM/RESEARCH/)
NEW
Pesquisar…
ACESSE DADOS AO
VIVO GRATUITOS
VIA API REST
WEBINAR: CRIANDO
UM SISTEMA ALGO
(https://www.quantnews.com/wp-
content/uploads/2018/11/pyticommand.png)
/
# hon
pyt Returns true if stream1 crossed over stream2 in most rec
def crossesOver(stream1, stream2): Tweets by
@FXCM_MarketData
# If stream2 is an int or float, check if stream1 has
if isinstance(stream2, int) or isinstance(stream2, flo
if stream1[len(stream1)-1] <= stream2:
FXCM Market D
@FXCM_Market
return False
else:
#USDJPY SSI is
at 1.98
if stream1[len(stream1)-2] > stream2:
return False
Risk Warning:
elif stream1[len(stream1)-2] < stream2:
Losses can
return True
exceed deposits.
else: Disclaimer: Past
x = 2 performance is
while stream1[len(stream1)-x] == stream2: not indicative of
x = x + 1 future results.
if stream1[len(stream1)-x] < stream2:
return True
else:
return False
# Check if stream1 has crossed over stream2
else:
if stream1[len(stream1)-1] <= stream2[len(stream2)
return False
else: Jul 9, 2020
/
# hon
pyt Returns true if stream1 crossed under stream2 in most re
def crossesUnder(stream1, stream2):
# If stream2 is an int or float, check if stream1 has
if isinstance(stream2, int) or isinstance(stream2, flo
if stream1[len(stream1)-1] >= stream2:
return False
else:
if stream1[len(stream1)-2] < stream2:
return False
elif stream1[len(stream1)-2] > stream2:
return True
else:
x = 2
while stream1[len(stream1)-x] == stream2:
x = x + 1
if stream1[len(stream1)-x] > stream2:
return True
else:
return False
# Check if stream1 has crossed under stream2
else:
if stream1[len(stream1)-1] >= stream2[len(stream2)
return False
else:
if stream1[len(stream1)-2] < stream2[len(strea
return False
elif stream1[len(stream1)-2] > stream2[len(str
return True
else:
x = 2
while stream1[len(stream1)-x] == stream2[l
x = x + 1
if stream1[len(stream1)-x] > stream2[len(s
return True
else:
return False
/
# hon
pyt Returns number of Open Positions for symbol in the direc
def countOpenTrades(BuySell=None):
openpositions = con.get_open_positions(kind='list')
isbuy = True
counter = 0
if BuySell == "S":
isbuy = False
for position in openpositions:
if position['currency'] == symbol:
if BuySell is None or position['isBuy'] == isb
counter+=1
return counter
# hon
pyt This function is run every time a candle closes
def Update():
print(str(dt.datetime.now()) + " " + timeframe + "
# Calculate Indicators
iFastSMA = sma(pricedata['bidclose'], fast_sma_periods
iSlowSMA = sma(pricedata['bidclose'], slow_sma_periods
# Print Price/Indicators
print("Close Price: " + str(pricedata['bidclose'][len(
print("Fast SMA: " + str(iFastSMA[len(iFastSMA)-1]))
print("Slow SMA: " + str(iSlowSMA[len(iSlowSMA)-1]))
Next, we need to code our entry logic. If the Fast SMA crosses over the
Slow SMA, we buy. If the Fast SMA crosses under the Slow SMA, we sell.
We will use our crossesOver(), crossesUnder() and enter() functions. Also,
note that we want to exit opposing positions if close_on_opposing_signal
equals True and an opposing position exists. We use the
countOpenTrades() function to see if we have any opposing positions and
the exit() function to close them out if we do.
/
Agora precisamos importar a lógica do SMA para o nosso código.
Adicionaremos isso logo abaixo de nossas outras declarações de Best Practices fo
importação. 00:00 59:30
import
python fxcmpy
import time
SEMINÁRIO ON-
import datetime as dt
from pyti.simple_moving_average import simple_moving_avera LINE: USANDO
DADOS PREMIUM
######
python USER PARAMETERS ######
token = 'INSERT-TOKEN-HERE' INTRODUÇÃO AO
symbol = 'GBP/USD'
SEMINÁRIO ON-
timeframe = "m1" # (m1,m5,m15,m30,H1,H2,H3,H4,H6,H8,D1,W1,
fast_sma_periods = 10 LINE DE
slow_sma_periods = 20 APRENDIZADO DE
close_on_opposing_signal = True
amount = 1 MÁQUINA
stop = -10
limit = 30
#############################
Algo Trading | Int
/
# hon
pyt TRADING LOGIC
# If Fast SMA crosses over Slow SMA, Open Buy Trade
if crossesOver(iFastSMA,iSlowSMA):
print(" BUY SIGNAL!")
if close_on_opposing_signal and countOpenTrades("S") >
print(" Closing Sell Trade(s)...")
exit("S")
print(" Opening Buy Trade...")
enter("B")
# If Fast SMA crosses under Slow SMA, Open Sell Trade
if crossesUnder(iFastSMA,iSlowSMA):
print(" SELL SIGNAL!")
if close_on_opposing_signal and countOpenTrades("B") >
print(" Closing Buy Trade(s)...")
exit("B")
print(" Opening Sell Trade...")
enter("S")
(https://www.quantnews.com/wp-content/uploads/2019/01/SMA-
Crossover-Strategy-Command-Start.png)
The strategy is now up and running and will open and close trades per our
rules!
/
(https://www.quantnews.com/wp-content/uploads/2019/01/SMA-
Crossover-Strategy-Running.png)
WHAT NEXT?
This SMA Crossover strategy is a classic trend trading strategy, but there
are definitely ways it can be expanded upon and improved. Please edit and
make this strategy your own! Also, make sure to check out our other
Python strategies we have available at https://github.com/fxcm/RestAPI
(https://github.com/fxcm/RestAPI)
Risk Warning: The FXCM Group does not guarantee accuracy and will not accept
liability for any loss or damage which arise directly or indirectly from use of or
reliance on information contained within the webinars. The FXCM Group may
provide general commentary which is not intended as investment advice and
must not be construed as such. FX/CFD trading carries a risk of losses in excess
of your deposited funds and may not be suitable for all investors. Please ensure
that you fully understand the risks involved.
Quantnews is the education website of FXCM Group. Quantnews will not accept liability for any loss or damage including,
without limitation, to any loss of profit which may arise directly or indirectly from use of or reliance on such information.
Quantnews assumes no liability for errors, inaccuracies or omissions; does not warrant the accuracy, completeness of
information, text, graphics, links or other items contained within these materials. Any opinions, news, research, analyses,
prices, other information, or links to third-party sites contained on this website are provided as general market
commentary and do not constitute investment advice. The market commentary has not been prepared in accordance with
legal requirements designed to promote the independence of investment research, and it is therefore not subject to any
prohibition on dealing ahead of dissemination. Links to third-party sites are provided for your convenience. Such sites are
not within our control and Quantnews does not endorse nor is responsible for the security, content or availability of the
information contained within third-party sites.
Market Opinions: Any opinions, news, research, analyses, prices, other information, or links to third-party sites contained
on this website are provided as general market commentary and do not constitute investment advice. The market
commentary has not been prepared in accordance with legal requirements designed to promote the independence of
investment research, and it is therefore not subject to any prohibition on dealing ahead of dissemination. Quantnews will
/
not accept liability for any loss or damage including, without limitation, to any loss of profit which may arise directly or
indirectly from use of or reliance on such information. Quantnews assumes no liability for errors, inaccuracies or omissions;
does not warrant the accuracy, completeness of information, text, graphics, links or other items contained within these
materials.
/
# hon
pyt This function places a market order in the direction Buy 00:00 01:26:36
def enter(BuySell): Algo Trading We
direction = True;
if BuySell == "S":
direction = False; VÍDEO DO
try: SEMINÁRIO ON-
opentrade = con.open_trade(symbol=symbol, is_buy=d
except:
LINE ALGO
print(" Error Opening Trade.") TRADING: PT 2
else:
print(" Trade Opened Successfully.")
Algo Trading We
A função exit ()