Help with Code moving average crossover

Forums ProRealTime English forum ProOrder support Help with Code moving average crossover

  • This topic has 10 replies, 2 voices, and was last updated 8 years ago by avatarMark.
Viewing 11 posts - 1 through 11 (of 11 total)
  • #16401

    Hello,

     

    I was wondering if someone would be kind enough to help me with something, I’m sure it would be an easy job for someone who knows how to code. I am new to automated trading, i usually manual trade but I’m keen to play around with automating my systems.

    What i would like is a code to do the following…

     

    LONG

    Entry – 5EMA crosses above 200EMA

    Exit – 5EMA crosses below 100EMA

     

    SHORT

    Entry – 5EMA crosses below 200EMA

    Exit – 5EMA crosses above 100EMA

     

    The entry and exit signals are pretty straight forward but i struggle with the risk management, position size and stop loss part. Here is the criteria…

     

    I want to risk 3% per trade

    I want my stop loss to be positioned at the previous 15 bar high or low (depending on whether we are long or short)

     

    This system may be a very simple bit of code for someone in the know, any help would be greatly appreciated to start me on my automated trading journey.

     

    Mark

    #16479

    You are right, this is something simple for someone in the know 🙂

    Did you test the code creator assistant? I’m pretty sure it can handle this with ease 🙂

    #16495

    Thank you for your reply,

    its the stop loss part I’m struggling with, I want my stop loss to be the previous 15 bar high low depending on whether I’m going long or short, I then want to stop loss to determine my position size by calculating 3% of my account size divided by my stop loss.

     

    on a separate note..

    why does pro real time only allow the pointsize to be round numbers and not pounds and pence?

     

    Mark

    #16500

    I coded your EMA cross trading strategy accordingly to your description. Money management lot calculation are made upon the last 15 bars highest high and lowest low.

    You’ll find the ITF file to import into your platform attached to this post. Please let us know if you have trouble importing it.

     

    #16523

    I have successfully imported the code, many thanks for you’re help.

    Can i just add, i think the website is brilliant, and very helpful, i am gradually becoming converted to automated trading. If only i could find some simple systems that work well for the long haul.

     

    Mark

    #16537

    Hi again Nicolas,

    I wondered if you could give me your thoughts on my system and its results? It is the system you coded for me but i have altered some of the parameters as follows…

    • Market – EUR/GBP
    • Spread – 2
    • EMA 25/100/600 crossover
    • Starting Capital – 3000.00
    • Risk – 3%

    I have attached a screenshot of my results, is this the sort of results i need to expect before putting a system live?

    Mark

     

    1 user thanked author for this post.
    avatar ALE
    #16571

    Well, since you have optimised a bit the values, it is quite over-fit on past market data. But the strategy would have done the same thing as your backtest in real time (only stoploss and no takeprofit at all in the code).

    But, what I see here just tell me what you can expect of any trend following method: lot of consecutive loss when market is in a tight range. The real question is: do you want to suffer 10 consecutive loss with a drawdown  5765GBP in real life? when your starting account were only 3000GBP..  Don’t tell, I already know the answer 🙂

    #16576

    Nicolas,

    Trend following systems on average make 30% wining trades, the reason i have no take profit is because the big winning trades pay off all the small loosing trades, this is why strict risk management is neccessary.

    But isn’t that what you should expect from a trend following system? The 5765GBP drawdown wasn’t on 3000GBP, that was just the starting balance, the 5765GBP drawdown was on a balance of 16,000GBP which is all in proportion to the 3% risk per trade. Compounding the profits will obviously increase the amount of drawdown but it is all relevant? Trend following systems on average make 30% wining trades, the reason i have no take profit is because the big winning trades pay off all the small loosing trades, this is why strict risk management is neccessary.

    Would you advise any changed or additions for a trend following code? alternatively would you recommend trying a different system to make a steady profit? If so, what?

     

    Also the system you coded for me comes up with an error message when i try to take it live, the code is as follows…

    “this trading system had to be stopped because it tried to place a stop or limit at a negative price level. Please add protections to your code to prevent orders with negative price levels”

     

    Mark

    #16578

    To prevent the negative calculation, please delete the [1] from the lines 22,23,30,31 and see what happen.

    About the trend following method and my previous post, please don’t be offend. I understood perfectly why there were no takeprofit and of course why it is very important to embed the money management code in this strategy. Finding the best edge with mechanical trade entries is very difficult, especially with moving average crossover. Because you used tight stop and round moving average periods, I believe you are on the good way to find something nice to be traded in a live environment.

    Maybe use of breakeven of even adding orders on the same trend (like Reiner is doing with Pathfinder or cfta with the grid system) would be a nice feature to add..

    #16580

    I remove the [1] and the error has gone away. thankyou

     

    I am not offended by any of your comments, far from it, i take everything on board, i’m keen to learn. If i knew how to add breakeven and adding orders to trends i would, as i said in my original post, coding isn’t my strength haha

    #17326

    Nicolas,

    I wonder if you can add something to the code for me,

    In the code you wrote for me above it works out a stop loss of the previous 10 bar high or low…

    Im looking to keep this but have a minimum stop loss of 10, or simply add 5 to the calculated stop loss, i would like to try both options.

     

    Many thanks, mark

Viewing 11 posts - 1 through 11 (of 11 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login