DailyFX Home | Español | Français | 中文 | Deutsch | Italiano | العربية | Sverige | Ελληνικά


+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    David Rodriguez's Avatar
    David Rodriguez is offline Moderator David Rodriguez is an unknown quantity at this time
    Join Date
    Jan 2007
    Posts
    725

    ENTRY/EXIT - FX Seasonality Coding Example

    Years of forex market data shows that currencies will most likely set their highs and lows for the week at the beginning and end of the trading week. Intuitively this makes sense: if a currency is in a fairly consistent uptrend, its low on Monday will likely hold through Friday and the opposite should also be true. Furthermore, major European and North American currencies will also tend to see larger price moves towards the end of the week.

    Of course this is all very interesting, but the first question that immediately comes to mind should be obvious: how do we use this in our trading?

    Using FXCM’s Strategy Trader software, we will code a strategy based on intra-week seasonality and apply it to a number of different currency pairs.

    The .zip attachment below contains an .fxd source code file and an .fxw workspace to use the following example seasonality strategy:

    Entry Rule: On Tuesday, set a Buy Stop entry order at Monday’s high, a Sell Stop entry order at Monday’s low. We will maintain these Buy and Sell Stop entry orders throughout the week unless we have already gone long or short the pair, respectively.

    Stop Loss: The opposite stop entry order will take us out of a given position and set a trade in the opposite direction. This will be the case unless there was already an order triggered in the other direction through the previous week of trade. In other words, if the strategy goes long at Monday’s high but subsequently flips direction at Monday’s low, there will be no stop order in place on the ensuing short position.

    Take Profit: None

    Exit Rule: Close as near to Friday’s closing price as possible.


    View the full article on DailyFX.com here: Forex @ DailyFX - Forex Strategy Corner: Using Seasonality Strategies in Your Trading

    I've edited the code and the workspace so that the strategy now uses a 15min time series and 1-day chart for the weekday signals. Backtesting on a 15-min chart makes the results somewhat more accurate, though backtesting is never a good substitute for live testing.

    There are now four inputs on the strategy.

    Profit target: In individual currency terms. e.g. an input of .0150 for the EURUSD would translate to a 150 pip profit target on individual positions. If set to "0", there is no profit target used.

    Stop Loss: Same mechanics as Profit Target. If set to "0", no stop loss is used. Given that this strategy has no stop loss by default, this much is highly recommended.

    FridayHour: The hour of day on Friday that this will close the position.

    FridayMinute: The minute of said hour on Friday that this will close the position.

    e.g. a FridayHour of 16 and FridayMinute of 25 would make the strategy close its open position at 16:25 on Friday.
    Attached Files
    Last edited by Lucas Izidoro; 11-24-2010 at 09:29 AM.
    David Rodriguez is the author of Forex Trading Signals and Forex Trading Weekly Forecast on DailyFX.com.

  2. #2
    Wilko042 is offline Member Wilko042 is on a distinguished road
    Join Date
    Mar 2008
    Posts
    29
    I really like your coding examples and they are helping me out with my own understanding of how to code.

    I have plenty of experience in MT4 and EasyLanguage but trying to get to grips with this new platform.

    In your code you use

    Code:
    			btc_market  = 
    				OrdersFactory.CreateMarketThisBar(new OrdersCreateParams(Lots.Variable, "FridayCloseBuy", OrderAction.BuyToCover));
    Code:
    			if(MarketPosition != 0){ //If strategy currently holds a long or short position
    					if(stopLoss>0) GenerateStopLoss(stopLoss); //if stopLoss input is used (not zero), set stop
    					if(profitTarget>0) GenerateProfitTarget(profitTarget); //if profitTarget input used (not zero), set target
    			}
    I really like this style of coding but have not found any reference in the help pages to GenerateStopLoss. Presumably there are more of these functions in OrdersFactory but where is the documentation on this?

    Many thanks.

  3. #3
    David Rodriguez's Avatar
    David Rodriguez is offline Moderator David Rodriguez is an unknown quantity at this time
    Join Date
    Jan 2007
    Posts
    725
    Quote Originally Posted by Wilko042 View Post
    I really like your coding examples and they are helping me out with my own understanding of how to code.

    I have plenty of experience in MT4 and EasyLanguage but trying to get to grips with this new platform.

    In your code you use

    Code:
    			btc_market  = 
    				OrdersFactory.CreateMarketThisBar(new OrdersCreateParams(Lots.Variable, "FridayCloseBuy", OrderAction.BuyToCover));
    Code:
    			if(MarketPosition != 0){ //If strategy currently holds a long or short position
    					if(stopLoss>0) GenerateStopLoss(stopLoss); //if stopLoss input is used (not zero), set stop
    					if(profitTarget>0) GenerateProfitTarget(profitTarget); //if profitTarget input used (not zero), set target
    			}
    I really like this style of coding but have not found any reference in the help pages to GenerateStopLoss. Presumably there are more of these functions in OrdersFactory but where is the documentation on this?

    Many thanks.
    Hi Wilco, sorry for the super-late response.

    The documentation is a bit lacking at the moment. I've moved away from using the GenerateStopLoss and GenerateProfitTarget for that reason in subsequent articles and used iPriceOrders instead.
    David Rodriguez is the author of Forex Trading Signals and Forex Trading Weekly Forecast on DailyFX.com.

  4. #4
    David Rodriguez's Avatar
    David Rodriguez is offline Moderator David Rodriguez is an unknown quantity at this time
    Join Date
    Jan 2007
    Posts
    725
    Bumping this thread because I've made some changes to the strategy.
    David Rodriguez is the author of Forex Trading Signals and Forex Trading Weekly Forecast on DailyFX.com.

  5. #5
    jedi11 is offline Member jedi11 is an unknown quantity at this time
    Join Date
    Sep 2010
    Posts
    17
    Hi, when I put the advisor into the strategy trader, it tells me the data is miss, please reload data 2.

  6. #6
    Gaurav is offline Gold Member Gaurav is an unknown quantity at this time
    Join Date
    Mar 2010
    Posts
    496
    Quote Originally Posted by jedi11 View Post
    Hi, when I put the advisor into the strategy trader, it tells me the data is miss, please reload data 2.
    This error means that you are missing a data stream on the chart. Right click on the chart and select "Insert Symbol". From there you can add another price stream to the same chart window.

  7. #7
    David Rodriguez's Avatar
    David Rodriguez is offline Moderator David Rodriguez is an unknown quantity at this time
    Join Date
    Jan 2007
    Posts
    725
    Quote Originally Posted by jedi11 View Post
    Hi, when I put the advisor into the strategy trader, it tells me the data is miss, please reload data 2.
    Gaurav is right. Open the sample workspace included in the above zip file and you will see the format necessary to run this strategy. (i.e. 15min chart with Data2 set as a 1-day chart of the same symbol)
    David Rodriguez is the author of Forex Trading Signals and Forex Trading Weekly Forecast on DailyFX.com.

  8. #8
    FXTrader33 is offline Member FXTrader33 is an unknown quantity at this time
    Join Date
    Nov 2010
    Posts
    19

    Problems?

    There are some problems I have come across when using this stEA.

    1. I need to set the inputs at 1:3 risk reward ratio profit 150 stoploss 50 which are not as set on the attachment. currently profit 0.5 stop 0.4, how should the inputs be set.
    2. I currently have the inputs set at profit 78 stoploss 38 and they are not triggering.
    3. When running with "trading station" on an open position i am not seeing any information in the stop or limit window
    4. I have the inputs set to close positions fridays at 16:55 on trading station this morning they are still open, the EA should have closed them.

  9. #9
    bomberoneuno is offline Member bomberoneuno is an unknown quantity at this time
    Join Date
    Dec 2010
    Posts
    31
    Quote Originally Posted by FXTrader33 View Post
    There are some problems I have come across when using this stEA.

    1. I need to set the inputs at 1:3 risk reward ratio profit 150 stoploss 50 which are not as set on the attachment. currently profit 0.5 stop 0.4, how should the inputs be set.
    2. I currently have the inputs set at profit 78 stoploss 38 and they are not triggering.
    3. When running with "trading station" on an open position i am not seeing any information in the stop or limit window
    4. I have the inputs set to close positions fridays at 16:55 on trading station this morning they are still open, the EA should have closed them.
    I am a begginer with this platform i could try to help you, let me knoe if you need my help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.