Help with automated strategy for EURUSD

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #54819 quote
    edozar
    Participant
    New

    Hi everybody,  First posts so be sweet with me pls. I am looking to code an automated strategy for EURUSD trends. I need to add a feature where if the market moves in one direction with candles > x it trades, while if candles are < than x it stops.  Any suggestions? Thanks, Edoardo

    #54828 quote
    robertogozzi
    Moderator
    Master

    By “candles > x” do you mean:

    1. candles whose Opening/Closing/Highest/Lowest (which one?) is > x?
    2. candles whose range is > x?
    3. number of consecutive bullish/bearish candles greater than x?

    Also, what does “candles are < than x it stops” mean? What should be stopped, the strategy, the current trade…?

    Please post a real example, so we can try to be of some help.

    Roberto

    #54911 quote
    edozar
    Participant
    New

    Hello Roberto

    Thanks for offering help. I have an example below so that you can help further, but I also want to explain what I-m trying to do.

     

    I have a strategy that buys into eurusd trends, it makes money when the market raises with more than 3 green 1 min candles or falls with more than 3 red 1 minute candles, but loses money when market does a red and a green candle or viceversa. I define this market absence of trend FLAPPING.

    So I-d like to have a code, which I can-t program yet, that tells the auto trading system not to initiate a new trade if the previous difference between candles is small.

     

    Here is what I have come up with

     

    // Initialization of Amplitude
    Amplitude = 0.001
    // Initialization of detector
    Detector = 0

    // Definition of Flapping

    IF ABS((Low – High [1]) / High [1]) < Amplitude THEN
    // Behavior of the detector
    Detector = 1
    ENDIF


    // Absence of Flapping

    IF ABS((High – Low [1]) / Low [1]) > Amplitude THEN
    // Behavior of the detector
    Detector = -1
    ENDIF

    Thank you for your contributions, Edoardo

    #54936 quote
    robertogozzi
    Moderator
    Master

    Please use the “Insert PRT code” button identified by <> on the grey bar when you are posting, to make code more readable and easier to understand, as follows:

    // Initialization of Amplitude
    Amplitude = 0.001
    // Initialization of detector
    Detector = 0
    
    // Definition of Flapping
    
    IF ABS((Low – High [1]) / High [1]) < Amplitude THEN
    // Behavior of the detector
    Detector = 1
    ENDIF
    
    // Absence of Flapping
    
    IF ABS((High – Low [1]) / Low [1]) > Amplitude THEN
    // Behavior of the detector
    Detector = -1
    ENDIF

    A few questions:

    1. in your code you did not check whether 3 consecutive matching bars have elapsed or not (3 green bars or 3 red ones)
    2. 0.001 is the difference in price between two bars?
    3. a difference between candles/bars should be computed using which price (low,high,open,close) or maybe their range?
    #55006 quote
    edozar
    Participant
    New
    DEFPARAM CumulateOrders = False // No cumulative orders allowed.
    
    DEFPARAM FlatBefore = 093000 // Cancel any pending orders, close any positions and prevent placement of additional orders.
    
    DEFPARAM FlatAfter = 160000 // Cancel any pending orders, close any positions and prevent placement of additional orders.
    
    StopLoss = 10 //stoploss in points
    TakeProfit = 20 //takeprofit in points
    
    // Initialization of Amplitude
    Amplitude = 0.001
    // Initialization of detector
    Detector = 0
    
    // Definition of Flapping
    
    IF ABS((Low - High [1]) / High [1]) < Amplitude THEN
    // Behavior of the detector
    Detector = 1
    ENDIF
    
    
    // Absence of Flapping
    
    IF ABS((High - Low [1]) / Low [1]) > Amplitude THEN
    // Behavior of the detector
    Detector = -1
    ENDIF
    
    // Go Long
    
    IF close[1] > open [1] and Detector = -1 THEN
    BUY AT MARKET
    ENDIF
    
    // Go Short
    
    IF close[1] < open [1] and Detector = -1 THEN
    SELLSHORT AT MARKET
    ENDIF
    
    // Close Long
    
    IF LONGONMARKET and close < open THEN
    SELL AT MARKET
    ENDIF
    
    // Close Short
    
    IF SHORTONMARKET and close > open THEN
    BUY AT MARKET
    ENDIF
    
    SET STOP PLOSS StopLoss
    SET TARGET PPROFIT TakeProfit
    

    Answers to your questions

     

    1. I-m not at the stage of defining the three candles yet (trend), so far I check only if the current close is higher or lower than the previous.
    2. yes is what I intended to use to define the range of the candle in %
    3. what I think is most relevant is the difference between the closes.

    thanks for your help, 


    Edoardo

    #55225 quote
    robertogozzi
    Moderator
    Master

    Your code works, though it seems not profitable at this stage.

    What kind of help are looking for?

     

    #55256 quote
    edozar
    Participant
    New

    Hi Roberto,

    Glad to hear you found no glitches in the SW. Do you think that the way I have designed it to stop trading in absence of trend works well. Is there a better way to do it in your opinion, thanks, Edoardo

    #55260 quote
    robertogozzi
    Moderator
    Master

    You might use this code to detect whether your are in a range or not:

    //************************************************************************
    //    variables to be initialized once before being used
    ONCE RangeBars          = 50                      //50 bars
    ONCE RangePips          = 20                      //20 pips
    //    check if it's arnge or not
    hh = highest[RangeBars](high)                     //highest price in the last bars
    ll = lowest[RangeBars](low)                       //lowest  price in the last bars
    OutOfRange = (hh - ll) > (RangePips * pipsize)    //set OUTOFRANGE if enough pips have moved in the last bars
    //************************************************************************

    IF OutOfRange is true you will know you are not within a range (according to your settings, 50, 20 or whatever you choose).

    You may try to find out other and better ways to determine if an instrument is trending or not. With the help of the serach box you may scan this forum for, say, the words TREND or RANGE. You may even search the web and then translate to PRT any way you may find worth while spending some time.

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

Help with automated strategy for EURUSD


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
edozar @edozar Participant
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by robertogozzi
8 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/05/2017
Status: Active
Attachments: No files
Logo Logo
Loading...