Results 1 to 9 of 9

Thread: Fractals in a fast moving market

  1. #1
    Hi All,

    I'm attempting to invent the ideal way to ch a fractal at a fast moving market, and generally speaking, too.
    My code is appearing at the third bar back to find the most recent fractal, when initially put on a chart, when there's no fractal in the previous three pubs, it might indie that some entries may be lost because the EA is working with fractals since the entrance points (only me playing around with code, no egy here).
    Will it be better to ch the newest lower and upper fractals with a loop? But at a fast moving market, wouldn't it also mean way more resources absorbed by the EA? And maybe at the time that the calculation is completed, the price had already moved on and also the entrance may be taken at a different price than planned?

    Hope I explained myself well.

  2. #2
    Quote Originally Posted by ;
    The most effective way is to utilize iFractals and loop through it only when a new bar forms. Something like that struct Fractaldouble price; datetime time;; //p ------------------------------------------------------------------ void OnTick() { static datetime last_bar=0; static Fractal last_upper = 0; static Fractal last_lower = 0; datetime current_bar = (datetime)SeriesInfoInteger(_Symbol,_Period,SERIES _LASTBAR_DATE); should (last_bar! = current_bar) { if(! LatestFractal(MODE_UPPER, last_upper) || ! LatestFractal(MODE_LOWER, last_lower)) printf(%s::...
    Hi!

    Thank you for the answer.
    I am attaching my code, tested on XAUUSD with 5 factors (?) Renko bars, it doesn't ch the fractals in any way.
    On a diminished currency like EURUSD it does not have any problem.

    I am not sure how to exit the loop if both fractals have been found.

    Inserted Code void IsNewFractal() for (int I = 3; I lt;= BarsToScan; I ) UpperFractal = iFractals(NULL,0,MODE_UPPER,I); LowerFractal = iFractals(NULL,0,MODE_LOWER,I); if ((UpperFractal gt; 0) (! UpFractal)) UpperFractalHigh = High#91;I#93;; UpperFractalLow = Low#91;I#93;; UpFractal = true; break; if ((LowerFractal gt; 0) (! LowFractal)) LowerFractalHigh = High#91;t #93;; LowerFractalLow = Low#91;I#93;; LowFractal = true; break;

  3. #3
    Quote Originally Posted by ;
    quote Hi! Thanks for the reply. I'm minding my own code, analyzed on XAUUSD with 5 points(?) Renko bars, it does not ch the fractals at all. On a diminished currency such as EURUSD it has no issue. I'm not sure how to leave the loop when both fractals are found. Void IsNewFractal() { for (int I = 3; I lt;= BarsToScan; I ) { UpperFractal = iFractals(NULL,0,MODE_UPPER,I); LowerFractal = iFractals(NULL,0,MODE_LOWER,I); if ((UpperFractal gt; 0) (! ) UpFractal)) { UpperFractalHigh = High; UpperFractalLow = Low; UpFractal = true; split;...
    it may serve you well to study several design patterns and code etiquette outside the MQL community... I can see from your snippet that all your variables are global, and as a developer, you need to be striving for clean encapsulated functions/classes with no over-use of global factors. Here are some additional things that can be improved with your own code snippet:IFractals will only work with regular charts / timeframes. Don't assume MQL works will always resolve NULL and 0 into the emblem and period you want to work with. Always complete your work calls together with the _Symbol and _Period not NULL and 0. You should be starting your hunt from the next index which is [1] - not [3] Your code will break when you've got a bar that's both upper and lower fractal. Make a function you may call with each mode separately. See my case. Using global variables when it is not entirely necessary is idle practice which not only ruins code re-usability but also makes your program more challenging to debug.

  4. #4
    Quote Originally Posted by ;
    quote It might serve you well to study several design patterns and code etiquette outside the MQL community... I can see from your snippet which all your variables are global, and as a developer, you should be striving for blank encapsulated functions/classes without the over-use of global factors. Here are some extra things which can be made better with your own code snippet: iFractals will only use regular charts / timeframes. Do not assume MQL functions will always resolve NULL and 0 into the emblem and period you want to utilize....
    I get what your saying but I don't understand how to code. Aside from Bash scripts I haven't written anything in my entire life and now I am learning MQL4.
    My variables are global because I don't understand how to return values from a function which should yield both Boolean and integers/doubles, it's also part of the illuions at formal MQL4 documentation.IFractals work on Renko, at least with my Renko generator, so iFractals should work also Thanks, I'll look it up and alter my code so Well, if a fractal is loed nearer than three pubs back, it's not a @proper@ fractal, I believe, or am I confused here? Additionally, it doesn't return the last fractal correctly, funny enough, it was suggested more than at MQL5 as the greater option of code from many. I had it written into two separated functions and united it after reading this post Point noted, I'll Attempt to better myself (still need to see this online course link you gave me earlier, real life is getting in the way)

  5. #5
    Quote Originally Posted by ;
    quote I get what your saying but I don't understand how to code. Other than Bash scripts I haven't written anything in my entire life and now I am learning MQL4. All my variables are global because I don't understand how to return values from a function that should return both Boolean and integers/doubles, it's also part of the examples at formal MQL4 documentation. IFractals work on Renko, at least with my Renko generator, therefore iFractals should work too Thanks, I'll look it up and change my code so Well, in case a fractal is loed nearer than three pubs back,...
    Hi Remasesa,

    Congratulations on taking the step to understand how to code. Additionally, I learned on MQL, also at the beginning I learned from other MQL examples and picked up some really bad habits, which I presume is generally true because MQL is not a mainstream language and also the draw to MQL is from traders wanting to create robots that are simple. The problems I ran into early was my progr weren't reusable (I could not call my functions from various situations ) along with also my progr were hitting a ceiling in terms of complexity. It wasn't until I studied other languages and design patterns that I managed to conquer these obstacles.

    In order to pass a variable into a function, do some actions, and return the boolean result - you need to pass the variable as a reference and also return type bool. Here's a good example of a divide by zero function.
    Inserted Code bool Split (double num1, double num2, double result) result = 0.0; if(num2 == 0.0) return false; //can't divide by zero - error result = num1 / num2; return true; Things can get wonkey with offline charts. If you're working offline I'd prevent the use of built-in indiors for debugging purposes. Fractals are easy to program so just create your own function. Inserted Code bool LatestFractal(const int style,Fractal result) if(style == MODE_UPPER) for(int I=2;ilt;Bars-2;I ) if(High#91;I 2#93; lt; Top #91;I#93; Top #91;I 1#93; lt; Top #91;I#93; Top #91;I#93; gt; Top #91;i-1#93; Top #91;I#93; gt; Top #91;i-2#93;-RRB- result.price = High#91;I#93;; result.time = Time#91;I#93;; return true; else if(style == MODE_LOWER) for(int I=2;ilt;Bars-2;I ) if(Low#91;I 2#93; gt; Low#91;I#93; Low#91;I 1#93; gt; Low Cost #91;I#93; Low Cost #91;I#93; lt; Low Cost #91;i-1#93; Low Cost #91;I#93; lt; Low Cost #91;i-2#93;-RRB- result.price = Low#91;I#93;; result.time = Time#91;I#93;; return true; return false; - We both were incorrect, the right starting index is 2 (third bar) Most of the active users at the MQL5 help forums are old-school... they clinic religious-like beliefs (without evidence or motive ) and/or have enormous conflicts of interest because they create a living off of freelance services and also will intentionally confuse things in order to steer you to freelance. You have to be careful who you chose to take counsel from over there. You don't have to learn all the libraries and nuances, but at minimum you should have a working understanding of OOP and how to make good functions.

  6. #6
    Quote Originally Posted by ;
    quote Hi Remasesa....
    Except for deleting your response but it's simpler for me to answer like this.

    Thanks to this code snippets.
    On your second example, if you call the function twice, once for upper and once for lower, result.price (and result.time, I think, too ) get's over-written, no? How do you utilize result.price if it's a variable outside of the function? So many things to learn and lacking of information.

    As for your Fractal, I think it is 3 three pubs back since the conventional way of determining a fractal, is using 5 pubs so you want to check out pub [3] if you're at pub [0], I think.
    In Renko in most cases it's safe to presume a Fractal is at pub [2] because of how the Renko pubs are constructed. I think.

    Not certain why you've the sign there, I figure it's part of the language and I'll have to look it up.
    What I did discover are a few examples of how to manipulate arrays so I am thinking that perhaps I could have an UpperFractalArray and a LowerFractalArray and also have my functions work on private variables but change the international arrays as a result (return value, possibly? Still new to this idea so I'll have to read up on this).

    As for MQL5, I obtained some EAs coded with a very wonderful man over there and I learned a lot studying his code and because one of my phrases for the job(s) was that the code would be simple so I could read and learn from it, he skipped out on the more intrie stuff which I, now, might have to ch up on.

    Thank you very much for the help and if it's possible, I'd love to PM you from time to time (or keep it as a public thread as I expect others might find out from it).

  7. #7
    Quote Originally Posted by ;
    quote Sorry for deleting your reply but it's easier for me to reply such as this. Thank you to this code snippets. In your second example, when you call the function twice, once for upper and once for lesser, result.price (and result.time, I believe, too ) get's over-written, no? How can you utilize result.price if it's a local variable outside of the function? So many things to understand and lacking of information. As for the Fractal, I think it is 3 three pubs back because the traditional manner of discovering a fractal, is utilizing 5 bars so that you have to look in...
    http://www.learncpp.com is a site you really should check out. The lessons in http://www.learncpp.com/cpp-tutorial...and-arguments/ will teach you everything you need to know in order to understand works, but it would be ideal for you to start at the start so you are not overlooking the basic fundamentals.

  8. #8

  9. #9
    The most efficient method is to use iFractals and loop only when a new bar creates. Something like that Inserted Code struct Fractaldouble price; datetime period;; // ------------------------------------------------------------------ void OnTick() static datetime last_bar=0; static Fractal last_upper = 0; static Fractal last_lower = 0; datetime current_bar = (datetime)SeriesInfoInteger(_Symbol,_Phase,SERIES_ LASTBAR_DATE); should (last_bar! = current_bar) string comm = StringFormat(Last upper fractal @%s =%.5f\nLast lower fractal @%s =%.5f, TimeToString(last_upper. time),last_upper. price, TimeToString(last_lower. time),last_lower. Price); Comment(comm); // ------------------------------------------------------------------ bool LatestFractal(int mode,Fractal Id ) for(int I=0;ilt;Bars;I ) f.price = iFractals(_Symbol, _Phase, mode, I); should (f.price gt; 0.0 f.price ! ) = EMPTY_VALUE) f.time = Time#91;I#93;; return true; return false;
    BTW, even if you failed loop on every tick the complete calculation only takes approximately 500 microseconds. The quickest I've seen MT ticks in a fast market is around 10 milliseconds, which means finding fractals in the indior buffers is not going to function as bottle-neck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.