Help with automated strategy for EURUSD
Forums › ProRealTime English forum › ProOrder support › Help with automated strategy for EURUSD
- This topic has 7 replies, 2 voices, and was last updated 6 years ago by robertogozzi.
-
-
12/05/2017 at 8:07 PM #54819
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
12/05/2017 at 10:15 PM #54828By “candles > x” do you mean:
- candles whose Opening/Closing/Highest/Lowest (which one?) is > x?
- candles whose range is > x?
- 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
12/06/2017 at 7:33 PM #54911Hello 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
ENDIFThank you for your contributions, Edoardo
12/07/2017 at 1:20 AM #54936Please 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:
123456789101112131415161718// Initialization of AmplitudeAmplitude = 0.001// Initialization of detectorDetector = 0// Definition of FlappingIF ABS((Low – High [1]) / High [1]) < Amplitude THEN// Behavior of the detectorDetector = 1ENDIF// Absence of FlappingIF ABS((High – Low [1]) / Low [1]) > Amplitude THEN// Behavior of the detectorDetector = -1ENDIFA few questions:
- in your code you did not check whether 3 consecutive matching bars have elapsed or not (3 green bars or 3 red ones)
- 0.001 is the difference in price between two bars?
- a difference between candles/bars should be computed using which price (low,high,open,close) or maybe their range?
12/07/2017 at 7:20 PM #55006This is the whole code so far12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455DEFPARAM 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 pointsTakeProfit = 20 //takeprofit in points// Initialization of AmplitudeAmplitude = 0.001// Initialization of detectorDetector = 0// Definition of FlappingIF ABS((Low - High [1]) / High [1]) < Amplitude THEN// Behavior of the detectorDetector = 1ENDIF// Absence of FlappingIF ABS((High - Low [1]) / Low [1]) > Amplitude THEN// Behavior of the detectorDetector = -1ENDIF// Go LongIF close[1] > open [1] and Detector = -1 THENBUY AT MARKETENDIF// Go ShortIF close[1] < open [1] and Detector = -1 THENSELLSHORT AT MARKETENDIF// Close LongIF LONGONMARKET and close < open THENSELL AT MARKETENDIF// Close ShortIF SHORTONMARKET and close > open THENBUY AT MARKETENDIFSET STOP PLOSS StopLossSET TARGET PPROFIT TakeProfitAnswers to your questions
- 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.
- yes is what I intended to use to define the range of the candle in %
- what I think is most relevant is the difference between the closes.
thanks for your help,
Edoardo
12/09/2017 at 4:03 PM #55225Your code works, though it seems not profitable at this stage.
What kind of help are looking for?
12/10/2017 at 10:54 AM #5525612/10/2017 at 11:53 AM #55260You might use this code to detect whether your are in a range or not:
123456789//************************************************************************// variables to be initialized once before being usedONCE RangeBars = 50 //50 barsONCE RangePips = 20 //20 pips// check if it's arnge or nothh = highest[RangeBars](high) //highest price in the last barsll = lowest[RangeBars](low) //lowest price in the last barsOutOfRange = (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.
-
AuthorPosts
Find exclusive trading pro-tools on