A continuación, siga el video para ver cómo instalar este sitio como una aplicación web en su pantalla de inicio.
Nota: This feature may not be available in some browsers.
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.order import Order
import threading
import time
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def error(self, reqId, errorCode, errorString):
print("Error:", reqId, errorCode, errorString)
def nextValidId(self, orderId):
self.nextOrderId = orderId
self.start()
def contractDetails(self, reqId, contractDetails):
print("ContractDetails:", reqId, contractDetails)
def historicalData(self, reqId, bar):
print("HistoricalData:", reqId, bar)
def start(self):
contract = Contract()
contract.symbol = "M6E"
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
contract.lastTradeDateOrContractMonth = "202406"
self.reqMarketDataType(4)
self.reqHistoricalData(1, contract, "", "1 D", "1 hour", "TRADES", 1, 1, False, [])
# Example order placement (uncomment to place an order)
# order = Order()
# order.action = "BUY"
# order.totalQuantity = 1
# order.orderType = "MKT"
# self.placeOrder(self.nextOrderId, contract, order)
def run_loop():
app.run()
app = IBapi()
app.connect("127.0.0.1", 7497, clientId=1)
# Start the socket in a thread
api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()
time.sleep(1) # Allow time for connection to establish
# Request contract details
contract = Contract()
contract.symbol = "M6E"
contract.secType = "FUT"
contract.exchange = "GLOBEX"
contract.currency = "USD"
app.reqContractDetails(0, contract)
time.sleep(5) # Wait for contract details to be received
app.disconnect()
// Namespace declaration
using System;
using NinjaTrader.Cbi;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.StrategyAnalyzer;
using NinjaTrader.NinjaScript.StrategyAnalyzer.Optimization;
// Define your strategy class
public class MyM6EStrategy : Strategy
{
// Initialize method (called once at startup)
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your strategy here.";
Name = "MyM6EStrategy";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsOverlay = false;
ExitOnSessionClose = true;
IsAccountOrderActionAllowed = true;
// Configure default parameters for your strategy
AddEma("EMA", 14);
}
else if (State == State.Configure)
{
// Add your instruments here
AddDataSeries("M6E", BarsPeriodType.Minute, 5);
}
}
// OnBarUpdate method (called on each incoming tick)
protected override void OnBarUpdate()
{
// Define your trading logic here
if (BarsInProgress != 0)
return;
// Example: Simple EMA crossover strategy
if (CrossAbove(EMA(14), Close, 1))
{
EnterLong("EMA_CrossAbove");
}
else if (CrossBelow(EMA(14), Close, 1))
{
EnterShort("EMA_CrossBelow");
}
}
}