Back

Python and Forex

Hey all, 

I'm new to this system, and still trying to get my bearings from the documentation and the python examples. There does not seem to be any examples for forex trading with python, all of them appear to use stocks. This shouldn't be a problem as its just a different type of equity, but I keep running into problems getting 'simple' scripts to run. Anyway, I attempted to mod the MACD stock example code as a test case, but it has backtest issues. 

Any advice/insight/guidance would be greatly appreciated. (I attached the backtest, but because it wont run the only merit is being able to see the code) {Still a really cool feature though}

 

Update Backtest








bump.
I also would be highly interested in getting an example on how to trade on fxcm with python code. just anyold "hello world" ma cross would do just fine.
0

self.AddSecurity(SecurityType.Forex, self.__Symbol)
should do the trick
1

@Andreas

Do you mind sharing your example by embedding your backtest? I haven't had the chance to try your solution?

 

0

I hope the attaching of the backtest works. I am very new here too.
anyway, I just took the code from github

just replaced "Equity" with "Forex" and ofcourse "EURUSD" instead of "SPY".

If you stumble across some good python documentation, I'd be thankfull, if you shared with me ;)

 

1


@Andreas Dekrout

At this point the best documentation, I have seen is the style guide. Which they are going to update. However, they are working on adding numpy and pandas support which will be amazing.

1

Thanks a ton for the specifics btw, (can't edit previous posts)

0

I also haven't had much luck finding other users on here that code forex algo's using python. Here;s my most successful backtest. I just joined the site a week ago. I'm learning on my feet. I'm doing a simple buy low sell high, sell high/buy low,  strategy with CCI indicator. Feedback?

0


Hi Apollos Hill, your algorithm looks fine to me. It is a clean, easy to read, code and you used the API properly.
My only critic is on the order quantity: why are you fixing the order quantity to 40000 shares? This is not optimal, because you are not taking advantage of compounding.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Alexandre. 
when you say compounding, do you mean trading on my winnings instead of a flat number of 40,000? that thought hadn't occured to me yet. I should implement that. Can you start me on that code? I guess I would need to write a statement that says...setmarket order of a particular percentage of my portfolio (that i'm willing to risk)?

0

Alex means sizing your position based on the total number of assets available in your account (e.g. 50% of portfolio value / share price = quantity). 

Personally, I prefer to use a fixed position sizing like you've done here as it eliminates compounding allowing you to judge the algorithm purely on its insights over time. Compounding and leverage are mechanisms available to every algorithm so its best to remove them from backtests so it is easier to compare algorithms. 

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi thanks for the feedback Jared. That is my goal to purely test the skill of the strategy before i start "optimizing" and managing risk. Can someone take a look at this? I've run a few tests and my algo only logs like 5 trades but on the chart it shows that its buying and selling throughout the year. I have the timeframe set to minute...? is there something wrong with m CCI values? 

0


Hi Apollos,in your algorithm,  orders are placed when "not self.Portfolio.Invested". It means if you have any open positions in the portfolio, "self.SetHoldings" or "self.StopMarketOrder" wouldn't be triggered. The custom chart plots the CCI value, it does not reveal the internal trading logic of your algorithm. You can not check the order execution with only CCI indicator value. It is better to add the log message in the algorithm to find out if the trading conditions are met in the algorithm.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed