Rinalva Ferreira
Rinalva Ferreira
  • 情報
7+ 年
経験
0
製品
0
デモバージョン
0
ジョブ
0
シグナル
0
購読者
Rinalva Ferreira
Rinalva Ferreira
import MetaTrader5 as mt5

def initialize():
# Inicializa o MetaTrader 5
if not mt5.initialize():
print("Erro ao inicializar o MetaTrader 5")
return False

# Verifica se a corretora suporta negociação no ativo desejado
if not mt5.symbol_info("WINZ20").visible or not mt5.symbol_info("WDOZ20").visible:
print("O ativo WINZ20 ou WDOZ20 não está disponível")
return False

return True

def open_order(symbol, action, volume):
# Verifica a tendência do mercado
if not check_trend(symbol):
print("Não há tendência suficiente para abrir uma ordem")
return

# Verifica se já há ordens abertas
positions = mt5.positions_get(symbol=symbol)
if positions is not None:
print("Já há ordens abertas para o ativo", symbol)
return

# Calcula o stop loss e take profit
point = mt5.symbol_info(symbol).point
stop_loss = point * StopLoss
take_profit = point * TakeProfit

# Abre a ordem de acordo com a ação desejada
if action == 'buy':
lot = volume * Lots
result = mt5.order_send(mt5.ORDER_TYPE_BUY, symbol, lot, mt5.symbol_info(symbol).bid,
0, stop_loss, take_profit, "EA MT5", None)
elif action == 'sell':
lot = volume * Lots
result = mt5.order_send(mt5.ORDER_TYPE_SELL, symbol, lot, mt5.symbol_info(symbol).ask,
0, stop_loss, take_profit, "EA MT5", None)

# Verifica se a ordem foi aberta com sucesso
if result.retcode != mt5.TRADE_RETCODE_DONE:
print("Erro ao abrir a ordem:", result.comment)


def check_trend(symbol):
# Implemente aqui a lógica para verificar a tendência do ativo
# Utilize os topos e fundos para determinar se a tendência é de alta ou baixa
# Retorne True se a tendência for válida ou False caso contrário return True


# Parâmetros EA
TrailingStop = 20
TrailingStep = 1
LotMultiplier = 2
Lots = 1
StopLoss = = 100
TrailingStart = 30
TrailingMinimum = 10

# Inicializa o MetaTrader 5
if initialize():
# Verifica a tendência e abre as ordens
open_order("WINZ20", "buy", 1)
open_order("WDOZ20", "sell", 1)

# Finaliza o MetaTrader 5
mt5.shutdown()


ALGUEM PODE MIM AJUDA E CORRIGI ESTE CODIGO PARA TESTA NO WIN MINI INDINCE
Rinalva Ferreira
Rinalva Ferreira
bom dia gostaria de ajuda ,alguem consegue corrigir o erro para min eu agradeço


import MetaTrader5 as mt5

def initialize():
# Inicializa o MetaTrader 5
if not mt5.initialize():
print("Erro ao inicializar o MetaTrader 5")
return False

# Verifica se a corretora suporta negociação no ativo desejado
if not mt5.symbol_info("WINZ20").visible:
print("O ativo WINZ20 não está disponível")
return False

return True

def open_order(symbol, action, volume):
# Verifica a tendência do mercado
if not check_trend(symbol):
print("Não há tendência suficiente para abrir uma ordem")
return

# Verifica se já há ordens abertas
positions = mt5_get(symbol=symbol)
if positions is not None:
print("Já há ordens abertas para o ativo", symbol)
return

# Calcula o stop loss e take profit
point = mt5.symbol_info(symbol).point
stop_loss = StopLoss * point
take_profit TakeProfit * point

# Abre a ordem de acordo com a ação desejada
if action == 'buy':
lot = volume * Lots result = mt5.order_send(mt5.ORDER_TYPE_BUY, symbol, lot, mt5.symbol_info(symbol).bid,
0, stop_loss, take_profit, "EA MT5", None)
elif action == 'sell':
lot = volume * Lots
result = mt5.order_send(mt5.ORDER_TYPE_SELL, symbol, lot, mt5.symbol(symbol).ask,
0, stop_loss, take_profit, "EA MT5", None)

# Verifica se a ordem foi aberta com sucesso
if result.retcode != mt5.TRADE_RETCODE_DONE:
print("Erro ao abrir a ordem:", result.comment)


def check_trend(symbol):
# Implemente aqui a lógica para verificar a tendência do ativo
# Utilize os topos e fundos como referência

#emplo: Verifica se os 10 últimos topos ascendentes
tops = mt5.copy_rates_from_pos(symbol, mt5.TIMEFRAME_M1, 0, 10)
for i in range(1, 11):
if tops[i]['high'] > tops[i1]['high']:
return False

# Exemplo: Verifica se os 10 últimos fundos são descendentes
bottoms = mt5.copy_rates_from_pos(symbol, mt5.TIMEFRAME_M1, 0, 10)
for i in range(1, 11):
if bottoms[i]['low'] bottoms[i-1]['low']:
return False

return True


# Parâmetros EA
TrailingStop = 20
TrailingStep = 1
LotMultiplier = 2
Lots = 1
StopLoss = 15
TakeProfit = 30
TrailingStart = 15
TrailingMinimum = 10

# Inicializa o MetaTrader 5
if initialize():
# Verifica a tendência e abre as ordens
if check_trend("WINZ20"):
open_order("WINZ20", "buy", 1)

if check_trend("WINZ20"):
open_order("WINZ20", "sell", 1)

# Finaliza o MetaTrader 5
mt5.shutdown()