Page 1 of 1

Moving Average Crossover strategy

PostPosted: Thu Oct 11, 2018 11:50 am
by JuliaS
Sample script showing how to develop Moving Average Crossover strategy using ForexConnect-Python API is available at github.

Re: Moving Average Crossover strategy

PostPosted: Fri Aug 09, 2019 11:16 am
by neural.senz
Hi,
I am trying to use this code from GitHub https://github.com/gehtsoft/forex-connect/tree/master/samples/Python, along with that I also want to close a previously open trade each time a signal reverses.
I am using below code but as soon as the previous position gets closed using this function my python code gets frozen and then didn't get price updates. I suspect the possible point I am missing is to be is threading, since i am new with ForecConnect Python API, i could not understand how to take up this issue.

Code: Select all
def close_trade(fc, buy_sell):
    open_trades_table = fc.get_table(ForexConnect.TRADES)
    open_trades_table = Common.convert_table_to_dataframe(open_trades_table)
    try:
        open_trades_table['trade_id'] = open_trades_table.index
        open_trades_table.reset_index(inplace=True, drop=True)
        open_trades_table = open_trades_table.tail(1)
        trade_id = open_trades_table.trade_id[0]

        offer = open_trades_table.offer_id[0]
        account_id = open_trades_table.account_id[0]
        amount = open_trades_table.amount[0]
        print("closing last trade")
        request = fc.create_order_request(order_type=fxcorepy.Constants.Orders.TRUE_MARKET_CLOSE, OFFER_ID=offer,
                                          ACCOUNT_ID=account_id, BUY_SELL=buy_sell, AMOUNT=str(amount), TRADE_ID=trade_id)
    except IndexError as e:
        request = None
        print("No Previous Trade Found..",str(e))

    if request is None:
        raise Exception("Cannot create close trade request")
    elif request is not None:
        try:
            resp = fc.send_request(request)
            # sometimes i get a warning to use send_request_async
            order_id = resp.order_id
            print(
                "Following trade with trade_id {} has been closed successfully and order_id is {}".format(trade_id, order_id))
        except Exception as e:
            print(e)


Please throw some light on this issue.

Re: Moving Average Crossover strategy

PostPosted: Fri Oct 04, 2019 12:33 pm
by Konstantin.Toporov
We will investigate