<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Forex Software — In search of the fastest Strategy Generator]]></title>
		<link>https://forexsb.com/forum/topic/9912/in-search-of-the-fastest-strategy-generator/</link>
		<atom:link href="https://forexsb.com/forum/feed/rss/topic/9912" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in In search of the fastest Strategy Generator.]]></description>
		<lastBuildDate>Sat, 01 Feb 2025 21:02:12 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: In search of the fastest Strategy Generator]]></title>
			<link>https://forexsb.com/forum/post/82505/#p82505</link>
			<description><![CDATA[<p>I just uploaded the code at GitHub: <a href="https://github.com/PopovMP/ma_benchmark">https://github.com/PopovMP/ma_benchmark</a></p><p>You may take a look or even download and test it. (It will work on Linux and probably MakOS).</p><p>Here is how the Simple MA looks in JS:</p><div class="codebox"><pre><code>function simpleMA(maRef, price, period, shift) {
    maRef.fill(0.0, 0, period + shift - 1);

    let sum = 0.0;
    for (let bar = 0; bar &lt; period; ++bar) {
        sum += price[bar];
    }

    let prev = sum / period;
    maRef[period + shift - 1] = prev;

    for (let bar = period, len = price.length - shift; bar &lt; len; ++bar) {
        let temp;
        temp  = price[bar];
        temp -= price[bar - period];
        temp /= period;
        prev += temp;
        maRef[bar + shift] = prev;
    }
}</code></pre></div><br /><p>in C</p><div class="codebox"><pre><code>void simpleMA(double* restrict ma_ref, const double* const price,
              const int bars, const int period, const int shift) {
    memset(ma_ref, 0.0, (period + shift - 1) * sizeof(double));

    double sum = 0.0;
    for (int bar = 0; bar &lt; period; ++bar) {
        sum += price[bar];
    }

    double prev = sum / period;
    ma_ref[period + shift - 1] = prev;

    for (int bar = period, len = bars - shift; bar &lt; len; ++bar) {
        register double temp;
        temp  = price[bar];
        temp -= price[bar - period];
        temp /= period;
        prev += temp;
        ma_ref[bar + shift] = prev;
    }
}</code></pre></div><br /><p>and Fortran:</p><div class="codebox"><pre><code>subroutine simple_ma(ma_ref, price, bars, period, shift)
    real(real64), dimension(:), intent(inout) :: ma_ref
    real(real64), dimension(:), intent(in)    :: price
    integer,                    intent(in)    :: bars
    integer,                    intent(in)    :: period
    integer,                    intent(in)    :: shift

    real(real64) :: temp, prev, sum
    integer      :: bar

    ma_ref(1:period + shift) = 0.0_real64

    sum = 0.0_real64
    do bar = 1, period
        sum = sum + price(bar)
    end do

    prev = sum / period
    ma_ref(period + shift) = prev

    do bar = period + 1, bars - shift
        temp = price(bar)
        temp = temp - price(bar - period)
        temp = temp / period
        prev = prev + temp
        ma_ref(bar + shift) = prev
    end do
end subroutine simple_ma</code></pre></div><p>Trade Safe!</p>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Sat, 01 Feb 2025 21:02:12 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/82505/#p82505</guid>
		</item>
		<item>
			<title><![CDATA[In search of the fastest Strategy Generator]]></title>
			<link>https://forexsb.com/forum/post/82503/#p82503</link>
			<description><![CDATA[<p>Hello Traders,</p><p>I spent a lot of time analysing the performance of EA Studio and Express Generator&#039;s indicators over the last two weeks.</p><p>I designed a simulation program to load a particular data file and calculate the Moving Average and RSI indicators.</p><p>I made it first in JavaScript using the code from Express Generator.</p><p>After testing, refactoring and optimisation, I made a similar program in C.</p><p>The C version was 2 times faster for calculating the Moving Average and 15% faster for RSI.</p><p>Then, I made it in Fortran. It took me a week to read several Fortran books and to &quot;master&quot; the language.<br />Expectedly, the Frotran version was about 30% faster than the C version.</p><p>I continued researching and learned that Fortran is faster than C, not because of the features it has but because of the features it does not have.</p><p>I almost accepted those results. However, I wondered &quot;why&quot; it happens and the particular reason.<br />Several days later, I learned a lot about modern 64-bit Assembly, disassembled the programs and studied the code.</p><p>I was very happy when I found the reason the Fortran code was faster. (It was rather geeky, but if you are interested, I may explain).</p><p>On that latter, I decided to use this knowledge to improve my current code.</p><p>The first result is compiling C to a similar assembly as Fortran. It practically made the program very similar.<br />Then, I did the same in JavaScript.</p><p>And ... surprise, surprise. All three programs, Fortran, C, and JavaScript, performed similarly.</p><p>Calculating 2000 indicators with periods from 1 to 200 on 200k bars.</p><div class="codebox"><pre><code>=======================================
Indicator  Language       Time      
---------------------------------------
MA         Fortran        1.70 sec 
MA         C              1.72 sec 
MA         JavaScript     1.72 sec 
---------------------------------------
RSI        Fortran        6.81 sec 
RSI        C              6.80 sec 
RSI        JavaScript     6.84 sec 
=======================================</code></pre></div><p>The tests are made under Linux with the latest GFortran, GCC, and NodeJS.<br />The optimisation level for Fortran and C was &quot;O2&quot;.</p><p>I also made a test with the optimisation level &quot;-Ofast.&quot; Both C and Fortran showed double improvement in performance. <br />&quot;Ofast&quot; option is not suitable for code distribution.</p><p>I&#039;m going to use this knowledge in the PineGen generator.</p>]]></description>
			<author><![CDATA[null@example.com (Popov)]]></author>
			<pubDate>Sat, 01 Feb 2025 20:23:35 +0000</pubDate>
			<guid>https://forexsb.com/forum/post/82503/#p82503</guid>
		</item>
	</channel>
</rss>
