EMA SLOPE

Viewing 15 posts - 1 through 15 (of 30 total)
  • Author
    Posts
  • #44905 quote
    grimweasel47
    Participant
    Senior

    Hi All,

    I’m just trying to add a line of code as per below to my ProOrder. What I want is to take long or short positions as long as ‘Close’ is >< than ema, but with a further condition that longer term ema (50 in this case) is sloping UP for longs and DOWN for shorts, but within bounds (ie not over extended either way). On backtest the results from the code below are promising but I want to check the Long and/or Short command line is correct and not overly optimized?

    Thanks in Advance

    // --- indicators
    ema = exponentialaverage[15](close)
    ema2 = exponentialaverage[20](close)
    //change = ROC(exponentialaverage[48](close))
    atr = averagetruerange[24]
    hh = highest[15](high)
    ll = lowest[15](low)
    Slope = ema2 - ema2[6]
    Long = slope >0.01 and slope <2
    Short = slope <0 and slope >2
    #44912 quote
    Nicolas
    Keymaster
    Master

    I think there is something wrong with your “Short” variable. The slope could not be at the same time inferior to 0 and superior to 2 🙂 I think it should be >-2?

    #44947 quote
    grimweasel47
    Participant
    Senior

    Thanks Nicolas I will adjust. But if ema-ema(4) is negative then putting >- would be a double negative ie positive no? Is there a better way of determining ma slope (ie not flat)?

    Also, is there an easy way of rather than buy above ‘n’ bars low/high on chart based on bar count, can PRT determine the previous swing high/low to the left of price (ie previous HH or LL) rather than telling PRT to look for a certain amount of bars? what I have found is that the HH and LL could occur between 1-24 hours prior so using count misses some – or would n=24 only trade above/below the HH or LL in that 24hr period?

    hh = highest[a](high)
    ll = lowest[a](low)
    #44948 quote
    Nicolas
    Keymaster
    Master

    Superior to -2 is everything between 0 and -2 in your example. So I think your code is right. You can make a simple indicator that return this slope calculation to see how it goes..

    If n=24,then your code will return you the real highest high and lowest low of this whole data serie (from now to 24 bars ago).

    #46634 quote
    grimweasel47
    Participant
    Senior

    Thanks Nicolas

    I have another issue in that PRT code is such :

    // --- settings
    balance = 10000 //balance of the strategy when activated the first time
    minlot = 1 //minimum lot size for the current instrument (example: 1 for DAX)
    riskpercent = 2 //risk percent per trade
    activationtime = 060000 //Close time of the candle to activate the strategy
    LimitHour = 130000//limit time>

     

    then later in code…

    if time=activationtime then
    // case 1 : If price candle touches MA (even wicks) then look at high or low of signal candle
    if high>ema and low<ema then
    case = 1

    but the system on IGindex is not respecting the activateontime instruction. It seems to be activating trades at 00:01? Is there something I am missing?

    Many thanks

    #46643 quote
    Nicolas
    Keymaster
    Master

    The ‘activationtime’ must be met in the timeframe that the strategy is currently running on. On a Daily timeframe, that’s impossible since the code is only read once per bar at Close. So to check if the current time is 6 o’clock in the morning, your strategy must run in a intraday timeframe.

    #46696 quote
    grimweasel47
    Participant
    Senior

    Hi Nicolas -thanks for the reply.  I have moved the strategy on to other pairs now using IGindex. I replicated your original code but changed the ‘activationtime’ from 070000 to ‘x’ depending on the back tests in PRT. When I took this code across to IGindex I had to make a few changes such as they report FX as 11200 instead of 1.1200 for example which changed the #floor and ceil indicator settings. These are now all working. The problem is that the TIME function is not working even on H1 timeframe.  The strategy seems to be activating on the next candle when I start the automatic trading in IG. Is this because their time stamp is different?

    Thanks in advance!

    #46699 quote
    grimweasel47
    Participant
    Senior

    Looking at when the errant trades are happening it seems to be activating at 00:00.00hrs when the strategy has not traded for more than 2 days (it happens most over the weekend as the strategy doesn’t trade Fridays and Mondays so the opening on Tues seems to activate the trade instead of 060000hrs under command ‘activationtime = 060000’

    #46702 quote
    Nicolas
    Keymaster
    Master

    I’m sorry but what is the strategy we are talking about?

    #46705 quote
    grimweasel47
    Participant
    Senior

    The eurusd first-hour strategy that you coded for me privately.  Should I email instead? Everything else is now working just it seems on a few pairs the trades are being taken before the activateontime =x.  Could this be related to later parts of code that cause the issues if it has not traded the day before:

    if onmarket or (onmarket[1] and not onmarket) or (currentprofit<>strategy rofit) then
    alreadytraded = 1
    endif
    
    #46783 quote
    grimweasel47
    Participant
    Senior

    As you can see from the attached, this system should not open new trades after 2100hrs each day; yet it is still opening trades at 00:00.00 hrs??

    usdjpy-orders.png usdjpy-orders.png
    #46786 quote
    grimweasel47
    Participant
    Senior

    The part of the code that sets the pending orders shouldn’t allow trading past 2100 when Limithour = 210000

    while case <> 0  and daytrading=1 and time <=LimitHour do
    if levelhi>0 then
    buy size contract at levelhi stop
    endif
    if levello>0 then
    sellshort size contract at levello stop
    endif
    wend
    endif

    Any help appreciated.

    #47235 quote
    grimweasel47
    Participant
    Senior

    Is the ever devout Nicolas ill or on holiday? Hope all is well?

    #47264 quote
    Nicolas
    Keymaster
    Master

    I’m well but kinda overwhelm 🙂 What is the timeframe you are using for that strategy? A pending order is active during 1 bar, so set STOP orders at 210000 and they will last until the end of the bar which is 220000 if you are trading on a 1 hour timeframe for instance.

    #47308 quote
    grimweasel47
    Participant
    Senior

    Ahh right, thanks Nicolas. That makes sense now. So if limithour= 1800(00) then the system would not enter any new orders after 1859(59)hrs then?

     

    I take it that with activationtime= 0800(00) then the strategy would not take any trades until after 0800 then?

     

    Yes, using the H1 timeframe

Viewing 15 posts - 1 through 15 (of 30 total)
  • You must be logged in to reply to this topic.

EMA SLOPE


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 29 replies,
has 2 voices, and was last updated by grimweasel47
8 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/30/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...