Moving Average Crossover strategy

Moderator: Moderator

Moving Average Crossover strategy

Postby JuliaS » Thu Oct 11, 2018 11:50 am

Sample script showing how to develop Moving Average Crossover strategy using ForexConnect-Python API is available at github.
Posts: 16
Joined: Wed Jan 25, 2017 11:19 am

Re: Moving Average Crossover strategy

Postby neural.senz » Fri Aug 09, 2019 11:16 am

I am trying to use this code from GitHub, 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)
        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:
            resp = fc.send_request(request)
            # sometimes i get a warning to use send_request_async
            order_id = resp.order_id
                "Following trade with trade_id {} has been closed successfully and order_id is {}".format(trade_id, order_id))
        except Exception as e:

Please throw some light on this issue.
Posts: 1
Joined: Fri Aug 09, 2019 8:18 am

Re: Moving Average Crossover strategy

Postby Konstantin.Toporov » Fri Oct 04, 2019 12:33 pm

We will investigate
FXCodeBase: Initiate
Posts: 113
Joined: Mon Aug 31, 2015 10:16 am

Return to ForexConnect-Python API

Who is online

Users browsing this forum: No registered users and 1 guest