[Python] Cannot trigger off the action in the "IF" statement for building up the trading bot...

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to building up my trading bot by trying to validate "IF" statement below can be executed or not. I can see the price data was streaming in and the price moved up above 144 (USDJPY). However, I wonder why the "IF" statement cannot be executed. Anything wrong of my code? please help if anyone knows it. Thanks

    from ib_insync import *
    import pandas as pd
    import numpy as np

    util.startLoop()
    ib = IB()
    ib.connect(host='127.0.0.1', port=4002, clientId=1)

    contract = Forex(pair="USDJPY")
    ib.qualifyContracts(contract)

    bars = ib.reqHistoricalData(
    contract,
    endDateTime="",
    durationStr="1 D",
    barSizeSetting="5 mins",
    whatToShow="MIDPOINT",
    useRTH=True,
    keepUpToDate=True
    )

    if bars[-1].close > 144:
    print("It's time to open a long position to USDJPY or close the short position")

    if bars[-1].close < 143.75:
    print("It's time to open a short position to USDJPY or close the long position")


    enter code here

    enter image description here

    Continue reading...

Compartilhe esta Página