diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d55ecc44a..4b3a33d5c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,7 +1,7 @@ --- name: Check -# yamllint disable rule:truthy +# yamllint disable-line rule:truthy on: pull_request: push: @@ -10,6 +10,10 @@ jobs: Pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v1 - - uses: pre-commit/action@v2.0.0 + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: ~/.cache/pre-commit + key: pre-commit|${{ hashFiles('.pre-commit-config.yaml') }} + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/compile-cpp.yml b/.github/workflows/compile-cpp.yml index 1aecc1521..8bcbc0cb6 100644 --- a/.github/workflows/compile-cpp.yml +++ b/.github/workflows/compile-cpp.yml @@ -4,50 +4,31 @@ name: Compile C++ # yamllint disable-line rule:truthy on: pull_request: - paths-ignore: - - '**.md' + paths: + - '**.h' + - '**.mq?' push: - paths-ignore: - - '**.md' + paths: + - '**.h' + - '**.mq?' jobs: - FileList: - outputs: - filelist: ${{ steps.get-files.outputs.filelist }} + Compile-Cpp: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set output with list of files - id: get-files - run: | - import glob, json, os - files = glob.glob("**/tests/*.cpp") - print("::set-output name=filelist::{}".format(json.dumps(files))) - shell: python - - name: Display output - run: echo ${{ steps.get-files.outputs.filelist }} - - Compile: - runs-on: ubuntu-latest - needs: [FileList] - strategy: - matrix: - file: ${{ fromJson(needs.FileList.outputs.filelist) }} - steps: - - uses: actions/checkout@v2 - - name: Install Emscripten toolchain - uses: mymindstorm/setup-emsdk@v11 + - uses: actions/checkout@v3 - name: Install CPP compiler uses: rlalik/setup-cpp-compiler@v1.1 with: compiler: gcc-latest - - name: Compile ${{ matrix.file }} via emcc - if: always() - run: > - emcc -s WASM=1 -s ENVIRONMENT=node -s EXIT_RUNTIME=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=1 -Wall -s - MODULARIZE=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 --bind -s EXPORTED_FUNCTIONS="[]" -g -std=c++17 - "${{ matrix.file }}" - - name: Compile ${{ matrix.file }} via g++ - if: always() - run: g++ -g -std=c++17 -c "${{ matrix.file }}" + - name: Compile via make + run: make + Compile-Emscripten: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Emscripten toolchain + uses: mymindstorm/setup-emsdk@v11 + - name: Compile via emcc + run: make CC=emcc diff --git a/.github/workflows/compile.yml b/.github/workflows/compile-mql.yml similarity index 97% rename from .github/workflows/compile.yml rename to .github/workflows/compile-mql.yml index a5b9c6875..99fd72a2f 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile-mql.yml @@ -1,5 +1,5 @@ --- -name: Compile +name: Compile MQL env: ARTIFACT_PREFIX: ${{ inputs.artifact_prefix || 'mt' }} @@ -11,6 +11,7 @@ on: pull_request: paths-ignore: - '**.md' + - '.github/workflows/compile-mql.yml' push: paths-ignore: - '**.md' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 9dffc2b59..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,18 +0,0 @@ -# yamllint disable rule:line-length ---- -name: Lint - -# yamllint disable rule:truthy -on: - - pull_request - - push - -jobs: - YAML: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: YAML check (yamllint) - uses: ibiqlik/action-yamllint@master - with: - strict: true diff --git a/.github/workflows/sync-fork.yml b/.github/workflows/sync-fork.yml index b2fd6e168..f05a3c53c 100644 --- a/.github/workflows/sync-fork.yml +++ b/.github/workflows/sync-fork.yml @@ -1,7 +1,7 @@ --- name: Sync Fork -# yamllint disable rule:truthy +# yamllint disable-line rule:truthy on: push: branches: @@ -14,11 +14,11 @@ jobs: if: github.repository != 'EA31337/EA31337-classes' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 persist-credentials: false - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 path: upstream diff --git a/.github/workflows/test-account.yml b/.github/workflows/test-exchange-account.yml similarity index 68% rename from .github/workflows/test-account.yml rename to .github/workflows/test-exchange-account.yml index 8aa03b4ad..1099074e0 100644 --- a/.github/workflows/test-account.yml +++ b/.github/workflows/test-exchange-account.yml @@ -1,32 +1,32 @@ --- -name: Test Account +name: Test Exchange/Account # yamllint disable-line rule:truthy on: pull_request: paths: - - 'Account/**.h' - - '.github/workflows/test-account.yml' + - 'Exchange/Account/**' + - '.github/workflows/test-exchange/account.yml' push: paths: - - 'Account/**.h' - - '.github/workflows/test-account.yml' + - 'Exchange/Account/**' + - '.github/workflows/test-exchange/account.yml' jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Account skip_cleanup: true - Account-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash - working-directory: Account/tests + working-directory: Exchange/Account/tests if: false needs: compile runs-on: ubuntu-latest @@ -37,7 +37,7 @@ jobs: - AccountForex.test - AccountMt.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} diff --git a/.github/workflows/test-exchange-symbolinfo.yml b/.github/workflows/test-exchange-symbolinfo.yml new file mode 100644 index 000000000..230dfccc2 --- /dev/null +++ b/.github/workflows/test-exchange-symbolinfo.yml @@ -0,0 +1,60 @@ +--- +name: Test Exchange/SymbolInfo + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Exchange/SymbolInfo/**' + - '.github/workflows/test-exchange/symbolinfo.yml' + push: + paths: + - 'Exchange/SymbolInfo/**' + - '.github/workflows/test-exchange/symbolinfo.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Exchange/SymbolInfo/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Exchange/SymbolInfo/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - SymbolInfo.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-exchange.yml b/.github/workflows/test-exchange.yml index 408fb5ed0..3cd0d77f2 100644 --- a/.github/workflows/test-exchange.yml +++ b/.github/workflows/test-exchange.yml @@ -18,13 +18,13 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Exchange skip_cleanup: true - Exchange-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash @@ -37,7 +37,7 @@ jobs: test: - Exchange.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} diff --git a/.github/workflows/test-indicator.yml b/.github/workflows/test-indicator.yml index 812437b2e..bc76892f3 100644 --- a/.github/workflows/test-indicator.yml +++ b/.github/workflows/test-indicator.yml @@ -18,13 +18,13 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Indicator skip_cleanup: true - Indicator-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash @@ -43,7 +43,7 @@ jobs: - IndicatorTick.test - IndicatorRenko.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} @@ -52,7 +52,7 @@ jobs: BtDays: 4-8 BtMonths: 1 BtYears: 2021 - MtVersion: 4.0.0.1359 + GitHubApiToken: ${{ github.token }} RunOnError: show_logs 200 TestExpert: ${{ matrix.test }} timeout-minutes: 10 diff --git a/.github/workflows/test-indicators-bitwise.yml b/.github/workflows/test-indicators-bitwise.yml new file mode 100644 index 000000000..70ed04efb --- /dev/null +++ b/.github/workflows/test-indicators-bitwise.yml @@ -0,0 +1,68 @@ +--- +name: Test Indicators (Bitwise) + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Indicator/**' + - 'Indicators/Bitwise/**' + - '.github/workflows/test-indicators-bitwise.yml' + push: + paths: + - 'Indicator**' + - 'Indicators/Bitwise/**' + - '.github/workflows/test-indicators-bitwise.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Indicators/Bitwise/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Indicators/Bitwise/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Indi_Candle.test + - Indi_Pattern.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + BtDays: 4-8 + BtMonths: 1 + BtYears: 2021 + GitHubApiToken: ${{ github.token }} + RunOnError: show_logs 200 + TestExpert: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-indicators-ohlc.yml b/.github/workflows/test-indicators-ohlc.yml new file mode 100644 index 000000000..9885fa5ff --- /dev/null +++ b/.github/workflows/test-indicators-ohlc.yml @@ -0,0 +1,67 @@ +--- +name: Test Indicators (OHLC) + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Indicator/**' + - 'Indicators/OHLC/**' + - '.github/workflows/test-indicators-special.yml' + push: + paths: + - 'Indicator/**' + - 'Indicators/OHLC/**' + - '.github/workflows/test-indicators-special.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Indicators/OHLC/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Indicators/OHLC/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Indi_OHLC.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + BtDays: 4-8 + BtMonths: 1 + BtYears: 2021 + GitHubApiToken: ${{ github.token }} + RunOnError: show_logs 200 + TestExpert: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-indicators-oscillator.yml b/.github/workflows/test-indicators-oscillator.yml new file mode 100644 index 000000000..a66ff3177 --- /dev/null +++ b/.github/workflows/test-indicators-oscillator.yml @@ -0,0 +1,70 @@ +--- +name: Test Indicators (Oscillator) + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Indicator/**' + - 'Indicators/Oscillator/**' + - '.github/workflows/test-indicators-oscillator.yml' + push: + paths: + - 'Indicator/**' + - 'Indicators/Oscillator/**' + - '.github/workflows/test-indicators-oscillator.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Indicators/Oscillator/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Indicators/Oscillator/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Indi_MACD.test + - Indi_RSI.test + - Indi_Stochastic.test + - Indi_WPR.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + BtDays: 4-8 + BtMonths: 1 + BtYears: 2021 + GitHubApiToken: ${{ github.token }} + RunOnError: show_logs 200 + TestExpert: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-indicators-price.yml b/.github/workflows/test-indicators-price.yml new file mode 100644 index 000000000..38442d2fe --- /dev/null +++ b/.github/workflows/test-indicators-price.yml @@ -0,0 +1,69 @@ +--- +name: Test Indicators (Price) + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Indicator/**' + - 'Indicators/Price/**' + - '.github/workflows/test-indicators-price.yml' + push: + paths: + - 'Indicator/**' + - 'Indicators/Price/**' + - '.github/workflows/test-indicators-price.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Indicators/Price/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Indicators/Price/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Indi_AppliedPrice.test + - Indi_MA.test + - Indi_Price.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + BtDays: 4-8 + BtMonths: 1 + BtYears: 2021 + GitHubApiToken: ${{ github.token }} + RunOnError: show_logs 200 + TestExpert: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-indicators-pricemulti.yml b/.github/workflows/test-indicators-pricemulti.yml new file mode 100644 index 000000000..ffbb50135 --- /dev/null +++ b/.github/workflows/test-indicators-pricemulti.yml @@ -0,0 +1,67 @@ +--- +name: Test Indicators (PriceMulti) + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Indicator/**' + - 'Indicators/PriceMulti/**' + - '.github/workflows/test-indicators-pricemulti.yml' + push: + paths: + - 'Indicator/**' + - 'Indicators/Price/**' + - '.github/workflows/test-indicators-pricemulti.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Indicators/PriceMulti/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Indicators/Price/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Indi_Alligator.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + BtDays: 4-8 + BtMonths: 1 + BtYears: 2021 + GitHubApiToken: ${{ github.token }} + RunOnError: show_logs 200 + TestExpert: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-indicators-pricerange.yml b/.github/workflows/test-indicators-pricerange.yml new file mode 100644 index 000000000..1a9b1938d --- /dev/null +++ b/.github/workflows/test-indicators-pricerange.yml @@ -0,0 +1,70 @@ +--- +name: Test Indicators (PriceRange) + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Indicator/**' + - 'Indicators/PriceRange/**' + - '.github/workflows/test-indicators-pricerange.yml' + push: + paths: + - 'Indicator/**' + - 'Indicators/Price/**' + - '.github/workflows/test-indicators-pricerange.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Indicators/PriceRange/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Indicators/Price/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Indi_Bands.test + - Indi_Envelopes.test + - Indi_Pivot.test + - Indi_SAR.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + BtDays: 4-8 + BtMonths: 1 + BtYears: 2021 + GitHubApiToken: ${{ github.token }} + RunOnError: show_logs 200 + TestExpert: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-indicators-special.yml b/.github/workflows/test-indicators-special.yml index 7c6693493..cfce8ca75 100644 --- a/.github/workflows/test-indicators-special.yml +++ b/.github/workflows/test-indicators-special.yml @@ -18,17 +18,40 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml - with: - artifact_prefix: mt - path: Indicators/Special - skip_cleanup: true + needs: [mt4, mt5] + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: mt${{ matrix.version }} + path: .mt${{ matrix.version }} + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: ${{ env.SKIP_INIT == 'false' }} + mt-path: .mt${{ matrix.version }} + path-ignore: .mt${{ matrix.version }} + path: '${{ env.COMPILE_PATH }}/**/*.mq${{ matrix.version }}' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: files-ex${{ matrix.version }} + path: '**/*.ex[45]' + + strategy: + matrix: + version: [4, 5] - Indicators-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash - working-directory: Indicators/tests + working-directory: Indicators/Special/tests if: false needs: compile runs-on: ubuntu-latest @@ -36,8 +59,9 @@ jobs: matrix: test: - Indi_Custom.test + - Indi_Universal.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} @@ -46,7 +70,7 @@ jobs: BtDays: 4-8 BtMonths: 1 BtYears: 2021 - MtVersion: 4.0.0.1359 + GitHubApiToken: ${{ github.token }} RunOnError: show_logs 200 TestExpert: ${{ matrix.test }} timeout-minutes: 10 diff --git a/.github/workflows/test-indicators-tick.yml b/.github/workflows/test-indicators-tick.yml index b94bf626e..cfa0ddf4e 100644 --- a/.github/workflows/test-indicators-tick.yml +++ b/.github/workflows/test-indicators-tick.yml @@ -18,13 +18,13 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Indicators/Tick skip_cleanup: true - Indicators-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash @@ -37,7 +37,7 @@ jobs: test: - Indi_Tick.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} @@ -46,7 +46,7 @@ jobs: BtDays: 4-8 BtMonths: 1 BtYears: 2021 - MtVersion: 4.0.0.1359 + GitHubApiToken: ${{ github.token }} RunOnError: show_logs 200 TestExpert: ${{ matrix.test }} timeout-minutes: 10 diff --git a/.github/workflows/test-indicators.yml b/.github/workflows/test-indicators.yml index 47782f989..03c4067f7 100644 --- a/.github/workflows/test-indicators.yml +++ b/.github/workflows/test-indicators.yml @@ -18,13 +18,13 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Indicators skip_cleanup: true - Indicators-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash @@ -35,6 +35,7 @@ jobs: strategy: matrix: test: + - DrawIndicator.test - Indi_AC.test - Indi_AD.test - Indi_ADX.test @@ -43,25 +44,17 @@ jobs: - Indi_AO.test - Indi_ASI.test - Indi_ATR.test - - Indi_Alligator.test - - Indi_AppliedPrice.test - Indi_BWMFI.test - Indi_BWZT.test - - Indi_Bands.test - Indi_BearsPower.test - Indi_BullsPower.test - Indi_CCI.test - Indi_CHO.test - Indi_CHV.test - # - Indi_ColorBars.test # @fixme - - Indi_ColorCandlesDaily.test - - Indi_ColorLine.test - - Indi_CustomMovingAverage.test - Indi_DeMarker.test - Indi_Demo.test - Indi_DetrendedPrice.test - Indi_Drawer.test - - Indi_Envelopes.test - Indi_Force.test - Indi_FractalAdaptiveMA.test - Indi_Fractals.test @@ -69,41 +62,32 @@ jobs: - Indi_HeikenAshi.test - Indi_Ichimoku.test - Indi_Killzones.test - - Indi_MA.test - - Indi_MACD.test - Indi_MFI.test - Indi_MassIndex.test - Indi_Momentum.test - Indi_OBV.test - - Indi_OHLC.test - Indi_OsMA.test - - Indi_Pattern.test - - Indi_Pivot.test - - Indi_Price.test - Indi_PriceChannel.test - Indi_PriceFeeder.test - Indi_PriceVolumeTrend.test - Indi_RS.test - - Indi_RSI.test - Indi_RVI.test - Indi_RateOfChange.test - - Indi_SAR.test - Indi_StdDev.test - - Indi_Stochastic.test - Indi_TEMA.test - Indi_TRIX.test - Indi_UltimateOscillator.test - Indi_VIDYA.test - Indi_VROC.test - Indi_Volumes.test - - Indi_WPR.test - Indi_WilliamsAD.test - Indi_ZigZag.test - Indi_ZigZagColor.test + - Indicators.test # Requires refactoring: # - Indi_DEMA.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} @@ -112,7 +96,7 @@ jobs: BtDays: 4-8 BtMonths: 1 BtYears: 2021 - MtVersion: 4.0.0.1359 + GitHubApiToken: ${{ github.token }} RunOnError: show_logs 200 TestExpert: ${{ matrix.test }} timeout-minutes: 10 diff --git a/.github/workflows/test-math.yml b/.github/workflows/test-math.yml new file mode 100644 index 000000000..ac0651ac6 --- /dev/null +++ b/.github/workflows/test-math.yml @@ -0,0 +1,62 @@ +--- +name: Test Math + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Math/**' + - '.github/workflows/test-math.yml' + push: + paths: + - 'Math/**' + - '.github/workflows/test-math.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Math/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Math/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Math.test + - Matrix.test + - MatrixMini.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} + RunOnError: show_logs 200 diff --git a/.github/workflows/test-platform-chart.yml b/.github/workflows/test-platform-chart.yml new file mode 100644 index 000000000..181040804 --- /dev/null +++ b/.github/workflows/test-platform-chart.yml @@ -0,0 +1,61 @@ +--- +name: Test Platform + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Platform/Chart/**' + - '.github/workflows/test-platform-chart.yml' + push: + paths: + - 'Platform/Chart/**' + - '.github/workflows/test-platform-chart.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Platform/Chart/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Platform/Chart/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Chart.test + - ChartMt.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-platform-chart3d.yml b/.github/workflows/test-platform-chart3d.yml new file mode 100644 index 000000000..d54da30fe --- /dev/null +++ b/.github/workflows/test-platform-chart3d.yml @@ -0,0 +1,60 @@ +--- +name: Test Platform + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Platform/Chart3D/**' + - '.github/workflows/test-platform-chart3d.yml' + push: + paths: + - 'Platform/Chart3D/**' + - '.github/workflows/test-platform-chart3d.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Platform/Chart3D/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Platform/Chart3D/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Chart3D.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-platform-web.yml b/.github/workflows/test-platform-web.yml new file mode 100644 index 000000000..de505e93c --- /dev/null +++ b/.github/workflows/test-platform-web.yml @@ -0,0 +1,63 @@ +--- +name: Test Platform/Web + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Platform/Web/**' + - '.github/workflows/test-platform-web.yml' + push: + paths: + - 'Platform/Web/**' + - '.github/workflows/test-platform-web.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Platform/Web/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Platform/Web/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + # @fixme: GH-266 + - Web.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} + RunOnFail: "exit 0" + if: always() + timeout-minutes: 10 diff --git a/.github/workflows/test-platform.yml b/.github/workflows/test-platform.yml new file mode 100644 index 000000000..acad78f40 --- /dev/null +++ b/.github/workflows/test-platform.yml @@ -0,0 +1,65 @@ +--- +name: Test Platform + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Platform/**' + - '.github/workflows/test-platform.yml' + push: + paths: + - 'Platform/**' + - '.github/workflows/test-platform.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Platform/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Platform/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Order.test + - OrderQuery.test + - Orders.test + - Platform.test + - Plot.test + - Terminal.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} + timeout-minutes: 10 diff --git a/.github/workflows/test-serializer.yml b/.github/workflows/test-serializer.yml index 58beea468..69fe1a57d 100644 --- a/.github/workflows/test-serializer.yml +++ b/.github/workflows/test-serializer.yml @@ -16,13 +16,13 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Exchange skip_cleanup: true - Serializer-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash @@ -35,7 +35,7 @@ jobs: test: - Serializer.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} @@ -44,7 +44,7 @@ jobs: BtDays: 4-8 BtMonths: 1 BtYears: 2021 - MtVersion: 4.0.0.1359 + GitHubApiToken: ${{ github.token }} RunOnError: show_logs 200 TestExpert: ${{ matrix.test }} timeout-minutes: 10 diff --git a/.github/workflows/test-storage-cache.yml b/.github/workflows/test-storage-cache.yml new file mode 100644 index 000000000..e15f21057 --- /dev/null +++ b/.github/workflows/test-storage-cache.yml @@ -0,0 +1,62 @@ +--- +name: Test Storage/Cache + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Storage/Cache/**' + - '.github/workflows/test-storage-cache.yml' + push: + paths: + - 'Storage/Cache/**' + - '.github/workflows/test-storage-cache.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Storage/Cache/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Storage/Cache/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - IndiBufferCache.test + - ObjectsCache.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} + RunOnError: show_logs 200 + timeout-minutes: 10 diff --git a/.github/workflows/test-storage-dict-buffer.yml b/.github/workflows/test-storage-dict-buffer.yml new file mode 100644 index 000000000..ef4bf3bb9 --- /dev/null +++ b/.github/workflows/test-storage-dict-buffer.yml @@ -0,0 +1,66 @@ +--- +name: Test Storage/Dict/Buffer + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - 'Storage/Dict/Buffer/**' + - '.github/workflows/test-storage-dict-buffer.yml' + push: + paths: + - 'Storage/Dict/Buffer/**' + - '.github/workflows/test-storage-dict-buffer.yml' + +jobs: + + Compile: + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Compile + uses: fx31337/mql-compile-action@master + with: + init-platform: true + path: 'Storage/Dict/Buffer/tests' + verbose: true + - name: Print compiled files + run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname' + shell: powershell + - name: Upload artifacts (MQL4) + uses: actions/upload-artifact@v3 + with: + name: files-ex4 + path: '**/*.ex4' + - name: Upload artifacts (MQL5) + uses: actions/upload-artifact@v3 + with: + name: files-ex5 + path: '**/*.ex5' + + Tests-MQL4: + defaults: + run: + shell: bash + working-directory: Storage/Dict/Buffer/tests + needs: Compile + runs-on: ubuntu-latest + strategy: + matrix: + test: + - Buffer.test + - BufferCandle.test + - BufferCompileAll.test + - BufferFXT.test + - BufferStruct.test + - BufferTick.test + steps: + - uses: actions/download-artifact@v3 + with: + name: files-ex4 + - name: Run ${{ matrix.test }} + uses: fx31337/mql-tester-action@master + with: + Script: ${{ matrix.test }} + RunOnError: show_logs 200 + timeout-minutes: 10 diff --git a/.github/workflows/test-buffer.yml b/.github/workflows/test-storage-dict.yml similarity index 66% rename from .github/workflows/test-buffer.yml rename to .github/workflows/test-storage-dict.yml index 41a5b6411..4892af569 100644 --- a/.github/workflows/test-buffer.yml +++ b/.github/workflows/test-storage-dict.yml @@ -1,42 +1,41 @@ --- -name: Test Buffer +name: Test Storage/Dict # yamllint disable-line rule:truthy on: pull_request: paths: - - 'Buffer/**' - - '.github/workflows/test-buffer.yml' + - 'Storage/Dict/**' + - '.github/workflows/test-storage-dict.yml' push: paths: - - 'Buffer/**' - - '.github/workflows/test-buffer.yml' + - 'Storage/Dict/**' + - '.github/workflows/test-storage-dict.yml' jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Buffer skip_cleanup: true - Buffer-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash - working-directory: Buffer/tests + working-directory: Storage/Dict/tests if: false needs: compile runs-on: ubuntu-latest strategy: matrix: test: - - BufferCandle.test - - BufferTick.test + - Dict.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} diff --git a/.github/workflows/test-storage.yml b/.github/workflows/test-storage.yml index 3c0ac50d3..ea7280f73 100644 --- a/.github/workflows/test-storage.yml +++ b/.github/workflows/test-storage.yml @@ -16,29 +16,36 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Exchange skip_cleanup: true - Storage-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash working-directory: Storage/tests - if: false - needs: compile + needs: Compile runs-on: ubuntu-latest strategy: matrix: test: - Collection.test + - Database.test + - DateTime.test + - ItemsHistory.test + - Object.test + - Redis.test + - ValueStorage.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} uses: fx31337/mql-tester-action@master with: Script: ${{ matrix.test }} + RunOnError: show_logs 200 + timeout-minutes: 10 diff --git a/.github/workflows/test-task.yml b/.github/workflows/test-task.yml index 499f4751c..febf6b8c5 100644 --- a/.github/workflows/test-task.yml +++ b/.github/workflows/test-task.yml @@ -16,13 +16,13 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Exchange skip_cleanup: true - Task-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash @@ -43,7 +43,7 @@ jobs: - Taskable.car.test - Taskable.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} diff --git a/.github/workflows/test-tick.yml b/.github/workflows/test-tick.yml index 335a30a51..f74713321 100644 --- a/.github/workflows/test-tick.yml +++ b/.github/workflows/test-tick.yml @@ -16,13 +16,13 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Tick skip_cleanup: true - Tick-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash @@ -35,7 +35,7 @@ jobs: test: - TickManager.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} diff --git a/.github/workflows/test-trade.yml b/.github/workflows/test-trade.yml index 5ac8cea05..8e866201b 100644 --- a/.github/workflows/test-trade.yml +++ b/.github/workflows/test-trade.yml @@ -18,13 +18,13 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt path: Trade skip_cleanup: true - Trade-Tests-MQL4: + Tests-MQL4: defaults: run: shell: bash @@ -35,10 +35,10 @@ jobs: strategy: matrix: test: - - TradeSignalTest - - TradeSignalManagerTest + - TradeSignal.test + - TradeSignalManager.test steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2b2c96d05..5393d78b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: compile: name: Compile - uses: ./.github/workflows/compile.yml + uses: ./.github/workflows/compile-mql.yml with: artifact_prefix: mt skip_cleanup: true @@ -39,30 +39,18 @@ jobs: strategy: matrix: test: - - AccountTest - - BufferStructTest - - BufferTest - - ChartTest - - CompileIndicatorsTest - - DatabaseTest - # - DrawIndicatorTest - EATest - - IndicatorsTest - MailTest - MarketTest - - MatrixTest - - OrderTest - - OrdersTest - StatsTest - StrategyTest - StrategyTest-RSI - - SymbolInfoTest - SummaryReportTest - TickerTest - TradeTest max-parallel: 4 steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: files-ex4 - name: Run ${{ matrix.test }} @@ -71,7 +59,7 @@ jobs: BtDays: 4-12 BtMonths: 1 BtYears: 2021 - Version: 4 + GitHubApiToken: ${{ github.token }} TestExpert: ${{ matrix.test }} RunOnError: show_logs 200 if: always() @@ -88,72 +76,13 @@ jobs: strategy: matrix: test: - # - 3DTest - - CollectionTest - ConfigTest - ConvertTest - - DateTimeTest - - DictTest - LogTest - MD5Test - - MathTest - - OrderQuery - ProfilerTest - RefsTest - - TerminalTest - TimerTest - - ValueStorageTest - max-parallel: 4 - steps: - - uses: actions/download-artifact@v2 - with: - name: files-ex4 - - name: Run ${{ matrix.test }} - uses: fx31337/mql-tester-action@master - with: - Script: ${{ matrix.test }} - if: always() - timeout-minutes: 10 - - Scripts-MQL4-Ignore: - defaults: - run: - shell: bash - working-directory: tests - if: false - needs: compile - runs-on: ubuntu-latest - strategy: - matrix: - test: - # @fixme: GH-266 - - RedisTest - # @fixme: GH-266 - - WebTest - steps: - - uses: actions/download-artifact@v2 - with: - name: files-ex4 - - name: Run ${{ matrix.test }} - uses: fx31337/mql-tester-action@master - with: - Script: ${{ matrix.test }} - RunOnFail: "exit 0" - if: always() - timeout-minutes: 10 - - Trade-Tests-MQL4: - defaults: - run: - shell: bash - working-directory: Trade/tests - if: false - needs: compile - runs-on: ubuntu-latest - strategy: - matrix: - test: - - TradeSignalTest steps: - uses: actions/download-artifact@v2 with: @@ -164,8 +93,3 @@ jobs: Script: ${{ matrix.test }} if: always() timeout-minutes: 10 - - cleanup: - name: Clean-up - needs: [compile] - uses: ./.github/workflows/cleanup.yml diff --git a/.gitignore b/.gitignore index 3883ac4b4..d689d2162 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ docs/api/build # Ignores compiled binary files. *.ex? +*.o # Ignores log files. *.log @@ -15,3 +16,7 @@ docs/api/build .DS_Store docs/build +.vs +x64 +*.sln +*.vcx* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a99a55cc2..9fdd623ce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,4 @@ --- -exclude: '\.md$' repos: # - repo: https://github.com/pre-commit/mirrors-clang-format diff --git a/3D/Material.h b/3D/Material.h deleted file mode 100644 index 1cb05704b..000000000 --- a/3D/Material.h +++ /dev/null @@ -1,18 +0,0 @@ -#include "Math.h" - -/** - * Generic vertex to be used by meshes. - */ -class Material { - public: - DXColor Color; - - Material(unsigned int _color = 0xFFFFFFFF) { Color = DXColor(_color); } - - Material(const Material& _r) { Color = _r.Color; } - - Material* SetColor(unsigned int _color) { - Color = DXColor(_color); - return &this; - } -}; diff --git a/3D/Vertex.h b/3D/Vertex.h deleted file mode 100644 index f9b84851e..000000000 --- a/3D/Vertex.h +++ /dev/null @@ -1,31 +0,0 @@ -#include "../Refs.mqh" - -/** - * Generic vertex to be used by meshes. - */ -struct Vertex { - DXVector3 Position; - DXVector3 Normal; - DXColor Color; - - // Default constructor. - Vertex(float r = 1, float g = 1, float b = 1, float a = 1) { - Color.r = r; - Color.g = g; - Color.b = b; - Color.a = a; - } - - Vertex(const Vertex &r) { - Position = r.Position; - Normal = r.Normal; - Color = r.Color; - } - - static const ShaderVertexLayout Layout[3]; -}; - -const ShaderVertexLayout Vertex::Layout[3] = { - {"POSITION", 0, GFX_VAR_TYPE_FLOAT, 3, false, sizeof(Vertex), 0}, - {"NORMAL", 0, GFX_VAR_TYPE_FLOAT, 3, false, sizeof(Vertex), sizeof(float) * 3}, - {"COLOR", 0, GFX_VAR_TYPE_FLOAT, 4, false, sizeof(Vertex), sizeof(float) * 6}}; diff --git a/Bar.enum.h b/Bar.enum.h index cea47aeee..be8ed3a4a 100644 --- a/Bar.enum.h +++ b/Bar.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Bar.struct.h b/Bar.struct.h index 3b9074271..f931af0a4 100644 --- a/Bar.struct.h +++ b/Bar.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -35,7 +35,7 @@ class Serializer; // Includes. #include "Bar.enum.h" -#include "Chart.enum.h" +#include "Platform/Chart/Chart.enum.h" #include "Serializer/Serializable.h" #include "Serializer/Serializer.enum.h" #include "Serializer/Serializer.h" @@ -70,6 +70,18 @@ struct BarOHLC low = fmin(low, _prices[i]); } } + BarOHLC(CONST_FIXED_ARRAY_REF(double, _prices, 4), datetime _time = 0) : time(_time) { + _time = _time == (datetime)0 ? TimeCurrent() : _time; + int _size = 4; + close = _prices[0]; + open = _prices[_size - 1]; + high = fmax(close, open); + low = fmin(close, open); + for (int i = 0; i < _size; i++) { + high = fmax(high, _prices[i]); + low = fmin(low, _prices[i]); + } + } // Struct methods. // Getters bool GetPivots(ENUM_PP_TYPE _type, double &_pp, double &_r1, double &_r2, double &_r3, double &_r4, double &_s1, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 33f02d0d0..6dc12782a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,6 +39,7 @@ To improve code compatibility, please use the following syntax: | `T name[]` | `_cpp_array name` | `ARRAY(T, name)` | | `T N[]` | `_cpp_array> N` | `ARRAY(T, N)` | | `obj.Method()` | `obj->Method()` | `obj PTR_DEREF Method()` | +| `obj.Ptr().a` | `obj.Ptr()->a` | `obj REF_DEREF a` | | `obj.a1.a2` | `obj->a1->a2` | `PTR_ATTRIB2(obj, a1, a2)` | | `obj.attr` | `obj->attr` | `PTR_ATTRIB(obj, attr)` | | `str == NULL` | `str == NULL` | `IsNull(str)` | diff --git a/Candle.struct.h b/Candle.struct.h index 74e9c9bab..4d01e0474 100644 --- a/Candle.struct.h +++ b/Candle.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -35,7 +35,7 @@ class Serializer; // Includes. #include "Bar.enum.h" -#include "Chart.enum.h" +#include "Platform/Chart/Chart.enum.h" #include "Serializer/Serializable.h" #include "Serializer/Serializer.enum.h" #include "Serializer/Serializer.h" @@ -231,14 +231,14 @@ struct CandleOCTOHLC : CandleOHLC { int length; // Open and close timestamps of ticks that were part of this candle. - long open_timestamp_ms, close_timestamp_ms; + int64 open_timestamp_ms, close_timestamp_ms; // Number of ticks which formed the candle. Also known as volume. int volume; // Struct constructor. CandleOCTOHLC(T _open = 0, T _high = 0, T _low = 0, T _close = 0, int _start_time = -1, int _length = 0, - long _open_timestamp_ms = -1, long _close_timestamp_ms = -1, int _volume = 0) + int64 _open_timestamp_ms = -1, int64 _close_timestamp_ms = -1, int _volume = 0) : CandleOHLC(_open, _high, _low, _close), is_complete(true), start_time(_start_time), @@ -264,7 +264,7 @@ struct CandleOCTOHLC : CandleOHLC { /** * Initializes candle with a given start time, length in seconds, first tick's timestamp and its price. */ - void Init(int _start_time, int _length, long _timestamp_ms = -1, T _price = 0) { + void Init(int _start_time, int _length, int64 _timestamp_ms = -1, T _price = 0) { if (_start_time < 0) { Print("Error!"); } @@ -280,7 +280,7 @@ struct CandleOCTOHLC : CandleOHLC { /** * Updates OHLC values taking into consideration tick's timestamp. */ - void Update(long _timestamp_ms, T _price) { + void Update(int64 _timestamp_ms, T _price) { if (!ContainsTimeMs(_timestamp_ms)) { Print("Error: Cannot update candle. Given time doesn't fit in candle's time-frame! Given time ", _timestamp_ms, ", but candle range is ", (long)start_time * 1000, " - ", (long)(start_time + length) * 1000, "."); @@ -321,12 +321,12 @@ struct CandleOCTOHLC : CandleOHLC { /** * Method used by ItemsHistory. */ - long GetTimeMs() { return (long)start_time * 1000; } + int64 GetTimeMs() { return (int64)start_time * 1000; } /** * Method used by ItemsHistory. */ - long GetLengthMs() { return (long)length * 1000; } + int64 GetLengthMs() { return (int64)length * 1000; } /** * Returns candle's start time. @@ -336,18 +336,18 @@ struct CandleOCTOHLC : CandleOHLC { /** * Returns timestamp of open price. */ - long GetOpenTimestamp() { return open_timestamp_ms / 1000; } + int64 GetOpenTimestamp() { return open_timestamp_ms / 1000; } /** * Returns timestamp of close price. */ - long GetCloseTimestamp() { return close_timestamp_ms / 1000; } + int64 GetCloseTimestamp() { return close_timestamp_ms / 1000; } /** * Whether given time fits in the candle. */ - bool ContainsTimeMs(long _time_ms) { - return _time_ms >= (long)start_time * 1000 && _time_ms < (long)(start_time + length) * 1000; + bool ContainsTimeMs(int64 _time_ms) { + return _time_ms >= (int64)start_time * 1000 && _time_ms < (int64)(start_time + length) * 1000; } // Serializers. diff --git a/Common.define.h b/Common.define.h index f98a475e3..4fa357132 100644 --- a/Common.define.h +++ b/Common.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,7 +24,11 @@ * @file * Defines common defines. */ + #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once + // Data types. #include typedef std::string string; diff --git a/Common.extern.h b/Common.extern.h index 34fc0cde6..c009e9115 100644 --- a/Common.extern.h +++ b/Common.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -22,13 +22,15 @@ // Define external global functions. #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once + #include #include -#include "Chart.enum.h" -#include "DateTime.enum.h" -#include "Terminal.define.h" +#include "Platform/Chart/Chart.enum.h" +#include "Platform/Terminal.define.h" +#include "Storage/DateTime.enum.h" void DebugBreak() { #ifdef _MSC_VER diff --git a/Config.mqh b/Config.mqh index 81872f23f..9da4819c8 100644 --- a/Config.mqh +++ b/Config.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,10 +30,10 @@ #define CONFIG_MQH // Includes. -#include "DictStruct.mqh" #include "File.mqh" -#include "Object.mqh" #include "Serializer/Serializer.h" +#include "Storage/Dict/DictStruct.h" +#include "Storage/Object.h" enum CONFIG_FORMAT { CONFIG_FORMAT_JSON, CONFIG_FORMAT_JSON_NO_WHITESPACES, CONFIG_FORMAT_INI }; @@ -84,7 +84,7 @@ struct ConfigEntry : public MqlParam { ConfigEntry() { type = (ENUM_DATATYPE)-1; } ConfigEntry(const ConfigEntry& _r) { THIS_REF = _r; } - ConfigEntry(long _value) { + ConfigEntry(int64 _value) { type = ENUM_DATATYPE::TYPE_LONG; integer_value = _value; } @@ -198,7 +198,7 @@ class Config : public DictStruct { return Set(key, param); } - bool Set(string key, long value) { + bool Set(string key, int64 value) { ConfigEntry param = value; return Set(key, param); } diff --git a/Convert.basic.h b/Convert.basic.h index 05ee81dcc..b985b961a 100644 --- a/Convert.basic.h +++ b/Convert.basic.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,17 @@ * */ -// Prevents processing this includes file for the second time. #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once #endif // Includes. -#include "Array.mqh" #include "Common.extern.h" -#include "DateTime.mqh" #include "Std.h" -#include "String.mqh" +#include "Storage/Array.h" +#include "Storage/DateTime.h" +#include "Storage/String.h" /** * Class to provide conversion methods. @@ -40,7 +40,7 @@ class ConvertBasic { /** * Convert integer to hex. */ - static string IntToHex(long long_number) { + static string IntToHex(int64 long_number) { string result; int integer_number = (int)long_number; for (int i = 0; i < 4; i++) { @@ -88,8 +88,8 @@ class ConvertBasic { static void StringToType(string _value, unsigned int& _out) { _out = (unsigned int)StringToInteger(_value); } static void StringToType(string _value, char& _out) { _out = (char)_value[0]; } static void StringToType(string _value, unsigned char& _out) { _out = (unsigned char)_value[0]; } - static void StringToType(string _value, long& _out) { _out = StringToInteger(_value); } - static void StringToType(string _value, unsigned long& _out) { _out = StringToInteger(_value); } + static void StringToType(string _value, int64& _out) { _out = StringToInteger(_value); } + static void StringToType(string _value, uint64& _out) { _out = StringToInteger(_value); } static void StringToType(string _value, short& _out) { _out = (short)StringToInteger(_value); } static void StringToType(string _value, unsigned short& _out) { _out = (unsigned short)StringToInteger(_value); } static void StringToType(string _value, float& _out) { _out = (float)StringToDouble(_value); } @@ -116,8 +116,8 @@ class ConvertBasic { static void BoolToType(bool _value, unsigned char& _out) { _out = (unsigned char)_value; } static void BoolToType(bool _value, int& _out) { _out = (int)_value; } static void BoolToType(bool _value, unsigned int& _out) { _out = (unsigned int)_value; } - static void BoolToType(bool _value, long& _out) { _out = (long)_value; } - static void BoolToType(bool _value, unsigned long& _out) { _out = (unsigned long)_value; } + static void BoolToType(bool _value, int64& _out) { _out = (int64)_value; } + static void BoolToType(bool _value, uint64& _out) { _out = (uint64)_value; } static void BoolToType(bool _value, short& _out) { _out = (short)_value; } static void BoolToType(bool _value, unsigned short& _out) { _out = (unsigned short)_value; } static void BoolToType(bool _value, float& _out) { _out = (float)_value; } @@ -133,23 +133,23 @@ class ConvertBasic { return _out; } - static void LongToType(long _value, bool& _out) { _out = (bool)_value; } - static void LongToType(long _value, char& _out) { _out = (char)_value; } - static void LongToType(long _value, unsigned char& _out) { _out = (unsigned char)_value; } - static void LongToType(long _value, int& _out) { _out = (int)_value; } - static void LongToType(long _value, unsigned int& _out) { _out = (unsigned int)_value; } - static void LongToType(long _value, long& _out) { _out = (long)_value; } - static void LongToType(long _value, unsigned long& _out) { _out = (unsigned long)_value; } - static void LongToType(long _value, short& _out) { _out = (short)_value; } - static void LongToType(long _value, unsigned short& _out) { _out = (unsigned short)_value; } - static void LongToType(long _value, float& _out) { _out = (float)_value; } - static void LongToType(long _value, double& _out) { _out = (double)_value; } - static void LongToType(long _value, string& _out) { _out = _value ? "1" : "0"; } - static void LongToType(long _value, color& _out) { _out = 0; } - static void LongToType(long _value, datetime& _out) {} + static void LongToType(int64 _value, bool& _out) { _out = (bool)_value; } + static void LongToType(int64 _value, char& _out) { _out = (char)_value; } + static void LongToType(int64 _value, unsigned char& _out) { _out = (unsigned char)_value; } + static void LongToType(int64 _value, int& _out) { _out = (int)_value; } + static void LongToType(int64 _value, unsigned int& _out) { _out = (unsigned int)_value; } + static void LongToType(int64 _value, int64& _out) { _out = (int64)_value; } + static void LongToType(int64 _value, uint64& _out) { _out = (uint64)_value; } + static void LongToType(int64 _value, short& _out) { _out = (short)_value; } + static void LongToType(int64 _value, unsigned short& _out) { _out = (unsigned short)_value; } + static void LongToType(int64 _value, float& _out) { _out = (float)_value; } + static void LongToType(int64 _value, double& _out) { _out = (double)_value; } + static void LongToType(int64 _value, string& _out) { _out = _value ? "1" : "0"; } + static void LongToType(int64 _value, color& _out) { _out = 0; } + static void LongToType(int64 _value, datetime& _out) {} template - static X LongTo(long _value) { + static X LongTo(int64 _value) { X _out; LongToType(_value, _out); return _out; @@ -160,8 +160,8 @@ class ConvertBasic { static void DoubleToType(double _value, unsigned char& _out) { _out = (unsigned char)_value; } static void DoubleToType(double _value, int& _out) { _out = (int)_value; } static void DoubleToType(double _value, unsigned int& _out) { _out = (unsigned int)_value; } - static void DoubleToType(double _value, long& _out) { _out = (long)_value; } - static void DoubleToType(double _value, unsigned long& _out) { _out = (unsigned long)_value; } + static void DoubleToType(double _value, int64& _out) { _out = (int64)_value; } + static void DoubleToType(double _value, uint64& _out) { _out = (uint64)_value; } static void DoubleToType(double _value, short& _out) { _out = (short)_value; } static void DoubleToType(double _value, unsigned short& _out) { _out = (unsigned short)_value; } static void DoubleToType(double _value, float& _out) { _out = (float)_value; } @@ -176,4 +176,34 @@ class ConvertBasic { DoubleToType(_value, _out); return _out; } + + template + static T Convert(bool _value, T& _out) { + BoolToType(_value, _out); + return _out; + } + + template + static T Convert(int _value, T& _out) { + LongToType((long)_value, _out); + return _out; + } + + template + static T Convert(int64 _value, T& _out) { + LongToType(_value, _out); + return _out; + } + + template + static T Convert(double _value, T& _out) { + DoubleToType(_value, _out); + return _out; + } + + template + static T Convert(CONST_REF_TO_SIMPLE(string) _value, T& _out) { + StringToType(_value, _out); + return _out; + } }; diff --git a/Convert.extern.h b/Convert.extern.h index 753f0156a..195d8fda1 100644 --- a/Convert.extern.h +++ b/Convert.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,14 +20,16 @@ * */ -// Prevents processing this includes file for the second time. #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once // Includes. #include #include +#include "Storage/String.h" + // Define external global functions. double NormalizeDouble(double value, int digits) { return std::round(value / digits) * digits; } diff --git a/Convert.mqh b/Convert.mqh index 29cee521a..ad687fdcb 100644 --- a/Convert.mqh +++ b/Convert.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,17 +30,17 @@ #endif // Includes. -#include "Account/Account.enum.h" -#include "Account/Account.extern.h" -#include "Array.mqh" #include "Convert.extern.h" -#include "DateTime.extern.h" -#include "DateTime.mqh" -#include "Math.extern.h" -#include "Order.enum.h" -#include "SymbolInfo.enum.h" -#include "SymbolInfo.extern.h" -#include "SymbolInfo.struct.static.h" +#include "Exchange/Account/Account.enum.h" +#include "Exchange/Account/Account.extern.h" +#include "Exchange/SymbolInfo/SymbolInfo.enum.h" +#include "Exchange/SymbolInfo/SymbolInfo.extern.h" +#include "Exchange/SymbolInfo/SymbolInfo.struct.static.h" +#include "Math/Math.extern.h" +#include "Platform/Order.enum.h" +#include "Storage/Array.h" +#include "Storage/DateTime.extern.h" +#include "Storage/DateTime.h" /** * Class to provide conversion methods. @@ -168,12 +168,12 @@ class Convert { /** * Convert points into pips. */ - static double PointsToPips(long pts, int digits) { return (double)(pts / PointsPerPip(digits)); } + static double PointsToPips(int64 pts, int digits) { return (double)(pts / PointsPerPip(digits)); } /** * Convert points into pips. */ - static double PointsToPips(long pts, string _symbol = NULL) { + static double PointsToPips(int64 pts, string _symbol = NULL) { return PointsToPips(pts, (unsigned int)SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_DIGITS)); } @@ -181,7 +181,7 @@ class Convert { * Convert points into price value. * */ - static double PointsToValue(long pts, int mode, string _symbol = NULL) { + static double PointsToValue(int64 pts, int mode, string _symbol = NULL) { switch (mode) { case 0: // Forex. // In currencies a tick is a point. @@ -205,7 +205,7 @@ class Convert { /** * Convert points into price value. */ - static double PointsToValue(long pts, int mode, int digits) { + static double PointsToValue(int64 pts, int mode, int digits) { switch (mode) { case 0: // Forex. return PipsToValue((double)pts / PointsPerPip(digits), digits); @@ -226,7 +226,7 @@ class Convert { /** * Convert points into price value. */ - static double PointsToValue(long pts, string _symbol = NULL) { + static double PointsToValue(int64 pts, string _symbol = NULL) { return PointsToValue(pts, (int)SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_TRADE_CALC_MODE)); } diff --git a/Database.mqh b/Database.mqh deleted file mode 100644 index 3fe4d6386..000000000 --- a/Database.mqh +++ /dev/null @@ -1,344 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/* - * Implements Database class. - * - * The methods for working with databases uses SQLite engine. - * - * @docs https://www.mql5.com/en/docs/database - */ - -// Prevents processing this includes file for the second time. -#ifndef DATABASE_MQH -#define DATABASE_MQH - -// Includes. -#include "DictStruct.mqh" -#include "MiniMatrix.h" - -// Enums. -enum DATABASE_COLUMN_FLAGS { - DATABASE_COLUMN_FLAG_NONE = 0, - DATABASE_COLUMN_FLAG_IS_KEY = 1, - DATABASE_COLUMN_FLAG_IS_NULL = 2, -}; - -// Structs. -struct DatabaseTableColumnEntry { - string name; - ENUM_DATATYPE type; - unsigned short flags; - unsigned short char_size; - // Getter methods; - string GetDatatype() { - switch (type) { - case TYPE_BOOL: - return "BOOL"; - case TYPE_CHAR: - return StringFormat("CHAR(%d)", char_size); - case TYPE_DOUBLE: - return "REAL"; - case TYPE_INT: - return "INT"; - case TYPE_LONG: - return "LONG"; - case TYPE_STRING: - return "TEXT"; - } - return "UNKNOWN"; - } - string GetFlags() { return GetKey() + " " + GetNull(); } - string GetName() { return name; } - string GetNull() { return !IsNull() ? "NOT NULL" : ""; } - string GetKey() { return IsKey() ? "KEY" : ""; } - // State methods. - bool IsKey() { return bool(flags & DATABASE_COLUMN_FLAG_IS_KEY); } - bool IsNull() { return bool(flags & DATABASE_COLUMN_FLAG_IS_NULL); } - - DatabaseTableColumnEntry() {} - DatabaseTableColumnEntry(const string _name, const ENUM_DATATYPE _type, unsigned short _flags = 0, - unsigned short _char_size = 0) { - name = _name; - type = _type; - flags = _flags; - char_size = _char_size; - } - DatabaseTableColumnEntry(const DatabaseTableColumnEntry &r) { - name = r.name; - type = r.type; - flags = r.flags; - char_size = r.char_size; - } -}; -struct DatabaseTableSchema { - DictStruct columns; - // Constructor. - DatabaseTableSchema() {} - DatabaseTableSchema(DatabaseTableColumnEntry &_columns[]) { - for (int i = 0; i < ArraySize(_columns); i++) { - columns.Push(_columns[i]); - } - } - DatabaseTableSchema(const DatabaseTableSchema &r) { columns = r.columns; } - // Methods. - bool AddColumn(DatabaseTableColumnEntry &column) { return columns.Push(column); } -}; -// Struct table entry for SymbolInfo. -#ifdef SYMBOLINFO_MQH -struct DbSymbolInfoEntry : public SymbolInfoEntry { - DatabaseTableSchema schema; - // Constructors. - DbSymbolInfoEntry() { DefineSchema(); } - DbSymbolInfoEntry(const DbSymbolInfoEntry &r) { schema = r.schema; } - DbSymbolInfoEntry(const MqlTick &_tick, const string _symbol = NULL) : SymbolInfoEntry(_tick, _symbol) { - DefineSchema(); - } - // Methods. - void DefineSchema() { - schema.columns.Push(DatabaseTableColumnEntry("bid", TYPE_DOUBLE)); - schema.columns.Push(DatabaseTableColumnEntry("ask", TYPE_DOUBLE)); - schema.columns.Push(DatabaseTableColumnEntry("last", TYPE_DOUBLE)); - schema.columns.Push(DatabaseTableColumnEntry("spread", TYPE_DOUBLE)); - schema.columns.Push(DatabaseTableColumnEntry("volume", TYPE_INT)); - } -}; -#endif - -class Database { - private: - int handle; - DictStruct tables; - - public: - /** - * Class constructor. - */ -#ifndef __MQL4__ - Database(string _filename, unsigned int _flags = DATABASE_OPEN_CREATE){ -#else - Database(string _filename, unsigned int _flags = 0) { -#endif -#ifndef __MQL4__ - handle = DatabaseOpen(_filename, _flags); -#else - handle = -1; - SetUserError(ERR_USER_NOT_SUPPORTED); -#endif -} - -/** - * Class deconstructor. - */ -~Database() { -#ifndef __MQL4__ - DatabaseClose(handle); -#endif -} - -/* Table methods */ - -/** - * Checks if table exists. - */ -bool TableExists(string _name) { -#ifndef __MQL4__ - return DatabaseTableExists(handle, _name); -#else - SetUserError(ERR_USER_NOT_SUPPORTED); - return false; -#endif -} - -/** - * Creates table if not yet exist. - */ -bool CreateTableIfNotExist(string _name, DatabaseTableSchema &_schema) { - if (TableExists(_name)) { - return true; - } - return CreateTable(_name, _schema); -} - -/** - * Creates table. - */ -bool CreateTable(string _name, DatabaseTableSchema &_schema) { - bool _result = false; -#ifndef __MQL4__ - if (DatabaseTableExists(handle, _name)) { - // Generic error (ERR_DATABASE_ERROR). - SetUserError(5601); - return _result; - } - - string query = "", subquery = ""; - - if (_schema.columns.Size() == 0) { - // SQLite does'nt allow tables without columns; - subquery = "`dummy` INTEGER"; - } else { - for (DictStructIterator iter = _schema.columns.Begin(); iter.IsValid(); ++iter) { - subquery += - StringFormat("`%s` %s %s,", iter.Value().GetName(), iter.Value().GetDatatype(), iter.Value().GetFlags()); - } - subquery = StringSubstr(subquery, 0, StringLen(subquery) - 1); // Removes extra comma. - } - - query = StringFormat("CREATE TABLE `%s`(%s);", _name, subquery); - -#ifdef __debug__ - Print("Database: Executing query:\n", query); -#endif - - if (_result = DatabaseExecute(handle, query)) { - ResetLastError(); - SetTableSchema(_name, _schema); - } else { -#ifdef __debug__ - Print("Database: Query failed with error ", _LastError); - DebugBreak(); -#endif - } -#endif - return _result; -} - -/** - * Drops table. - */ -bool DropTable(string _name) { - tables.Unset(_name); -#ifndef __MQL4__ - return DatabaseExecute(handle, "DROP TABLE IF EXISTS `" + _name + "`"); -#else - return false; -#endif -} - -/* Import methods */ - -/** - * Imports data into table. First row must contain column names. Strings must be enclosed with double quotes. - */ -bool ImportData(const string _name, MiniMatrix2d &data) { - if (data.SizeY() < 2 || data.SizeX() == 0) { - // No data to import or there are no columns in input data (Serialize() serialized no fields). - return true; - } - int x; - bool _result = true; - DatabaseTableSchema _schema = GetTableSchema(_name); - string _query = "", _cols = "", _vals = ""; - for (x = 0; x < data.SizeX(); ++x) { - const string key = data.Get(x, 0); - _cols += "`" + StringSubstr(key, 1, StringLen(key) - 2) + "`,"; - } - _cols = StringSubstr(_cols, 0, StringLen(_cols) - 1); // Removes extra comma. -#ifndef __MQL4__ - if (DatabaseTransactionBegin(handle)) { - _query = StringFormat("INSERT INTO `%s`(%s) VALUES\n", _name, _cols); - for (int y = 1; y < data.SizeY(); ++y) { - _query += "("; - for (x = 0; x < data.SizeX(); ++x) { - _query += data.Get(x, y) + (x < data.SizeX() - 1 ? ", " : ""); - } - _query += ")" + (y < data.SizeY() - 1 ? ",\n" : ""); - } - -#ifdef __debug__ - Print("Database: Executing query:\n", _query); -#endif - - _result &= DatabaseExecute(handle, _query); - } - if (_result) { - DatabaseTransactionCommit(handle); - } else { - Print("Database: Query failed with error ", _LastError); - DebugBreak(); - DatabaseTransactionRollback(handle); - } -#else - return false; -#endif - return _result; -} - -#ifdef BUFFER_STRUCT_MQH -/** - * Imports BufferStruct records into a table. - */ -template -bool Import(const string _name, BufferStruct &_bstruct) { - bool _result = true; - DatabaseTableSchema _schema = GetTableSchema(_name); - string _query = "", _cols = "", _vals = ""; - for (DictStructIterator iter = _schema.columns.Begin(); iter.IsValid(); ++iter) { - _cols += iter.Value().name + ","; - } - _cols = StringSubstr(_cols, 0, StringLen(_cols) - 1); // Removes extra comma. -#ifndef __MQL4__ - if (DatabaseTransactionBegin(handle)) { - for (DictStructIterator iter = _bstruct.Begin(); iter.IsValid(); ++iter) { - _query = StringFormat("INSERT INTO %s(%s) VALUES (%s)", _name, _cols, iter.Value().ToCSV()); - _result &= DatabaseExecute(handle, _query); - } - } - if (_result) { - DatabaseTransactionCommit(handle); - } else { - DatabaseTransactionRollback(handle); - } -#else - return false; -#endif - return _result; -} -#endif - -/* Getters */ - -/** - * Gets database handle. - */ -int GetHandle() { return handle; } - -/** - * Gets table schema. - */ -DatabaseTableSchema GetTableSchema(string _name) { return tables.GetByKey(_name); } - -/** - * Checks if table schema exists. - */ -bool SchemaExists(string _name) { return tables.KeyExists(_name); } - -/* Setters */ - -/** - * Sets table schema. - */ -bool SetTableSchema(string _name, DatabaseTableSchema &_schema) { return tables.Set(_name, _schema); } -} -; -#endif // DATABASE_MQH diff --git a/EA.enum.h b/EA.enum.h index e2ba9ea47..30825b722 100644 --- a/EA.enum.h +++ b/EA.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/EA.mqh b/EA.mqh index 16cccca33..97f0f6471 100644 --- a/EA.mqh +++ b/EA.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,25 +25,27 @@ * Implements Expert Advisor class for writing custom trading robots. */ -// Prevents processing this includes file for the second time. -#ifndef EA_MQH -#define EA_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "./Chart.struct.static.h" -#include "Chart.mqh" -#include "Data.struct.h" -#include "Dict.mqh" -#include "DictObject.mqh" +#include "Platform/Chart/Chart.struct.static.h" #include "EA.enum.h" #include "EA.struct.h" #include "Market.mqh" -#include "Platform.h" +#include "Platform/Chart/Chart.h" +#include "Platform/Platform.h" +#include "Platform/Terminal.h" #include "Refs.struct.h" #include "Serializer/SerializerConverter.h" #include "Serializer/SerializerCsv.h" #include "Serializer/SerializerJson.h" #include "Serializer/SerializerSqlite.h" +#include "Storage/Data.struct.h" +#include "Storage/Dict/Dict.h" +#include "Storage/Dict/DictObject.h" #include "Strategy.mqh" #include "SummaryReport.mqh" #include "Task/Task.h" @@ -51,7 +53,6 @@ #include "Task/TaskCondition.enum.h" #include "Task/TaskManager.h" #include "Task/Taskable.h" -#include "Terminal.mqh" #include "Trade.mqh" #include "Trade/TradeSignal.h" #include "Trade/TradeSignalManager.h" @@ -60,7 +61,7 @@ class EA : public Taskable { protected: // Class variables. AccountMt *account; - DictStruct> strats; + DictStruct> strats; Log logger; Terminal terminal; @@ -70,8 +71,8 @@ class EA : public Taskable { Dict ddata; // Custom user data. Dict idata; // Custom user data. DictObject trade; - DictObject> data_indi; - DictObject> data_stg; + DictObject> data_indi; + DictObject> data_stg; EAParams eparams; EAProcessResult eresults; EAState estate; @@ -113,7 +114,7 @@ class EA : public Taskable { // Add and process tasks. Init(); // Initialize a trade instance for the current chart and symbol. - Ref _source = Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_CURRENT); + Ref _source = Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_CURRENT); TradeParams _tparams(0, 1.0f, 0, (ENUM_LOG_LEVEL)eparams.Get(STRUCT_ENUM(EAParams, EA_PARAM_PROP_LOG_LEVEL))); Trade _trade(_tparams, _source.Ptr()); trade.Set(_Symbol, _trade); @@ -179,16 +180,16 @@ class EA : public Taskable { */ TradeSignalEntry GetStrategySignalEntry(Strategy *_strat, bool _trade_allowed = true, int _shift = 0) { // float _bf = 1.0; - float _scl = _strat.Get(STRAT_PARAM_SCL); - float _sol = _strat.Get(STRAT_PARAM_SOL); - int _scfm = _strat.Get(STRAT_PARAM_SCFM); - int _scft = _strat.Get(STRAT_PARAM_SCFT); - int _scm = _strat.Get(STRAT_PARAM_SCM); - int _sob = _strat.Get(STRAT_PARAM_SOB); - int _sofm = _strat.Get(STRAT_PARAM_SOFM); - int _soft = _strat.Get(STRAT_PARAM_SOFT); - int _som = _strat.Get(STRAT_PARAM_SOM); - int _ss = _shift >= 0 ? _shift : _strat.Get(STRAT_PARAM_SHIFT); + float _scl = _strat PTR_DEREF Get(STRAT_PARAM_SCL); + float _sol = _strat PTR_DEREF Get(STRAT_PARAM_SOL); + int _scfm = _strat PTR_DEREF Get(STRAT_PARAM_SCFM); + int _scft = _strat PTR_DEREF Get(STRAT_PARAM_SCFT); + int _scm = _strat PTR_DEREF Get(STRAT_PARAM_SCM); + int _sob = _strat PTR_DEREF Get(STRAT_PARAM_SOB); + int _sofm = _strat PTR_DEREF Get(STRAT_PARAM_SOFM); + int _soft = _strat PTR_DEREF Get(STRAT_PARAM_SOFT); + int _som = _strat PTR_DEREF Get(STRAT_PARAM_SOM); + int _ss = _shift >= 0 ? _shift : _strat PTR_DEREF Get(STRAT_PARAM_SHIFT); unsigned int _signals = 0; // sparams.Get(STRAT_PARAM_WEIGHT)); if (_trade_allowed) { @@ -196,20 +197,22 @@ class EA : public Taskable { // sresult.SetBoostFactor(sparams.IsBoosted() ? SignalOpenBoost(ORDER_TYPE_BUY, _sob) : 1.0f); // sresult.SetLotSize(sparams.GetLotSizeWithFactor()); // Process open signals when trade is allowed. - _signals |= _strat.SignalOpen(ORDER_TYPE_BUY, _som, _sol, _ss) ? SIGNAL_OPEN_BUY_MAIN : 0; - _signals |= !_strat.SignalOpenFilterMethod(ORDER_TYPE_BUY, _sofm) ? SIGNAL_OPEN_BUY_FILTER : 0; - _signals |= _strat.SignalOpen(ORDER_TYPE_SELL, _som, _sol, _ss) ? SIGNAL_OPEN_SELL_MAIN : 0; - _signals |= !_strat.SignalOpenFilterMethod(ORDER_TYPE_SELL, _sofm) ? SIGNAL_OPEN_SELL_FILTER : 0; - _signals |= !_strat.SignalOpenFilterTime(_soft) ? SIGNAL_OPEN_TIME_FILTER : 0; + _signals |= _strat PTR_DEREF SignalOpen(ORDER_TYPE_BUY, _som, _sol, _ss) ? SIGNAL_OPEN_BUY_MAIN : 0; + _signals |= !_strat PTR_DEREF SignalOpenFilterMethod(ORDER_TYPE_BUY, _sofm) ? SIGNAL_OPEN_BUY_FILTER : 0; + _signals |= _strat PTR_DEREF SignalOpen(ORDER_TYPE_SELL, _som, _sol, _ss) ? SIGNAL_OPEN_SELL_MAIN : 0; + _signals |= !_strat PTR_DEREF SignalOpenFilterMethod(ORDER_TYPE_SELL, _sofm) ? SIGNAL_OPEN_SELL_FILTER : 0; + _signals |= !_strat PTR_DEREF SignalOpenFilterTime(_soft) ? SIGNAL_OPEN_TIME_FILTER : 0; } // Process close signals. - _signals |= _strat.SignalClose(ORDER_TYPE_BUY, _scm, _scl, _ss) ? SIGNAL_CLOSE_BUY_MAIN : 0; - _signals |= !_strat.SignalCloseFilter(ORDER_TYPE_BUY, _scfm) ? SIGNAL_CLOSE_BUY_FILTER : 0; - _signals |= _strat.SignalClose(ORDER_TYPE_SELL, _scm, _scl, _ss) ? SIGNAL_CLOSE_SELL_MAIN : 0; - _signals |= !_strat.SignalCloseFilter(ORDER_TYPE_SELL, _scfm) ? SIGNAL_CLOSE_SELL_FILTER : 0; - _signals |= !_strat.SignalCloseFilterTime(_scft) ? SIGNAL_CLOSE_TIME_FILTER : 0; - TradeSignalEntry _sentry(_signals, _strat.GetSource() PTR_DEREF GetTf(), _strat.Get(STRAT_PARAM_ID)); - _sentry.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_STRENGTH), _strat.SignalOpen(_sofm, _sol, _ss)); + _signals |= _strat PTR_DEREF SignalClose(ORDER_TYPE_BUY, _scm, _scl, _ss) ? SIGNAL_CLOSE_BUY_MAIN : 0; + _signals |= !_strat PTR_DEREF SignalCloseFilter(ORDER_TYPE_BUY, _scfm) ? SIGNAL_CLOSE_BUY_FILTER : 0; + _signals |= _strat PTR_DEREF SignalClose(ORDER_TYPE_SELL, _scm, _scl, _ss) ? SIGNAL_CLOSE_SELL_MAIN : 0; + _signals |= !_strat PTR_DEREF SignalCloseFilter(ORDER_TYPE_SELL, _scfm) ? SIGNAL_CLOSE_SELL_FILTER : 0; + _signals |= !_strat PTR_DEREF SignalCloseFilterTime(_scft) ? SIGNAL_CLOSE_TIME_FILTER : 0; + TradeSignalEntry _sentry(_signals, _strat PTR_DEREF GetSource() PTR_DEREF GetTf(), + _strat PTR_DEREF Get(STRAT_PARAM_ID)); + _sentry.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_STRENGTH), + _strat PTR_DEREF SignalOpen(_sofm, _sol, _ss)); _sentry.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TIME), ::TimeGMT()); return _sentry; } @@ -239,9 +242,9 @@ class EA : public Taskable { */ template void Set(ENUM_STRATEGY_PARAM _param, T _value) { - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strat = iter.Value().Ptr(); - _strat.Set(_param, _value); + _strat PTR_DEREF Set(_param, _value); } } @@ -252,11 +255,11 @@ class EA : public Taskable { void Set(ENUM_TRADE_PARAM _param, T _value) { for (DictObjectIterator iter = trade.Begin(); iter.IsValid(); ++iter) { Trade *_trade = iter.Value(); - _trade.Set(_param, _value); + _trade PTR_DEREF Set(_param, _value); } - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strat = iter.Value().Ptr(); - _strat.Set(_param, _value); + _strat PTR_DEREF Set(_param, _value); } } @@ -272,56 +275,56 @@ class EA : public Taskable { for (DictObjectIterator _iter = tsm.GetIterSignalsActive(); _iter.IsValid(); ++_iter) { bool _result_local = true; TradeSignal *_signal = _iter.Value(); - if (_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED))) { + if (_signal PTR_DEREF Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED))) { // Ignores already processed signals. continue; } Trade *_trade = trade.GetByKey(_Symbol); Strategy *_strat = - strats.GetByKey(_signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID))).Ptr(); + strats.GetByKey(_signal PTR_DEREF Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID))).Ptr(); _trade_allowed &= _trade.IsTradeAllowed(); - if (_trade.Get(TRADE_STATE_ORDERS_ACTIVE)) { - float _sig_close = _signal.GetSignalClose(); + if (_trade PTR_DEREF Get(TRADE_STATE_ORDERS_ACTIVE)) { + float _sig_close = _signal PTR_DEREF GetSignalClose(); string _comment_close = - _strat != NULL && _sig_close != 0.0f ? _strat.GetOrderCloseComment() : __FUNCTION_LINE__; + _strat != NULL && _sig_close != 0.0f ? _strat PTR_DEREF GetOrderCloseComment() : __FUNCTION_LINE__; // Check if we should close the orders. - // _trade_allowed &= _strat.GetTrade().IsTradeAllowed(_sig_close != 0.0f); + // _trade_allowed &= _strat PTR_DEREF GetTrade().IsTradeAllowed(_sig_close != 0.0f); if (_sig_close != 0.0f && _trade_allowed) { if (_sig_close >= 0.5f) { // Close signal for buy order. - _trade.OrdersCloseViaProp2( - ORDER_MAGIC, _signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID)), ORDER_TYPE, + _trade PTR_DEREF OrdersCloseViaProp2( + ORDER_MAGIC, _signal PTR_DEREF Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID)), ORDER_TYPE, ORDER_TYPE_BUY, MATH_COND_EQ, ORDER_REASON_CLOSED_BY_SIGNAL, _comment_close); // Buy orders closed. - _strat.OnOrderClose(ORDER_TYPE_BUY); + _strat PTR_DEREF OnOrderClose(ORDER_TYPE_BUY); } if (_sig_close <= -0.5f) { // Close signal for sell order. - _trade.OrdersCloseViaProp2( - ORDER_MAGIC, _signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID)), ORDER_TYPE, + _trade PTR_DEREF OrdersCloseViaProp2( + ORDER_MAGIC, _signal PTR_DEREF Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_MAGIC_ID)), ORDER_TYPE, ORDER_TYPE_SELL, MATH_COND_EQ, ORDER_REASON_CLOSED_BY_SIGNAL, _comment_close); // Sell orders closed. - _strat.OnOrderClose(ORDER_TYPE_SELL); + _strat PTR_DEREF OnOrderClose(ORDER_TYPE_SELL); } } } - _trade_allowed &= !_strat.IsSuspended(); + _trade_allowed &= !_strat PTR_DEREF IsSuspended(); if (_trade_allowed) { - float _sig_open = _signal.GetSignalOpen(); + float _sig_open = _signal PTR_DEREF GetSignalOpen(); unsigned int _sig_f = eparams.Get(STRUCT_ENUM(EAParams, EA_PARAM_PROP_SIGNAL_FILTER)); - string _comment_open = _strat != NULL && _sig_open != 0.0f ? _strat.GetOrderOpenComment() : __FUNCTION_LINE__; + string _comment_open = _strat != NULL && _sig_open != 0.0f ? _strat PTR_DEREF GetOrderOpenComment() : __FUNCTION_LINE__; // Open orders on signals. - // _trade_allowed &= _strat.GetTrade().IsTradeAllowed(_sig_open != 0.0f); + // _trade_allowed &= _strat PTR_DEREF GetTrade() PTR_DEREF IsTradeAllowed(_sig_open != 0.0f); if (_sig_open != 0.0f && _trade_allowed) { if (_sig_open >= 0.5f) { // Open signal for buy. // When H1 or H4 signal filter is enabled, do not open minute-based orders on opposite or neutral signals. if (GetSignalOpenFiltered(_signal, _sig_f) >= 0.5f) { - _strat.Set(TRADE_PARAM_ORDER_COMMENT, _comment_open); + _strat PTR_DEREF Set(TRADE_PARAM_ORDER_COMMENT, _comment_open); // Buy order open. _result_local &= TradeRequest(ORDER_TYPE_BUY, _Symbol, _strat); if (_result_local && eparams.CheckSignalFilter(STRUCT_ENUM(EAParams, EA_PARAM_SIGNAL_FILTER_FIRST))) { - _signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); + _signal PTR_DEREF Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); break; } } else { @@ -332,11 +335,11 @@ class EA : public Taskable { // Open signal for sell. // When H1 or H4 signal filter is enabled, do not open minute-based orders on opposite or neutral signals. if (GetSignalOpenFiltered(_signal, _sig_f) <= -0.5f) { - _strat.Set(TRADE_PARAM_ORDER_COMMENT, _comment_open); + _strat PTR_DEREF Set(TRADE_PARAM_ORDER_COMMENT, _comment_open); // Sell order open. _result_local &= TradeRequest(ORDER_TYPE_SELL, _Symbol, _strat); if (_result_local && eparams.CheckSignalFilter(STRUCT_ENUM(EAParams, EA_PARAM_SIGNAL_FILTER_FIRST))) { - _signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); + _signal PTR_DEREF Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); break; } } else { @@ -345,19 +348,20 @@ class EA : public Taskable { } } if (_result_local) { - _signal.Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); + _signal PTR_DEREF Set(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_FLAG_PROCESSED), true); } else { _last_error = GetLastError(); if (_last_error > 0) { - logger.Warning(StringFormat("Error: %d", _last_error), __FUNCTION_LINE__, _strat.GetName()); + logger.Warning(StringFormat("Error: %d", _last_error), __FUNCTION_LINE__, _strat PTR_DEREF GetName()); #ifdef __debug_ea__ Print(__FUNCTION_LINE__ + "(): " + SerializerConverter::FromObject(_signal).ToString()); #endif ResetLastError(); } - if (_trade.Get(TRADE_STATE_MONEY_NOT_ENOUGH)) { - logger.Warning(StringFormat("Suspending strategy.", _last_error), __FUNCTION_LINE__, _strat.GetName()); - _strat.Suspended(true); + if (_trade PTR_DEREF Get(TRADE_STATE_MONEY_NOT_ENOUGH)) { + logger.Warning(StringFormat("Suspending strategy.", _last_error), __FUNCTION_LINE__, + _strat PTR_DEREF GetName()); + _strat PTR_DEREF Suspended(true); } } } @@ -382,14 +386,14 @@ class EA : public Taskable { bool _result = false; Trade *_trade = trade.GetByKey(_symbol); // Prepare a request. - MqlTradeRequest _request = _trade.GetTradeOpenRequest(_cmd); - _request.comment = _strat.GetOrderOpenComment(); - _request.magic = _strat.Get(STRAT_PARAM_ID); + MqlTradeRequest _request = _trade PTR_DEREF GetTradeOpenRequest(_cmd); + _request.comment = _strat PTR_DEREF GetOrderOpenComment(); + _request.magic = _strat PTR_DEREF Get(STRAT_PARAM_ID); _request.price = SymbolInfoStatic::GetOpenOffer(_symbol, _cmd); - _request.volume = fmax(_strat.Get(STRAT_PARAM_LS), SymbolInfoStatic::GetVolumeMin(_symbol)); + _request.volume = fmax(_strat PTR_DEREF Get(STRAT_PARAM_LS), SymbolInfoStatic::GetVolumeMin(_symbol)); // @fixit Uncomment - // _request.volume = _trade.NormalizeLots(_request.volume); + // _request.volume = _trade PTR_DEREF NormalizeLots(_request.volume); // Check strategy's trade states. switch (_request.action) { @@ -406,9 +410,9 @@ class EA : public Taskable { } // Prepare an order parameters. OrderParams _oparams; - _strat.OnOrderOpen(_oparams); + _strat PTR_DEREF OnOrderOpen(_oparams); // Send the request. - _result = _trade.RequestSend(_request, _oparams); + _result = _trade PTR_DEREF RequestSend(_request, _oparams); if (!_result) { // && _strade.IsTradeRecommended( logger.Debug( StringFormat("Error while sending a trade request! Entry: %s", @@ -443,28 +447,28 @@ class EA : public Taskable { if (estate.IsActive()) { ProcessPeriods(); // Process all enabled strategies and retrieve their signals. - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { bool _can_trade = true; Strategy *_strat = iter.Value().Ptr(); Trade *_trade = trade.GetByKey(_Symbol); - if (_strat.IsEnabled()) { + if (_strat PTR_DEREF IsEnabled()) { if (estate.Get(STRUCT_ENUM(EAState, EA_STATE_PROP_NEW_PERIODS)) >= DATETIME_MINUTE) { // Process when new periods started. - _strat.OnPeriod(estate.Get(STRUCT_ENUM(EAState, EA_STATE_PROP_NEW_PERIODS))); - _strat.ProcessTasks(); - _trade.OnPeriod(estate.Get(STRUCT_ENUM(EAState, EA_STATE_PROP_NEW_PERIODS))); + _strat PTR_DEREF OnPeriod(estate.Get(STRUCT_ENUM(EAState, EA_STATE_PROP_NEW_PERIODS))); + _strat PTR_DEREF ProcessTasks(); + _trade PTR_DEREF OnPeriod(estate.Get(STRUCT_ENUM(EAState, EA_STATE_PROP_NEW_PERIODS))); eresults.stg_processed_periods++; } - if (_strat.TickFilter(_tick)) { - _can_trade &= !_trade.HasState(TRADE_STATE_MODE_DISABLED); - _can_trade &= !_strat.IsSuspended(); - TradeSignalEntry _sentry = GetStrategySignalEntry(_strat, _can_trade, _strat.Get(STRAT_PARAM_SHIFT)); + if (_strat PTR_DEREF TickFilter(_tick)) { + _can_trade &= !_trade PTR_DEREF HasState(TRADE_STATE_MODE_DISABLED); + _can_trade &= !_strat PTR_DEREF IsSuspended(); + TradeSignalEntry _sentry = GetStrategySignalEntry(_strat, _can_trade, _strat PTR_DEREF Get(STRAT_PARAM_SHIFT)); if (_sentry.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_SIGNALS)) > 0) { TradeSignal _signal(_sentry); if (_signal.GetSignalClose() != _signal.GetSignalOpen()) { tsm.SignalAdd(_signal); //, _tick.time); } - StgProcessResult _strat_result = _strat.GetProcessResult(); + StgProcessResult _strat_result = _strat PTR_DEREF GetProcessResult(); eresults.last_error = fmax(eresults.last_error, _strat_result.last_error); eresults.stg_errored += (int)_strat_result.last_error > ERR_NO_ERROR; eresults.stg_processed++; @@ -472,7 +476,7 @@ class EA : public Taskable { } } } - if (tsm.GetSignalsActive().Size() > 0 && tsm.IsReady()) { + if (tsm.GetSignalsActive() PTR_DEREF Size() > 0 && tsm.IsReady()) { // Process all strategies' signals and trigger trading orders. ProcessSignals(_tick, eparams.Get(STRUCT_ENUM(EAParams, EA_PARAM_PROP_SIGNAL_FILTER))); } @@ -499,35 +503,35 @@ class EA : public Taskable { * Process data to store. */ void ProcessData() { - long _timestamp = estate.last_updated.GetEntry().GetTimestamp(); + int64 _timestamp = estate.last_updated.GetEntry().GetTimestamp(); if (eparams.CheckFlagDataStore(EA_DATA_STORE_CHART)) { ChartEntry _entry = Chart().GetEntry(); data_chart.Add(_entry, _entry.bar.ohlc.time); } /* @fixme if (eparams.CheckFlagDataStore(EA_DATA_STORE_INDICATOR)) { - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strati = iter.Value().Ptr(); - IndicatorData *_indi = _strati.GetIndicator(); + IndicatorData *_indi = _strati PTR_DEREF GetIndicator(); if (_indi != NULL) { ENUM_TIMEFRAMES _itf = _indi PTR_DEREF GetTf(); - IndicatorDataEntry _ientry = _indi.GetEntry(); + IndicatorDataEntry _ientry = _indi PTR_DEREF GetEntry(); if (!data_indi.KeyExists(_itf)) { // Create new timeframe buffer if does not exist. BufferStruct *_ide = new BufferStruct; - data_indi.Set(_itf, _ide); + data_indi.Set(_itf, PTR_TO_REF(_ide)); } // Save entry into data_indi. - data_indi[_itf].Add(_ientry); + data_indi[_itf] PTR_DEREF Add(_ientry); } } } */ /* if (eparams.CheckFlagDataStore(EA_DATA_STORE_STRATEGY)) { - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strat = iter.Value().Ptr(); - StgEntry _sentry = _strat.GetEntry(); + StgEntry _sentry = _strat PTR_DEREF GetEntry(); ENUM_TIMEFRAMES _stf = iter_tf.Key(); // @fixme if (!data_stg.KeyExists(_stf)) { // Create new timeframe buffer if does not exist. @@ -560,7 +564,7 @@ class EA : public Taskable { * Export data. */ void DataExport(unsigned short _methods) { - long _timestamp = estate.last_updated.GetEntry().GetTimestamp(); + int64 _timestamp = estate.last_updated.GetEntry().GetTimestamp(); int _serializer_flags = SERIALIZER_FLAG_SKIP_HIDDEN | SERIALIZER_FLAG_INCLUDE_DEFAULT | SERIALIZER_FLAG_INCLUDE_DYNAMIC | SERIALIZER_FLAG_REUSE_STUB | SERIALIZER_FLAG_REUSE_OBJECT; @@ -592,14 +596,14 @@ class EA : public Taskable { SerializerConverter::MakeStubObject>(_serializer_flags); /* - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { ENUM_TIMEFRAMES _itf = iter_tf.Key(); // @fixme if (data_indi.KeyExists(_itf)) { BufferStruct _indi_buff = data_indi.GetByKey(_itf); SerializerConverter _obj = SerializerConverter::FromObject(_indi_buff, _serializer_flags); - for (DictStructIterator> iter = strats[_itf].Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats[_itf].Begin(); iter.IsValid(); ++iter) { string _key_indi = "Indicator"; _key_indi += StringFormat("-%d-%d-%d", _itf, _indi_buff.GetMin(), _indi_buff.GetMax()); @@ -627,7 +631,7 @@ class EA : public Taskable { SerializerConverter _stub = SerializerConverter::MakeStubObject>(_serializer_flags); /* @fixme - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { ENUM_TIMEFRAMES _stf = iter_tf.Key(); // @fixme if (data_stg.KeyExists(_stf)) { string _key_stg = StringFormat("Strategy-%d", _stf); @@ -677,7 +681,7 @@ class EA : public Taskable { } if (eparams.CheckFlagDataStore(EA_DATA_STORE_TRADE)) { string _key_trade = "Trade"; - // _key_sym += StringFormat("-%d-%d", data_trade.GetMin(), data_trade.GetMax()); + // _key_sym += StringFormat("-%d-%d", data_trade PTR_DEREF GetMin(), data_trade PTR_DEREF GetMax()); if ((_methods & EA_DATA_EXPORT_CSV) != 0) { // @todo // SerializerConverter _stub_trade = @@ -716,26 +720,26 @@ class EA : public Taskable { float _sig_open = _signal.GetSignalOpen(); ENUM_TIMEFRAMES _sig_tf = _signal.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TF)); if (ChartTf::TfToHours(_sig_tf) < 1 && bool(_sf & STRUCT_ENUM(EAParams, EA_PARAM_SIGNAL_FILTER_OPEN_M_IF_H))) { - for (DictStructIterator> _iter = GetStrategies().Begin(); _iter.IsValid(); ++_iter) { + for (DictStructIterator> _iter = GetStrategies().Begin(); _iter.IsValid(); ++_iter) { Strategy *_strat = _iter.Value().Ptr(); - ENUM_TIMEFRAMES _stf = _strat.Get(STRAT_PARAM_TF); + ENUM_TIMEFRAMES _stf = _strat PTR_DEREF Get(STRAT_PARAM_TF); if (ChartTf::TfToHours(_stf) >= 1) { TradeSignal *_hsignal0 = - tsm.GetSignalByCid(_strat.Get(STRAT_PARAM_ID), (int)_stf, (int)ChartStatic::iTime(_Symbol, _stf)); + tsm.GetSignalByCid(_strat PTR_DEREF Get(STRAT_PARAM_ID), (int)_stf, (int)ChartStatic::iTime(_Symbol, _stf)); TradeSignal *_hsignal1 = - tsm.GetSignalByCid(_strat.Get(STRAT_PARAM_ID), (int)_stf, (int)ChartStatic::iTime(_Symbol, _stf, 1)); + tsm.GetSignalByCid(_strat PTR_DEREF Get(STRAT_PARAM_ID), (int)_stf, (int)ChartStatic::iTime(_Symbol, _stf, 1)); TradeSignal *_hsignal2 = - tsm.GetSignalByCid(_strat.Get(STRAT_PARAM_ID), (int)_stf, (int)ChartStatic::iTime(_Symbol, _stf, 2)); + tsm.GetSignalByCid(_strat PTR_DEREF Get(STRAT_PARAM_ID), (int)_stf, (int)ChartStatic::iTime(_Symbol, _stf, 2)); // Increase signal if confirmed by hourly signal. - if (_hsignal0 != NULL && _hsignal0.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TIME)) > 0) { + if (_hsignal0 != NULL && _hsignal0.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TIME)) > 0) { _sig_open += ((_sig_open > 0) == (_hsignal0.GetSignalOpen() > 0)) ? 1.0f : -1.0f; _sig_open -= ((_sig_open < 0) == (_hsignal0.GetSignalOpen() < 0)) ? 1.0f : -1.0f; } else if (_hsignal1 != NULL && - _hsignal1.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TIME)) > 0) { + _hsignal1.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TIME)) > 0) { _sig_open += ((_sig_open > 0) == (_hsignal1.GetSignalOpen() > 0)) ? 0.5f : -0.5f; _sig_open -= ((_sig_open < 0) == (_hsignal1.GetSignalOpen() < 0)) ? 0.5f : -0.5f; } else if (_hsignal2 != NULL && - _hsignal2.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TIME)) > 0) { + _hsignal2.Get(STRUCT_ENUM(TradeSignalEntry, TRADE_SIGNAL_PROP_TIME)) > 0) { _sig_open += ((_sig_open > 0) == (_hsignal2.GetSignalOpen() > 0)) ? 0.2f : -0.2f; _sig_open -= ((_sig_open < 0) == (_hsignal2.GetSignalOpen() < 0)) ? 0.2f : -0.2f; } else { @@ -761,24 +765,24 @@ class EA : public Taskable { * Returns true if the strategy has been initialized correctly, otherwise false. */ template - bool StrategyAdd(ENUM_TIMEFRAMES _tf, long _magic_no = 0, int _type = 0) { + bool StrategyAdd(ENUM_TIMEFRAMES _tf, int64 _magic_no = 0, int _type = 0) { bool _result = true; _magic_no = _magic_no > 0 ? _magic_no : rand(); Ref _strat = ((SClass *)NULL).Init(_tf, THIS_PTR); - _strat.Ptr().Set(STRAT_PARAM_ID, _magic_no); - _strat.Ptr().Set(TRADE_PARAM_MAGIC_NO, _magic_no); - _strat.Ptr().Set(STRAT_PARAM_LOG_LEVEL, + _strat PTR_DEREF Ptr().Set(STRAT_PARAM_ID, _magic_no); + _strat PTR_DEREF Ptr().Set(TRADE_PARAM_MAGIC_NO, _magic_no); + _strat PTR_DEREF Ptr().Set(STRAT_PARAM_LOG_LEVEL, (ENUM_LOG_LEVEL)eparams.Get(STRUCT_ENUM(EAParams, EA_PARAM_PROP_LOG_LEVEL))); - _strat.Ptr().Set(STRAT_PARAM_TF, _tf); - _strat.Ptr().Set(STRAT_PARAM_TYPE, _type); - _strat.Ptr().OnInit(); + _strat PTR_DEREF Ptr().Set(STRAT_PARAM_TF, _tf); + _strat PTR_DEREF Ptr().Set(STRAT_PARAM_TYPE, _type); + _strat PTR_DEREF Ptr().OnInit(); if (!strats.KeyExists(_magic_no)) { _result &= strats.Set(_magic_no, _strat); } else { logger.Error("Strategy adding conflict!", __FUNCTION_LINE__); DebugBreak(); } - OnStrategyAdd(_strat.Ptr()); + OnStrategyAdd(_strat PTR_DEREF Ptr()); return _result; } @@ -799,7 +803,7 @@ class EA : public Taskable { * Returns true if all strategies has been initialized correctly, otherwise false. */ template - bool StrategyAdd(unsigned int _tfs, long _init_magic = 0, int _type = 0) { + bool StrategyAdd(unsigned int _tfs, int64 _init_magic = 0, int _type = 0) { bool _result = true; for (int _tfi = 0; _tfi < sizeof(int) * 8; ++_tfi) { if ((_tfs & (1 << _tfi)) != 0) { @@ -816,15 +820,15 @@ class EA : public Taskable { bool _result = true; Trade *_trade = trade.GetByKey(_Symbol); // Load active trades. - _result &= _trade.OrdersLoadByMagic(_strat.Get(STRAT_PARAM_ID)); + _result &= _trade.OrdersLoadByMagic(_strat PTR_DEREF Get(STRAT_PARAM_ID)); // Load strategy-specific order parameters (e.g. conditions). // This is a temporary workaround for GH-705. // @todo: To move to Strategy class. Ref _order; - for (DictStructIterator> iter = _trade.GetOrdersActive().Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = _trade.GetOrdersActive().Begin(); iter.IsValid(); ++iter) { _order = iter.Value(); if (_order.IsSet() && _order.Ptr().IsOpen()) { - _strat.OnOrderLoad(_order.Ptr()); + _strat PTR_DEREF OnOrderLoad(_order.Ptr()); } } return _result; @@ -844,50 +848,52 @@ class EA : public Taskable { for (DictObjectIterator titer = trade.Begin(); titer.IsValid(); ++titer) { Trade *_trade = titer.Value(); if (_trade.Get(TRADE_STATE_ORDERS_ACTIVE) && !_trade.Get(TRADE_STATE_MARKET_CLOSED)) { - for (DictStructIterator> oiter = _trade.GetOrdersActive().Begin(); oiter.IsValid(); ++oiter) { + for (DictStructIterator> oiter = _trade.GetOrdersActive().Begin(); oiter.IsValid(); ++oiter) { bool _sl_valid = false, _tp_valid = false; double _sl_new = 0, _tp_new = 0; Order *_order = oiter.Value().Ptr(); - if (!_order.ShouldUpdate()) { + if (!_order PTR_DEREF ShouldUpdate()) { continue; } - _order.ProcessConditions(); - if (_order.IsClosed()) { - _trade.OrderMoveToHistory(_order); + _order PTR_DEREF ProcessConditions(); + if (_order PTR_DEREF IsClosed()) { + _trade PTR_DEREF OrderMoveToHistory(_order); continue; } - ENUM_ORDER_TYPE _otype = _order.Get(ORDER_TYPE); - Strategy *_strat = strats.GetByKey(_order.Get(ORDER_MAGIC)).Ptr(); - Strategy *_strat_sl = _strat.GetStratSl(); - Strategy *_strat_tp = _strat.GetStratTp(); + ENUM_ORDER_TYPE _otype = _order PTR_DEREF Get(ORDER_TYPE); + Strategy *_strat = strats.GetByKey(_order PTR_DEREF Get(ORDER_MAGIC)).Ptr(); + Strategy *_strat_sl = _strat PTR_DEREF GetStratSl(); + Strategy *_strat_tp = _strat PTR_DEREF GetStratTp(); if (_strat_sl != NULL || _strat_tp != NULL) { - float _olots = _order.Get(ORDER_VOLUME_CURRENT); - float _trisk = _trade.Get(TRADE_PARAM_RISK_MARGIN); + float _olots = _order PTR_DEREF Get(ORDER_VOLUME_CURRENT); + float _trisk = _trade PTR_DEREF Get(TRADE_PARAM_RISK_MARGIN); if (_strat_sl != NULL) { - float _psl = _strat_sl.Get(STRAT_PARAM_PSL); - float _sl_max = _trade.GetMaxSLTP(_otype, _olots, ORDER_TYPE_SL, _trisk); - int _psm = _strat_sl.Get(STRAT_PARAM_PSM); - _sl_new = _strat_sl.PriceStop(_otype, ORDER_TYPE_SL, _psm, _psl); - _sl_new = _trade.GetSaferSLTP(_sl_new, _sl_max, _otype, ORDER_TYPE_SL); - _sl_new = _trade.NormalizeSL(_sl_new, _otype); - _sl_valid = _trade.IsValidOrderSL(_sl_new, _otype, _order.Get(ORDER_SL), _psm > 0); - _sl_new = _sl_valid ? _sl_new : _order.Get(ORDER_SL); + float _psl = _strat_sl PTR_DEREF Get(STRAT_PARAM_PSL); + float _sl_max = _trade PTR_DEREF GetMaxSLTP(_otype, _olots, ORDER_TYPE_SL, _trisk); + int _psm = _strat_sl PTR_DEREF Get(STRAT_PARAM_PSM); + _sl_new = _strat_sl PTR_DEREF PriceStop(_otype, ORDER_TYPE_SL, _psm, _psl); + _sl_new = _trade PTR_DEREF GetSaferSLTP(_sl_new, _sl_max, _otype, ORDER_TYPE_SL); + _sl_new = _trade PTR_DEREF NormalizeSL(_sl_new, _otype); + _sl_valid = + _trade PTR_DEREF IsValidOrderSL(_sl_new, _otype, _order PTR_DEREF Get(ORDER_SL), _psm > 0); + _sl_new = _sl_valid ? _sl_new : _order PTR_DEREF Get(ORDER_SL); } if (_strat_tp != NULL) { - float _ppl = _strat_tp.Get(STRAT_PARAM_PPL); - float _tp_max = _trade.GetMaxSLTP(_otype, _olots, ORDER_TYPE_TP, _trisk); - int _ppm = _strat_tp.Get(STRAT_PARAM_PPM); - _tp_new = _strat_tp.PriceStop(_otype, ORDER_TYPE_TP, _ppm, _ppl); - _tp_new = _trade.GetSaferSLTP(_tp_new, _tp_max, _otype, ORDER_TYPE_TP); - _tp_new = _trade.NormalizeTP(_tp_new, _otype); - _tp_valid = _trade.IsValidOrderTP(_tp_new, _otype, _order.Get(ORDER_TP), _ppm > 0); - _tp_new = _tp_valid ? _tp_new : _order.Get(ORDER_TP); + float _ppl = _strat_tp PTR_DEREF Get(STRAT_PARAM_PPL); + float _tp_max = _trade PTR_DEREF GetMaxSLTP(_otype, _olots, ORDER_TYPE_TP, _trisk); + int _ppm = _strat_tp PTR_DEREF Get(STRAT_PARAM_PPM); + _tp_new = _strat_tp PTR_DEREF PriceStop(_otype, ORDER_TYPE_TP, _ppm, _ppl); + _tp_new = _trade PTR_DEREF GetSaferSLTP(_tp_new, _tp_max, _otype, ORDER_TYPE_TP); + _tp_new = _trade PTR_DEREF NormalizeTP(_tp_new, _otype); + _tp_valid = + _trade PTR_DEREF IsValidOrderTP(_tp_new, _otype, _order PTR_DEREF Get(ORDER_TP), _ppm > 0); + _tp_new = _tp_valid ? _tp_new : _order PTR_DEREF Get(ORDER_TP); } } if (_sl_valid || _tp_valid) { - _result &= _order.OrderModify(_sl_new, _tp_new); + _result &= _order PTR_DEREF OrderModify(_sl_new, _tp_new); if (_result) { - _order.Set(ORDER_PROP_TIME_LAST_UPDATE, TimeCurrent()); + _order PTR_DEREF Set(ORDER_PROP_TIME_LAST_UPDATE, TimeCurrent()); } else { _trade.UpdateStates(true); } @@ -904,12 +910,12 @@ class EA : public Taskable { * Update EA state flags. */ void UpdateStateFlags() { - estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_CONNECTED), GetTerminal().IsConnected()); - estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_LIBS_ALLOWED), GetTerminal().IsLibrariesAllowed()); - estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_OPTIMIZATION), GetTerminal().IsOptimization()); - estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_TESTING), GetTerminal().IsTesting()); - estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_TRADE_ALLOWED), GetTerminal().IsTradeAllowed()); - estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_VISUAL_MODE), GetTerminal().IsVisualMode()); + estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_CONNECTED), GetTerminal() PTR_DEREF IsConnected()); + estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_LIBS_ALLOWED), GetTerminal() PTR_DEREF IsLibrariesAllowed()); + estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_OPTIMIZATION), GetTerminal() PTR_DEREF IsOptimization()); + estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_TESTING), GetTerminal() PTR_DEREF IsTesting()); + estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_TRADE_ALLOWED), GetTerminal() PTR_DEREF IsTradeAllowed()); + estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_VISUAL_MODE), GetTerminal() PTR_DEREF IsVisualMode()); } /** @@ -936,8 +942,8 @@ class EA : public Taskable { if (eparams.CheckFlag(EA_PARAM_FLAG_LOTSIZE_AUTO)) { // Auto calculate lot size for all strategies. Trade *_trade = trade.GetByKey(_Symbol); - _result &= _trade.Run(TRADE_ACTION_CALC_LOT_SIZE); - Set(STRAT_PARAM_LS, _trade.Get(TRADE_PARAM_LOT_SIZE)); + _result &= _trade PTR_DEREF Run(TRADE_ACTION_CALC_LOT_SIZE); + Set(STRAT_PARAM_LS, _trade PTR_DEREF Get(TRADE_PARAM_LOT_SIZE)); } return _result; } @@ -981,7 +987,7 @@ class EA : public Taskable { case EA_COND_IS_ENABLED: return estate.IsEnabled(); case EA_COND_IS_NOT_CONNECTED: - estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_CONNECTED), GetTerminal().IsConnected()); + estate.Set(STRUCT_ENUM(EAState, EA_STATE_FLAG_CONNECTED), GetTerminal() PTR_DEREF IsConnected()); return !estate.IsConnected(); case EA_COND_ON_NEW_MINUTE: // On new minute. return (estate.Get(STRUCT_ENUM(EAState, EA_STATE_PROP_NEW_PERIODS)) & DATETIME_MINUTE) != 0; @@ -1000,7 +1006,7 @@ class EA : public Taskable { case EA_COND_ON_QUIT: return estate.IsOnQuit(); default: - GetLogger().Error(StringFormat("Invalid EA condition: %d!", _entry.GetId(), __FUNCTION_LINE__)); + GetLogger() PTR_DEREF Error(StringFormat("Invalid EA condition: %d!", _entry.GetId(), __FUNCTION_LINE__)); SetUserError(ERR_INVALID_PARAMETER); break; } @@ -1039,11 +1045,11 @@ class EA : public Taskable { // 1st (i:0) - Strategy's enum action to execute. // 2nd (i:1) - Strategy's argument to pass. TaskActionEntry _entry_strat = _entry; - _entry_strat.ArgRemove(0); - for (DictStructIterator> iter_strat = strats.Begin(); iter_strat.IsValid(); ++iter_strat) { - Strategy *_strat = iter_strat.Value().Ptr(); + _entry_strat PTR_DEREF ArgRemove(0); + for (DictStructIterator> iter_strat = strats.Begin(); iter_strat PTR_DEREF IsValid(); ++iter_strat) { + Strategy *_strat = iter_strat PTR_DEREF Value().Ptr(); - _result &= _strat.Run(_entry_strat); + _result &= _strat PTR_DEREF Run(_entry_strat); } return _result; } @@ -1051,7 +1057,7 @@ class EA : public Taskable { tasks.GetTasks().Clear(); return tasks.GetTasks().Size() == 0; default: - GetLogger().Error(StringFormat("Invalid EA action: %d!", _entry.GetId(), __FUNCTION_LINE__)); + GetLogger() PTR_DEREF Error(StringFormat("Invalid EA action: %d!", _entry.GetId(), __FUNCTION_LINE__)); SetUserError(ERR_INVALID_PARAMETER); } return _result; @@ -1081,9 +1087,9 @@ class EA : public Taskable { */ template Strategy *GetStrategyViaProp(ENUM_STRATEGY_PARAM _prop, T _value, ENUM_MATH_CONDITION _op = MATH_COND_EQ) { - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strat = iter.Value().Ptr(); - if (Math::Compare(_strat.Get(_prop), _value, _op)) { + if (Math::Compare(_strat PTR_DEREF Get(_prop), _value, _op)) { return _strat; } } @@ -1100,9 +1106,10 @@ class EA : public Taskable { template Strategy *GetStrategyViaProp2(ENUM_STRATEGY_PARAM _prop1, T1 _value1, ENUM_STRATEGY_PARAM _prop2, T2 _value2, ENUM_MATH_CONDITION _op = MATH_COND_EQ) { - for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = strats.Begin(); iter.IsValid(); ++iter) { Strategy *_strat = iter.Value().Ptr(); - if (Math::Compare(_strat.Get(_prop1), _value1, _op) && Math::Compare(_strat.Get(_prop2), _value2, _op)) { + if (Math::Compare(_strat PTR_DEREF Get(_prop1), _value1, _op) && + Math::Compare(_strat PTR_DEREF Get(_prop2), _value2, _op)) { return _strat; } } @@ -1122,7 +1129,7 @@ class EA : public Taskable { /** * Gets DictStruct reference to strategies. */ - DictStruct> *GetStrategies() { return GET_PTR(strats); } + DictStruct> *GetStrategies() { return GET_PTR(strats); } /** * Gets EA state. @@ -1144,7 +1151,7 @@ class EA : public Taskable { /** * Gets reference to strategies. */ - DictStruct> *Strategies() { return &strats; } + DictStruct> *Strategies() { return &strats; } /* Setters */ @@ -1194,9 +1201,9 @@ class EA : public Taskable { virtual void OnStrategyAdd(Strategy *_strat) { // Sets margin risk. float _margin_risk = eparams.Get(STRUCT_ENUM(EAParams, EA_PARAM_PROP_RISK_MARGIN_MAX)); - _strat.Set(TRADE_PARAM_RISK_MARGIN, _margin_risk); + _strat PTR_DEREF Set(TRADE_PARAM_RISK_MARGIN, _margin_risk); // Link a logger instance. - logger.Link(_strat.GetLogger()); + logger.Link(_strat PTR_DEREF GetLogger()); // Load existing strategy trades. StrategyLoadTrades(_strat); } @@ -1219,15 +1226,15 @@ class EA : public Taskable { * Returns serialized representation of the object instance. */ SerializerNodeType Serialize(Serializer &_s) { - _s.Pass(THIS_REF, "account", account, SERIALIZER_FIELD_FLAG_DYNAMIC); + _s.PassObject(THIS_REF, "account", PTR_TO_REF(account), SERIALIZER_FIELD_FLAG_DYNAMIC); - for (DictStructIterator> _iter = GetStrategies().Begin(); _iter.IsValid(); ++_iter) { + for (DictStructIterator> _iter = GetStrategies() PTR_DEREF Begin(); _iter.IsValid(); ++_iter) { Strategy *_strat = _iter.Value().Ptr(); // @fixme: GH-422 - // _s.PassWriteOnly(this, "strat:" + _strat.GetName(), _strat); - string _sname = _strat.GetName(); // + "@" + Chart::TfToString(_strat.GetTf()); // @todo - string _sparams = _strat.GetParams().ToString(); - string _sresults = _strat.GetProcessResult().ToString(); + // _s.PassWriteOnly(this, "strat:" + _strat PTR_DEREF GetName(), _strat); + string _sname = _strat PTR_DEREF GetName(); // + "@" + Chart::TfToString(_strat PTR_DEREF GetTf()); // @todo + string _sparams = _strat PTR_DEREF GetParams().ToString(); + string _sresults = _strat PTR_DEREF GetProcessResult().ToString(); _s.Pass(THIS_REF, "strat:params:" + _sname, _sparams); _s.Pass(THIS_REF, "strat:results:" + _sname, _sresults); } @@ -1236,4 +1243,3 @@ class EA : public Taskable { return SerializerNodeObject; } }; -#endif // EA_MQH diff --git a/EA.struct.h b/EA.struct.h index 6378f65c7..46eae797c 100644 --- a/EA.struct.h +++ b/EA.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,7 +31,8 @@ #endif // Includes. -#include "DateTime.mqh" +#include "Log.mqh" +#include "Storage/DateTime.h" #include "Task/Task.struct.h" /* Defines EA config parameters. */ @@ -81,7 +82,7 @@ struct EAParams { }; // Struct special methods. - EAParams(string _name = __FILE__, ENUM_LOG_LEVEL _ll = V_INFO, unsigned long _magic = 0) + EAParams(string _name = __FILE__, ENUM_LOG_LEVEL _ll = V_INFO, uint64 _magic = 0) : author("unknown"), data_store(EA_DATA_STORE_NONE), flags(EA_PARAM_FLAG_NONE), @@ -110,9 +111,11 @@ struct EAParams { // Getters. template T Get(unsigned int _param) { + T _out; switch (_param) { case EA_PARAM_PROP_AUTHOR: - return (T)author; + ConvertBasic::StringToType(author, _out); + return _out; case EA_PARAM_PROP_CHART_INFO_FREQ: return (T)chart_info_freq; case EA_PARAM_PROP_DATA_EXPORT: @@ -120,19 +123,23 @@ struct EAParams { case EA_PARAM_PROP_DATA_STORE: return (T)data_store; case EA_PARAM_PROP_DESC: - return (T)desc; + ConvertBasic::StringToType(desc, _out); + return _out; case EA_PARAM_PROP_LOG_LEVEL: return (T)log_level; case EA_PARAM_PROP_NAME: - return (T)name; + ConvertBasic::StringToType(name, _out); + return _out; case EA_PARAM_PROP_RISK_MARGIN_MAX: return (T)risk_margin_max; case EA_PARAM_PROP_SIGNAL_FILTER: return (T)signal_filter; case EA_PARAM_PROP_SYMBOL: - return (T)symbol; + ConvertBasic::StringToType(symbol, _out); + return _out; case EA_PARAM_PROP_VER: - return (T)ver; + ConvertBasic::StringToType(ver, _out); + return _out; } SetUserError(ERR_INVALID_PARAMETER); return (T)WRONG_VALUE; @@ -144,7 +151,7 @@ struct EAParams { return (T)task_init; } SetUserError(ERR_INVALID_PARAMETER); - T _empty(); + T _empty; return _empty; } // Setters. diff --git a/Account/Account.define.h b/Exchange/Account/Account.define.h similarity index 81% rename from Account/Account.define.h rename to Exchange/Account/Account.define.h index 08d727a18..6f1df8c05 100644 --- a/Account/Account.define.h +++ b/Exchange/Account/Account.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,6 +20,11 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. #define ACC_OP_BALANCE 6 // Undocumented balance history statement entry. #define ACC_OP_CREDIT 7 // Undocumented credit history statement entry. diff --git a/Account/Account.enum.h b/Exchange/Account/Account.enum.h similarity index 97% rename from Account/Account.enum.h rename to Exchange/Account/Account.enum.h index 4e48eeca6..9d6246b8d 100644 --- a/Account/Account.enum.h +++ b/Exchange/Account/Account.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Account/Account.extern.h b/Exchange/Account/Account.extern.h similarity index 78% rename from Account/Account.extern.h rename to Exchange/Account/Account.extern.h index 4e84eb30c..63d25ff58 100644 --- a/Account/Account.extern.h +++ b/Exchange/Account/Account.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,8 +20,13 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../String.extern.h" +#include "../../Storage/String.extern.h" #include "Account.enum.h" // Define external global functions. diff --git a/Account/Account.h b/Exchange/Account/Account.h similarity index 79% rename from Account/Account.h rename to Exchange/Account/Account.h index adc51adac..3179fc274 100644 --- a/Account/Account.h +++ b/Exchange/Account/Account.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,14 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef ACCOUNT_H -#define ACCOUNT_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../BufferStruct.mqh" -#include "../Serializer/Serializer.h" +#include "../../Serializer/Serializer.h" +#include "../../Storage/Dict/Buffer/BufferStruct.h" #include "AccountBase.h" /** @@ -56,5 +57,3 @@ class Account : public AccountBase { */ ~Account() {} }; - -#endif // ACCOUNT_H diff --git a/Account/Account.struct.h b/Exchange/Account/Account.struct.h similarity index 92% rename from Account/Account.struct.h rename to Exchange/Account/Account.struct.h index 8a33fe210..eeb5324ee 100644 --- a/Account/Account.struct.h +++ b/Exchange/Account/Account.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,15 +28,16 @@ #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once -#include "../Serializer/Serializer.enum.h" #endif // Forward class declaration. class Serializer; // Includes. -#include "../Serializer/Serializer.h" -#include "../Terminal.define.h" +#include "Account.enum.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/Serializer.enum.h" +#include "../../Platform/Terminal.define.h" // Struct for account entries. struct AccountEntry { diff --git a/Account/AccountBase.h b/Exchange/Account/AccountBase.h similarity index 88% rename from Account/AccountBase.h rename to Exchange/Account/AccountBase.h index 4ee21ddf1..a2011f01f 100644 --- a/Account/AccountBase.h +++ b/Exchange/Account/AccountBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,12 +20,13 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef ACCOUNTBASE_H -#define ACCOUNTBASE_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../Refs.mqh" +#include "../../Refs.mqh" #include "AccountBase.struct.h" /** @@ -98,5 +99,3 @@ class AccountBase : public Dynamic { */ virtual float GetMarginAvail() = 0; }; - -#endif // ACCOUNTBASE_H diff --git a/Account/AccountBase.struct.h b/Exchange/Account/AccountBase.struct.h similarity index 86% rename from Account/AccountBase.struct.h rename to Exchange/Account/AccountBase.struct.h index 50641290f..d94d14f10 100644 --- a/Account/AccountBase.struct.h +++ b/Exchange/Account/AccountBase.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,16 +28,17 @@ #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once -#include "../Serializer/Serializer.enum.h" #endif // Forward class declaration. class Serializer; // Includes. -#include "../Serializer/Serializer.h" -#include "../Std.h" -#include "../Terminal.define.h" +#include "Account.enum.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/Serializer.enum.h" +#include "../../Std.h" +#include "../../Platform/Terminal.define.h" // Struct for account entries. struct AccountBaseEntry { diff --git a/Account/AccountForex.h b/Exchange/Account/AccountForex.h similarity index 81% rename from Account/AccountForex.h rename to Exchange/Account/AccountForex.h index 98b65c03f..ad7a97722 100644 --- a/Account/AccountForex.h +++ b/Exchange/Account/AccountForex.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,12 +20,13 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef ACCOUNTFOREX_H -#define ACCOUNTFOREX_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../Serializer/Serializer.h" +#include "../../Serializer/Serializer.h" #include "Account.h" #include "AccountForex.struct.h" @@ -53,4 +54,3 @@ class AccountForex : public Account { */ ~AccountForex() {} }; -#endif // ACCOUNTFOREX_H diff --git a/Account/AccountForex.struct.h b/Exchange/Account/AccountForex.struct.h similarity index 92% rename from Account/AccountForex.struct.h rename to Exchange/Account/AccountForex.struct.h index 30575505c..34abc2abc 100644 --- a/Account/AccountForex.struct.h +++ b/Exchange/Account/AccountForex.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,15 +28,15 @@ #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once -#include "Serializer.enum.h" #endif // Forward class declaration. class Serializer; // Includes. -#include "../Serializer/Serializer.h" -#include "../Terminal.define.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/Serializer.enum.h" +#include "../../Platform/Terminal.define.h" // Struct for account entries. struct AccountForexEntry : public AccountBaseEntry { diff --git a/Account/AccountMt.h b/Exchange/Account/AccountMt.h similarity index 94% rename from Account/AccountMt.h rename to Exchange/Account/AccountMt.h index b0ff5decd..7b71ebf3c 100644 --- a/Account/AccountMt.h +++ b/Exchange/Account/AccountMt.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,25 +20,26 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef ACCOUNT_MT_MQH -#define ACCOUNT_MT_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Forward class declaration. class AccountMt; // Includes. -#include "../Array.mqh" -#include "../BufferStruct.mqh" -#include "../Convert.mqh" -#include "../Data.struct.h" -#include "../Indicator/Indicator.struct.h" -#include "../Order.struct.h" -#include "../Orders.mqh" -#include "../Serializer/Serializer.h" -#include "../SymbolInfo.mqh" -#include "../Task/TaskCondition.enum.h" -#include "../Trade.struct.h" +#include "../../Convert.mqh" +#include "../../Exchange/SymbolInfo/SymbolInfo.h" +#include "../../Indicator/Indicator.struct.h" +#include "../../Platform/Order.struct.h" +#include "../../Platform/Orders.h" +#include "../../Serializer/Serializer.h" +#include "../../Storage/Array.h" +#include "../../Storage/Data.struct.h" +#include "../../Storage/Dict/Buffer/BufferStruct.h" +#include "../../Task/TaskCondition.enum.h" +#include "../../Trade.struct.h" #include "Account.define.h" #include "Account.enum.h" #include "Account.extern.h" @@ -220,14 +221,14 @@ class AccountMt : public AccountBase { /** * Returns the current account number. */ - static long AccountNumber() { return AccountInfoInteger(ACCOUNT_LOGIN); } - long GetLogin() { return AccountNumber(); } + static int64 AccountNumber() { return AccountInfoInteger(ACCOUNT_LOGIN); } + int64 GetLogin() { return AccountNumber(); } /** * Returns leverage of the current account. */ - static long AccountLeverage() { return AccountInfoInteger(ACCOUNT_LEVERAGE); } - long GetLeverage() { return AccountLeverage(); } + static int64 AccountLeverage() { return AccountInfoInteger(ACCOUNT_LEVERAGE); } + int64 GetLeverage() { return AccountLeverage(); } /** * Returns the calculation mode for the Stop Out level. @@ -250,9 +251,9 @@ class AccountMt : public AccountBase { * @return * Returns the limit orders (0 for unlimited). */ - static long AccountLimitOrders() { return AccountInfoInteger(ACCOUNT_LIMIT_ORDERS); } - long GetLimitOrders(unsigned int _max = 999) { - long _limit = AccountLimitOrders(); + static int64 AccountLimitOrders() { return AccountInfoInteger(ACCOUNT_LIMIT_ORDERS); } + int64 GetLimitOrders(unsigned int _max = 999) { + int64 _limit = AccountLimitOrders(); return _limit > 0 ? _limit : _max; } @@ -595,13 +596,13 @@ class AccountMt : public AccountBase { ARRAY(DataParamEntry, _args); return AccountMt::CheckCondition(_cond, _args); } - bool CheckCondition(ENUM_ACCOUNT_CONDITION _cond, long _arg1) { + bool CheckCondition(ENUM_ACCOUNT_CONDITION _cond, int64 _arg1) { ARRAY(DataParamEntry, _args); DataParamEntry _param1 = _arg1; ArrayPushObject(_args, _param1); return AccountMt::CheckCondition(_cond, _args); } - bool CheckCondition(ENUM_ACCOUNT_CONDITION _cond, long _arg1, long _arg2) { + bool CheckCondition(ENUM_ACCOUNT_CONDITION _cond, int64 _arg1, int64 _arg2) { ARRAY(DataParamEntry, _args); DataParamEntry _param1 = _arg1; DataParamEntry _param2 = _arg2; @@ -666,7 +667,7 @@ class AccountMt : public AccountBase { * @docs * - https://www.mql5.com/en/docs/account/accountinfointeger */ - static long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER _prop_id) { return ::AccountInfoInteger(_prop_id); } + static int64 AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER _prop_id) { return ::AccountInfoInteger(_prop_id); } /** * Returns the string value of the appropriate account property. @@ -679,4 +680,3 @@ class AccountMt : public AccountBase { */ static string AccountInfoString(ENUM_ACCOUNT_INFO_STRING _prop_id) { return ::AccountInfoString(_prop_id); } }; -#endif // ACCOUNT_MT_MQH diff --git a/Exchange/Account/README.md b/Exchange/Account/README.md new file mode 100644 index 000000000..a0d04639a --- /dev/null +++ b/Exchange/Account/README.md @@ -0,0 +1,47 @@ +# Account + +## Classes + +```mermaid +classDiagram + AccountBase <|-- Account + Dynamic <|-- AccountBase + Account <|-- AccountForex + AccountMt <|-- _ + Account : +state + Account : +entries + AccountMt: +entries + AccountMt: GetEntry() +``` + +### `Account` class + +The class for managing the current trading account. + +#### Example 1 - Managing account (dynamic calls) + +```cpp +Account *acc = new Account(); +double _balance = acc.GetBalance(); +double _credit = acc.GetCredit(); +double _equity = acc.GetEquity(); +double _margin_free = acc.GetMarginFree(); +double _margin_used = acc.GetMarginUsed(); +if (acc.IsExpertEnabled() && acc.IsTradeAllowed()) { + // Some trade code. +} +delete acc; +``` + +#### Example 2 - Managing account (static calls) + +```cpp +double _balance = Account::AccountBalance(); +double _credit = Account::AccountCredit(); +double _equity = Account::AccountEquity(); +double _margin_free = Account::AccountFreeMargin(); +double _margin_used = Account::AccountMargin(); +if (Account::IsExpertEnabled() && Account::IsTradeAllowed()) { + // Some trade code. +} +``` diff --git a/Exchange/Account/tests/Account.test.cpp b/Exchange/Account/tests/Account.test.cpp new file mode 100644 index 000000000..c5bb725bf --- /dev/null +++ b/Exchange/Account/tests/Account.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Account class. + */ + +// Includes. +#include "../Account.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Account/tests/Account.test.mq4 b/Exchange/Account/tests/Account.test.mq4 similarity index 87% rename from Account/tests/Account.test.mq4 rename to Exchange/Account/tests/Account.test.mq4 index 0ef0d6c3f..2dbc1eb1d 100644 --- a/Account/tests/Account.test.mq4 +++ b/Exchange/Account/tests/Account.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Account/tests/Account.test.mq5 b/Exchange/Account/tests/Account.test.mq5 similarity index 92% rename from Account/tests/Account.test.mq5 rename to Exchange/Account/tests/Account.test.mq5 index 286017e2c..a50189202 100644 --- a/Account/tests/Account.test.mq5 +++ b/Exchange/Account/tests/Account.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes. -#include "../../Test.mqh" +#include "../../../Test.mqh" #include "../Account.h" // Test classes. diff --git a/Exchange/Account/tests/AccountBase.test.cpp b/Exchange/Account/tests/AccountBase.test.cpp new file mode 100644 index 000000000..70b25df78 --- /dev/null +++ b/Exchange/Account/tests/AccountBase.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of AccountBase class. + */ + +// Includes. +#include "../AccountBase.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Exchange/Account/tests/AccountForex.test.cpp b/Exchange/Account/tests/AccountForex.test.cpp new file mode 100644 index 000000000..b112b792f --- /dev/null +++ b/Exchange/Account/tests/AccountForex.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of AccountForex class. + */ + +// Includes. +#include "../AccountForex.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Account/tests/AccountForex.test.mq4 b/Exchange/Account/tests/AccountForex.test.mq4 similarity index 87% rename from Account/tests/AccountForex.test.mq4 rename to Exchange/Account/tests/AccountForex.test.mq4 index ad049cb6f..9c1464d99 100644 --- a/Account/tests/AccountForex.test.mq4 +++ b/Exchange/Account/tests/AccountForex.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Account/tests/AccountForex.test.mq5 b/Exchange/Account/tests/AccountForex.test.mq5 similarity index 92% rename from Account/tests/AccountForex.test.mq5 rename to Exchange/Account/tests/AccountForex.test.mq5 index 2e01162b8..ec66bc39e 100644 --- a/Account/tests/AccountForex.test.mq5 +++ b/Exchange/Account/tests/AccountForex.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes. -#include "../../Test.mqh" +#include "../../../Test.mqh" #include "../AccountForex.h" // Test classes. diff --git a/Exchange/Account/tests/AccountMt.test.cpp b/Exchange/Account/tests/AccountMt.test.cpp new file mode 100644 index 000000000..534ed683d --- /dev/null +++ b/Exchange/Account/tests/AccountMt.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of AccountMt class. + */ + +// Includes. +#include "../AccountMt.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Account/tests/AccountMt.test.mq4 b/Exchange/Account/tests/AccountMt.test.mq4 similarity index 87% rename from Account/tests/AccountMt.test.mq4 rename to Exchange/Account/tests/AccountMt.test.mq4 index 6aa260b2d..35ee786ee 100644 --- a/Account/tests/AccountMt.test.mq4 +++ b/Exchange/Account/tests/AccountMt.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Account/tests/AccountMt.test.mq5 b/Exchange/Account/tests/AccountMt.test.mq5 similarity index 96% rename from Account/tests/AccountMt.test.mq5 rename to Exchange/Account/tests/AccountMt.test.mq5 index cc7398f40..cd3724580 100644 --- a/Account/tests/AccountMt.test.mq5 +++ b/Exchange/Account/tests/AccountMt.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes. -#include "../../Test.mqh" +#include "../../../Test.mqh" #include "../AccountMt.h" /** diff --git a/Exchange/Account/tests/Makefile b/Exchange/Account/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Exchange/Account/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Exchange/Exchange.h b/Exchange/Exchange.h index 5551c69b9..54c70277c 100644 --- a/Exchange/Exchange.h +++ b/Exchange/Exchange.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,16 @@ * */ -/** - * Exchange class. - */ -#ifndef EXCHANGE_H -#define EXCHANGE_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../Account/Account.h" -#include "../DictObject.mqh" -#include "../SymbolInfo.mqh" +#include "../Exchange/SymbolInfo/SymbolInfo.h" +#include "../Storage/Dict/DictObject.h" #include "../Trade.mqh" +#include "Account/Account.h" #include "Exchange.struct.h" class Exchange : public Dynamic { @@ -99,4 +98,3 @@ class Exchange : public Dynamic { */ void TradeRemove(string _name) { trades.Unset(_name); } }; -#endif // EXCHANGE_H diff --git a/Exchange/Exchange.struct.h b/Exchange/Exchange.struct.h index ace6b30a9..13c9c569b 100644 --- a/Exchange/Exchange.struct.h +++ b/Exchange/Exchange.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -38,5 +38,5 @@ struct ExchangeParams { // Constructors. ExchangeParams() {} ExchangeParams(const ExchangeParams &_eparams) {} - long id; + int64 id; }; diff --git a/Exchange/README.md b/Exchange/README.md new file mode 100644 index 000000000..31411ab33 --- /dev/null +++ b/Exchange/README.md @@ -0,0 +1,12 @@ +# Exchange + +## Classes + +```mermaid +classDiagram + Dynamic <|-- Exchange + Exchange: Account[] + Exchange: Symbol[] + Exchange: Trade[] + Exchange: eparams +``` diff --git a/SymbolInfo.define.h b/Exchange/SymbolInfo/SymbolInfo.define.h similarity index 85% rename from SymbolInfo.define.h rename to Exchange/SymbolInfo/SymbolInfo.define.h index f0475b166..4d09f8a77 100644 --- a/SymbolInfo.define.h +++ b/Exchange/SymbolInfo/SymbolInfo.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * SymbolInfo's defines. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + /* Defines */ #ifdef __MQL5__ diff --git a/SymbolInfo.enum.h b/Exchange/SymbolInfo/SymbolInfo.enum.h similarity index 99% rename from SymbolInfo.enum.h rename to Exchange/SymbolInfo/SymbolInfo.enum.h index b2f05e249..b40946b3e 100644 --- a/SymbolInfo.enum.h +++ b/Exchange/SymbolInfo/SymbolInfo.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/SymbolInfo.enum.symbols.h b/Exchange/SymbolInfo/SymbolInfo.enum.symbols.h similarity index 97% rename from SymbolInfo.enum.symbols.h rename to Exchange/SymbolInfo/SymbolInfo.enum.symbols.h index 575210219..8c2ba98b9 100644 --- a/SymbolInfo.enum.symbols.h +++ b/Exchange/SymbolInfo/SymbolInfo.enum.symbols.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/SymbolInfo.extern.h b/Exchange/SymbolInfo/SymbolInfo.extern.h similarity index 81% rename from SymbolInfo.extern.h rename to Exchange/SymbolInfo/SymbolInfo.extern.h index dd768d866..98a2f4a7c 100644 --- a/SymbolInfo.extern.h +++ b/Exchange/SymbolInfo/SymbolInfo.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,19 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "Order.enum.h" +#include "../../Platform/Order.enum.h" +#include "../../Tick/Tick.struct.h" #include "SymbolInfo.enum.h" -#include "Tick/Tick.struct.h" // Define external global functions. #ifndef __MQL__ -// Allows the preprocessor to include a header file when it is needed. -#pragma once - -extern long SymbolInfoInteger(string name, ENUM_SYMBOL_INFO_INTEGER prop_id); +extern int64 SymbolInfoInteger(string name, ENUM_SYMBOL_INFO_INTEGER prop_id); extern bool SymbolInfoMarginRate(string name, ENUM_ORDER_TYPE order_type, double &initial_margin_rate, double &maintenance_margin_rate); extern bool SymbolInfoTick(string symbol, MqlTick &tick); diff --git a/SymbolInfo.mqh b/Exchange/SymbolInfo/SymbolInfo.h similarity index 96% rename from SymbolInfo.mqh rename to Exchange/SymbolInfo/SymbolInfo.h index 3de9448bb..7b94f8e50 100644 --- a/SymbolInfo.mqh +++ b/Exchange/SymbolInfo/SymbolInfo.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,13 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SYMBOLINFO_MQH -#define SYMBOLINFO_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Flag for Database.struct.h so SymbolInfo structure will be supported by it. +#define DATABASE_INCLUDE_SYMBOLINFO_STRUCT // Includes symbol defines, enums and structs. #include "SymbolInfo.define.h" @@ -37,9 +41,9 @@ class Log; class SymbolInfo; // Includes. -#include "Log.mqh" -#include "Serializer/Serializer.h" -#include "Serializer/SerializerNode.enum.h" +#include "../../Log.mqh" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/SerializerNode.enum.h" /** * Class to provide symbol information. @@ -174,12 +178,12 @@ class SymbolInfo : public Object { * * @see: https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants */ - unsigned long GetVolume() { return SymbolInfoStatic::GetTick(symbol).volume; } + uint64 GetVolume() { return SymbolInfoStatic::GetTick(symbol).volume; } /** * Gets the last volume for the current price (without updating). */ - unsigned long GetLastVolume() { return last_tick.volume; } + uint64 GetLastVolume() { return last_tick.volume; } /** * Get summary volume of current session deals. @@ -362,7 +366,7 @@ class SymbolInfo : public Object { * * @see: https://book.mql4.com/appendix/limits */ - long GetTradeStopsLevel() { return SymbolInfoStatic::SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL); } + int64 GetTradeStopsLevel() { return SymbolInfoStatic::SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL); } /** * Get a contract lot size in the base currency. @@ -566,4 +570,3 @@ class SymbolInfo : public Object { */ Log *GetLogger() { return GET_PTR(logger); } }; -#endif // SYMBOLINFO_MQH diff --git a/SymbolInfo.struct.h b/Exchange/SymbolInfo/SymbolInfo.struct.h similarity index 92% rename from SymbolInfo.struct.h rename to Exchange/SymbolInfo/SymbolInfo.struct.h index 89cdc9ae8..d210a504d 100644 --- a/SymbolInfo.struct.h +++ b/Exchange/SymbolInfo/SymbolInfo.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,11 +31,11 @@ #endif // Includes. -#include "Serializer/Serializable.h" -#include "Serializer/Serializer.h" -#include "Std.h" +#include "../../Serializer/Serializable.h" +#include "../../Serializer/Serializer.h" +#include "../../Std.h" +#include "../../Tick/Tick.struct.h" #include "SymbolInfo.struct.static.h" -#include "Tick/Tick.struct.h" // Defines struct to store symbol data. struct SymbolInfoEntry @@ -43,11 +43,11 @@ struct SymbolInfoEntry : public Serializable #endif { - double bid; // Current Bid price. - double ask; // Current Ask price. - double last; // Price of the last deal. - double spread; // Current spread. - unsigned long volume; // Volume for the current last price. + double bid; // Current Bid price. + double ask; // Current Ask price. + double last; // Price of the last deal. + double spread; // Current spread. + uint64 volume; // Volume for the current last price. // Constructors. SymbolInfoEntry() : bid(0), ask(0), last(0), spread(0), volume(0) {} SymbolInfoEntry(const MqlTick& _tick, const string _symbol = "") { diff --git a/SymbolInfo.struct.static.h b/Exchange/SymbolInfo/SymbolInfo.struct.static.h similarity index 96% rename from SymbolInfo.struct.static.h rename to Exchange/SymbolInfo/SymbolInfo.struct.static.h index d88e53e0c..ff9092244 100644 --- a/SymbolInfo.struct.static.h +++ b/Exchange/SymbolInfo/SymbolInfo.struct.static.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,18 +20,18 @@ * */ -// Prevents processing this includes file for the second time. #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once #endif -#include "MQL5.mqh" -#include "Order.enum.h" -#include "Platform.extern.h" -#include "Std.h" +#include "../../Platform/MQL5.mqh" +#include "../../Platform/Order.enum.h" +#include "../../Platform/Platform.extern.h" +#include "../../Std.h" +#include "../../Tick/Tick.struct.h" #include "SymbolInfo.enum.h" #include "SymbolInfo.extern.h" -#include "Tick/Tick.struct.h" /** * Struct to provide symbol information. @@ -72,7 +72,7 @@ struct SymbolInfoStatic { * * @see: https://www.mql5.com/en/docs/constants/environment_state/marketinfoconstants */ - static unsigned long GetVolume(string _symbol) { return GetTick(_symbol).volume; } + static uint64 GetVolume(string _symbol) { return GetTick(_symbol).volume; } /** * Get summary volume of current session deals. @@ -310,7 +310,7 @@ struct SymbolInfoStatic { * * @see: https://book.mql4.com/appendix/limits */ - static long GetTradeStopsLevel(string _symbol) { + static int64 GetTradeStopsLevel(string _symbol) { return SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_TRADE_STOPS_LEVEL); } @@ -493,7 +493,7 @@ struct SymbolInfoStatic { * @param ENUM_SYMBOL_INFO_INTEGER prop_id * Identifier of a property. * - * @return long + * @return int64 * Returns the value of the property. * In case of error, information can be obtained using GetLastError() function. * @@ -502,7 +502,7 @@ struct SymbolInfoStatic { * - https://www.mql5.com/en/docs/marketinformation/symbolinfointeger * */ - static long SymbolInfoInteger(string name, ENUM_SYMBOL_INFO_INTEGER prop_id) { + static int64 SymbolInfoInteger(string name, ENUM_SYMBOL_INFO_INTEGER prop_id) { return ::SymbolInfoInteger(name, prop_id); } diff --git a/Exchange/SymbolInfo/tests/Makefile b/Exchange/SymbolInfo/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Exchange/SymbolInfo/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Exchange/SymbolInfo/tests/SymbolInfo.test.cpp b/Exchange/SymbolInfo/tests/SymbolInfo.test.cpp new file mode 100644 index 000000000..2ac8589ce --- /dev/null +++ b/Exchange/SymbolInfo/tests/SymbolInfo.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SymbolInfo class. + */ + +// Includes. +#include "../SymbolInfo.h" +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + + // @todo + + return 0; +} diff --git a/tests/SymbolInfoTest.mq4 b/Exchange/SymbolInfo/tests/SymbolInfo.test.mq4 similarity index 85% rename from tests/SymbolInfoTest.mq4 rename to Exchange/SymbolInfo/tests/SymbolInfo.test.mq4 index 577dd3003..7d028fbf4 100644 --- a/tests/SymbolInfoTest.mq4 +++ b/Exchange/SymbolInfo/tests/SymbolInfo.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "SymbolInfoTest.mq5" +#include "SymbolInfo.test.mq5" diff --git a/tests/SymbolInfoTest.mq5 b/Exchange/SymbolInfo/tests/SymbolInfo.test.mq5 similarity index 97% rename from tests/SymbolInfoTest.mq5 rename to Exchange/SymbolInfo/tests/SymbolInfo.test.mq5 index 569a6f460..38ef1471b 100644 --- a/tests/SymbolInfoTest.mq5 +++ b/Exchange/SymbolInfo/tests/SymbolInfo.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,8 +25,8 @@ */ // Includes. -#include "../SymbolInfo.mqh" -#include "../Test.mqh" +#include "../SymbolInfo.h" +#include "../../../Test.mqh" /** * Implements OnInit(). diff --git a/Exchange/tests/Exchange.test.cpp b/Exchange/tests/Exchange.test.cpp new file mode 100644 index 000000000..968da6b53 --- /dev/null +++ b/Exchange/tests/Exchange.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Exchange class. + */ + +// Includes. +#include "../Exchange.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Exchange/tests/Exchange.test.mq4 b/Exchange/tests/Exchange.test.mq4 index d7b0b8f3b..da3f58d01 100644 --- a/Exchange/tests/Exchange.test.mq4 +++ b/Exchange/tests/Exchange.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Exchange/tests/Exchange.test.mq5 b/Exchange/tests/Exchange.test.mq5 index aff8fa3f9..5d94b2246 100644 --- a/Exchange/tests/Exchange.test.mq5 +++ b/Exchange/tests/Exchange.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Exchange.h" diff --git a/Exchange/tests/Makefile b/Exchange/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Exchange/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/File.define.h b/File.define.h index d95eb025b..4453466bc 100644 --- a/File.define.h +++ b/File.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -21,6 +21,7 @@ */ // Defines. #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once // File constants to read the whole value of char, short or int type. diff --git a/File.extern.h b/File.extern.h index fa4ff6204..efa21a23c 100644 --- a/File.extern.h +++ b/File.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,16 +20,19 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "File.define.h" +#include "Platform/Terminal.define.h" #include "Storage/MemoryFileSystem.h" -#include "String.extern.h" -#include "Terminal.define.h" +#include "Storage/String.extern.h" // Define external global functions. #ifndef __MQL__ -#pragma once - MemoryFileSystem _memfs; extern bool FileIsEnding(int file_handle); diff --git a/File.mqh b/File.mqh index dc27741af..2342032de 100644 --- a/File.mqh +++ b/File.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -38,9 +38,9 @@ #include "File.define.h" #include "File.extern.h" #include "Std.h" -#include "Terminal.define.h" -#include "Terminal.enum.h" -#include "Terminal.extern.h" +#include "Platform/Terminal.define.h" +#include "Platform/Terminal.enum.h" +#include "Platform/Terminal.extern.h" /** * Class to provide a group of functions for working with files. diff --git a/Indicator/Details.md b/Indicator/Details.md deleted file mode 100644 index bc258f7b7..000000000 --- a/Indicator/Details.md +++ /dev/null @@ -1,90 +0,0 @@ - #Explanation of shift parameters in Indicator / IndicatorData / other classes for following methods: -- `GetEntryValue(int _mode = 0, int _abs_shift = 0)` -- `GetEntryAlter(IndicatorDataEntry &_entry, int _rel_shift)` -- `GetValue(int _mode = 0, int _rel_shift = 0)` -- `GetEntry(int _rel_shift = 0)` -- `GetBarTime(int _rel_shift = 0)` - -## GetEntryValue(int _mode, int _abs_shift) - overridable method - -Method must be overriden in any new indicator and MUST NOT apply shift from `iparams.shift`/`iparams.GetShift()`! Shift 0 must always point to the value for the current tick. - -Returns indicators's value for a given mode and absolute shift (the shift is directly passed to built-in methods such as iATR(), OnCalculate methods such as `iVIDyAOnIndicator()` and also to `iCustom()`). - -For `OnCalculate()` methods such as iVIDyAOnIndicator(), the shift is passed to `return _cache.GetTailValue(_mode, _shift);` so we can return value calculated in the past (or just retrieve **DBL_MAX** in case the value was not yet calculated). -Note that `OnCalculate()` methods uses single/multiple price buffers, e.g., applied price or OHLCs from base indicator. - -In scenario of `VIDyA[shift = 2] <- Candle <- TickMt` call hierarchy looks like: -```cpp -- VIDyA::GetEntry(_rel_shift = 1) // Then per each mode: -- entry.values[_mode] = Indicator::GetValue(_mode, _rel_shift = 1) -- VIDyA::GetEntryValue(_mode, _abs_shift = iparams.shift + 1) -- VIDyA::iVIDyAOnIndicator(..., _mode, _shift = 3) then: // Shift is absolute. -- VIDyA::iVIDyAOnArray(..., _mode, _shift = 3) then: // Shift is absolute. - return _cache.GetTailValue(_mode, _shift = 3); // Shift is absolute. -``` -Last line means that we will retrieve **VIDyA** value shifted by 3 (2 from `iparams.shift` + 1 from `GetEntry()`). It is correct. - -## GetEntryAlter(IndicatorDataEntry &_entry, int _rel_shift) - overridable method - -Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). - -Method calls (seen in **MWMFI**, **CCI**, **Envelopes**, **Momentum**, **Pivot**): -```cpp -- GetValue(_mode, _rel_shift) // GetValue() takes relative shift. -``` - -## GetValue(int _mode = 0, int _rel_shift = 0) - non-overridable method - -Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). - -Method calls: -```cpp -- GetEntryValue(_mode, _abs_shift = iparams.shift + _rel_shift) -``` - -## GetEntry(int _rel_shift = 0) - overridable method - -Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). - -If you need to access entries from absolute shift, use `GetEntryByAbsShift(int _abs_shift)`. - -Note that values accessed via index operator `storage[rel_shift]` e.g., inside `OnCalculate()` methods like `double _o = open[rel_shift = 4].Get()` will take relative shift and retrieve open price shifted by (in this scenario) `4 + iparams.shift` set in base indicator: -```cpp -- double _o = open[_rel_shift = 4] -- IndicatorBufferValueStorage::Fetch(_rel_shift = 4) -- IndicatorData::GetValue(_mode, _rel_shift = 4) -- Indicator::GetEntryValue(_mode, _abs_shift = iparams.shift + 4) // As GetEntryValue() takes absolute shift, we add shift from iparams.shift. -- Indicator::GetEntry(_rel_shift = _abs_shift - iparams.shift)... // Converting absolute shift into relative one for GetEntry(). -- ...[_mode]; // IndicatorDataEntry.values[_mode].Get(...); -``` - -## GetBarTime(int _rel_shift = 0) - -Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). - -## GetPrice(ENUM_APPLIED_PRICE _ap, int _rel_shift = 0) - -Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). - -## GetBars() - -Number of returned bars is decremented by `IndicatorParams::shift` (read via `Indicator::iparams.shift`). Thus if there are **10** bars and *shift* is **8** then `GetBars()` will return **2**. That means that you can safely do `GetEntry()` for relative shifts **0** or **1**. There won't be any value in other relative shifts. - -## HistoryValueStorage::Fetch(int _rel_shift) - -Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). - -## Indi_\*::\*OnIndicator(..., _shift, [_shift1], [_shift2]) - -All shifts passed are relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). - -## IndicatorCalculateCache::GetValue()/GetTailValue(int _buffer_index, int _shift) - -Shift passed may be relative or absolute. It depends on the ValueStorage specialization. - -E.g., `HistoryValueStorage` operates on relative shifts, but `NativeValueStorage` operates on absolute shift, because it is unaware for which indicator values are stored. - -Thus way, `IndicatorCalculateCache::GetValue()` and `IndicatorCalculateCache::GetTailValue()` also don't know which type of shift was passed. However, all current indicators uses `NativeValueStorage` for storing indicator values, so shift passed must is treated as absolute. - -In scenario where indicator (shift **2**) has **8** values in the buffer with (assuming **10** candles have passed), `GetEntry(0)` would retrieve cache value from shift \ No newline at end of file diff --git a/Indicator/Indicator.define.h b/Indicator/Indicator.define.h index 5d2cd3437..75b2c22a4 100644 --- a/Indicator/Indicator.define.h +++ b/Indicator/Indicator.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,7 +26,7 @@ */ // Includes. -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. @@ -104,32 +104,33 @@ #define EMPTY_VALUE DBL_MAX #endif -#define INDICATOR_BUILTIN_CALL_AND_RETURN(NATIVE_METHOD_CALL, MODE, SHIFT) \ - int _handle = Object::IsValid(_obj) ? _obj PTR_DEREF Get(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : 0; \ - ARRAY(double, _res); \ - ResetLastError(); \ - if (_handle == 0 || _handle == INVALID_HANDLE) { \ - if ((_handle = NATIVE_METHOD_CALL) == INVALID_HANDLE) { \ - SetUserError(ERR_USER_INVALID_HANDLE); \ - return EMPTY_VALUE; \ - } else if (Object::IsValid(_obj)) { \ - _obj.SetHandle(_handle); \ - } \ - } \ - if (Terminal::IsVisualMode()) { \ - /* To avoid error 4806 (ERR_INDICATOR_DATA_NOT_FOUND), */ \ - /* we check the number of calculated data only in visual mode. */ \ - int _bars_calc = BarsCalculated(_handle); \ - if (GetLastError() > 0) { \ - return EMPTY_VALUE; \ - } else if (_bars_calc <= 2) { \ - SetUserError(ERR_USER_INVALID_BUFF_NUM); \ - return EMPTY_VALUE; \ - } \ - } \ - if (CopyBuffer(_handle, MODE, SHIFT, 1, _res) < 0) { \ - return ArraySize(_res) > 0 ? _res[0] : EMPTY_VALUE; \ - } \ +#define INDICATOR_BUILTIN_CALL_AND_RETURN(NATIVE_METHOD_CALL, MODE, SHIFT) \ + int _handle = \ + Object::IsValid(_obj) ? _obj PTR_DEREF Get(IndicatorDataState::INDICATOR_DATA_STATE_PROP_HANDLE) : 0; \ + ARRAY(double, _res); \ + ResetLastError(); \ + if (_handle == 0 || _handle == INVALID_HANDLE) { \ + if ((_handle = NATIVE_METHOD_CALL) == INVALID_HANDLE) { \ + SetUserError(ERR_USER_INVALID_HANDLE); \ + return EMPTY_VALUE; \ + } else if (Object::IsValid(_obj)) { \ + _obj PTR_DEREF SetHandle(_handle); \ + } \ + } \ + if (Terminal::IsVisualMode()) { \ + /* To avoid error 4806 (ERR_INDICATOR_DATA_NOT_FOUND), */ \ + /* we check the number of calculated data only in visual mode. */ \ + int _bars_calc = BarsCalculated(_handle); \ + if (GetLastError() > 0) { \ + return EMPTY_VALUE; \ + } else if (_bars_calc <= 2) { \ + SetUserError(ERR_USER_INVALID_BUFF_NUM); \ + return EMPTY_VALUE; \ + } \ + } \ + if (CopyBuffer(_handle, MODE, SHIFT, 1, _res) < 0) { \ + return ArraySize(_res) > 0 ? _res[0] : EMPTY_VALUE; \ + } \ return _res[0]; #define INDI_REQUIRE_BARS_OR_RETURN(_indi, _period, _ret) \ diff --git a/Indicator/Indicator.enum.h b/Indicator/Indicator.enum.h index 7e0bc061c..ff9e7be2c 100644 --- a/Indicator/Indicator.enum.h +++ b/Indicator/Indicator.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -96,7 +96,7 @@ enum ENUM_INDICATOR_TYPE { INDI_OHLC, // OHLC (Open-High-Low-Close) INDI_OSMA, // OsMA INDI_PATTERN, // Pattern Detector - INDI_PIVOT, // Pivot Detector + INDI_PIVOT, // Pivot INDI_PRICE, // Price INDI_PRICE_CHANNEL, // Price Channel INDI_PRICE_FEEDER, // Indicator which returns prices from custom array @@ -108,6 +108,7 @@ enum ENUM_INDICATOR_TYPE { INDI_RVI, // Relative Vigor Index INDI_SAR, // Parabolic SAR INDI_SPECIAL_MATH, // Math operations over given + INDI_SPECIAL_UNIVERSAL, // Universal INDI_STDDEV, // Standard Deviation INDI_STDDEV_ON_MA_SMA, // Standard Deviation on Moving Average in SMA mode INDI_STDDEV_ON_PRICE, // Standard Deviation (on Price) @@ -126,7 +127,7 @@ enum ENUM_INDICATOR_TYPE { INDI_VIDYA, // Variable Index Dynamic Average INDI_VOLUMES, // Volumes INDI_VROC, // Volume Rate of Change - INDI_WILLIAMS_AD, // Larry Williams' Accumulation/Distribution + INDI_WILLIAMS_AD, // Williams' Accumulation/Distribution INDI_WPR, // Williams' Percent Range INDI_ZIGZAG, // ZigZag INDI_ZIGZAG_COLOR, // ZigZag Color @@ -190,8 +191,8 @@ enum ENUM_SIGNAL_LINE { enum ENUM_APPLIED_VOLUME { VOLUME_TICK = 0, VOLUME_REAL = 1 }; #endif -#define INDI_VS_TYPE_ACCOUNT_STATS_BUFFERS_COUNT \ - (INDI_VS_TYPE_ACCOUNT_STATS_INDEX_LAST - INDI_VS_TYPE_ACCOUNT_STATS_INDEX_FIRST + 1) +#define INDI_DATA_VS_TYPE_ACCOUNT_STATS_BUFFERS_COUNT \ + (INDI_DATA_VS_TYPE_ACCOUNT_STATS_INDEX_LAST - INDI_DATA_VS_TYPE_ACCOUNT_STATS_INDEX_FIRST + 1) // Indicator flags. enum ENUM_INDI_FLAGS { @@ -219,9 +220,9 @@ enum ENUM_INDI_SUITABLE_DS_TYPE { // Type of data source mode. Required to determine what "mode" means for the user. enum ENUM_INDI_DS_MODE_KIND { INDI_DS_MODE_KIND_INDEX, // Mode is a buffer index. - INDI_DS_MODE_KIND_VS_TYPE, // Mode is a value from ENUM_INDI_VS_TYPE enumeration, e.g., ENUM_INDI_VS_PRICE_OPEN. + INDI_DS_MODE_KIND_VS_TYPE, // Mode is a value from ENUM_INDI_DATA_VS_TYPE enumeration, e.g., ENUM_INDI_VS_PRICE_OPEN. INDI_DS_MODE_KIND_AP, // Mode is a value from ENUM_APPLIED_PRICE enumeration. It is used to retrieve value storage - // based on ENUM_INDI_VS_TYPE enumeration, e.g., PRICE_OPEN becomes ENUM_INDI_VS_PRICE_OPEN. + // based on ENUM_INDI_DATA_VS_TYPE enumeration, e.g., PRICE_OPEN becomes ENUM_INDI_VS_PRICE_OPEN. }; // Type of entry @@ -230,4 +231,3 @@ enum ENUM_INDI_EMITTED_ENTRY_TYPE { INDI_EMITTED_ENTRY_TYPE_TICK, INDI_EMITTED_ENTRY_TYPE_CANDLE, }; -//+------------------------------------------------------------------+ diff --git a/Indicator/Indicator.h b/Indicator/Indicator.h index a91a5cdb0..87c6adcf6 100644 --- a/Indicator/Indicator.h +++ b/Indicator/Indicator.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,10 @@ * */ -// Ignore processing of this file if already included. -#ifndef INDICATOR_MQH -#define INDICATOR_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Forward class declaration. struct IndicatorParams; @@ -34,20 +35,21 @@ struct IndicatorParams; #include "IndicatorData.h" // Includes. -#include "../Array.mqh" -#include "../BufferStruct.mqh" -#include "../DateTime.mqh" -#include "../DrawIndicator.mqh" -#include "../Flags.h" -#include "../Math.h" -#include "../Object.mqh" +#include "../Indicators/DrawIndicator.mqh" +#include "../Math/Math.h" #include "../Refs.mqh" #include "../Serializer/Serializer.h" #include "../Serializer/SerializerCsv.h" #include "../Serializer/SerializerJson.h" +#include "../Storage/Array.h" +#include "../Storage/DateTime.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" +#include "../Storage/Flags.struct.h" +#include "../Storage/Object.h" #include "../Storage/ValueStorage.h" #include "../Storage/ValueStorage.indicator.h" #include "../Storage/ValueStorage.native.h" +#include "../Task/TaskCondition.enum.h" #ifndef __MQL4__ // Defines global functions (for MQL4 backward compatibility). @@ -155,10 +157,10 @@ class Indicator : public IndicatorData { } /** - * Gets a value from IndicatorState struct. + * Gets a value from IndicatorDataState struct. */ template - T Get(STRUCT_ENUM_INDICATOR_STATE_PROP _param) { + T Get(STRUCT_ENUM_INDICATOR_DATA_STATE_PROP _param) { return istate.Get(_param); } @@ -225,7 +227,7 @@ class Indicator : public IndicatorData { /** * Sets whether indicator's buffers should be drawn on the chart. */ - void SetDraw(bool _value, color _color = clrAquamarine, int _window = 0) { + void SetPlot(bool _value, color _color = clrAquamarine, int _window = 0) { // draw.SetEnabled(_value); // draw.SetColorLine(_color); // draw.SetWindow(_window); @@ -269,7 +271,7 @@ class Indicator : public IndicatorData { * cache_key.Add(period); * cache_key.Add(foo_method); * - * Ref cache = Indicator::OnCalculateProxy(cache_key.ToString(), price, total); + * Ref cache = Indicator::OnCalculateProxy(cache_key.ToString(), price, total); * * int prev_calculated = * Indi_Foo::Calculate(total, cache.Ptr().prev_calculated, 0, price, cache.Ptr().buffer1, ma_method, period); @@ -285,21 +287,21 @@ class Indicator : public IndicatorData { * WARNING: Do not use shifts when creating cache_key, as this will create many invalid buffers. */ /* - static IndicatorCalculateCache OnCalculateProxy(string key, double& price[], int& total) { + static IndiBufferCache OnCalculateProxy(string key, double& price[], int& total) { if (total == 0) { total = ArraySize(price); } // Stores previously calculated value. - static DictStruct cache; + static DictStruct cache; unsigned int position; - IndicatorCalculateCache cache_item; + IndiBufferCache cache_item; if (cache.KeyExists(key, position)) { cache_item = cache.GetByKey(key); } else { - IndicatorCalculateCache cache_item_new(1, ArraySize(price)); + IndiBufferCache cache_item_new(1, ArraySize(price)); cache_item = cache_item_new; cache.Set(key, cache_item); } @@ -503,7 +505,7 @@ class Indicator : public IndicatorData { */ virtual bool ExecuteAction(ENUM_INDICATOR_ACTION _action, ARRAY_REF(DataParamEntry, _args)) { bool _result = true; - long _arg1 = ArraySize(_args) > 0 ? DataParamEntry::ToInteger(_args[0]) : WRONG_VALUE; + int64 _arg1 = ArraySize(_args) > 0 ? DataParamEntry::ToInteger(_args[0]) : WRONG_VALUE; switch (_action) { case INDI_ACTION_CLEAR_CACHE: _arg1 = _arg1 > 0 ? _arg1 : TimeCurrent(); @@ -520,7 +522,7 @@ class Indicator : public IndicatorData { ARRAY(DataParamEntry, _args); return ExecuteAction(_action, _args); } - bool ExecuteAction(ENUM_INDICATOR_ACTION _action, long _arg1) { + bool ExecuteAction(ENUM_INDICATOR_ACTION _action, int64 _arg1) { ARRAY(DataParamEntry, _args); DataParamEntry _param1 = _arg1; ArrayPushObject(_args, _param1); @@ -604,13 +606,13 @@ class Indicator : public IndicatorData { } else { if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_UNSIGNED)) { if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLED)) { - _result &= !_entry.HasValue(ULONG_MAX); + _result &= !_entry.HasValue(ULONG_MAX); } else { _result &= !_entry.HasValue(UINT_MAX); } } else { if (_entry.CheckFlags(INDI_ENTRY_FLAG_IS_DOUBLED)) { - _result &= !_entry.HasValue(LONG_MAX); + _result &= !_entry.HasValue(LONG_MAX); } else { _result &= !_entry.HasValue(INT_MAX); } @@ -634,7 +636,7 @@ class Indicator : public IndicatorData { */ IndicatorDataEntry GetEntry(int _rel_shift = 0) override { ResetLastError(); - long _bar_time = GetBarTime(_rel_shift); + int64 _bar_time = GetBarTime(_rel_shift); if (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE)) == IDATA_BUILTIN && (GetPossibleDataModes() & IDATA_BUILTIN) == 0) { @@ -655,10 +657,10 @@ class Indicator : public IndicatorData { _entry.Resize(_max_modes); _entry.timestamp = _bar_time; #ifndef __MQL4__ - if (IndicatorData::Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_CHANGED))) { + if (IndicatorData::Get(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_IS_CHANGED))) { // Resets the handle on any parameter changes. - IndicatorData::Set(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_HANDLE), INVALID_HANDLE); - IndicatorData::Set(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_CHANGED), false); + IndicatorData::Set(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_HANDLE), INVALID_HANDLE); + IndicatorData::Set(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_IS_CHANGED), false); } #endif for (int _mode = 0; _mode < _max_modes; _mode++) { @@ -669,13 +671,13 @@ class Indicator : public IndicatorData { _entry.values[_mode] = GetValue(_mode, _rel_shift); break; case TYPE_LONG: - _entry.values[_mode] = GetValue(_mode, _rel_shift); + _entry.values[_mode] = GetValue(_mode, _rel_shift); break; case TYPE_UINT: _entry.values[_mode] = GetValue(_mode, _rel_shift); break; case TYPE_ULONG: - _entry.values[_mode] = GetValue(_mode, _rel_shift); + _entry.values[_mode] = GetValue(_mode, _rel_shift); break; case TYPE_DOUBLE: _entry.values[_mode] = GetValue(_mode, _rel_shift); @@ -755,5 +757,3 @@ class Indicator : public IndicatorData { return false; }; }; - -#endif diff --git a/Indicator/Indicator.struct.h b/Indicator/Indicator.struct.h index 12e47fbd2..ff3da54e5 100644 --- a/Indicator/Indicator.struct.h +++ b/Indicator/Indicator.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -36,13 +36,13 @@ class Indicator; struct ChartParams; // Includes. -#include "../Array.mqh" -#include "../Chart.struct.tf.h" -#include "../Data.struct.h" -#include "../DateTime.struct.h" +#include "../Platform/Chart/Chart.struct.tf.h" #include "../Serializer/SerializerNode.enum.h" +#include "../Storage/Array.h" +#include "../Storage/Cache/IndiBufferCache.h" +#include "../Storage/Data.struct.h" +#include "../Storage/DateTime.struct.h" #include "Indicator.enum.h" -#include "IndicatorData.struct.cache.h" //#include "Indicator.struct.serialize.h" /* Structure for indicator parameters. */ diff --git a/Indicator/Indicator.struct.serialize.h b/Indicator/Indicator.struct.serialize.h index b71f4ede1..22528afa7 100644 --- a/Indicator/Indicator.struct.serialize.h +++ b/Indicator/Indicator.struct.serialize.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Includes Indicator's struct serializers. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "../Serializer/Serializer.h" #include "../Serializer/SerializerNode.enum.h" #include "Indicator.struct.h" diff --git a/Indicator/IndicatorBase.h b/Indicator/IndicatorBase.h index 78d1e9f05..e15aaff42 100644 --- a/Indicator/IndicatorBase.h +++ b/Indicator/IndicatorBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,18 +31,23 @@ #endif // Includes. -#include "../Array.mqh" -#include "../BufferStruct.mqh" -#include "../Chart.struct.tf.h" -#include "../DateTime.mqh" +#include "../Bar.struct.h" #include "../Log.mqh" -#include "../Object.mqh" -#include "../Platform.extern.h" +#include "../Platform/Chart/Chart.struct.tf.h" +#include "../Platform/Platform.extern.h" #include "../Refs.mqh" #include "../Serializer/Serializer.h" #include "../Serializer/SerializerCsv.h" #include "../Serializer/SerializerJson.h" +#include "../Storage/Array.h" +#include "../Storage/DateTime.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" +#include "../Storage/Object.h" #include "../Util.h" +#include "IndicatorData.struct.h" + +// Forward declarations. +class IndicatorData; /** * Class to deal with indicators. @@ -104,7 +109,7 @@ class IndicatorBase : public Object { * cache_key.Add(period); * cache_key.Add(foo_method); * - * Ref cache = Indicator::OnCalculateProxy(cache_key.ToString(), price, total); + * Ref cache = Indicator::OnCalculateProxy(cache_key.ToString(), price, total); * * int prev_calculated = * Indi_Foo::Calculate(total, cache.Ptr().prev_calculated, 0, price, cache.Ptr().buffer1, ma_method, period); @@ -120,21 +125,21 @@ class IndicatorBase : public Object { * WARNING: Do not use shifts when creating cache_key, as this will create many invalid buffers. */ /* - static IndicatorCalculateCache OnCalculateProxy(string key, double& price[], int& total) { + static IndiBufferCache OnCalculateProxy(string key, double& price[], int& total) { if (total == 0) { total = ArraySize(price); } // Stores previously calculated value. - static DictStruct cache; + static DictStruct cache; unsigned int position; - IndicatorCalculateCache cache_item; + IndiBufferCache cache_item; if (cache.KeyExists(key, position)) { cache_item = cache.GetByKey(key); } else { - IndicatorCalculateCache cache_item_new(1, ArraySize(price)); + IndiBufferCache cache_item_new(1, ArraySize(price)); cache_item = cache_item_new; cache.Set(key, cache_item); } @@ -186,8 +191,30 @@ class IndicatorBase : public Object { */ // void SetSymbol(string _symbol) { Set(CHART_PARAM_SYMBOL, _symbol); } + template + T GetValue(int _mode = 0, int _rel_shift = 0) { + T _out; + GetEntryValue(_mode, ToAbsShift(_rel_shift)).Get(_out); + return _out; + } + /* Virtual methods */ + /** + * Returns the indicator's entry value. + */ + virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _abs_shift = 0) = 0; + + /** + * Converts relative shift into absolute one. + */ + virtual int ToAbsShift(int _rel_shift) = 0; + + /** + * Converts absolute shift into relative one. + */ + virtual int ToRelShift(int _abs_shift) = 0; + /** * Get name of the indicator. */ @@ -203,6 +230,46 @@ class IndicatorBase : public Object { */ virtual string GetDescriptiveName() { return GetName(); } + /** + * Traverses source indicators' hierarchy and tries to find OHLC-featured + * indicator. IndicatorCandle satisfies such requirements. + */ + virtual IndicatorData* GetCandle(bool _warn_if_not_found = true, IndicatorData* _originator = nullptr) = 0; + + /** + * Returns the number of bars on the chart decremented by iparams.shift. + */ + virtual int GetBars() = 0; + + /** + * Returns time of the bar for a given shift. + */ + virtual datetime GetBarTime(int _rel_shift = 0) = 0; + + /** + * Gets OHLC price values. + */ + virtual BarOHLC GetOHLC(int _rel_shift = 0) = 0; + + /** + * Returns the current price value given applied price type, symbol and timeframe. + */ + virtual double GetPrice(ENUM_APPLIED_PRICE _ap, int _rel_shift = 0) = 0; + + /** + * Returns spread for the bar. + * + * If local history is empty (not loaded), function returns 0. + */ + virtual int64 GetSpread(int _shift = 0) = 0; + + /** + * Returns volume value for the bar. + * + * If local history is empty (not loaded), function returns 0. + */ + virtual int64 GetVolume(int _shift = 0) = 0; + /** * Returns indicator value for a given shift and mode. */ @@ -214,7 +281,7 @@ class IndicatorBase : public Object { /* virtual bool HasValidEntry(int _index = 0) { unsigned int position; - long bar_time = GetBarTime(_index); + int64 bar_time = GetBarTime(_index); return bar_time > 0 && idata.KeyExists(bar_time, position) ? idata.GetByPos(position).IsValid() : false; } */ diff --git a/Indicator/IndicatorCandle.h b/Indicator/IndicatorCandle.h index 7b8ad1c86..2e415cce1 100644 --- a/Indicator/IndicatorCandle.h +++ b/Indicator/IndicatorCandle.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,6 @@ * */ -// Ignore processing of this file if already included. -#ifndef INDICATOR_CANDLE_H -#define INDICATOR_CANDLE_H - #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once @@ -228,7 +224,7 @@ class IndicatorCandle : public Indicator { * * If local history is empty (not loaded), function returns 0. */ - long GetVolume(int _shift = 0) override { + int64 GetVolume(int _shift = 0) override { CandleOCTOHLC _candle; if (history.TryGetItemByShift(_shift, _candle)) { @@ -243,14 +239,14 @@ class IndicatorCandle : public Indicator { * * If local history is empty (not loaded), function returns 0. */ - long GetSpread(int _shift = 0) override { return 0; } + int64 GetSpread(int _shift = 0) override { return 0; } /** * Returns tick volume value for the bar. * * If local history is empty (not loaded), function returns 0. */ - long GetTickVolume(int _shift = 0) override { return GetVolume(); } + int64 GetTickVolume(int _shift = 0) override { return GetVolume(); } /** * Returns the indicator's data entry. @@ -287,7 +283,7 @@ class IndicatorCandle : public Indicator { case INDI_CANDLE_MODE_SPREAD: case INDI_CANDLE_MODE_TICK_VOLUME: case INDI_CANDLE_MODE_VOLUME: - THIS_ATTR value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); + THIS_ATTR value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); break; case INDI_CANDLE_MODE_TIME: THIS_ATTR value_storages[_mode] = new IndicatorBufferValueStorage(THIS_PTR, _mode); @@ -313,7 +309,7 @@ class IndicatorCandle : public Indicator { /** * Converts candle into indicator's data entry. */ - IndicatorDataEntry CandleToEntry(long _timestamp, CandleOCTOHLC& _candle) { + IndicatorDataEntry CandleToEntry(int64 _timestamp, CandleOCTOHLC& _candle) { IndicatorDataEntry _entry(FINAL_INDI_CANDLE_MODE_ENTRY); _entry.timestamp = _timestamp; _entry.values[INDI_CANDLE_MODE_PRICE_OPEN] = _candle.open; @@ -370,29 +366,29 @@ class IndicatorCandle : public Indicator { /** * Returns value storage of given kind. */ - IValueStorage* GetSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + IValueStorage* GetSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { switch (_type) { - case INDI_VS_TYPE_PRICE_OPEN: + case INDI_DATA_VS_TYPE_PRICE_OPEN: return GetValueStorage(INDI_CANDLE_MODE_PRICE_OPEN); - case INDI_VS_TYPE_PRICE_HIGH: + case INDI_DATA_VS_TYPE_PRICE_HIGH: return GetValueStorage(INDI_CANDLE_MODE_PRICE_HIGH); - case INDI_VS_TYPE_PRICE_LOW: + case INDI_DATA_VS_TYPE_PRICE_LOW: return GetValueStorage(INDI_CANDLE_MODE_PRICE_LOW); - case INDI_VS_TYPE_PRICE_CLOSE: + case INDI_DATA_VS_TYPE_PRICE_CLOSE: return GetValueStorage(INDI_CANDLE_MODE_PRICE_CLOSE); - case INDI_VS_TYPE_PRICE_MEDIAN: + case INDI_DATA_VS_TYPE_PRICE_MEDIAN: return GetValueStorage(INDI_CANDLE_MODE_PRICE_MEDIAN); - case INDI_VS_TYPE_PRICE_TYPICAL: + case INDI_DATA_VS_TYPE_PRICE_TYPICAL: return GetValueStorage(INDI_CANDLE_MODE_PRICE_TYPICAL); - case INDI_VS_TYPE_PRICE_WEIGHTED: + case INDI_DATA_VS_TYPE_PRICE_WEIGHTED: return GetValueStorage(INDI_CANDLE_MODE_PRICE_WEIGHTED); - case INDI_VS_TYPE_SPREAD: + case INDI_DATA_VS_TYPE_SPREAD: return GetValueStorage(INDI_CANDLE_MODE_SPREAD); - case INDI_VS_TYPE_TICK_VOLUME: + case INDI_DATA_VS_TYPE_TICK_VOLUME: return GetValueStorage(INDI_CANDLE_MODE_TICK_VOLUME); - case INDI_VS_TYPE_TIME: + case INDI_DATA_VS_TYPE_TIME: return GetValueStorage(INDI_CANDLE_MODE_TIME); - case INDI_VS_TYPE_VOLUME: + case INDI_DATA_VS_TYPE_VOLUME: return GetValueStorage(INDI_CANDLE_MODE_VOLUME); default: // Trying in parent class. @@ -403,19 +399,19 @@ class IndicatorCandle : public Indicator { /** * Checks whether indicator support given value storage type. */ - bool HasSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + bool HasSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { switch (_type) { - case INDI_VS_TYPE_PRICE_OPEN: - case INDI_VS_TYPE_PRICE_HIGH: - case INDI_VS_TYPE_PRICE_LOW: - case INDI_VS_TYPE_PRICE_CLOSE: - case INDI_VS_TYPE_PRICE_MEDIAN: - case INDI_VS_TYPE_PRICE_TYPICAL: - case INDI_VS_TYPE_PRICE_WEIGHTED: - case INDI_VS_TYPE_SPREAD: - case INDI_VS_TYPE_TICK_VOLUME: - case INDI_VS_TYPE_TIME: - case INDI_VS_TYPE_VOLUME: + case INDI_DATA_VS_TYPE_PRICE_OPEN: + case INDI_DATA_VS_TYPE_PRICE_HIGH: + case INDI_DATA_VS_TYPE_PRICE_LOW: + case INDI_DATA_VS_TYPE_PRICE_CLOSE: + case INDI_DATA_VS_TYPE_PRICE_MEDIAN: + case INDI_DATA_VS_TYPE_PRICE_TYPICAL: + case INDI_DATA_VS_TYPE_PRICE_WEIGHTED: + case INDI_DATA_VS_TYPE_SPREAD: + case INDI_DATA_VS_TYPE_TICK_VOLUME: + case INDI_DATA_VS_TYPE_TIME: + case INDI_DATA_VS_TYPE_VOLUME: return true; default: // Trying in parent class. @@ -430,5 +426,3 @@ class IndicatorCandle : public Indicator { /* Virtual methods */ }; - -#endif diff --git a/Indicator/IndicatorCandle.provider.h b/Indicator/IndicatorCandle.provider.h index 1b45a6cac..4eb894c06 100644 --- a/Indicator/IndicatorCandle.provider.h +++ b/Indicator/IndicatorCandle.provider.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -47,7 +47,7 @@ class ItemsHistoryCandleProvider : public ItemsHistoryItemProvider, ItemsHistoryItemProvider>>* _history, long _time_ms, + void OnTick(ItemsHistory, ItemsHistoryItemProvider>>* _history, int64 _time_ms, float _ask, float _bid) { // Should be overrided. } @@ -56,7 +56,7 @@ class ItemsHistoryCandleProvider : public ItemsHistoryItemProvider, ItemsHistoryCandleProvider>* _history, long _from_time_ms, + bool GetItems(ItemsHistory, ItemsHistoryCandleProvider>* _history, int64 _from_time_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _num_items, ARRAY_REF(CandleOCTOHLC, _out_arr)) { // Method is called if there is a missing item (candle) in the history. We need to regenerate it. return false; diff --git a/Indicator/IndicatorData.enum.h b/Indicator/IndicatorData.enum.h index ef7414643..f5275543f 100644 --- a/Indicator/IndicatorData.enum.h +++ b/Indicator/IndicatorData.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,66 +31,66 @@ #endif /* Indicator entry flags. */ -enum INDICATOR_ENTRY_FLAGS { +enum INDICATOR_DATA_ENTRY_FLAGS { INDI_ENTRY_FLAG_NONE = 0 << 0, INDI_ENTRY_FLAG_IS_BITWISE = 1 << 0, - INDI_ENTRY_FLAG_IS_DOUBLED = 1 << 1, // Type is doubled in size (e.g. double or long). + INDI_ENTRY_FLAG_IS_DOUBLED = 1 << 1, // Type is doubled in size (e.g. double or int64). INDI_ENTRY_FLAG_IS_EXPIRED = 1 << 2, INDI_ENTRY_FLAG_IS_REAL = 1 << 3, // Type is real (float or double). INDI_ENTRY_FLAG_IS_PRICE = 1 << 4, - INDI_ENTRY_FLAG_IS_UNSIGNED = 1 << 5, // Type is unsigned (unsigned int or unsigned long). + INDI_ENTRY_FLAG_IS_UNSIGNED = 1 << 5, // Type is unsigned (unsigned int or uint64). INDI_ENTRY_FLAG_IS_VALID = 1 << 6, INDI_ENTRY_FLAG_INSUFFICIENT_DATA = 1 << 7, // Entry has missing value for that shift and probably won't ever have. }; /* Define indicator index. */ -enum ENUM_INDICATOR_INDEX { +enum ENUM_INDICATOR_DATA_INDEX { CURR = 0, PREV = 1, PPREV = 2, - FINAL_ENUM_INDICATOR_INDEX = 3 // Should be the last one. Used to calculate the number of enum items. + FINAL_ENUM_INDICATOR_DATA_INDEX = 3 // Should be the last one. Used to calculate the number of enum items. }; // Storage type for IndicatorBase::GetSpecificValueStorage(). -enum ENUM_INDI_VS_TYPE { - INDI_VS_TYPE_NONE, // Not set. - INDI_VS_TYPE_TIME, // Candle. - INDI_VS_TYPE_TICK_VOLUME, // Candle. - INDI_VS_TYPE_VOLUME, // Candle. - INDI_VS_TYPE_SPREAD, // Candle. - INDI_VS_TYPE_PRICE_OPEN, // Candle. - INDI_VS_TYPE_PRICE_HIGH, // Candle. - INDI_VS_TYPE_PRICE_LOW, // Candle. - INDI_VS_TYPE_PRICE_CLOSE, // Candle. - INDI_VS_TYPE_PRICE_MEDIAN, // Candle. - INDI_VS_TYPE_PRICE_TYPICAL, // Candle. - INDI_VS_TYPE_PRICE_WEIGHTED, // Candle. - INDI_VS_TYPE_PRICE_BID, // Tick. - INDI_VS_TYPE_PRICE_ASK, // Tick. - // Indexed value storages, available if indicator have buffer at this index: - INDI_VS_TYPE_INDEX_0, - INDI_VS_TYPE_INDEX_1, - INDI_VS_TYPE_INDEX_2, - INDI_VS_TYPE_INDEX_4, - INDI_VS_TYPE_INDEX_5, - INDI_VS_TYPE_INDEX_6, - INDI_VS_TYPE_INDEX_7, - INDI_VS_TYPE_INDEX_8, - INDI_VS_TYPE_INDEX_9, - INDI_VS_TYPE_INDEX_FIRST = INDI_VS_TYPE_INDEX_0, - INDI_VS_TYPE_INDEX_LAST = INDI_VS_TYPE_INDEX_9, +enum ENUM_INDI_DATA_VS_TYPE { + INDI_DATA_VS_TYPE_NONE, // Not set. + INDI_DATA_VS_TYPE_TIME, // Candle. + INDI_DATA_VS_TYPE_TICK_VOLUME, // Candle. + INDI_DATA_VS_TYPE_VOLUME, // Candle. + INDI_DATA_VS_TYPE_SPREAD, // Candle. + INDI_DATA_VS_TYPE_PRICE_OPEN, // Candle. + INDI_DATA_VS_TYPE_PRICE_HIGH, // Candle. + INDI_DATA_VS_TYPE_PRICE_LOW, // Candle. + INDI_DATA_VS_TYPE_PRICE_CLOSE, // Candle. + INDI_DATA_VS_TYPE_PRICE_MEDIAN, // Candle. + INDI_DATA_VS_TYPE_PRICE_TYPICAL, // Candle. + INDI_DATA_VS_TYPE_PRICE_WEIGHTED, // Candle. + INDI_DATA_VS_TYPE_PRICE_BID, // Tick. + INDI_DATA_VS_TYPE_PRICE_ASK, // Tick. + // Indexed value storages, available if indicator have buffer at this index: + INDI_DATA_VS_TYPE_INDEX_0, + INDI_DATA_VS_TYPE_INDEX_1, + INDI_DATA_VS_TYPE_INDEX_2, + INDI_DATA_VS_TYPE_INDEX_4, + INDI_DATA_VS_TYPE_INDEX_5, + INDI_DATA_VS_TYPE_INDEX_6, + INDI_DATA_VS_TYPE_INDEX_7, + INDI_DATA_VS_TYPE_INDEX_8, + INDI_DATA_VS_TYPE_INDEX_9, + INDI_DATA_VS_TYPE_INDEX_FIRST = INDI_DATA_VS_TYPE_INDEX_0, + INDI_DATA_VS_TYPE_INDEX_LAST = INDI_DATA_VS_TYPE_INDEX_9, // Account Stats. - INDI_VS_TYPE_ACCOUNT_STATS_DATE_TIME, - INDI_VS_TYPE_ACCOUNT_STATS_BALANCE, - INDI_VS_TYPE_ACCOUNT_STATS_CREDIT, - INDI_VS_TYPE_ACCOUNT_STATS_EQUITY, - INDI_VS_TYPE_ACCOUNT_STATS_PROFIT, - INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_USED, - INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_FREE, - INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL, - INDI_VS_TYPE_ACCOUNT_STATS_INDEX_FIRST = INDI_VS_TYPE_ACCOUNT_STATS_DATE_TIME, - INDI_VS_TYPE_ACCOUNT_STATS_INDEX_LAST = INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_DATE_TIME, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_BALANCE, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_CREDIT, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_EQUITY, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_PROFIT, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_USED, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_FREE, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_INDEX_FIRST = INDI_DATA_VS_TYPE_ACCOUNT_STATS_DATE_TIME, + INDI_DATA_VS_TYPE_ACCOUNT_STATS_INDEX_LAST = INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL, }; /* Defines type of source data for. Also used for Indicator::GetPossibleDataModes(). */ diff --git a/Indicator/IndicatorData.h b/Indicator/IndicatorData.h index 01befb765..e08ab6799 100644 --- a/Indicator/IndicatorData.h +++ b/Indicator/IndicatorData.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,6 @@ * */ -// Ignore processing of this file if already included. -#ifndef INDICATOR_DATA_H -#define INDICATOR_DATA_H - #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once @@ -40,18 +36,18 @@ struct ExternInstantiateIndicatorBufferValueStorageDouble { // Includes. #include "../Bar.struct.h" -#include "../Chart.struct.tf.h" -#include "../Flags.h" +#include "../Exchange/SymbolInfo/SymbolInfo.struct.h" +#include "../Platform/Chart/Chart.struct.tf.h" +#include "../Storage/Cache/IndiBufferCache.h" +#include "../Storage/Flags.struct.h" #include "../Storage/IValueStorage.h" #include "../Storage/ItemsHistory.h" #include "../Storage/ValueStorage.h" #include "../Storage/ValueStorage.indicator.h" #include "../Storage/ValueStorage.native.h" -#include "../SymbolInfo.struct.h" #include "Indicator.enum.h" #include "IndicatorBase.h" #include "IndicatorData.enum.h" -#include "IndicatorData.struct.cache.h" #include "IndicatorData.struct.h" #include "IndicatorData.struct.serialize.h" #include "IndicatorData.struct.signal.h" @@ -64,22 +60,22 @@ class IndicatorData : public IndicatorBase { // Class variables. bool do_draw; bool indicator_builtin; - bool is_fed; // Whether calc_start_bar is already calculated. - int calc_start_bar; // Index of the first valid bar (from 0). - int flags; // Flags such as INDI_FLAG_INDEXABLE_BY_SHIFT. - int last_tick_index; // Index of the last tick. - long first_tick_time_ms; // Time of the first ask/bid tick. + bool is_fed; // Whether calc_start_bar is already calculated. + int calc_start_bar; // Index of the first valid bar (from 0). + int flags; // Flags such as INDI_FLAG_INDEXABLE_BY_SHIFT. + int last_tick_index; // Index of the last tick. + int64 first_tick_time_ms; // Time of the first ask/bid tick. void* mydata; - bool last_tick_result; // Result of the last Tick() invocation. - ENUM_INDI_VS_TYPE retarget_ap_av; // Value storage type to be used as applied price/volume. + bool last_tick_result; // Result of the last Tick() invocation. + ENUM_INDI_DATA_VS_TYPE retarget_ap_av; // Value storage type to be used as applied price/volume. ARRAY(Ref, value_storages); ARRAY(WeakRef, listeners); // List of indicators that listens for events from this one. BufferStruct idata; DictStruct> indicators; // Indicators list keyed by id. // DrawIndicator* draw; - IndicatorCalculateCache cache; + IndiBufferCache cache; IndicatorDataParams idparams; // Indicator data params. - IndicatorState istate; + IndicatorDataState istate; Ref indi_src; // Indicator used as data source. protected: @@ -114,7 +110,7 @@ class IndicatorData : public IndicatorBase { flags = INDI_FLAG_INDEXABLE_BY_SHIFT | INDI_FLAG_SOURCE_REQ_INDEXABLE_BY_SHIFT; calc_start_bar = 0; last_tick_index = -1; - retarget_ap_av = INDI_VS_TYPE_NONE; + retarget_ap_av = INDI_DATA_VS_TYPE_NONE; InitDraw(); return true; } @@ -182,7 +178,7 @@ class IndicatorData : public IndicatorBase { return GetEntry(_rel_shift); } - IndicatorDataEntry operator[](ENUM_INDICATOR_INDEX _rel_shift) { return GetEntry((int)_rel_shift); } + IndicatorDataEntry operator[](ENUM_INDICATOR_DATA_INDEX _rel_shift) { return GetEntry((int)_rel_shift); } /* Getters */ @@ -198,14 +194,14 @@ class IndicatorData : public IndicatorBase { * Gets an indicator's state property value. */ template - T Get(STRUCT_ENUM_INDICATOR_STATE_PROP _prop) { + T Get(STRUCT_ENUM_INDICATOR_DATA_STATE_PROP _prop) { return istate.Get(_prop); } /** * Gets an indicator property flag. */ - bool GetFlag(INDICATOR_ENTRY_FLAGS _prop, int _rel_shift = 0) { + bool GetFlag(INDICATOR_DATA_ENTRY_FLAGS _prop, int _rel_shift = 0) { IndicatorDataEntry _entry = GetEntry(_rel_shift); return _entry.CheckFlag(_prop); } @@ -219,7 +215,7 @@ class IndicatorData : public IndicatorBase { * Returns time of the first ask/bid tick (time of first global OnTick()). * Time is compatible with time generated by IndicatorTick, e.g., Indi_TickMt. */ - long GetFirstTickTimeMs() { return first_tick_time_ms; } + int64 GetFirstTickTimeMs() { return first_tick_time_ms; } /** * Get full name of the indicator (with "over ..." part). @@ -267,7 +263,7 @@ class IndicatorData : public IndicatorBase { _price = (float)GetPrice(_ap, _shift); } else if (_idvrange == IDATA_RANGE_PRICE) { // When indicator values are the actual prices. - T _values[4]; + FIXED_ARRAY(T, _values, 4); if (!CopyValues(_values, 4, _shift, _mode)) { // When values aren't valid, return 0. return _price; @@ -569,6 +565,25 @@ class IndicatorData : public IndicatorBase { return _is_valid; } +#ifdef __cplusplus + template + bool CopyValues(FIXED_ARRAY_REF(T, _data, size), int _count, int _start_shift = 0, int _mode = 0) { + bool _is_valid = true; + if (size < _count) { + Alert("Error: CopyValues(): Provided _count = ", IntegerToString(_count), " is too much for fixed array of size ", + IntegerToString(size)); + return false; + } + for (int i = 0; i < _count; i++) { + IndicatorDataEntry _entry = GetEntry(_start_shift + i); + _is_valid &= _entry.IsValid(); + _data[i] = (T)_entry[_mode]; + } + return _is_valid; + } + +#endif + /* Getters */ int GetBarsCalculated() { return GetBars(); } @@ -576,7 +591,7 @@ class IndicatorData : public IndicatorBase { /** * Returns buffers' cache. */ - IndicatorCalculateCache* GetCache() { return &cache; } + IndiBufferCache* GetCache() { return &cache; } /** * Get pointer to data of indicator. @@ -656,7 +671,7 @@ class IndicatorData : public IndicatorBase { /** * Gets value storage type previously set by SetDataSourceAppliedPrice() or SetDataSourceAppliedVolume(). */ - ENUM_INDI_VS_TYPE GetDataSourceAppliedType() { return retarget_ap_av; } + ENUM_INDI_DATA_VS_TYPE GetDataSourceAppliedType() { return retarget_ap_av; } // int GetDataSourceMode() { return indi_src_mode; } @@ -780,7 +795,7 @@ class IndicatorData : public IndicatorBase { * Sets an indicator's state property value. */ template - void Set(STRUCT_ENUM_INDICATOR_STATE_PROP _prop, T _value) { + void Set(STRUCT_ENUM_INDICATOR_DATA_STATE_PROP _prop, T _value) { istate.Set(_prop, _value); } @@ -836,7 +851,7 @@ class IndicatorData : public IndicatorBase { /** * Uses custom value storage type as applied price. */ - void SetDataSourceAppliedPrice(ENUM_INDI_VS_TYPE _vs_type) { + void SetDataSourceAppliedPrice(ENUM_INDI_DATA_VS_TYPE _vs_type) { // @todo Check if given value storage is of compatible type (double)! retarget_ap_av = _vs_type; } @@ -857,10 +872,13 @@ class IndicatorData : public IndicatorBase { * Checks whether current indicator has all buffers required to be a Candle-compatible indicator. */ bool IsCandleIndicator() { - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_OPEN) && HasSpecificValueStorage(INDI_VS_TYPE_PRICE_HIGH) && - HasSpecificValueStorage(INDI_VS_TYPE_PRICE_LOW) && HasSpecificValueStorage(INDI_VS_TYPE_PRICE_CLOSE) && - HasSpecificValueStorage(INDI_VS_TYPE_SPREAD) && HasSpecificValueStorage(INDI_VS_TYPE_TICK_VOLUME) && - HasSpecificValueStorage(INDI_VS_TYPE_TIME) && HasSpecificValueStorage(INDI_VS_TYPE_VOLUME); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_OPEN) && + HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_HIGH) && + HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_LOW) && + HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_CLOSE) && + HasSpecificValueStorage(INDI_DATA_VS_TYPE_SPREAD) && + HasSpecificValueStorage(INDI_DATA_VS_TYPE_TICK_VOLUME) && HasSpecificValueStorage(INDI_DATA_VS_TYPE_TIME) && + HasSpecificValueStorage(INDI_DATA_VS_TYPE_VOLUME); } /* Tick methods */ @@ -869,9 +887,9 @@ class IndicatorData : public IndicatorBase { * Checks whether current indicator has all buffers required to be a Tick-compatible indicator. */ bool IsTickIndicator() { - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_ASK) && HasSpecificValueStorage(INDI_VS_TYPE_PRICE_BID) && - HasSpecificValueStorage(INDI_VS_TYPE_SPREAD) && HasSpecificValueStorage(INDI_VS_TYPE_VOLUME) && - HasSpecificValueStorage(INDI_VS_TYPE_TICK_VOLUME); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_ASK) && + HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_BID) && HasSpecificValueStorage(INDI_DATA_VS_TYPE_SPREAD) && + HasSpecificValueStorage(INDI_DATA_VS_TYPE_VOLUME) && HasSpecificValueStorage(INDI_DATA_VS_TYPE_TICK_VOLUME); } bool Tick(int _global_tick_index) { @@ -1053,13 +1071,6 @@ class IndicatorData : public IndicatorBase { return SerializerConverter::FromObject(_entry, _serializer_flags).ToString(0, &_stub); } - template - T GetValue(int _mode = 0, int _rel_shift = 0) { - T _out; - GetEntryValue(_mode, ToAbsShift(_rel_shift)).Get(_out); - return _out; - } - /* Virtual methods */ /** @@ -1075,42 +1086,42 @@ class IndicatorData : public IndicatorBase { * Returns value storage's buffer type from this indicator's applied price (indicator must override GetAppliedPrice() * method!). */ - virtual ENUM_INDI_VS_TYPE GetAppliedPriceValueStorageType() { - if (retarget_ap_av != INDI_VS_TYPE_NONE) { + virtual ENUM_INDI_DATA_VS_TYPE GetAppliedPriceValueStorageType() { + if (retarget_ap_av != INDI_DATA_VS_TYPE_NONE) { // User wants to use custom value storage type as applied price. return retarget_ap_av; } switch (GetAppliedPrice()) { case PRICE_ASK: - return INDI_VS_TYPE_PRICE_ASK; + return INDI_DATA_VS_TYPE_PRICE_ASK; case PRICE_BID: - return INDI_VS_TYPE_PRICE_BID; + return INDI_DATA_VS_TYPE_PRICE_BID; case PRICE_OPEN: - return INDI_VS_TYPE_PRICE_OPEN; + return INDI_DATA_VS_TYPE_PRICE_OPEN; case PRICE_HIGH: - return INDI_VS_TYPE_PRICE_HIGH; + return INDI_DATA_VS_TYPE_PRICE_HIGH; case PRICE_LOW: - return INDI_VS_TYPE_PRICE_LOW; + return INDI_DATA_VS_TYPE_PRICE_LOW; case PRICE_CLOSE: - return INDI_VS_TYPE_PRICE_CLOSE; + return INDI_DATA_VS_TYPE_PRICE_CLOSE; case PRICE_MEDIAN: - return INDI_VS_TYPE_PRICE_MEDIAN; + return INDI_DATA_VS_TYPE_PRICE_MEDIAN; case PRICE_TYPICAL: - return INDI_VS_TYPE_PRICE_TYPICAL; + return INDI_DATA_VS_TYPE_PRICE_TYPICAL; case PRICE_WEIGHTED: - return INDI_VS_TYPE_PRICE_WEIGHTED; + return INDI_DATA_VS_TYPE_PRICE_WEIGHTED; default: if ((int)GetAppliedPrice() == (int)PRICE_ASK) { - return INDI_VS_TYPE_PRICE_ASK; + return INDI_DATA_VS_TYPE_PRICE_ASK; } else if ((int)GetAppliedPrice() == (int)PRICE_BID) { - return INDI_VS_TYPE_PRICE_BID; + return INDI_DATA_VS_TYPE_PRICE_BID; } } Print("Error: ", GetFullName(), " has not supported applied price set: ", EnumToString(GetAppliedPrice()), "!"); DebugBreak(); - return (ENUM_INDI_VS_TYPE)-1; + return (ENUM_INDI_DATA_VS_TYPE)-1; } /** @@ -1126,22 +1137,22 @@ class IndicatorData : public IndicatorBase { * Returns value storage's buffer type from this indicator's applied volume (indicator must override * GetAppliedVolume() method!). */ - virtual ENUM_INDI_VS_TYPE GetAppliedVolumeValueStorageType() { - if (retarget_ap_av != INDI_VS_TYPE_NONE) { + virtual ENUM_INDI_DATA_VS_TYPE GetAppliedVolumeValueStorageType() { + if (retarget_ap_av != INDI_DATA_VS_TYPE_NONE) { // User wants to use custom value storage type as applied volume. return retarget_ap_av; } switch (GetAppliedVolume()) { case VOLUME_TICK: - return INDI_VS_TYPE_TICK_VOLUME; + return INDI_DATA_VS_TYPE_TICK_VOLUME; case VOLUME_REAL: - return INDI_VS_TYPE_VOLUME; + return INDI_DATA_VS_TYPE_VOLUME; } Print("Error: ", GetFullName(), " has not supported applied volume set: ", EnumToString(GetAppliedVolume()), "!"); DebugBreak(); - return (ENUM_INDI_VS_TYPE)-1; + return (ENUM_INDI_DATA_VS_TYPE)-1; } /** @@ -1157,7 +1168,7 @@ class IndicatorData : public IndicatorBase { /** * Returns the number of bars on the chart decremented by iparams.shift. */ - virtual int GetBars() { return GetCandle() PTR_DEREF GetBars(); } + int GetBars() override { return GetCandle() PTR_DEREF GetBars(); } /** * Returns index of the current bar. @@ -1167,7 +1178,7 @@ class IndicatorData : public IndicatorBase { /** * Returns time of the bar for a given shift. */ - virtual datetime GetBarTime(int _rel_shift = 0) { + datetime GetBarTime(int _rel_shift = 0) override { IndicatorData* _indi = GetCandle(false); if (_indi == nullptr) _indi = GetTick(false); @@ -1198,7 +1209,7 @@ class IndicatorData : public IndicatorBase { * Traverses source indicators' hierarchy and tries to find OHLC-featured * indicator. IndicatorCandle satisfies such requirements. */ - virtual IndicatorData* GetCandle(bool _warn_if_not_found = true, IndicatorData* _originator = nullptr) { + IndicatorData* GetCandle(bool _warn_if_not_found = true, IndicatorData* _originator = nullptr) override { if (_originator == nullptr) { _originator = THIS_PTR; } @@ -1253,7 +1264,7 @@ class IndicatorData : public IndicatorBase { */ virtual void GetEntryAlter(IndicatorDataEntry& _entry, int _rel_shift) {} - // virtual ENUM_IDATA_VALUE_RANGE GetIDataValueRange() = NULL; + // virtual ENUM_IDATA_VALUE_RANGE GetIDataValueRange() = nullptr; /** * Returns the indicator's entry value. @@ -1318,7 +1329,7 @@ class IndicatorData : public IndicatorBase { /** * Returns the current price value given applied price type, symbol and timeframe. */ - virtual double GetPrice(ENUM_APPLIED_PRICE _ap, int _rel_shift = 0) { + double GetPrice(ENUM_APPLIED_PRICE _ap, int _rel_shift = 0) override { return GetCandle() PTR_DEREF GetPrice(_ap, _rel_shift); } @@ -1334,7 +1345,7 @@ class IndicatorData : public IndicatorBase { * * If local history is empty (not loaded), function returns 0. */ - virtual long GetSpread(int _shift = 0) { return GetCandle() PTR_DEREF GetSpread(_shift); } + int64 GetSpread(int _shift = 0) override { return GetCandle() PTR_DEREF GetSpread(_shift); } /** * Returns spread in pips. @@ -1345,7 +1356,7 @@ class IndicatorData : public IndicatorBase { virtual bool HasSpecificAppliedPriceValueStorage(ENUM_APPLIED_PRICE _ap, IndicatorData* _target = nullptr) { if (_target != nullptr) { - if (_target PTR_DEREF GetDataSourceAppliedType() != INDI_VS_TYPE_NONE) { + if (_target PTR_DEREF GetDataSourceAppliedType() != INDI_DATA_VS_TYPE_NONE) { // User wants to use custom value storage type as applied price, so we forcefully override AP given as the // parameter. // @todo Check for value storage compatibility (double). @@ -1355,28 +1366,28 @@ class IndicatorData : public IndicatorBase { switch (_ap) { case PRICE_ASK: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_ASK); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_ASK); case PRICE_BID: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_BID); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_BID); case PRICE_OPEN: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_OPEN); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_OPEN); case PRICE_HIGH: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_HIGH); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_HIGH); case PRICE_LOW: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_LOW); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_LOW); case PRICE_CLOSE: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_CLOSE); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_CLOSE); case PRICE_MEDIAN: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_MEDIAN); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_MEDIAN); case PRICE_TYPICAL: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_TYPICAL); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_TYPICAL); case PRICE_WEIGHTED: - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_WEIGHTED); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_WEIGHTED); default: if ((int)GetAppliedPrice() == (int)PRICE_ASK) { - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_ASK); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_ASK); } else if ((int)GetAppliedPrice() == (int)PRICE_BID) { - return HasSpecificValueStorage(INDI_VS_TYPE_PRICE_BID); + return HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_BID); } Print("Error: Invalid applied price " + EnumToString(_ap) + ", only PRICE_(OPEN|HIGH|LOW|CLOSE|MEDIAN|TYPICAL|WEIGHTED) are currently supported by " @@ -1392,7 +1403,7 @@ class IndicatorData : public IndicatorBase { */ ValueStorage* GetSpecificAppliedPriceValueStorage(ENUM_APPLIED_PRICE _ap, IndicatorData* _target = nullptr) { if (_target != nullptr) { - if (_target PTR_DEREF GetDataSourceAppliedType() != INDI_VS_TYPE_NONE) { + if (_target PTR_DEREF GetDataSourceAppliedType() != INDI_DATA_VS_TYPE_NONE) { // User wants to use custom value storage type as applied price, so we forcefully override AP given as the // parameter. // @todo Check for value storage compatibility (double). @@ -1402,28 +1413,28 @@ class IndicatorData : public IndicatorBase { switch (_ap) { case PRICE_ASK: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_ASK); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_ASK); case PRICE_BID: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_BID); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_BID); case PRICE_OPEN: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_OPEN); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_OPEN); case PRICE_HIGH: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_HIGH); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_HIGH); case PRICE_LOW: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_LOW); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_LOW); case PRICE_CLOSE: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_CLOSE); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_CLOSE); case PRICE_MEDIAN: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_MEDIAN); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_MEDIAN); case PRICE_TYPICAL: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_TYPICAL); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_TYPICAL); case PRICE_WEIGHTED: - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_WEIGHTED); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_WEIGHTED); default: if ((int)GetAppliedPrice() == (int)PRICE_ASK) { - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_ASK); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_ASK); } else if ((int)GetAppliedPrice() == (int)PRICE_BID) { - return (ValueStorage*)GetSpecificValueStorage(INDI_VS_TYPE_PRICE_BID); + return (ValueStorage*)GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_BID); } Print("Error: Invalid applied price " + EnumToString(_ap) + ", only PRICE_(OPEN|HIGH|LOW|CLOSE|MEDIAN|TYPICAL|WEIGHTED) are currently supported by " @@ -1481,7 +1492,7 @@ class IndicatorData : public IndicatorBase { * * If local history is empty (not loaded), function returns 0. */ - virtual long GetTickVolume(int _shift = 0) { return GetCandle() PTR_DEREF GetTickVolume(_shift); } + virtual int64 GetTickVolume(int _shift = 0) { return GetCandle() PTR_DEREF GetTickVolume(_shift); } /** * Removes candle from the buffer. Used mainly for testing purposes. @@ -1491,7 +1502,7 @@ class IndicatorData : public IndicatorBase { /** * Fetches historic ticks for a given time range. */ - bool FetchHistoryByTimeRange(long _from_ms, long _to_ms, ARRAY_REF(TickTAB, _out_ticks)) { return false; } + bool FetchHistoryByTimeRange(int64 _from_ms, int64 _to_ms, ARRAY_REF(TickTAB, _out_ticks)) { return false; } /** * Fetches historic ticks for a given index (absolute shift) range. @@ -1503,7 +1514,7 @@ class IndicatorData : public IndicatorBase { /** * Fetches historic ticks for a given start time and minimum number of tick to retrieve. */ - bool FetchHistoryByStartTimeAndCount(long _from_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _min_count, + bool FetchHistoryByStartTimeAndCount(int64 _from_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _min_count, ARRAY_REF(TickTAB, _out_ticks)) { // Print("FetchHistoryByStartTimeAndCount:"); // Print("- Requested _from_ms = ", _from_ms, ", _dir = ", EnumToString(_dir), ", _min_count = ", _min_count); @@ -1517,7 +1528,7 @@ class IndicatorData : public IndicatorBase { static ARRAY(TickTAB, _recv_ticks); // Time-frames for which we'll be receiving ticks. - long _recv_range_ms = 1000 * 60 * 30; // 30 min time-frames. + int64 _recv_range_ms = 1000 * 60 * 30; // 30 min time-frames. // Calculating initial time frame. if (_dir == ITEMS_HISTORY_DIRECTION_BACKWARD) { @@ -1525,7 +1536,7 @@ class IndicatorData : public IndicatorBase { _from_ms -= _recv_range_ms - 1; } // _to_ms will be at the last ms of _from_ms's timeframe. - long _to_ms = _from_ms + _recv_range_ms - 1; + int64 _to_ms = _from_ms + _recv_range_ms - 1; // Print("- Initial _from_ms = ", _from_ms, "_to_ms = ", _to_ms); @@ -1583,7 +1594,7 @@ class IndicatorData : public IndicatorBase { /** * Returns value storage of given kind. */ - virtual IValueStorage* GetSpecificValueStorage(ENUM_INDI_VS_TYPE _type) { + virtual IValueStorage* GetSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) { Print("Error: ", GetFullName(), " indicator has no storage type ", EnumToString(_type), "!"); DebugBreak(); return nullptr; @@ -1695,7 +1706,7 @@ class IndicatorData : public IndicatorBase { } } - ENUM_INDI_VS_TYPE _requested_vs_type; + ENUM_INDI_DATA_VS_TYPE _requested_vs_type; // Requires a single buffered or OHLC-compatible indicator (targetted via applied price) in the hierarchy. if (_suitable_types.HasFlag(INDI_SUITABLE_DS_TYPE_AP)) { @@ -1731,7 +1742,7 @@ class IndicatorData : public IndicatorBase { // Requires a single buffered or OHLC-compatible indicator (targetted via applied price or volume) in the hierarchy. if (_suitable_types.HasAnyFlag(INDI_SUITABLE_DS_TYPE_AP | INDI_SUITABLE_DS_TYPE_AV)) { - _requested_vs_type = (ENUM_INDI_VS_TYPE)-1; + _requested_vs_type = (ENUM_INDI_DATA_VS_TYPE)-1; if (_suitable_types.HasFlag(INDI_SUITABLE_DS_TYPE_AP)) { // Applied price is defined by this indicator, so it must override GetAppliedPrice(). @@ -1809,7 +1820,7 @@ class IndicatorData : public IndicatorBase { * * If local history is empty (not loaded), function returns 0. */ - virtual long GetVolume(int _shift = 0) { return GetCandle() PTR_DEREF GetVolume(_shift); } + int64 GetVolume(int _shift = 0) override { return GetCandle() PTR_DEREF GetVolume(_shift); } /** * Sends entry to listening indicators. @@ -1846,10 +1857,10 @@ class IndicatorData : public IndicatorBase { /** * Checks whether indicator support given value storage type. */ - virtual bool HasSpecificValueStorage(ENUM_INDI_VS_TYPE _type) { - // Maybe indexed value storage? E.g., INDI_VS_TYPE_INDEX_0. - if ((int)_type >= INDI_VS_TYPE_INDEX_FIRST && (int)_type <= INDI_VS_TYPE_INDEX_LAST) { - return HasValueStorage((int)_type - INDI_VS_TYPE_INDEX_FIRST); + virtual bool HasSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) { + // Maybe indexed value storage? E.g., INDI_DATA_VS_TYPE_INDEX_0. + if ((int)_type >= INDI_DATA_VS_TYPE_INDEX_FIRST && (int)_type <= INDI_DATA_VS_TYPE_INDEX_LAST) { + return HasValueStorage((int)_type - INDI_DATA_VS_TYPE_INDEX_FIRST); } return false; } @@ -1874,7 +1885,7 @@ class IndicatorData : public IndicatorBase { return false; } - ENUM_INDI_VS_TYPE _requested_vs_type; + ENUM_INDI_DATA_VS_TYPE _requested_vs_type; if (_suitable_types.HasFlag(INDI_SUITABLE_DS_TYPE_AP)) { _requested_vs_type = GetAppliedPriceValueStorageType(); @@ -2040,5 +2051,3 @@ EMSCRIPTEN_BINDINGS(IndicatorData) { } #endif - -#endif // INDICATOR_DATA_H diff --git a/Indicator/IndicatorData.struct.h b/Indicator/IndicatorData.struct.h index 9b6d8525b..a73657229 100644 --- a/Indicator/IndicatorData.struct.h +++ b/Indicator/IndicatorData.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,9 +25,14 @@ * Includes IndicatorData's structs. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. #define STRUCT_ENUM_IDATA_PARAM STRUCT_ENUM(IndicatorDataParams, ENUM_IDATA_PARAM) -#define STRUCT_ENUM_INDICATOR_STATE_PROP STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP) +#define STRUCT_ENUM_INDICATOR_DATA_STATE_PROP STRUCT_ENUM(IndicatorDataState, ENUM_INDICATOR_DATA_STATE_PROP) // Includes. #include "../Serializer/SerializerConversions.h" @@ -39,7 +44,7 @@ union IndicatorDataEntryTypelessValue { double vdbl; float vflt; int vint; - long vlong; + int64 vlong; }; // Type-aware value for IndicatorDataEntry class. @@ -124,7 +129,7 @@ struct IndicatorDataEntryValue { double GetDbl() { return value.vdbl; } float GetFloat() { return value.vflt; } int GetInt() { return value.vint; } - long GetLong() { return value.vlong; } + int64 GetLong() { return value.vlong; } template void Get(T &_out) { _out = Get(); @@ -140,8 +145,8 @@ struct IndicatorDataEntryValue { void Get(float &_out) { _out = value.vflt; } void Get(int &_out) { _out = value.vint; } void Get(unsigned int &_out) { _out = (unsigned int)value.vint; } - void Get(long &_out) { _out = value.vlong; } - void Get(unsigned long &_out) { _out = (unsigned long)value.vint; } + void Get(int64 &_out) { _out = value.vlong; } + void Get(uint64 &_out) { _out = (uint64)value.vint; } // Setters. template void Set(T _value) { @@ -163,12 +168,12 @@ struct IndicatorDataEntryValue { value.vint = (int)_value; SetDataType(TYPE_UINT); } - void Set(long _value) { + void Set(int64 _value) { value.vlong = _value; SetDataType(TYPE_LONG); } - void Set(unsigned long _value) { - value.vlong = (long)_value; + void Set(uint64 _value) { + value.vlong = (int64)_value; SetDataType(TYPE_ULONG); } // Serializers. @@ -183,7 +188,7 @@ struct IndicatorDataEntryValue { /* Structure for indicator data entry. */ struct IndicatorDataEntry { - long timestamp; // Timestamp of the entry's bar. + int64 timestamp; // Timestamp of the entry's bar. unsigned short flags; // Indicator entry flags. ARRAY(IndicatorDataEntryValue, values); @@ -326,7 +331,7 @@ struct IndicatorDataEntry { int GetDayOfYear() { return DateTimeStatic::DayOfYear(timestamp); } int GetMonth() { return DateTimeStatic::Month(timestamp); } int GetYear() { return DateTimeStatic::Year(timestamp); } - long GetTime() { return timestamp; }; + int64 GetTime() { return timestamp; }; ENUM_DATATYPE GetDataType(int _mode) { return values[_mode].GetDataType(); } unsigned short GetDataTypeFlags(ENUM_DATATYPE _dt) { switch (_dt) { @@ -360,12 +365,12 @@ struct IndicatorDataEntry { // Setters. bool Resize(int _size = 0) { return _size > 0 ? ArrayResize(values, _size) > 0 : true; } // Value flag methods for bitwise operations. - bool CheckFlag(INDICATOR_ENTRY_FLAGS _prop) { return CheckFlags(_prop); } + bool CheckFlag(INDICATOR_DATA_ENTRY_FLAGS _prop) { return CheckFlags(_prop); } bool CheckFlags(unsigned short _flags) { return (flags & _flags) != 0; } bool CheckFlagsAll(unsigned short _flags) { return (flags & _flags) == _flags; } void AddFlags(unsigned short _flags) { flags |= _flags; } void RemoveFlags(unsigned short _flags) { flags &= ~_flags; } - void SetFlag(INDICATOR_ENTRY_FLAGS _flag, bool _value) { + void SetFlag(INDICATOR_DATA_ENTRY_FLAGS _flag, bool _value) { if (_value) { AddFlags(_flag); } else { @@ -407,7 +412,7 @@ struct IndicatorDataParams { protected: /* Struct protected variables */ int data_src_mode; // Mode used as input from data source. - int draw_window; // Drawing window. + int plot_window; // Ploting window. ENUM_DATATYPE dtype; // Type of basic data to store values (DTYPE_DOUBLE, DTYPE_INT). unsigned int max_modes; // Max supported indicator modes (values per entry). unsigned int max_buffers; // Max buffers to store. @@ -415,7 +420,7 @@ struct IndicatorDataParams { ENUM_IDATA_VALUE_RANGE idvrange; // Indicator's range value data type. color indi_color; // Indicator color. // @todo: Move to protected. - bool is_draw; // Draw active. + bool is_plot; // Plot active. bool is_fed; // Whether calc_start_bar is already calculated. int src_id; // Id of the indicator to be used as data source. int src_mode; // Mode of source indicator @@ -440,14 +445,14 @@ struct IndicatorDataParams { ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, ENUM_IDATA_VALUE_RANGE _idvrange = IDATA_RANGE_UNKNOWN, int _data_src_mode = 0) : data_src_mode(_data_src_mode), - draw_window(0), + plot_window(0), dtype(_dtype), max_modes(_max_modes), max_buffers(10), idstype(_idstype), idvrange(_idvrange), indi_color(clrNONE), - is_draw(false), + is_plot(false), is_fed(false), src_id(-1), src_mode(-1){}; @@ -523,43 +528,43 @@ struct IndicatorDataParams { } SetUserError(ERR_INVALID_PARAMETER); } - void SetDraw(bool _draw = true, int _window = 0) { - is_draw = _draw; - draw_window = _window; + void SetPlot(bool _plot = true, int _window = 0) { + is_plot = _plot; + plot_window = _window; } - void SetDraw(color _clr, int _window = 0) { - is_draw = true; + void SetPlot(color _clr, int _window = 0) { + is_plot = true; indi_color = _clr; - draw_window = _window; + plot_window = _window; } - bool IsDrawing() { return is_draw; } + bool IsPloting() { return is_plot; } void SetIndicatorColor(color _clr) { indi_color = _clr; } }; /* Structure for indicator state. */ -struct IndicatorState { +struct IndicatorDataState { public: // @todo: Change it to protected. int handle; // Indicator handle (MQL5 only). bool is_changed; // Set when params has been recently changed. bool is_ready; // Set when indicator is ready (has valid values). public: - enum ENUM_INDICATOR_STATE_PROP { - INDICATOR_STATE_PROP_HANDLE, - INDICATOR_STATE_PROP_IS_CHANGED, - INDICATOR_STATE_PROP_IS_READY, + enum ENUM_INDICATOR_DATA_STATE_PROP { + INDICATOR_DATA_STATE_PROP_HANDLE, + INDICATOR_DATA_STATE_PROP_IS_CHANGED, + INDICATOR_DATA_STATE_PROP_IS_READY, }; // Constructor. - IndicatorState() : handle(INVALID_HANDLE), is_changed(true), is_ready(false) {} + IndicatorDataState() : handle(INVALID_HANDLE), is_changed(true), is_ready(false) {} // Getters. template - T Get(STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP) _prop) { + T Get(STRUCT_ENUM(IndicatorDataState, ENUM_INDICATOR_DATA_STATE_PROP) _prop) { switch (_prop) { - case INDICATOR_STATE_PROP_HANDLE: + case INDICATOR_DATA_STATE_PROP_HANDLE: return (T)handle; - case INDICATOR_STATE_PROP_IS_CHANGED: + case INDICATOR_DATA_STATE_PROP_IS_CHANGED: return (T)is_changed; - case INDICATOR_STATE_PROP_IS_READY: + case INDICATOR_DATA_STATE_PROP_IS_READY: return (T)is_ready; }; SetUserError(ERR_INVALID_PARAMETER); @@ -567,15 +572,15 @@ struct IndicatorState { } // Setters. template - void Set(STRUCT_ENUM(IndicatorState, ENUM_INDICATOR_STATE_PROP) _prop, T _value) { + void Set(STRUCT_ENUM(IndicatorDataState, ENUM_INDICATOR_DATA_STATE_PROP) _prop, T _value) { switch (_prop) { - case INDICATOR_STATE_PROP_HANDLE: + case INDICATOR_DATA_STATE_PROP_HANDLE: handle = (T)_value; break; - case INDICATOR_STATE_PROP_IS_CHANGED: + case INDICATOR_DATA_STATE_PROP_IS_CHANGED: is_changed = (T)_value; break; - case INDICATOR_STATE_PROP_IS_READY: + case INDICATOR_DATA_STATE_PROP_IS_READY: is_ready = (T)_value; break; default: diff --git a/Indicator/IndicatorData.struct.serialize.h b/Indicator/IndicatorData.struct.serialize.h index 21b5ee051..e6a9508f7 100644 --- a/Indicator/IndicatorData.struct.serialize.h +++ b/Indicator/IndicatorData.struct.serialize.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Includes IndicatorData's struct serializers. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "../Serializer/Serializer.h" // Forward class declaration. diff --git a/Indicator/IndicatorData.struct.signal.h b/Indicator/IndicatorData.struct.signal.h index 84c36d2db..485beb2f5 100644 --- a/Indicator/IndicatorData.struct.signal.h +++ b/Indicator/IndicatorData.struct.signal.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/IndicatorRenko.h b/Indicator/IndicatorRenko.h index 89d459b46..d95cd531d 100644 --- a/Indicator/IndicatorRenko.h +++ b/Indicator/IndicatorRenko.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2022, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,20 +25,17 @@ * An abstract class to implement Renko indicators. */ -// Ignore processing of this file if already included. -#ifndef INDICATOR_RENKO_H -#define INDICATOR_RENKO_H - #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once #endif // Includes. -#include "../Chart.struct.tf.h" +#include "../Platform/Chart/Chart.struct.tf.h" #include "IndicatorCandle.h" #include "IndicatorRenko.provider.h" #include "IndicatorRenko.struct.h" +#include "IndicatorTf.struct.h" /** * Renko candle type. @@ -79,9 +76,9 @@ class IndicatorRenko : public IndicatorCandle { /** * Called when new tick was emitted from IndicatorTick-based source. */ - virtual void OnTick(ItemsHistory, ItemsHistoryRenkoCandleProvider>* _history, long _time_ms, + virtual void OnTick(ItemsHistory, ItemsHistoryRenkoCandleProvider>* _history, int64 _time_ms, float _ask, float _bid) { ++tick_index; @@ -68,7 +68,7 @@ class ItemsHistoryRenkoCandleProvider : public ItemsHistoryCandleProvider { * Retrieves given number of items starting from the given microseconds or index (inclusive). "_dir" identifies if we * want previous or next items from selected starting point. */ - bool GetItems(ItemsHistory, ItemsHistoryRenkoCandleProvider>* _history, long _from_time_ms, + bool GetItems(ItemsHistory, ItemsHistoryRenkoCandleProvider>* _history, int64 _from_time_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _num_items, ARRAY_REF(CandleOCTOHLC, _out_arr)) { // Method is called if there is a missing item (candle) in the history. We need to regenerate it. diff --git a/Indicator/IndicatorRenko.struct.h b/Indicator/IndicatorRenko.struct.h index d7e160798..f2785506f 100644 --- a/Indicator/IndicatorRenko.struct.h +++ b/Indicator/IndicatorRenko.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2022, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/IndicatorTf.h b/Indicator/IndicatorTf.h index f00021569..8de961cde 100644 --- a/Indicator/IndicatorTf.h +++ b/Indicator/IndicatorTf.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,13 @@ * */ -// Ignore processing of this file if already included. -#ifndef INDICATOR_TF_H -#define INDICATOR_TF_H - #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once #endif // Includes. -#include "../Chart.struct.tf.h" +#include "../Platform/Chart/Chart.struct.tf.h" #include "IndicatorCandle.h" #include "IndicatorTf.provider.h" @@ -93,5 +89,3 @@ class IndicatorTf : public IndicatorCandle { /** * Called when new tick was emitted from IndicatorTick-based source. */ - void OnTick(ItemsHistory, ItemsHistoryTfCandleProvider>* _history, long _time_ms, float _ask, + void OnTick(ItemsHistory, ItemsHistoryTfCandleProvider>* _history, int64 _time_ms, float _ask, float _bid) { ++tick_index; @@ -110,8 +110,8 @@ class ItemsHistoryTfCandleProvider : public ItemsHistoryCandleProvider { /** * Returns start time of the candle (the place it's on the chart) for the given tick's time in milliseconds. */ - int GetCandleTimeFromTimeMs(long _time_ms, int _length_in_secs) { - return (int)((_time_ms - _time_ms % ((long)_length_in_secs * 1000)) / 1000); + int GetCandleTimeFromTimeMs(int64 _time_ms, int _length_in_secs) { + return (int)((_time_ms - _time_ms % ((int64)_length_in_secs * 1000)) / 1000); } /** @@ -119,7 +119,7 @@ class ItemsHistoryTfCandleProvider : public ItemsHistoryCandleProvider { * want previous or next items from selected starting point. Should return false if retrieving items by this method * is not available. */ - bool GetItems(ItemsHistory, ItemsHistoryTfCandleProvider>* _history, long _from_time_ms, + bool GetItems(ItemsHistory, ItemsHistoryTfCandleProvider>* _history, int64 _from_time_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _num_items, ARRAY_REF(CandleOCTOHLC, _out_arr)) { // Method is called if there is a missing item (candle) in the history. We need to regenerate it. if (_from_time_ms != 0) { @@ -146,11 +146,9 @@ class ItemsHistoryTfCandleProvider : public ItemsHistoryCandleProvider { while (_num_items > 0) { // Calculating time from which and to which we want to retrieve ticks to form a candle. int _ticks_from_s = GetCandleTimeFromTimeMs(_from_time_ms, spc); - long _ticks_from_ms = (long)_ticks_from_s * 1000; - long _candle_length_ms = (long)spc * 1000; - long _ticks_to_ms; - - _ticks_to_ms = _ticks_from_ms + (_candle_length_ms - 1); + int64 _ticks_from_ms = (int64)_ticks_from_s * 1000; + int64 _candle_length_ms = (int64)spc * 1000; + int64 _ticks_to_ms = _ticks_from_ms + _candle_length_ms - 1; if (_dir == ITEMS_HISTORY_DIRECTION_FORWARD) { // Backwards. diff --git a/Indicator/IndicatorTf.struct.h b/Indicator/IndicatorTf.struct.h index 606023e17..5a4d80f92 100644 --- a/Indicator/IndicatorTf.struct.h +++ b/Indicator/IndicatorTf.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/IndicatorTick.h b/Indicator/IndicatorTick.h index f9bbfbb9e..eb1cf1e12 100644 --- a/Indicator/IndicatorTick.h +++ b/Indicator/IndicatorTick.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,7 +30,7 @@ #endif // Includes. -#include "../Buffer/BufferTick.h" +#include "../Storage/Dict/Buffer/BufferTick.h" #include "Indicator.h" #include "Indicator.struct.h" #include "IndicatorTick.provider.h" @@ -131,19 +131,19 @@ class IndicatorTick : public Indicator { /** * Returns value storage of given kind. */ - IValueStorage* GetSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + IValueStorage* GetSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { Print("IndicatorTick::GetSpecificValueStorage() is no longer available!"); /* switch (_type) { - case INDI_VS_TYPE_PRICE_ASK: + case INDI_DATA_VS_TYPE_PRICE_ASK: return (IValueStorage*)itdata.GetAskValueStorage(); - case INDI_VS_TYPE_PRICE_BID: + case INDI_DATA_VS_TYPE_PRICE_BID: return (IValueStorage*)itdata.GetBidValueStorage(); - case INDI_VS_TYPE_SPREAD: + case INDI_DATA_VS_TYPE_SPREAD: return (IValueStorage*)itdata.GetSpreadValueStorage(); - case INDI_VS_TYPE_VOLUME: + case INDI_DATA_VS_TYPE_VOLUME: return (IValueStorage*)itdata.GetVolumeValueStorage(); - case INDI_VS_TYPE_TICK_VOLUME: + case INDI_DATA_VS_TYPE_TICK_VOLUME: return (IValueStorage*)itdata.GetTickVolumeValueStorage(); default: // Trying in parent class. @@ -156,13 +156,13 @@ class IndicatorTick : public Indicator { /** * Checks whether indicator support given value storage type. */ - bool HasSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + bool HasSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { switch (_type) { - case INDI_VS_TYPE_PRICE_ASK: - case INDI_VS_TYPE_PRICE_BID: - case INDI_VS_TYPE_SPREAD: - case INDI_VS_TYPE_VOLUME: - case INDI_VS_TYPE_TICK_VOLUME: + case INDI_DATA_VS_TYPE_PRICE_ASK: + case INDI_DATA_VS_TYPE_PRICE_BID: + case INDI_DATA_VS_TYPE_SPREAD: + case INDI_DATA_VS_TYPE_VOLUME: + case INDI_DATA_VS_TYPE_TICK_VOLUME: return true; default: break; @@ -256,7 +256,7 @@ class IndicatorTick : public Indicator { * Converts TickAB into IndicatorDataEntry. */ template -IndicatorDataEntry TickToEntry(long _timestamp, TickAB& _tick) { +IndicatorDataEntry TickToEntry(int64 _timestamp, TickAB& _tick) { IndicatorDataEntry _entry(2); _entry.timestamp = _timestamp; _entry.values[INDI_TICK_MODE_PRICE_ASK] = _tick.ask; diff --git a/Indicator/IndicatorTick.provider.h b/Indicator/IndicatorTick.provider.h index 1b4e5a62d..991cf9357 100644 --- a/Indicator/IndicatorTick.provider.h +++ b/Indicator/IndicatorTick.provider.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -49,7 +49,7 @@ class ItemsHistoryTickProvider : public ItemsHistoryItemProvider> { /** * Called when new tick was emitted from IndicatorTick-based source. */ - virtual void OnTick(ItemsHistory, ItemsHistoryTickProvider>* _history, long _time_ms, float _ask, + virtual void OnTick(ItemsHistory, ItemsHistoryTickProvider>* _history, int64 _time_ms, float _ask, float _bid) { TickTAB _tick(_time_ms, _ask, _bid); _history PTR_DEREF Append(_tick); @@ -60,7 +60,7 @@ class ItemsHistoryTickProvider : public ItemsHistoryItemProvider> { * want previous or next items from selected starting point. Should return false if retrieving items by this method * is not available. */ - bool GetItems(ItemsHistory, ItemsHistoryTickProvider>* _history, long _from_time_ms, + bool GetItems(ItemsHistory, ItemsHistoryTickProvider>* _history, int64 _from_time_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _num_items, ARRAY_REF(TickTAB, _out_arr)) { return false; } diff --git a/Indicator/IndicatorTickSource.h b/Indicator/IndicatorTickSource.h index eab3590d2..2e323fe56 100644 --- a/Indicator/IndicatorTickSource.h +++ b/Indicator/IndicatorTickSource.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -67,32 +67,32 @@ class IndicatorTickSource : public Indicator { if (_input_mode == -1) { // Source mode which acts as an applied price wasn't selected, so we have to ensure that source is a Tick // indicator. Valid only if implements bid or ask price. - _result &= _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_BID) || - _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_ASK); + _result &= _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_BID) || + _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_ASK); } else { // Applied price selected. We will select source indicator only if it provides price buffer for given applied // price. switch (_input_mode) { case PRICE_OPEN: - _result &= _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_OPEN); + _result &= _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_OPEN); break; case PRICE_HIGH: - _result &= _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_HIGH); + _result &= _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_HIGH); break; case PRICE_LOW: - _result &= _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_LOW); + _result &= _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_LOW); break; case PRICE_CLOSE: - _result &= _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_CLOSE); + _result &= _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_CLOSE); break; case PRICE_MEDIAN: - _result &= _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_MEDIAN); + _result &= _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_MEDIAN); break; case PRICE_TYPICAL: - _result &= _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_TYPICAL); + _result &= _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_TYPICAL); break; case PRICE_WEIGHTED: - _result &= _indi.HasSpecificValueStorage(INDI_VS_TYPE_PRICE_WEIGHTED); + _result &= _indi.HasSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_WEIGHTED); break; default: Alert("Invalid input mode ", _input_mode, " for indicator ", _indi.GetFullName(), diff --git a/Indicator/README.md b/Indicator/README.md index 83aa4e568..efe21e8ca 100644 --- a/Indicator/README.md +++ b/Indicator/README.md @@ -9,7 +9,8 @@ They can help with storing and accessing values and indicator parameters. ```mermaid classDiagram Object <|-- IndicatorBase - IndicatorBase <|-- Indicator + IndicatorBase <|-- IndicatorData + IndicatorData <|-- Indicator Indicator <|-- IndicatorCandle Indicator <|-- IndicatorCandleSource Indicator <|-- IndicatorTick @@ -22,10 +23,141 @@ classDiagram An abstract class for all type of indicators (a base class). +### `IndicatorData` class + +The purpose of `IndicatorData` class is to store indicator data. +It is basically alternative implementation of `Indicator` class. + +For more details, please read: +[Class to hold indicator values]( https://ea31337.github.io/EA31337-classes/issues/23). + +For implementation example, +check [`tests/IndicatorDataTest.mq5`](tests/IndicatorDataTest.mq5). + +### `GetEntryValue(int _mode, int _abs_shift)` - overridable method + +Method must be overriden in any new indicator +and MUST NOT apply shift from `iparams.shift`/`iparams.GetShift()`! +Shift 0 must always point to the value for the current tick. + +Returns indicators's value for a given mode and absolute shift +(the shift is directly passed to built-in methods such as iATR(), + OnCalculate methods such as `iVIDyAOnIndicator()` and also to `iCustom()`). + +For `OnCalculate()` methods such as iVIDyAOnIndicator(), +the shift is passed to `return _cache.GetTailValue(_mode, _shift);` +so we can return value calculated in the past +(or just retrieve **DBL_MAX** in case the value was not yet calculated). +Note that `OnCalculate()` methods uses single/multiple price buffers, +e.g., applied price or OHLCs from base indicator. + +In scenario of `VIDyA[shift = 2] <- Candle <- TickMt` call hierarchy looks like: + +```cpp +- VIDyA::GetEntry(_rel_shift = 1) // Then per each mode: +- entry.values[_mode] = Indicator::GetValue(_mode, _rel_shift = 1) +- VIDyA::GetEntryValue(_mode, _abs_shift = iparams.shift + 1) +- VIDyA::iVIDyAOnIndicator(..., _mode, _shift = 3) then: // Shift is absolute. +- VIDyA::iVIDyAOnArray(..., _mode, _shift = 3) then: // Shift is absolute. + return _cache.GetTailValue(_mode, _shift = 3); // Shift is absolute. +``` + +Last line means that we will retrieve **VIDyA** value shifted by 3 +(2 from `iparams.shift` + 1 from `GetEntry()`). +It is correct. + +### `GetEntryAlter(IndicatorDataEntry &_entry, int _rel_shift)` - overridable method + +Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). + +Method calls (seen in **MWMFI**, **CCI**, **Envelopes**, **Momentum**, **Pivot**): + +```cpp +- GetValue(_mode, _rel_shift) // GetValue() takes relative shift. +``` + +### `GetValue(int _mode = 0, int _rel_shift = 0)` - non-overridable method + +Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). + +Method calls: + +```cpp +- GetEntryValue(_mode, _abs_shift = iparams.shift + _rel_shift) +``` + +### `GetEntry(int _rel_shift = 0)` - overridable method + +Shift passed is relative to the shift from `IndicatorParams::shift` (read via `Indicator::iparams.shift`). + +If you need to access entries from absolute shift, use `GetEntryByAbsShift(int _abs_shift)`. + +Note that values accessed via index operator `storage[rel_shift]` e.g., +inside `OnCalculate()` methods like `double _o = open[rel_shift = 4].Get()` +will take relative shift and retrieve open price shifted by (in this scenario) +`4 + iparams.shift` set in base indicator: + +- `double _o = open[_rel_shift = 4]` +- `IndicatorBufferValueStorage::Fetch(_rel_shift = 4)` +- `IndicatorData::GetValue(_mode, _rel_shift = 4)` +- `Indicator::GetEntryValue(_mode, _abs_shift = iparams.shift + 4)` + // As GetEntryValue() takes absolute shift, we add shift from iparams.shift. +- `Indicator::GetEntry(_rel_shift = _abs_shift - iparams.shift)...` + // Converting absolute shift into relative one for GetEntry(). +- `...[_mode]; // IndicatorDataEntry.values[_mode].Get(...);` + +### `GetBarTime(int _rel_shift = 0)` + +Shift passed is relative to the shift from `IndicatorParams::shift` +(read via `Indicator::iparams.shift`). + +### `GetPrice(ENUM_APPLIED_PRICE _ap, int _rel_shift = 0)` + +Shift passed is relative to the shift from `IndicatorParams::shift` +(read via `Indicator::iparams.shift`). + +### GetBars() + +Number of returned bars is decremented by `IndicatorParams::shift` +(read via `Indicator::iparams.shift`). +Thus if there are **10** bars and *shift* is **8** then `GetBars()` will return **2**. +That means that you can safely do `GetEntry()` for relative shifts **0** or **1**. +There won't be any value in other relative shifts. + +### HistoryValueStorage::Fetch(int _rel_shift) + +Shift passed is relative to the shift from `IndicatorParams::shift` +(read via `Indicator::iparams.shift`). + +### `Indi_*::*OnIndicator(..., _shift, [_shift1], [_shift2])` + +All shifts passed are relative to the shift from `IndicatorParams::shift` +(read via `Indicator::iparams.shift`). + +### IndiBufferCache::GetValue()/GetTailValue(int _buffer_index, int _shift) + +Shift passed may be relative or absolute. It depends on the ValueStorage specialization. + +E.g., `HistoryValueStorage` operates on relative shifts, +but `NativeValueStorage` operates on absolute shift, +because it is unaware for which indicator values are stored. + +Thus way, `IndiBufferCache::GetValue()` and `IndiBufferCache::GetTailValue()` +also don't know which type of shift was passed. +However, all current indicators uses `NativeValueStorage` for storing indicator values, +so shift passed must is treated as absolute. + +In scenario where indicator (shift **2**) has **8** values in the buffer +with (assuming **10** candles have passed), +`GetEntry(0)` would retrieve cache value from shift + ## `Indicator` An abstract class (subclass of `IndicatorBase`) to implement all type of indicators. +The purpose of `Indicator` class is to provide common functionality +across all indicators such as storing and searching for values. + It implements structure for storing input parameters and buffer for accessing cached values by a given timestamp. diff --git a/Indicator/TickBarCounter.h b/Indicator/TickBarCounter.h index 45f0a102c..81eaa17a3 100644 --- a/Indicator/TickBarCounter.h +++ b/Indicator/TickBarCounter.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/Indicator.test.cpp b/Indicator/tests/Indicator.test.cpp new file mode 100644 index 000000000..fda0b8620 --- /dev/null +++ b/Indicator/tests/Indicator.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of IndicatorBase class. + */ + +// Includes. +#include "../Indicator.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicator/tests/Indicator.test.mq4 b/Indicator/tests/Indicator.test.mq4 index d7d056e30..d52cb6515 100644 --- a/Indicator/tests/Indicator.test.mq4 +++ b/Indicator/tests/Indicator.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/Indicator.test.mq5 b/Indicator/tests/Indicator.test.mq5 index 56fa3ee98..750818713 100644 --- a/Indicator/tests/Indicator.test.mq5 +++ b/Indicator/tests/Indicator.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,8 +25,8 @@ */ // Includes. -#include "../Indicator.h" #include "../../Test.mqh" +#include "../Indicator.h" /** * Implements OnInit(). diff --git a/Indicator/tests/IndicatorBase.test.cpp b/Indicator/tests/IndicatorBase.test.cpp new file mode 100644 index 000000000..b63b617b4 --- /dev/null +++ b/Indicator/tests/IndicatorBase.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of IndicatorBase class. + */ + +// Includes. +#include "../IndicatorBase.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicator/tests/IndicatorBase.test.mq4 b/Indicator/tests/IndicatorBase.test.mq4 index fbff42af3..749a6949b 100644 --- a/Indicator/tests/IndicatorBase.test.mq4 +++ b/Indicator/tests/IndicatorBase.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/IndicatorBase.test.mq5 b/Indicator/tests/IndicatorBase.test.mq5 index 986873152..c0af977c1 100644 --- a/Indicator/tests/IndicatorBase.test.mq5 +++ b/Indicator/tests/IndicatorBase.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/IndicatorCandle.test.cpp b/Indicator/tests/IndicatorCandle.test.cpp new file mode 100644 index 000000000..ccc03a921 --- /dev/null +++ b/Indicator/tests/IndicatorCandle.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of IndicatorCandle class. + */ + +// Includes. +#include "../IndicatorCandle.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicator/tests/IndicatorCandle.test.mq4 b/Indicator/tests/IndicatorCandle.test.mq4 index abfdd62e5..181462e9f 100644 --- a/Indicator/tests/IndicatorCandle.test.mq4 +++ b/Indicator/tests/IndicatorCandle.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/IndicatorCandle.test.mq5 b/Indicator/tests/IndicatorCandle.test.mq5 index 460c31890..cc0221e8b 100644 --- a/Indicator/tests/IndicatorCandle.test.mq5 +++ b/Indicator/tests/IndicatorCandle.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../IndicatorCandle.h" diff --git a/Indicator/tests/IndicatorData.test.cpp b/Indicator/tests/IndicatorData.test.cpp new file mode 100644 index 000000000..8ee025c3f --- /dev/null +++ b/Indicator/tests/IndicatorData.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of IndicatorData class. + */ + +// Includes. +#include "../IndicatorData.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicator/tests/IndicatorData.test.mq4 b/Indicator/tests/IndicatorData.test.mq4 index a91592e9f..9b2ab7a18 100644 --- a/Indicator/tests/IndicatorData.test.mq4 +++ b/Indicator/tests/IndicatorData.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/IndicatorData.test.mq5 b/Indicator/tests/IndicatorData.test.mq5 index 0bf82d51a..26f706034 100644 --- a/Indicator/tests/IndicatorData.test.mq5 +++ b/Indicator/tests/IndicatorData.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/IndicatorRenko.test.cpp b/Indicator/tests/IndicatorRenko.test.cpp new file mode 100644 index 000000000..89ab2fc4e --- /dev/null +++ b/Indicator/tests/IndicatorRenko.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of IndicatorBase class. + */ + +// Includes. +#include "../IndicatorRenko.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicator/tests/IndicatorRenko.test.mq4 b/Indicator/tests/IndicatorRenko.test.mq4 index c1e3ff307..f33c4a776 100644 --- a/Indicator/tests/IndicatorRenko.test.mq4 +++ b/Indicator/tests/IndicatorRenko.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2022, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/IndicatorRenko.test.mq5 b/Indicator/tests/IndicatorRenko.test.mq5 index 80ff7d3b5..e28e4d959 100644 --- a/Indicator/tests/IndicatorRenko.test.mq5 +++ b/Indicator/tests/IndicatorRenko.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,8 +28,8 @@ // Includes. #include "../../Indicators/Indi_AMA.mqh" -#include "../../Indicators/Tick/Indi_TickMt.mqh" -#include "../../Platform.h" +#include "../../Indicators/Tick/Indi_TickMt.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../../Util.h" #include "../IndicatorRenko.h" diff --git a/Indicator/tests/IndicatorTf.test.cpp b/Indicator/tests/IndicatorTf.test.cpp new file mode 100644 index 000000000..6aab42928 --- /dev/null +++ b/Indicator/tests/IndicatorTf.test.cpp @@ -0,0 +1,37 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of IndicatorTf class. + * Test C++ compilation of IndicatorBase class. + */ + +// Includes. +#include "../IndicatorTf.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicator/tests/IndicatorTf.test.mq4 b/Indicator/tests/IndicatorTf.test.mq4 index e1641b942..0eb038602 100644 --- a/Indicator/tests/IndicatorTf.test.mq4 +++ b/Indicator/tests/IndicatorTf.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/IndicatorTf.test.mq5 b/Indicator/tests/IndicatorTf.test.mq5 index 11916f2ff..f2794f25e 100644 --- a/Indicator/tests/IndicatorTf.test.mq5 +++ b/Indicator/tests/IndicatorTf.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -27,12 +27,12 @@ */ // Includes. -#include "../../DictBase.mqh" +#include "../../Exchange/SymbolInfo/SymbolInfo.h" #include "../../Indicators/Indi_AMA.mqh" -#include "../../Indicators/Tick/Indi_TickMt.mqh" +#include "../../Indicators/Tick/Indi_TickMt.h" #include "../../Log.mqh" -#include "../../Platform.h" -#include "../../SymbolInfo.mqh" +#include "../../Platform/Platform.h" +#include "../../Storage/Dict/DictBase.h" #include "../../Test.mqh" #include "../../Util.h" #include "../IndicatorTf.h" @@ -119,7 +119,7 @@ void OnTick() { string c = DoubleToStr(iClose(_Symbol, PERIOD_CURRENT, 0), 5); string time = TimeToString(iTime(_Symbol, PERIOD_CURRENT, 0), TIME_DATE | TIME_MINUTES | TIME_SECONDS); - Util::Print("Tick: " + IntegerToString((long)iTime(indi_tf_real.Ptr().GetSymbol(), indi_tf_real.Ptr().GetTf(), 0)) + + Util::Print("Tick: " + IntegerToString((int64)iTime(indi_tf_real.Ptr().GetSymbol(), indi_tf_real.Ptr().GetTf(), 0)) + " (" + time + "), real = " + o + ", " + h + ", " + l + ", " + c); string c_o = DoubleToStr(indi_tf_real.Ptr().GetOpen(0), 5); diff --git a/Indicator/tests/IndicatorTick.test.cpp b/Indicator/tests/IndicatorTick.test.cpp new file mode 100644 index 000000000..123f8d6eb --- /dev/null +++ b/Indicator/tests/IndicatorTick.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of IndicatorTick class. + */ + +// Includes. +#include "../IndicatorTick.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicator/tests/IndicatorTick.test.mq4 b/Indicator/tests/IndicatorTick.test.mq4 index 8800317fb..3e306aae4 100644 --- a/Indicator/tests/IndicatorTick.test.mq4 +++ b/Indicator/tests/IndicatorTick.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/IndicatorTick.test.mq5 b/Indicator/tests/IndicatorTick.test.mq5 index 31ff469c3..6fdaff32f 100644 --- a/Indicator/tests/IndicatorTick.test.mq5 +++ b/Indicator/tests/IndicatorTick.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../IndicatorTick.h" #include "classes/IndicatorTickDummy.h" @@ -39,7 +39,7 @@ int OnInit() { Ref _indi_tick = new IndicatorTickDummy(_Symbol); Platform::Add(_indi_tick.Ptr()); - long _time = 1; + int64 _time = 1; for (double _price = 0.1; _price <= 2.0; _price += 0.1) { TickTAB _tick(_time++ * 1000, _price, _price); diff --git a/Indicator/tests/Makefile b/Indicator/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicator/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Indicator/tests/classes/IndicatorTfDummy.h b/Indicator/tests/classes/IndicatorTfDummy.h index 0648a1908..baab51c03 100644 --- a/Indicator/tests/classes/IndicatorTfDummy.h +++ b/Indicator/tests/classes/IndicatorTfDummy.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,7 +30,7 @@ #endif // Includes. -#include "../../../Platform.define.h" +#include "../../../Platform/Platform.define.h" #include "../../IndicatorTf.h" #include "../../IndicatorTf.struct.h" diff --git a/Indicator/tests/classes/IndicatorTickDummy.h b/Indicator/tests/classes/IndicatorTickDummy.h index b2b7247f3..21b93a5b5 100644 --- a/Indicator/tests/classes/IndicatorTickDummy.h +++ b/Indicator/tests/classes/IndicatorTickDummy.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicator/tests/classes/Indicators.h b/Indicator/tests/classes/Indicators.h index e5d11c23e..eeb845dbe 100644 --- a/Indicator/tests/classes/Indicators.h +++ b/Indicator/tests/classes/Indicators.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/Account/Indi_AccountStats.mqh b/Indicators/Account/Indi_AccountStats.mqh index 10f2946c8..7efd685d0 100644 --- a/Indicators/Account/Indi_AccountStats.mqh +++ b/Indicators/Account/Indi_AccountStats.mqh @@ -21,10 +21,10 @@ */ // Includes. -#include "../../Account/AccountBase.h" -#include "../../BufferStruct.mqh" +#include "../../Exchange/Account/AccountBase.h" +#include "../../Storage/Dict/Buffer/BufferStruct.h" #include "../../Indicator/Indicator.h" -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Storage/Objects.h" // Structs. @@ -71,7 +71,7 @@ class Indi_AccountStats : public Indicator { Indi_AccountStats(Indi_AccountStats_Params &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) : Indicator(_p, - IndicatorDataParams::GetInstance(INDI_VS_TYPE_ACCOUNT_STATS_BUFFERS_COUNT, TYPE_DOUBLE, _idstype, + IndicatorDataParams::GetInstance(INDI_DATA_VS_TYPE_ACCOUNT_STATS_BUFFERS_COUNT, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), _indi_src) { InitAccountStats(); @@ -79,7 +79,7 @@ class Indi_AccountStats : public Indicator { Indi_AccountStats(int _shift = 0, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) : Indicator(Indi_AccountStats_Params(), - IndicatorDataParams::GetInstance(INDI_VS_TYPE_ACCOUNT_STATS_BUFFERS_COUNT, TYPE_DOUBLE, _idstype, + IndicatorDataParams::GetInstance(INDI_DATA_VS_TYPE_ACCOUNT_STATS_BUFFERS_COUNT, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), _indi_src) { InitAccountStats(); @@ -120,19 +120,19 @@ class Indi_AccountStats : public Indicator { int _ishift = _shift >= 0 ? _shift : iparams.GetShift(); // Converting mode into value storage type. - ENUM_INDI_VS_TYPE _vs_type = (ENUM_INDI_VS_TYPE)(INDI_VS_TYPE_ACCOUNT_STATS_INDEX_FIRST + _mode); + ENUM_INDI_DATA_VS_TYPE _vs_type = (ENUM_INDI_DATA_VS_TYPE)(INDI_DATA_VS_TYPE_ACCOUNT_STATS_INDEX_FIRST + _mode); // Retrieving data from specific value storage. switch (_vs_type) { - case INDI_VS_TYPE_ACCOUNT_STATS_DATE_TIME: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_DATE_TIME: return ((ValueStorage *)GetSpecificValueStorage(_vs_type))PTR_DEREF FetchSeries(_ishift); - case INDI_VS_TYPE_ACCOUNT_STATS_BALANCE: - case INDI_VS_TYPE_ACCOUNT_STATS_CREDIT: - case INDI_VS_TYPE_ACCOUNT_STATS_EQUITY: - case INDI_VS_TYPE_ACCOUNT_STATS_PROFIT: - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_USED: - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_FREE: - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_BALANCE: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_CREDIT: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_EQUITY: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_PROFIT: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_USED: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_FREE: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL: return ((ValueStorage *)GetSpecificValueStorage(_vs_type))PTR_DEREF FetchSeries(_ishift); default: Alert("Error: Indi_AccountStats: Invalid mode passed to GetEntryValue()!"); @@ -144,23 +144,23 @@ class Indi_AccountStats : public Indicator { /** * Returns value storage of given kind. */ - IValueStorage *GetSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + IValueStorage *GetSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { switch (_type) { - case INDI_VS_TYPE_ACCOUNT_STATS_DATE_TIME: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_DATE_TIME: return buffer_date_time.Ptr(); - case INDI_VS_TYPE_ACCOUNT_STATS_BALANCE: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_BALANCE: return buffer_balance.Ptr(); - case INDI_VS_TYPE_ACCOUNT_STATS_CREDIT: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_CREDIT: return buffer_credit.Ptr(); - case INDI_VS_TYPE_ACCOUNT_STATS_EQUITY: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_EQUITY: return buffer_equity.Ptr(); - case INDI_VS_TYPE_ACCOUNT_STATS_PROFIT: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_PROFIT: return buffer_profit.Ptr(); - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_USED: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_USED: return buffer_margin_used.Ptr(); - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_FREE: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_FREE: return buffer_margin_free.Ptr(); - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL: return buffer_margin_avail.Ptr(); default: // Trying in parent class. @@ -171,16 +171,16 @@ class Indi_AccountStats : public Indicator { /** * Checks whether indicator support given value storage type. */ - bool HasSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + bool HasSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { switch (_type) { - case INDI_VS_TYPE_ACCOUNT_STATS_DATE_TIME: - case INDI_VS_TYPE_ACCOUNT_STATS_BALANCE: - case INDI_VS_TYPE_ACCOUNT_STATS_CREDIT: - case INDI_VS_TYPE_ACCOUNT_STATS_EQUITY: - case INDI_VS_TYPE_ACCOUNT_STATS_PROFIT: - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_USED: - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_FREE: - case INDI_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_DATE_TIME: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_BALANCE: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_CREDIT: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_EQUITY: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_PROFIT: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_USED: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_FREE: + case INDI_DATA_VS_TYPE_ACCOUNT_STATS_MARGIN_AVAIL: return true; default: // Trying in parent class. diff --git a/Indicators/Account/tests/Indi_AccountStats.test.mq4 b/Indicators/Account/tests/Indi_AccountStats.test.mq4 index d8a5e20cc..524d12dcd 100644 --- a/Indicators/Account/tests/Indi_AccountStats.test.mq4 +++ b/Indicators/Account/tests/Indi_AccountStats.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/Account/tests/Indi_AccountStats.test.mq5 b/Indicators/Account/tests/Indi_AccountStats.test.mq5 index 81bca2d2d..59f804970 100644 --- a/Indicators/Account/tests/Indi_AccountStats.test.mq5 +++ b/Indicators/Account/tests/Indi_AccountStats.test.mq5 @@ -20,8 +20,7 @@ */ // Includes. -#include "../../../Account/AccountMt.h" -#include "../../../Platform.h" +#include "../../../Exchange/Account/AccountMt.h" #include "../../../Test.mqh" #include "../Indi_AccountStats.mqh" @@ -50,7 +49,7 @@ void OnTick() { Platform::Tick(); if (Platform::IsNewMinute()) { IndicatorDataEntry _entry = indi_account_mt REF_DEREF GetEntry(); - bool _is_ready = indi_account_mt REF_DEREF Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY)); + bool _is_ready = indi_account_mt REF_DEREF Get(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_IS_READY)); bool _is_valid = _entry.IsValid(); Print(indi_account_mt REF_DEREF ToString(), _is_ready ? "" : " (Not yet ready)"); if (_is_ready && !_is_valid) { diff --git a/Indicators/Bitwise/Indi_Candle.mqh b/Indicators/Bitwise/Indi_Candle.mqh index 098146b8f..bd2bd31e0 100644 --- a/Indicators/Bitwise/Indi_Candle.mqh +++ b/Indicators/Bitwise/Indi_Candle.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,18 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../../Bar.struct.h" -#include "../../BufferStruct.mqh" #include "../../Indicator/Indicator.h" #include "../../Pattern.struct.h" #include "../../Serializer/Serializer.h" -#include "../Price/Indi_Price.mqh" +#include "../../Storage/Dict/Buffer/BufferStruct.h" +#include "../Price/Indi_Price.h" #include "../Special/Indi_Math.mqh" // Structs. @@ -105,7 +110,7 @@ class Indi_Candle : public Indicator { // must have at least 4 buffers and define OHLC in the first 4 buffers. // Indi_Price is an example of such indicator. if (!indi_src.IsSet()) { - GetLogger().Error( + GetLogger() PTR_DEREF Error( "In order use custom indicator as a source, you need to select one using SetIndicatorData() method, " "which is a part of CandleParams structure.", "Indi_Candle"); @@ -117,10 +122,10 @@ class Indi_Candle : public Indicator { break; } - _ohlcs[0].open = GetDataSource().GetValue(PRICE_OPEN, ToRelShift(_abs_shift)); - _ohlcs[0].high = GetDataSource().GetValue(PRICE_HIGH, ToRelShift(_abs_shift)); - _ohlcs[0].low = GetDataSource().GetValue(PRICE_LOW, ToRelShift(_abs_shift)); - _ohlcs[0].close = GetDataSource().GetValue(PRICE_CLOSE, ToRelShift(_abs_shift)); + _ohlcs[0].open = GetDataSource() PTR_DEREF GetValue(PRICE_OPEN, ToRelShift(_abs_shift)); + _ohlcs[0].high = GetDataSource() PTR_DEREF GetValue(PRICE_HIGH, ToRelShift(_abs_shift)); + _ohlcs[0].low = GetDataSource() PTR_DEREF GetValue(PRICE_LOW, ToRelShift(_abs_shift)); + _ohlcs[0].close = GetDataSource() PTR_DEREF GetValue(PRICE_CLOSE, ToRelShift(_abs_shift)); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Bitwise/Indi_Pattern.mqh b/Indicators/Bitwise/Indi_Pattern.mqh index cdcc5ae6a..6ad40f135 100644 --- a/Indicators/Bitwise/Indi_Pattern.mqh +++ b/Indicators/Bitwise/Indi_Pattern.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,14 +20,19 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../../Bar.struct.h" -#include "../../BufferStruct.mqh" #include "../../Indicator/Indicator.define.h" #include "../../Indicator/Indicator.h" #include "../../Pattern.struct.h" #include "../../Serializer/Serializer.h" -#include "../Price/Indi_Price.mqh" +#include "../../Storage/Dict/Buffer/BufferStruct.h" +#include "../Price/Indi_Price.h" #include "../Special/Indi_Math.mqh" // Structs. @@ -88,9 +93,9 @@ class Indi_Pattern : public Indicator { int i; int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); - INDI_REQUIRE_SHIFT_OR_RETURN(GetCandle(), ToRelShift(_abs_shift) + _max_modes, WRONG_VALUE); + INDI_REQUIRE_SHIFT_OR_RETURN(GetCandle(), ToRelShift(_abs_shift) + _max_modes, (double)WRONG_VALUE); - BarOHLC _ohlcs[8]; + FIXED_ARRAY(BarOHLC, _ohlcs, 8); switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_BUILTIN: @@ -99,7 +104,7 @@ class Indi_Pattern : public Indicator { _ohlcs[i] = GetCandle() PTR_DEREF GetOHLC(ToRelShift(_abs_shift) + i); if (!_ohlcs[i].IsValid()) { // Return empty entry on invalid candles. - return WRONG_VALUE; + return (double)WRONG_VALUE; } } break; @@ -108,7 +113,7 @@ class Indi_Pattern : public Indicator { // must have at least 4 buffers and define OHLC in the first 4 buffers. // Indi_Price is an example of such indicator. if (!indi_src.IsSet()) { - GetLogger().Error( + GetLogger() PTR_DEREF Error( "In order use custom indicator as a source, you need to select one using SetIndicatorData() method, " "which is a part of PatternParams structure.", "Indi_Pattern"); @@ -117,23 +122,23 @@ class Indi_Pattern : public Indicator { "SetIndicatorData() " "method, which is a part of PatternParams structure."); SetUserError(ERR_INVALID_PARAMETER); - return WRONG_VALUE; + return (double)WRONG_VALUE; } for (i = 0; i < _max_modes; ++i) { - _ohlcs[i].open = GetDataSource().GetValue(PRICE_OPEN, ToRelShift(_abs_shift) + i); - _ohlcs[i].high = GetDataSource().GetValue(PRICE_HIGH, ToRelShift(_abs_shift) + i); - _ohlcs[i].low = GetDataSource().GetValue(PRICE_LOW, ToRelShift(_abs_shift) + i); - _ohlcs[i].close = GetDataSource().GetValue(PRICE_CLOSE, ToRelShift(_abs_shift) + i); + _ohlcs[i].open = GetDataSource() PTR_DEREF GetValue(PRICE_OPEN, ToRelShift(_abs_shift) + i); + _ohlcs[i].high = GetDataSource() PTR_DEREF GetValue(PRICE_HIGH, ToRelShift(_abs_shift) + i); + _ohlcs[i].low = GetDataSource() PTR_DEREF GetValue(PRICE_LOW, ToRelShift(_abs_shift) + i); + _ohlcs[i].close = GetDataSource() PTR_DEREF GetValue(PRICE_CLOSE, ToRelShift(_abs_shift) + i); if (!_ohlcs[i].IsValid()) { // Return empty entry on invalid candles. - return WRONG_VALUE; + return (double)WRONG_VALUE; } } break; default: SetUserError(ERR_INVALID_PARAMETER); - return WRONG_VALUE; + return (double)WRONG_VALUE; } PatternEntry pattern(_ohlcs); return pattern[_mode + 1]; diff --git a/Indicators/Bitwise/README.md b/Indicators/Bitwise/README.md new file mode 100644 index 000000000..929d5a81f --- /dev/null +++ b/Indicators/Bitwise/README.md @@ -0,0 +1,35 @@ +# Bitwise indicators + +Bitwise indicators are a specialized category of technical indicators +in which information is stored and represented using binary bits instead of numerical values. +These indicators utilize a binary system, +with each bit representing a specific condition or pattern that is being analyzed. + +One example of a bitwise indicator is the Pattern indicator. +This indicator focuses on identifying various chart patterns, +such as bullish or bearish candles, doji patterns, +double top or bottom formations, reversals, or other candlestick patterns. +Instead of providing numerical values or calculations, +the Pattern indicator uses activation bits to store information +about the presence or absence of specific chart patterns. + +When a particular pattern is detected and considered active, +the corresponding bit or bits associated with that pattern are set to "1" (as active). +Conversely, if the pattern is not present or not active, +the associated bits are set to "0" (as inactive). + +By using the Pattern indicator or similar bitwise indicators, +traders can streamline their analysis and focus on specific patterns +that may indicate potential trading opportunities. + +By using bitwise representation, the Bitwise indicators can efficiently store information +about multiple conditions within a compact binary format. +Traders can then interpret the activated bits to identify +and analyze the occurrence of specific conditions in the market. + +These bitwise indicators can be helpful for traders who rely on pattern recognition +and want to automate the identification process. + +In summary, bitwise indicators in Forex utilize binary bits +to store and represent information about specific conditions or patterns. +This allows traders to efficiently automate pattern recognition and enhance their trading analysis. diff --git a/Indicators/Bitwise/indicators.h b/Indicators/Bitwise/includes.h similarity index 80% rename from Indicators/Bitwise/indicators.h rename to Indicators/Bitwise/includes.h index 2cb3bb23c..740c61001 100644 --- a/Indicators/Bitwise/indicators.h +++ b/Indicators/Bitwise/includes.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Include file to include all bitwise indicators. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Bitwise indicators. #include "Indi_Candle.mqh" #include "Indi_Pattern.mqh" diff --git a/Indicators/Bitwise/tests/Indi_Candle.test.cpp b/Indicators/Bitwise/tests/Indi_Candle.test.cpp new file mode 100644 index 000000000..edc1a920a --- /dev/null +++ b/Indicators/Bitwise/tests/Indi_Candle.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Candle indicator class. + */ + +// Includes. +#include "../Indi_Candle.mqh" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/Bitwise/tests/Indi_Candle.test.mq4 b/Indicators/Bitwise/tests/Indi_Candle.test.mq4 new file mode 100644 index 000000000..7d47515c3 --- /dev/null +++ b/Indicators/Bitwise/tests/Indi_Candle.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Indi_Candle indicator class. + */ + +#include "Indi_Candle.test.mq5" diff --git a/Indicators/Bitwise/tests/Indi_Candle.test.mq5 b/Indicators/Bitwise/tests/Indi_Candle.test.mq5 new file mode 100644 index 000000000..1ae0955ab --- /dev/null +++ b/Indicators/Bitwise/tests/Indi_Candle.test.mq5 @@ -0,0 +1,31 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Includes. +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Candle.mqh" + +/** + * @file + * Test functionality of Indi_Candle indicator class. + */ +TEST_INDICATOR_DEFAULT_BINDINGS(Indi_Candle); diff --git a/Indicators/Bitwise/tests/Indi_Pattern.test.cpp b/Indicators/Bitwise/tests/Indi_Pattern.test.cpp new file mode 100644 index 000000000..03983c4f8 --- /dev/null +++ b/Indicators/Bitwise/tests/Indi_Pattern.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Pattern indicator class. + */ + +// Includes. +#include "../Indi_Pattern.mqh" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Pattern.test.mq4 b/Indicators/Bitwise/tests/Indi_Pattern.test.mq4 similarity index 87% rename from Indicators/tests/Indi_Pattern.test.mq4 rename to Indicators/Bitwise/tests/Indi_Pattern.test.mq4 index 450365f04..d6d0b64c4 100644 --- a/Indicators/tests/Indi_Pattern.test.mq4 +++ b/Indicators/Bitwise/tests/Indi_Pattern.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Pattern.test.mq5 b/Indicators/Bitwise/tests/Indi_Pattern.test.mq5 similarity index 81% rename from Indicators/tests/Indi_Pattern.test.mq5 rename to Indicators/Bitwise/tests/Indi_Pattern.test.mq5 index 44e4c4409..8f0101e53 100644 --- a/Indicators/tests/Indi_Pattern.test.mq5 +++ b/Indicators/Bitwise/tests/Indi_Pattern.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Bitwise/Indi_Pattern.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Pattern.mqh" /** * @file diff --git a/Indicators/Bitwise/tests/Makefile b/Indicators/Bitwise/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/Bitwise/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/DrawIndicator.mqh b/Indicators/DrawIndicator.mqh similarity index 87% rename from DrawIndicator.mqh rename to Indicators/DrawIndicator.mqh index d9bc1da44..eb9c16a03 100644 --- a/DrawIndicator.mqh +++ b/Indicators/DrawIndicator.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,17 +25,16 @@ * Group of functions intended for working with graphic objects relating to any specified chart. */ -// Ignore processing of this file if already included. -#ifndef DRAW_INDICATOR_MQH -#define DRAW_INDICATOR_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "DictObject.mqh" -#include "Draw.mqh" -#include "Object.mqh" - -// Forward declaration. -class IndicatorBase; +#include "../Indicator/IndicatorBase.h" +#include "../Platform/Plot.h" +#include "../Storage/Dict/DictObject.h" +#include "../Storage/Object.h" class DrawPoint { public: @@ -54,7 +53,7 @@ class DrawPoint { class DrawIndicator { protected: color color_line; - Draw* draw; + Plot* draw; IndicatorBase* indi; bool enabled; int window; @@ -70,7 +69,7 @@ class DrawIndicator { */ DrawIndicator(IndicatorBase* _indi) : indi(_indi), enabled(false), window(0) { // color_line = Object::IsValid(_indi) ? _indi.GetParams().indi_color : clrRed; // @fixme - draw = new Draw(); + draw = new Plot(); } /** @@ -112,7 +111,7 @@ class DrawIndicator { void SetWindow(int _window) { window = _window; } /** - * Draw line from the last point. + * Plot a line from the last point. */ void DrawLineTo(string _name, datetime _time, double _value, int _window = -1) { if (!enabled) { @@ -137,4 +136,3 @@ class DrawIndicator { } } }; -#endif // DRAW_INDICATOR_MQH diff --git a/Indicators/Indi_AC.mqh b/Indicators/Indi_AC.mqh index 2e0a1f74e..26c957dad 100644 --- a/Indicators/Indi_AC.mqh +++ b/Indicators/Indi_AC.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,8 +26,8 @@ #endif // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" // Structs. struct IndiACParams : IndicatorParams { @@ -95,10 +95,18 @@ class Indi_AC : public Indicator { */ static double iAC(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iAC(_symbol, _tf, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iAC(_symbol, _tf), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -131,7 +139,7 @@ class Indi_AC : public Indicator { if (!Objects::TryGet(_key, _ptr)) { _ptr = Objects::Set(_key, new Indi_AC()); // Assigning the same candle indicator for AC as in _indi. - _ptr.SetDataSource(_indi PTR_DEREF GetCandle()); + _ptr PTR_DEREF SetDataSource(_indi PTR_DEREF GetCandle()); } return _ptr; } diff --git a/Indicators/Indi_AD.mqh b/Indicators/Indi_AD.mqh index 8ea1a1ddb..226001099 100644 --- a/Indicators/Indi_AD.mqh +++ b/Indicators/Indi_AD.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iAD(string _symbol, int _tf, int _shift) { - ResetLastError(); - return Indi_AD::iAD(_symbol, (ENUM_TIMEFRAMES)_tf, _shift); -} -#endif - // Structs. struct IndiADParams : IndicatorParams { // Struct constructor. @@ -86,10 +83,18 @@ class Indi_AD : public Indicator { */ static double iAD(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iAD(_symbol, _tf, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iAD(_symbol, _tf, VOLUME_TICK), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -112,3 +117,11 @@ class Indi_AD : public Indicator { return _value; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iAD(string _symbol, int _tf, int _shift) { + ResetLastError(); + return Indi_AD::iAD(_symbol, (ENUM_TIMEFRAMES)_tf, _shift); +} +#endif diff --git a/Indicators/Indi_ADX.mqh b/Indicators/Indi_ADX.mqh index 7d29eef1b..bc874f9ba 100644 --- a/Indicators/Indi_ADX.mqh +++ b/Indicators/Indi_ADX.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,18 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#include "Price/Indi_Price.mqh" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iADX(string _symbol, int _tf, int _period, int _ap, int _mode, int _shift) { - ResetLastError(); - return Indi_ADX::iADX(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, (ENUM_INDI_ADX_LINE)_mode, - _shift); -} -#endif +#include "Price/Indi_Price.h" // Structs. struct IndiADXParams : IndicatorParams { @@ -106,10 +102,18 @@ class Indi_ADX : public Indicator { int _mode = LINE_MAIN_ADX, // (MT4/MT5): 0 - MODE_MAIN/MAIN_LINE, 1 - // MODE_PLUSDI/PLUSDI_LINE, 2 - MODE_MINUSDI/MINUSDI_LINE int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iADX(_symbol, _tf, _period, _applied_price, _mode, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iADX(_symbol, _tf, _period), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -168,3 +172,12 @@ class Indi_ADX : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iADX(string _symbol, int _tf, int _period, int _ap, int _mode, int _shift) { + ResetLastError(); + return Indi_ADX::iADX(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, (ENUM_INDI_ADX_LINE)_mode, + _shift); +} +#endif diff --git a/Indicators/Indi_ADXW.mqh b/Indicators/Indi_ADXW.mqh index 1bd721f6f..6b7fd44a6 100644 --- a/Indicators/Indi_ADXW.mqh +++ b/Indicators/Indi_ADXW.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.applied_price.h" #include "../Storage/ValueStorage.h" #include "../Storage/ValueStorage.spread.h" @@ -31,7 +36,7 @@ #include "../Storage/ValueStorage.volume.h" #include "../Util.h" #include "Indi_ADX.mqh" -#include "Price/Indi_Price.mqh" +#include "Price/Indi_Price.h" // Structs. struct IndiADXWParams : IndiADXParams { @@ -105,9 +110,10 @@ class Indi_ADXW : public Indicator { */ static double iADXWilder(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _mode = LINE_MAIN_ADX, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iADXWilder(_symbol, _tf, _ma_period), _mode, _shift); -#else +#else // __MQL5__ if (_obj == nullptr) { Print( "Indi_ADXW::iADXWilder() can work without supplying pointer to IndicatorData only in MQL5. In this platform " @@ -116,6 +122,13 @@ class Indi_ADXW : public Indicator { return 0; } return iADXWilder(_obj, _ma_period, _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -123,26 +136,28 @@ class Indi_ADXW : public Indicator { * Calculates ADX Wilder on the array of values. */ static double iADXWilderOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _period, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(3 + 7); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(3 + 7); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_ADXW::Calculate( - INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _cache.GetBuffer(3), _cache.GetBuffer(4), - _cache.GetBuffer(5), _cache.GetBuffer(6), _cache.GetBuffer(7), - _cache.GetBuffer(8), _cache.GetBuffer(9), _period)); + _cache PTR_DEREF SetPrevCalculated( + Indi_ADXW::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _cache PTR_DEREF GetBuffer(4), + _cache PTR_DEREF GetBuffer(5), _cache PTR_DEREF GetBuffer(6), + _cache PTR_DEREF GetBuffer(7), _cache PTR_DEREF GetBuffer(8), + _cache PTR_DEREF GetBuffer(9), _period)); // Returns value from the first calculation buffer. // Returns first value for as-series array or last value for non-as-series array. - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_AMA.mqh b/Indicators/Indi_AMA.mqh index a34b4cca9..902f9032c 100644 --- a/Indicators/Indi_AMA.mqh +++ b/Indicators/Indi_AMA.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,11 +20,16 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.h" -#include "Price/Indi_Price.mqh" +#include "Price/Indi_Price.h" // Structs. struct IndiAMAParams : IndicatorParams { @@ -93,6 +98,7 @@ class Indi_AMA : public Indicator { static double iAMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ama_period, int _fast_ema_period, int _slow_ema_period, int _ama_shift, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN( ::iAMA(_symbol, _tf, _ama_period, _fast_ema_period, _slow_ema_period, _ama_shift, _ap), _mode, _shift); @@ -105,6 +111,13 @@ class Indi_AMA : public Indicator { return 0; } return iAMAOnIndicator(_obj, _ama_period, _fast_ema_period, _slow_ema_period, _ama_shift, _ap, _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -113,21 +126,22 @@ class Indi_AMA : public Indicator { */ static double iAMAOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, int _ama_period, int _fast_ema_period, int _slow_ema_period, int _ama_shift, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_price); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_AMA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), - _ama_period, _fast_ema_period, _slow_ema_period, _ama_shift)); + _cache PTR_DEREF SetPrevCalculated(Indi_AMA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, + _cache PTR_DEREF GetBuffer(0), _ama_period, + _fast_ema_period, _slow_ema_period, _ama_shift)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** @@ -210,7 +224,7 @@ class Indi_AMA : public Indicator { // Calculate AMA. double prevAMA = ExtAMABuffer[i - 1].Get(); - ExtAMABuffer[i] = MathPow(currentSSC, 2) * (price[i] - prevAMA) + prevAMA; + ExtAMABuffer[i] = MathPow(currentSSC, 2.0) * (price[i] - prevAMA) + prevAMA; } // Return value of prev_calculated for next call. return (rates_total); diff --git a/Indicators/Indi_AO.mqh b/Indicators/Indi_AO.mqh index a7554e38d..40ceaa897 100644 --- a/Indicators/Indi_AO.mqh +++ b/Indicators/Indi_AO.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iAO(string _symbol, int _tf, int _shift) { - ResetLastError(); - return Indi_AO::iAO(_symbol, (ENUM_TIMEFRAMES)_tf, _shift); -} -#endif - // Structs. struct IndiAOParams : IndicatorParams { // Struct constructor. @@ -96,11 +93,19 @@ class Indi_AO : public Indicator { */ static double iAO(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, int _mode = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ // Note: In MQL4 _mode is not supported. return ::iAO(_symbol, _tf, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iAO(_symbol, _tf), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -133,7 +138,7 @@ class Indi_AO : public Indicator { if (!Objects::TryGet(_key, _ptr)) { _ptr = Objects::Set(_key, new Indi_AO()); // Assigning the same candle indicator for AO as in _indi. - _ptr.SetDataSource(_indi PTR_DEREF GetCandle()); + _ptr PTR_DEREF SetDataSource(_indi PTR_DEREF GetCandle()); } return _ptr; } @@ -142,3 +147,11 @@ class Indi_AO : public Indicator { */ bool IsValidEntry(IndicatorDataEntry &_entry) override { return _entry.values[0].Get() != EMPTY_VALUE; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iAO(string _symbol, int _tf, int _shift) { + ResetLastError(); + return Indi_AO::iAO(_symbol, (ENUM_TIMEFRAMES)_tf, _shift); +} +#endif diff --git a/Indicators/Indi_ASI.mqh b/Indicators/Indi_ASI.mqh index 27744184f..bac96ecc3 100644 --- a/Indicators/Indi_ASI.mqh +++ b/Indicators/Indi_ASI.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,15 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Platform/Platform.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" // Defines. @@ -115,21 +121,22 @@ class Indi_ASI : public Indicator { * Calculates ASI on the array of values. */ static double iASIOnArray(INDICATOR_CALCULATE_PARAMS_LONG, double _mpc, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(3); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(3); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_ASI::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), - _cache.GetBuffer(1), _cache.GetBuffer(2), _mpc)); + _cache PTR_DEREF SetPrevCalculated( + Indi_ASI::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), _mpc)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** @@ -143,6 +150,7 @@ class Indi_ASI : public Indicator { ExtT = 300.0; PrintFormat("Input parameter T has wrong value. Indicator will use T = %f.", ExtT); } + // Calculate ExtTpoints value. if (_Point > 1e-7) ExtTpoints = ExtT * _Point; diff --git a/Indicators/Indi_ATR.mqh b/Indicators/Indi_ATR.mqh index 028562379..a00f08bf3 100644 --- a/Indicators/Indi_ATR.mqh +++ b/Indicators/Indi_ATR.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iATR(string _symbol, int _tf, int _period, int _shift) { - ResetLastError(); - return Indi_ATR::iATR(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _shift); -} -#endif - // Structs. struct IndiATRParams : IndicatorParams { unsigned int period; @@ -80,10 +77,18 @@ class Indi_ATR : public Indicator { */ static double iATR(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iATR(_symbol, _tf, _period, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iATR(_symbol, _tf, _period), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -117,7 +122,7 @@ class Indi_ATR : public Indicator { IndiATRParams _params(_period); _ptr = Objects::Set(_key, new Indi_ATR(_params)); // Assigning the same candle indicator for ATR as in _indi. - _ptr.SetDataSource(_indi PTR_DEREF GetCandle()); + _ptr PTR_DEREF SetDataSource(_indi PTR_DEREF GetCandle()); } return _ptr; } @@ -139,3 +144,11 @@ class Indi_ATR : public Indicator { iparams.period = _period; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iATR(string _symbol, int _tf, int _period, int _shift) { + ResetLastError(); + return Indi_ATR::iATR(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _shift); +} +#endif diff --git a/Indicators/Indi_BWMFI.mqh b/Indicators/Indi_BWMFI.mqh index 08769bbbe..bf742fb37 100644 --- a/Indicators/Indi_BWMFI.mqh +++ b/Indicators/Indi_BWMFI.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iBWMFI(string _symbol, int _tf, int _shift) { - ResetLastError(); - return Indi_BWMFI::iBWMFI(_symbol, (ENUM_TIMEFRAMES)_tf, _shift); -} -#endif - // Enumerations. // Indicator line identifiers used in BWMFI indicators. enum ENUM_BWMFI_BUFFER { BWMFI_BUFFER = 0, BWMFI_HISTCOLOR = 1, FINAL_BWMFI_BUFFER_ENTRY }; @@ -107,10 +104,18 @@ class Indi_BWMFI : public Indicator { */ static double iBWMFI(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0, ENUM_BWMFI_BUFFER _mode = BWMFI_BUFFER, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iBWMFI(_symbol, _tf, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iBWMFI(_symbol, _tf, VOLUME_TICK), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -188,3 +193,11 @@ class Indi_BWMFI : public Indicator { !_entry.HasValue(DBL_MAX); } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iBWMFI(string _symbol, int _tf, int _shift) { + ResetLastError(); + return Indi_BWMFI::iBWMFI(_symbol, (ENUM_TIMEFRAMES)_tf, _shift); +} +#endif diff --git a/Indicators/Indi_BWZT.mqh b/Indicators/Indi_BWZT.mqh index e5c9afff9..74137e580 100644 --- a/Indicators/Indi_BWZT.mqh +++ b/Indicators/Indi_BWZT.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,18 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. // 38 bars (DATA_LIMIT) was originally specified by Indicators/Examples/BW-ZoneTrade.mq5 #define INDI_BWZT_DATA_LIMIT 100 // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/IndicatorTf.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" #include "Indi_AC.mqh" #include "Indi_AO.mqh" @@ -139,24 +144,25 @@ class Indi_BWZT : public Indicator { * Calculates BWZT on the array of values. */ static double iBWZTOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _abs_shift, int _data_limit, - IndicatorCalculateCache *_cache, Indi_AC *_indi_ac, Indi_AO *_indi_ao, + IndiBufferCache *_cache, Indi_AC *_indi_ac, Indi_AO *_indi_ao, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(4 + 1 + 2); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(4 + 1 + 2); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_BWZT::Calculate( - INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _cache.GetBuffer(3), _cache.GetBuffer(4), - _cache.GetBuffer(5), _cache.GetBuffer(6), _data_limit, _indi_ac, _indi_ao)); + _cache PTR_DEREF SetPrevCalculated(Indi_BWZT::Calculate( + INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _cache PTR_DEREF GetBuffer(4), + _cache PTR_DEREF GetBuffer(5), _cache PTR_DEREF GetBuffer(6), _data_limit, _indi_ac, _indi_ao)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** @@ -165,10 +171,11 @@ class Indi_BWZT : public Indicator { static double iBWZTOnIndicator(IndicatorData *_indi, string _symbol, ENUM_TIMEFRAMES _tf, int _mode, int _rel_shift, int _data_limit, IndicatorData *_obj) { INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_indi, _data_limit); - INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_indi, Util::MakeKey("Indi_BWZT_ON_" + _indi.GetFullName())); + INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_indi, + Util::MakeKey("Indi_BWZT_ON_" + _indi PTR_DEREF GetFullName())); - Indi_AC *_indi_ac = _obj.GetDataSource(INDI_AC); - Indi_AO *_indi_ao = _obj.GetDataSource(INDI_AO); + Indi_AC *_indi_ac = (Indi_AC *)_obj PTR_DEREF GetDataSource(INDI_AC); + Indi_AO *_indi_ao = (Indi_AO *)_obj PTR_DEREF GetDataSource(INDI_AO); return iBWZTOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _indi PTR_DEREF ToAbsShift(_rel_shift), _data_limit, _cache, _indi_ac, _indi_ao); diff --git a/Indicators/Indi_BearsPower.mqh b/Indicators/Indi_BearsPower.mqh index 602686d7a..6881f8b8e 100644 --- a/Indicators/Indi_BearsPower.mqh +++ b/Indicators/Indi_BearsPower.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iBearsPower(string _symbol, int _tf, int _period, int _ap, int _shift) { - ResetLastError(); - return Indi_BearsPower::iBearsPower(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); -} -#endif - // Structs. struct IndiBearsPowerParams : IndicatorParams { unsigned int period; @@ -81,10 +78,18 @@ class Indi_BearsPower : public Indicator { static double iBearsPower(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, // (MT5): not used int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iBearsPower(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iBearsPower(_symbol, _tf, _period), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -142,3 +147,11 @@ class Indi_BearsPower : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iBearsPower(string _symbol, int _tf, int _period, int _ap, int _shift) { + ResetLastError(); + return Indi_BearsPower::iBearsPower(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); +} +#endif diff --git a/Indicators/Indi_BullsPower.mqh b/Indicators/Indi_BullsPower.mqh index d560bfb1f..31406c4bd 100644 --- a/Indicators/Indi_BullsPower.mqh +++ b/Indicators/Indi_BullsPower.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iBullsPower(string _symbol, int _tf, int _period, int _ap, int _shift) { - ResetLastError(); - return Indi_BullsPower::iBullsPower(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); -} -#endif - // Structs. struct IndiBullsPowerParams : IndicatorParams { unsigned int period; @@ -81,10 +78,18 @@ class Indi_BullsPower : public Indicator { static double iBullsPower(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, // (MT5): not used int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iBullsPower(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iBullsPower(_symbol, _tf, _period), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -141,3 +146,11 @@ class Indi_BullsPower : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iBullsPower(string _symbol, int _tf, int _period, int _ap, int _shift) { + ResetLastError(); + return Indi_BullsPower::iBullsPower(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); +} +#endif diff --git a/Indicators/Indi_CCI.mqh b/Indicators/Indi_CCI.mqh index c7c659883..06d7d0328 100644 --- a/Indicators/Indi_CCI.mqh +++ b/Indicators/Indi_CCI.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,23 +20,16 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#include "Indi_MA.mqh" #include "Indi_PriceFeeder.mqh" -#include "Price/Indi_Price.mqh" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iCCI(string _symbol, int _tf, int _period, int _ap, int _shift) { - ResetLastError(); - return Indi_CCI::iCCI(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); -} -double iCCIOnArray(double &_arr[], int _total, int _period, int _abs_shift) { - ResetLastError(); - return Indi_CCI::iCCIOnArray(_arr, _total, _period, _abs_shift); -} -#endif +#include "Price/Indi_MA.h" +#include "Price/Indi_Price.h" // Structs. struct IndiCCIParams : IndicatorParams { @@ -91,10 +84,18 @@ class Indi_CCI : public Indicator { */ static double iCCI(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iCCI(_symbol, _tf, _period, _applied_price, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iCCI(_symbol, _tf, _period, _applied_price), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -102,10 +103,10 @@ class Indi_CCI : public Indicator { int _mode, int _shift = 0) { INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_indi, _period); - _indi.ValidateDataSourceMode(_mode); + _indi PTR_DEREF ValidateDataSourceMode(_mode); - double _indi_value_buffer[]; - IndicatorDataEntry _entry(_indi.GetModeCount()); + ARRAY(double, _indi_value_buffer); + IndicatorDataEntry _entry(_indi PTR_DEREF GetModeCount()); ArrayResize(_indi_value_buffer, _period); @@ -140,12 +141,12 @@ class Indi_CCI : public Indicator { /** * CCI on array. */ - static double iCCIOnArray(double &array[], int total, int period, int shift) { + static double iCCIOnArray(CONST_ARRAY_REF(double, array), int total, int period, int shift) { #ifdef __MQL4__ return ::iCCIOnArray(array, total, period, shift); #else Indi_PriceFeeder indi_price_feeder(array); - return iCCIOnIndicator(&indi_price_feeder, NULL, NULL, period, /*unused*/ PRICE_OPEN, shift); + return iCCIOnIndicator(&indi_price_feeder, NULL, PERIOD_CURRENT, period, /*unused*/ PRICE_OPEN, shift); #endif } @@ -221,3 +222,15 @@ class Indi_CCI : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iCCI(string _symbol, int _tf, int _period, int _ap, int _shift) { + ResetLastError(); + return Indi_CCI::iCCI(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); +} +double iCCIOnArray(CONST_ARRAY_REF(double, _arr), int _total, int _period, int _abs_shift) { + ResetLastError(); + return Indi_CCI::iCCIOnArray(_arr, _total, _period, _abs_shift); +} +#endif diff --git a/Indicators/Indi_CHO.mqh b/Indicators/Indi_CHO.mqh index 3d87d5e6c..72f38904f 100644 --- a/Indicators/Indi_CHO.mqh +++ b/Indicators/Indi_CHO.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,16 +20,21 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. // 2 bars was originally specified by Indicators/Examples/CHO.mq5 #define INDI_CHO_MIN_BARS 2 // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" #include "../Util.h" -#include "Indi_MA.mqh" +#include "Price/Indi_MA.h" // Structs. struct IndiCHOParams : IndicatorParams { @@ -86,10 +91,11 @@ class Indi_CHO : public Indicator { static double iChaikin(string _symbol, ENUM_TIMEFRAMES _tf, int _fast_ma_period, int _slow_ma_period, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_VOLUME _av, int _mode = 0, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iChaikin(_symbol, _tf, _fast_ma_period, _slow_ma_period, _ma_method, _av), _mode, _shift); -#else +#else // __MQL5__ if (_obj == nullptr) { Print( "Indi_CHO::iChaikin() can work without supplying pointer to IndicatorData only in MQL5. In this platform the " @@ -102,6 +108,13 @@ class Indi_CHO : public Indicator { _obj, Util::MakeKey(_fast_ma_period, _slow_ma_period, (int)_ma_method, (int)_av)); return iChaikinOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _fast_ma_period, _slow_ma_period, _ma_method, _av, _mode, _shift, _cache); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -110,22 +123,23 @@ class Indi_CHO : public Indicator { */ static double iChaikinOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _fast_ma_period, int _slow_ma_period, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_VOLUME _av, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(4); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(4); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_CHO::Calculate( - INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _cache.GetBuffer(3), _fast_ma_period, _slow_ma_period, _ma_method, _av)); + _cache PTR_DEREF SetPrevCalculated( + Indi_CHO::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _fast_ma_period, _slow_ma_period, _ma_method, _av)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** @@ -175,7 +189,7 @@ class Indi_CHO : public Indicator { return (rates_total); } - static double AD(double high, double low, double close, long volume) { + static double AD(double high, double low, double close, int64 volume) { double res = 0.0; double sum = (close - low) - (high - close); if (sum != 0.0) { diff --git a/Indicators/Indi_CHV.mqh b/Indicators/Indi_CHV.mqh index cfc61a34f..2ad75eb3e 100644 --- a/Indicators/Indi_CHV.mqh +++ b/Indicators/Indi_CHV.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,12 +20,17 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" #include "../Util.h" -#include "Indi_MA.mqh" +#include "Price/Indi_MA.h" // Enums. enum ENUM_CHV_SMOOTH_METHOD { CHV_SMOOTH_METHOD_SMA = 0, CHV_SMOOTH_METHOD_EMA = 1 }; @@ -107,24 +112,25 @@ class Indi_CHV : public Indicator { */ static double iCHVOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _smooth_period, int _chv_period, ENUM_CHV_SMOOTH_METHOD _smooth_method, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(3); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(3); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_CHV::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), - _cache.GetBuffer(1), _cache.GetBuffer(2), - _smooth_period, _chv_period, _smooth_method)); + _cache PTR_DEREF SetPrevCalculated( + Indi_CHV::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _smooth_period, _chv_period, _smooth_method)); // Returns value from the first calculation buffer. // Returns first value for as-series array or last value for non-as-series array. - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_ColorBars.mqh b/Indicators/Indi_ColorBars.mqh deleted file mode 100644 index 527aeb3c1..000000000 --- a/Indicators/Indi_ColorBars.mqh +++ /dev/null @@ -1,149 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -// Includes. -#include "../BufferStruct.mqh" -#include "../Indicator/Indicator.h" -#include "../Storage/ValueStorage.all.h" - -// Structs. -struct IndiColorBarsParams : IndicatorParams { - // Struct constructor. - IndiColorBarsParams(int _shift = 0) : IndicatorParams(INDI_COLOR_BARS) { - SetCustomIndicatorName("Examples\\ColorBars"); - shift = _shift; - }; - IndiColorBarsParams(IndiColorBarsParams &_params) { THIS_REF = _params; }; -}; - -/** - * Implements Color Bars - */ -class Indi_ColorBars : public Indicator { - public: - /** - * Class constructor. - */ - Indi_ColorBars(IndiColorBarsParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, - IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) - : Indicator(_p, IndicatorDataParams::GetInstance(5, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode), - _indi_src){}; - Indi_ColorBars(int _shift = 0, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL, - int _indi_src_mode = 0) - : Indicator(IndiColorBarsParams(), - IndicatorDataParams::GetInstance(5, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode), - _indi_src){}; - /** - * Returns possible data source types. It is a bit mask of ENUM_INDI_SUITABLE_DS_TYPE. - */ - unsigned int GetSuitableDataSourceTypes() override { - return INDI_SUITABLE_DS_TYPE_CANDLE | INDI_SUITABLE_DS_TYPE_BASE_ONLY; - } - - /** - * Returns possible data source modes. It is a bit mask of ENUM_IDATA_SOURCE_TYPE. - */ - unsigned int GetPossibleDataModes() override { return IDATA_ONCALCULATE | IDATA_ICUSTOM | IDATA_INDICATOR; } - - /** - * OnCalculate-based version of Color Bars as there is no built-in one. - */ - static double iColorBars(IndicatorData *_indi, int _mode = 0, int _rel_shift = 0) { - INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_indi, ""); - return iColorBarsOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _indi PTR_DEREF ToAbsShift(_rel_shift), - _cache); - } - - /** - * Calculates Color Bars on the array of values. - */ - static double iColorBarsOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); - - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(4 + 1); - } - - if (_recalculate) { - _cache.ResetPrevCalculated(); - } - - _cache.SetPrevCalculated(Indi_ColorBars::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), - _cache.GetBuffer(1), _cache.GetBuffer(2), - _cache.GetBuffer(3), _cache.GetBuffer(4))); - - return _cache.GetTailValue(_mode, _abs_shift); - } - - /** - * OnCalculate() method for Color Bars indicator. - */ - static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtOpenBuffer, - ValueStorage &ExtHighBuffer, ValueStorage &ExtLowBuffer, - ValueStorage &ExtCloseBuffer, ValueStorage &ExtColorsBuffer) { - int i = 0; - bool vol_up = true; - // Set position for beginning. - if (i < prev_calculated) i = prev_calculated - 1; - // Start calculations. - while (i < rates_total && !IsStopped()) { - ExtOpenBuffer[i] = open[i]; - ExtHighBuffer[i] = high[i]; - ExtLowBuffer[i] = low[i]; - ExtCloseBuffer[i] = close[i]; - // Determine volume change. - if (i > 0) { - if (tick_volume[i] > tick_volume[i - 1]) vol_up = true; - if (tick_volume[i] < tick_volume[i - 1]) vol_up = false; - } - ExtColorsBuffer[i] = vol_up ? 0.0 : 1.0; - i++; - } - // Return value of prev_calculated for next call. - return (rates_total); - } - - /** - * Returns the indicator's value. - */ - virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _abs_shift = 0) { - double _value = EMPTY_VALUE; - switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { - case IDATA_BUILTIN: - case IDATA_ONCALCULATE: - _value = Indi_ColorBars::iColorBars(THIS_PTR, _mode, ToRelShift(_abs_shift)); - break; - case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, - ToRelShift(_abs_shift)); - break; - case IDATA_INDICATOR: - _value = Indi_ColorBars::iColorBars(THIS_PTR, _mode, ToRelShift(_abs_shift)); - break; - default: - SetUserError(ERR_INVALID_PARAMETER); - break; - } - return _value; - } -}; diff --git a/Indicators/Indi_ColorCandlesDaily.mqh b/Indicators/Indi_ColorCandlesDaily.mqh deleted file mode 100644 index 7803c32cb..000000000 --- a/Indicators/Indi_ColorCandlesDaily.mqh +++ /dev/null @@ -1,158 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -// Includes. -#include "../BufferStruct.mqh" -#include "../Indicator/Indicator.h" -#include "../Storage/ValueStorage.all.h" - -// Structs. -struct IndiColorCandlesDailyParams : IndicatorParams { - // Struct constructor. - IndiColorCandlesDailyParams(int _shift = 0) : IndicatorParams(INDI_COLOR_CANDLES_DAILY) { - SetCustomIndicatorName("Examples\\ColorCandlesDaily"); - shift = _shift; - }; - IndiColorCandlesDailyParams(IndiColorCandlesDailyParams &_params) { THIS_REF = _params; }; -}; - -/** - * Implements Color Bars - */ -class Indi_ColorCandlesDaily : public Indicator { - public: - /** - * Class constructor. - */ - Indi_ColorCandlesDaily(IndiColorCandlesDailyParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, - IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) - : Indicator(_p, IndicatorDataParams::GetInstance(5, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode), - _indi_src){}; - Indi_ColorCandlesDaily(int _shift = 0, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, - IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) - : Indicator(IndiColorCandlesDailyParams(), - IndicatorDataParams::GetInstance(5, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode), - _indi_src){}; - /** - * Returns possible data source types. It is a bit mask of ENUM_INDI_SUITABLE_DS_TYPE. - */ - unsigned int GetSuitableDataSourceTypes() override { return INDI_SUITABLE_DS_TYPE_CUSTOM; } - - /** - * Returns possible data source modes. It is a bit mask of ENUM_IDATA_SOURCE_TYPE. - */ - unsigned int GetPossibleDataModes() override { return IDATA_ONCALCULATE | IDATA_ICUSTOM | IDATA_INDICATOR; } - - /** - * Checks whether given data source satisfies our requirements. - */ - bool OnCheckIfSuitableDataSource(IndicatorData *_ds) override { - if (Indicator::OnCheckIfSuitableDataSource(_ds)) { - return true; - } - - // Volume uses volume only. - return _ds PTR_DEREF HasSpecificAppliedPriceValueStorage(PRICE_OPEN) && - _ds PTR_DEREF HasSpecificAppliedPriceValueStorage(PRICE_HIGH) && - _ds PTR_DEREF HasSpecificAppliedPriceValueStorage(PRICE_LOW) && - _ds PTR_DEREF HasSpecificAppliedPriceValueStorage(PRICE_CLOSE); - } - - /** - * OnCalculate-based version of Color Candles Daily as there is no built-in one. - */ - static double iCCD(IndicatorData *_indi, int _mode = 0, int _rel_shift = 0) { - INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_indi, ""); - return iCCDOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _indi PTR_DEREF ToAbsShift(_rel_shift), - _cache); - } - - /** - * Calculates Color Candles Daily on the array of values. - */ - static double iCCDOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); - - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(4 + 1); - } - - if (_recalculate) { - _cache.ResetPrevCalculated(); - } - - _cache.SetPrevCalculated(Indi_ColorCandlesDaily::Calculate( - INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _cache.GetBuffer(3), _cache.GetBuffer(4))); - - return _cache.GetTailValue(_mode, _abs_shift); - } - - /** - * OnCalculate() method for Color Candles Daily indicator. - */ - static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtOpenBuffer, - ValueStorage &ExtHighBuffer, ValueStorage &ExtLowBuffer, - ValueStorage &ExtCloseBuffer, ValueStorage &ExtColorsBuffer) { - color ExtColorOfDay[6] = {CLR_NONE, MediumSlateBlue, DarkGoldenrod, ForestGreen, BlueViolet, Red}; - - int pos; - MqlDateTime tstruct; - pos = prev_calculated < 1 ? 0 : prev_calculated - 1; - // Main cycle. - for (int i = pos; i < rates_total && !IsStopped(); i++) { - ExtOpenBuffer[i] = open[i]; - ExtHighBuffer[i] = high[i]; - ExtLowBuffer[i] = low[i]; - ExtCloseBuffer[i] = close[i]; - // Set color for every candle. - TimeToStruct(time[i].Get(), tstruct); - ExtColorsBuffer[i] = tstruct.day_of_week; - } - // Return value of prev_calculated for next call. - return (rates_total); - } - - /** - * Returns the indicator's value. - */ - virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _abs_shift = 0) { - double _value = EMPTY_VALUE; - switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { - case IDATA_BUILTIN: - case IDATA_ONCALCULATE: - _value = Indi_ColorCandlesDaily::iCCD(THIS_PTR, _mode, ToRelShift(_abs_shift)); - break; - case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, - ToRelShift(_abs_shift)); - break; - case IDATA_INDICATOR: - _value = Indi_ColorCandlesDaily::iCCD(THIS_PTR, _mode, ToRelShift(_abs_shift)); - break; - default: - SetUserError(ERR_INVALID_PARAMETER); - } - return _value; - } -}; diff --git a/Indicators/Indi_ColorLine.mqh b/Indicators/Indi_ColorLine.mqh deleted file mode 100644 index 60b8b06c2..000000000 --- a/Indicators/Indi_ColorLine.mqh +++ /dev/null @@ -1,242 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -// Includes. -#include "../BufferStruct.mqh" -#include "../Indicator/Indicator.h" -#include "../Storage/ValueStorage.all.h" -#include "Indi_MA.mqh" - -// Structs. -struct IndiColorLineParams : IndicatorParams { - IndicatorData *indi_ma; - // Struct constructor. - IndiColorLineParams(int _shift = 0) : IndicatorParams(INDI_COLOR_LINE) { - indi_ma = NULL; - SetCustomIndicatorName("Examples\\ColorLine"); - shift = _shift; - }; - IndiColorLineParams(IndiColorLineParams &_params) { THIS_REF = _params; }; -}; - -/** - * Implements Color Bars - */ -class Indi_ColorLine : public Indicator { - public: - /** - * Class constructor. - */ - Indi_ColorLine(IndiColorLineParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, - IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) - : Indicator(_p, IndicatorDataParams::GetInstance(2, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode), - _indi_src){}; - Indi_ColorLine(int _shift = 0, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL, - int _indi_src_mode = 0) - : Indicator(IndiColorLineParams(), - IndicatorDataParams::GetInstance(2, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode), - _indi_src){}; - /** - * Returns possible data source types. It is a bit mask of ENUM_INDI_SUITABLE_DS_TYPE. - * - * @fixit Should require Candle data source? - */ - unsigned int GetSuitableDataSourceTypes() override { return INDI_SUITABLE_DS_TYPE_CANDLE; } - - /** - * Returns possible data source modes. It is a bit mask of ENUM_IDATA_SOURCE_TYPE. - */ - unsigned int GetPossibleDataModes() override { return IDATA_ONCALCULATE | IDATA_ICUSTOM | IDATA_INDICATOR; } - - /** - * Checks whether given data source satisfies our requirements. - */ - bool OnCheckIfSuitableDataSource(IndicatorData *_ds) override { - if (Indicator::OnCheckIfSuitableDataSource(_ds)) { - return true; - } - - // Volume uses volume only. - return _ds PTR_DEREF HasSpecificValueStorage(INDI_VS_TYPE_VOLUME); - } - - /** - * OnCalculate-based version of Color Line as there is no built-in one. - */ - static double iColorLine(IndicatorData *_indi, int _mode = 0, int _rel_shift = 0) { - INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_indi, ""); - // Will return Indi_MA with the same candles source as _indi's. - // @fixit There should be Candle attached to MA! - Indi_MA *_indi_ma = Indi_MA::GetCached(_indi, 10, 0, MODE_EMA, PRICE_CLOSE); - return iColorLineOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _indi PTR_DEREF ToAbsShift(_rel_shift), - _cache, _indi_ma); - } - - /** - * Calculates Color Line on the array of values. - */ - static double iColorLineOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, IndicatorData *_indi_ma, - bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); - - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1 + 1); - } - - if (_recalculate) { - _cache.ResetPrevCalculated(); - } - - _cache.SetPrevCalculated(Indi_ColorLine::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), - _cache.GetBuffer(1), _indi_ma)); - - return _cache.GetTailValue(_mode, _abs_shift); - } - - /** - * On-indicator version of Color Line. - */ - static double iColorLineOnIndicator(IndicatorData *_indi, int _mode, int _rel_shift, IndicatorData *_obj) { - INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_indi, ""); - Indi_MA *_indi_ma = _obj.GetDataSource(INDI_MA); - return iColorLineOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _mode, _indi PTR_DEREF ToAbsShift(_rel_shift), - _cache, _indi_ma); - } - - /** - * Provides built-in indicators whose can be used as data source. - */ - virtual IndicatorData *FetchDataSource(ENUM_INDICATOR_TYPE _id) override { - switch (_id) { - case INDI_MA: - return iparams.indi_ma; - } - return NULL; - } - - /** - * OnCalculate() method for Color Line indicator. - */ - static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage &ExtColorLineBuffer, - ValueStorage &ExtColorsBuffer, IndicatorData *ExtMAHandle) { - static int ticks = 0, modified = 0; - // Check data. - int i, calculated = BarsCalculated(ExtMAHandle); - // @added History of 100 values should be enough for MA. - if (calculated < rates_total) { - // Not all data of ExtMAHandle is calculated. - return (0); - } - // First calculation or number of bars was changed. - if (prev_calculated == 0) { - // Copy values of MA into indicator buffer ExtColorLineBuffer. - if (CopyBuffer(ExtMAHandle, 0, 0, rates_total, ExtColorLineBuffer, rates_total) <= 0) return (0); - // Now set line color for every bar. - for (i = 0; i < rates_total && !IsStopped(); i++) ExtColorsBuffer[i] = GetIndexOfColor(i); - } else { - // We can copy not all data. - int to_copy; - if (prev_calculated > rates_total || prev_calculated < 0) - to_copy = rates_total; - else { - to_copy = rates_total - prev_calculated; - if (prev_calculated > 0) to_copy++; - } - // Copy values of MA into indicator buffer ExtColorLineBuffer. - int copied = CopyBuffer(ExtMAHandle, 0, 0, rates_total, ExtColorLineBuffer, rates_total); - if (copied <= 0) return (0); - - ticks++; - if (ticks >= 5) { - // Time to change color scheme. - ticks = 0; - // Counter of color changes. - modified++; - if (modified >= 3) modified = 0; - switch (modified) { - case 0: - // First color scheme. - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 0, Red); - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 1, Blue); - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 2, Green); - break; - case 1: - // Second color scheme. - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 0, Yellow); - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 1, Pink); - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 2, LightSlateGray); - break; - default: - // Third color scheme. - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 0, LightGoldenrod); - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 1, Orchid); - ExtColorLineBuffer.PlotIndexSetInteger(PLOT_LINE_COLOR, 2, LimeGreen); - } - } else { - // Set start position. - int start = prev_calculated - 1; - // Now we set line color for every bar. - for (i = start; i < rates_total && !IsStopped(); i++) ExtColorsBuffer[i] = GetIndexOfColor(i); - } - } - // Return value of prev_calculated for next call. - return (rates_total); - } - - static int GetIndexOfColor(const int i) { - int j = i % 300; - if (j < 100) { - // First index. - return (0); - } - if (j < 200) { - // Second index. - return (1); - } - // Third index. - return (2); - } - - /** - * Returns the indicator's value. - */ - virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _abs_shift = 0) { - double _value = EMPTY_VALUE; - switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { - case IDATA_BUILTIN: - case IDATA_ONCALCULATE: - _value = iColorLine(THIS_PTR, _mode, ToRelShift(_abs_shift)); - break; - case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), _mode, - ToRelShift(_abs_shift)); - break; - case IDATA_INDICATOR: - _value = iColorLine(THIS_PTR, _mode, ToRelShift(_abs_shift)); - break; - default: - SetUserError(ERR_INVALID_PARAMETER); - } - return _value; - } -}; diff --git a/Indicators/Indi_CustomMovingAverage.mqh b/Indicators/Indi_CustomMovingAverage.mqh deleted file mode 100644 index bc6a8aab6..000000000 --- a/Indicators/Indi_CustomMovingAverage.mqh +++ /dev/null @@ -1,137 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -// Includes. -#include "../BufferStruct.mqh" -#include "../Indicator/Indicator.h" - -// Structs. -struct IndiCustomMovingAverageParams : IndicatorParams { - unsigned int smooth_period; - unsigned int smooth_shift; - ENUM_MA_METHOD smooth_method; - // Struct constructor. - IndiCustomMovingAverageParams(int _smooth_period = 13, int _smooth_shift = 0, - ENUM_MA_METHOD _smooth_method = MODE_SMMA, int _shift = 0) - : IndicatorParams(INDI_CUSTOM_MOVING_AVG) { - if (custom_indi_name == "") { -#ifdef __MQL5__ - SetCustomIndicatorName("Examples\\Custom Moving Average"); -#else - SetCustomIndicatorName("Custom Moving Averages"); -#endif - } - shift = _shift; - smooth_method = _smooth_method; - smooth_period = _smooth_period; - smooth_shift = _smooth_shift; - }; - IndiCustomMovingAverageParams(IndiCustomMovingAverageParams& _params) { THIS_REF = _params; }; -}; - -/** - * Implements the Custom Moving Average indicator. - */ -class Indi_CustomMovingAverage : public Indicator { - public: - /** - * Class constructor. - */ - Indi_CustomMovingAverage(IndiCustomMovingAverageParams& _p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_ICUSTOM, - IndicatorData* _indi_src = NULL, int _indi_src_mode = 0) - : Indicator(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), - _indi_src){}; - Indi_CustomMovingAverage(int _shift = 0, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_ICUSTOM, - IndicatorData* _indi_src = NULL, int _indi_src_mode = 0) - : Indicator(IndiCustomMovingAverageParams(), - IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), - _indi_src){}; - - /** - * Returns possible data source types. It is a bit mask of ENUM_INDI_SUITABLE_DS_TYPE. - */ - unsigned int GetSuitableDataSourceTypes() override { return INDI_SUITABLE_DS_TYPE_EXPECT_NONE; } - - /** - * Returns possible data source modes. It is a bit mask of ENUM_IDATA_SOURCE_TYPE. - */ - unsigned int GetPossibleDataModes() override { return IDATA_ICUSTOM; } - - /** - * Returns the indicator's value. - */ - virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _abs_shift = 0) { - double _value = EMPTY_VALUE; - switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { - case IDATA_ICUSTOM: - _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetSmoothPeriod(), - GetSmoothShift(), GetSmoothMethod() /*]*/, 0, ToRelShift(_abs_shift)); - break; - default: - SetUserError(ERR_INVALID_PARAMETER); - } - return _value; - } - - /* Getters */ - - /** - * Get smooth period. - */ - unsigned int GetSmoothPeriod() { return iparams.smooth_period; } - - /** - * Get smooth shift. - */ - unsigned int GetSmoothShift() { return iparams.smooth_shift; } - - /** - * Get smooth method. - */ - ENUM_MA_METHOD GetSmoothMethod() { return iparams.smooth_method; } - - /* Setters */ - - /** - * Set smooth period. - */ - void SetSmoothPeriod(unsigned int _smooth_period) { - istate.is_changed = true; - iparams.smooth_period = _smooth_period; - } - - /** - * Set smooth shift. - */ - void SetSmoothShift(unsigned int _smooth_shift) { - istate.is_changed = true; - iparams.smooth_shift = _smooth_shift; - } - - /** - * Set smooth method. - */ - void SetSmoothMethod(ENUM_MA_METHOD _smooth_method) { - istate.is_changed = true; - iparams.smooth_method = _smooth_method; - } -}; diff --git a/Indicators/Indi_DEMA.mqh b/Indicators/Indi_DEMA.mqh index f7f94a417..af4de784b 100644 --- a/Indicators/Indi_DEMA.mqh +++ b/Indicators/Indi_DEMA.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,10 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef INDI_DEMA_MQH -#define INDI_DEMA_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Defines. #ifdef __MQL5__ @@ -32,15 +33,15 @@ #endif // Includes. -#include "../Dict.mqh" -#include "../DictObject.mqh" #include "../Indicator/Indicator.h" #include "../Refs.mqh" +#include "../Storage/Dict/Dict.h" +#include "../Storage/Dict/DictObject.h" #include "../Storage/Objects.h" +#include "../Storage/String.h" #include "../Storage/ValueStorage.h" -#include "../String.mqh" -#include "Indi_MA.mqh" -#include "Price/Indi_Price.mqh" +#include "Price/Indi_MA.h" +#include "Price/Indi_Price.h" // Structs. struct IndiDEMAParams : IndicatorParams { @@ -103,9 +104,10 @@ class Indi_DEMA : public Indicator { */ static double iDEMA(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, unsigned int _ma_shift, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, int _mode = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iDEMA(_symbol, _tf, _period, _ma_shift, _applied_price), _mode, _shift); -#else +#else // __MQL5__ if (_obj == nullptr) { Print( "Indi_DEMA::iDEMA() can work without supplying pointer to IndicatorData only in MQL5. In this platform the " @@ -115,34 +117,40 @@ class Indi_DEMA : public Indicator { } return iDEMAOnIndicator(_obj, _period, _ma_shift, _applied_price, _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } static double iDEMAOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, unsigned int _ma_period, unsigned int _ma_shift, - int _mode, int _shift, IndicatorCalculateCache *_cache = NULL, - bool _recalculate = false) { + int _mode, int _shift, IndiBufferCache *_cache = NULL, bool _recalculate = false) { if (_cache == nullptr) { Print("iDEMAOnArray() cannot yet work without cache object!"); DebugBreak(); return 0.0f; } - _cache.SetPriceBuffer(_price); + _cache PTR_DEREF SetPriceBuffer(_price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(3); // 3 buffers. + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(3); // 3 buffers. } if (_recalculate) { // We don't want to continue calculations, but to recalculate previous one. - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_DEMA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), - _cache.GetBuffer(1), _cache.GetBuffer(2), - _ma_period)); + _cache PTR_DEREF SetPrevCalculated( + Indi_DEMA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), _ma_period)); - return _cache.GetTailValue(0, _ma_shift + _shift); + return _cache PTR_DEREF GetTailValue(0, _ma_shift + _shift); } /** @@ -272,4 +280,3 @@ class Indi_DEMA : public Indicator { iparams.applied_price = _applied_price; } }; -#endif // INDI_DEMA_MQH diff --git a/Indicators/Indi_DeMarker.mqh b/Indicators/Indi_DeMarker.mqh index 3a1f9e638..34ea5034a 100644 --- a/Indicators/Indi_DeMarker.mqh +++ b/Indicators/Indi_DeMarker.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iDeMarker(string _symbol, int _tf, int _period, int _shift) { - ResetLastError(); - return Indi_DeMarker::iDeMarker(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _shift); -} -#endif - // Structs. struct IndiDeMarkerParams : IndicatorParams { unsigned int period; @@ -78,10 +75,18 @@ class Indi_DeMarker : public Indicator { */ static double iDeMarker(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iDeMarker(_symbol, _tf, _period, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iDeMarker(_symbol, _tf, _period), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -121,3 +126,11 @@ class Indi_DeMarker : public Indicator { iparams.period = _period; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iDeMarker(string _symbol, int _tf, int _period, int _shift) { + ResetLastError(); + return Indi_DeMarker::iDeMarker(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _shift); +} +#endif diff --git a/Indicators/Indi_Demo.mqh b/Indicators/Indi_Demo.mqh index ceb0fac4c..6dd70f256 100644 --- a/Indicators/Indi_Demo.mqh +++ b/Indicators/Indi_Demo.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,15 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" -#include "Price/Indi_Price.mqh" +#include "../Storage/Dict/Buffer/BufferStruct.h" +#include "Price/Indi_Price.h" /** * @file @@ -81,7 +86,7 @@ class Indi_Demo : public Indicator { */ virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _abs_shift = 0) { double _value = Indi_Demo::iDemo(THIS_PTR, ToRelShift(_abs_shift)); - if (idparams.IsDrawing()) { + if (idparams.IsPloting()) { // draw.DrawLineTo(GetName(), GetCandle() PTR_DEREF GetBarTime(ToRelShift(_abs_shift)), _value); } return _value; diff --git a/Indicators/Indi_DetrendedPrice.mqh b/Indicators/Indi_DetrendedPrice.mqh index 2cdc29e1c..e26bbeb4b 100644 --- a/Indicators/Indi_DetrendedPrice.mqh +++ b/Indicators/Indi_DetrendedPrice.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,15 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" -#include "Indi_MA.mqh" +#include "../Storage/Dict/Buffer/BufferStruct.h" +#include "Price/Indi_MA.h" // Structs. struct IndiDetrendedPriceParams : IndicatorParams { @@ -76,7 +81,7 @@ class Indi_DetrendedPrice : public Indicator { } // Volume uses volume only. - return _ds PTR_DEREF HasSpecificValueStorage(INDI_VS_TYPE_VOLUME); + return _ds PTR_DEREF HasSpecificValueStorage(INDI_DATA_VS_TYPE_VOLUME); } /** @@ -84,7 +89,7 @@ class Indi_DetrendedPrice : public Indicator { */ static double iDPO(IndicatorData *_indi, int _period, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _rel_shift = 0) { INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_indi, _period + _rel_shift); - INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_SHORT(_indi, _ap, Util::MakeKey(_indi.GetId())); + INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_SHORT(_indi, _ap, Util::MakeKey(_indi PTR_DEREF GetId())); return iDPOOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_SHORT, _period, _ap, _mode, _indi PTR_DEREF ToAbsShift(_rel_shift), _cache); } @@ -93,21 +98,22 @@ class Indi_DetrendedPrice : public Indicator { * Calculates DPO on the array of values. */ static double iDPOOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, int _period, ENUM_APPLIED_PRICE _ap, int _mode, - int _abs_shift, IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_price); + int _abs_shift, IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1 + 1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1 + 1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_DetrendedPrice::Calculate( - INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), _cache.GetBuffer(1), _period)); + _cache PTR_DEREF SetPrevCalculated(Indi_DetrendedPrice::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, + _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _period)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_Drawer.mqh b/Indicators/Indi_Drawer.mqh index 830284920..bd8ce5789 100644 --- a/Indicators/Indi_Drawer.mqh +++ b/Indicators/Indi_Drawer.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2020, 31337 Investments Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,18 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../DictStruct.mqh" #include "../Indicator/Indicator.h" -#include "../Redis.mqh" +#include "../Storage/Dict/DictStruct.h" +#include "../Storage/Redis.h" #include "../Task/TaskAction.h" #include "Indi_Drawer.struct.h" -#include "Price/Indi_Price.mqh" +#include "Price/Indi_Price.h" /** * Implements the Relative Strength Index indicator. @@ -83,7 +88,7 @@ class Indi_Drawer : public Indicator { */ } - virtual bool ExecuteAction(ENUM_INDICATOR_ACTION _action, DataParamEntry &_args[]) { + virtual bool ExecuteAction(ENUM_INDICATOR_ACTION _action, CONST_ARRAY_REF(DataParamEntry, _args)) { int num_args = ArraySize(_args), i; int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); @@ -93,8 +98,8 @@ class Indi_Drawer : public Indicator { Set(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), num_args - 1); if (num_args - 1 > _max_modes) { - GetLogger().Error( - StringFormat("Too many data for buffers for action %s!", EnumToString(_action), __FUNCTION_LINE__)); + GetLogger() PTR_DEREF Error(StringFormat("Too many data for buffers for action %s at %s!", + C_STR(EnumToString(_action)), __FUNCTION_LINE__)); return false; } @@ -161,7 +166,7 @@ class Indi_Drawer : public Indicator { */ } - Redis *Redis() { return &redis; } + Redis *GetRedis() { return &redis; } /** * Returns the indicator value. @@ -187,7 +192,7 @@ class Indi_Drawer : public Indicator { /** * Performs drawing from data in array. */ - static double iDrawerOnArray(double &array[], int total, int period, int shift) { return 0; } + static double iDrawerOnArray(CONST_ARRAY_REF(double, array), int total, int period, int shift) { return 0; } /* Getters */ diff --git a/Indicators/Indi_Drawer.struct.h b/Indicators/Indi_Drawer.struct.h index 2014e8894..82359ff26 100644 --- a/Indicators/Indi_Drawer.struct.h +++ b/Indicators/Indi_Drawer.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2020, 31337 Investments Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Includes Indi_Drawer's structs. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.struct.h" #include "../Serializer/SerializerNode.enum.h" diff --git a/Indicators/Indi_Force.mqh b/Indicators/Indi_Force.mqh index 5a6b02fa7..80c13e026 100644 --- a/Indicators/Indi_Force.mqh +++ b/Indicators/Indi_Force.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,17 +31,14 @@ * 3. Trading volume. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iForce(string _symbol, int _tf, int _period, int _ma_method, int _ap, int _shift) { - ResetLastError(); - return Indi_Force::iForce(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_MA_METHOD)_ma_method, (ENUM_APPLIED_PRICE)_ap, - _shift); -} -#endif +#include "../Indicators/Price/Indi_MA.h" // Structs. struct IndiForceParams : IndicatorParams { @@ -95,10 +92,18 @@ class Indi_Force : public Indicator { */ static double iForce(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iForce(_symbol, _tf, _period, _ma_method, _applied_price, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iForce(_symbol, _tf, _period, _ma_method, VOLUME_TICK), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -165,3 +170,12 @@ class Indi_Force : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iForce(string _symbol, int _tf, int _period, int _ma_method, int _ap, int _shift) { + ResetLastError(); + return Indi_Force::iForce(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_MA_METHOD)_ma_method, (ENUM_APPLIED_PRICE)_ap, + _shift); +} +#endif diff --git a/Indicators/Indi_FractalAdaptiveMA.mqh b/Indicators/Indi_FractalAdaptiveMA.mqh index 90457a785..5ef202933 100644 --- a/Indicators/Indi_FractalAdaptiveMA.mqh +++ b/Indicators/Indi_FractalAdaptiveMA.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" // Structs. @@ -92,10 +97,11 @@ class Indi_FrAMA : public Indicator { */ static double iFrAMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _rel_shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iFrAMA(_symbol, _tf, _ma_period, _ma_shift, _ap), _mode, _obj PTR_DEREF ToAbsShift(_rel_shift)); -#else +#else // __MQL5__ if (_obj == nullptr) { Print( "Indi_FrAMA::iFrAMA() can work without supplying pointer to IndicatorData only in MQL5. In this platform the " @@ -107,6 +113,13 @@ class Indi_FrAMA : public Indicator { INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_obj, Util::MakeKey(_ma_period, _ma_shift, (int)_ap)); return iFrAMAOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _ma_period, _ma_shift, _ap, _mode, _obj PTR_DEREF ToAbsShift(_rel_shift), _cache); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -114,22 +127,21 @@ class Indi_FrAMA : public Indicator { * Calculates FrAMA on the array of values. */ static double iFrAMAOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _ma_period, int _ma_shift, ENUM_APPLIED_PRICE _ap, - int _mode, int _abs_shift, IndicatorCalculateCache *_cache, - bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + int _mode, int _abs_shift, IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_FrAMA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), - _ma_period, _ma_shift, _ap)); + _cache PTR_DEREF SetPrevCalculated(Indi_FrAMA::Calculate( + INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), _ma_period, _ma_shift, _ap)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_Fractals.mqh b/Indicators/Indi_Fractals.mqh index 10903fe22..793e4197a 100644 --- a/Indicators/Indi_Fractals.mqh +++ b/Indicators/Indi_Fractals.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iFractals(string _symbol, int _tf, int _mode, int _shift) { - ResetLastError(); - return Indi_Fractals::iFractals(_symbol, (ENUM_TIMEFRAMES)_tf, (ENUM_LO_UP_LINE)_mode, _shift); -} -#endif - // Structs. struct IndiFractalsParams : IndicatorParams { // Struct constructors. @@ -94,10 +91,18 @@ class Indi_Fractals : public Indicator { ENUM_LO_UP_LINE _mode, // (MT4 _mode): 1 - MODE_UPPER, 2 - MODE_LOWER int _shift = 0, // (MT5 _mode): 0 - UPPER_LINE, 1 - LOWER_LINE IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iFractals(_symbol, _tf, _mode, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iFractals(_symbol, _tf), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -145,3 +150,11 @@ class Indi_Fractals : public Indicator { return !_entry.HasValue(_wrong_value); } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iFractals(string _symbol, int _tf, int _mode, int _shift) { + ResetLastError(); + return Indi_Fractals::iFractals(_symbol, (ENUM_TIMEFRAMES)_tf, (ENUM_LO_UP_LINE)_mode, _shift); +} +#endif diff --git a/Indicators/Indi_Gator.mqh b/Indicators/Indi_Gator.mqh index 61af56eda..65d1524e5 100644 --- a/Indicators/Indi_Gator.mqh +++ b/Indicators/Indi_Gator.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,6 +20,11 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + /** * @file * Gator Oscillator @@ -29,16 +34,7 @@ // Includes. #include "../Indicator/Indicator.h" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iGator(string _symbol, int _tf, int _jp, int _js, int _tp, int _ts, int _lp, int _ls, int _ma_method, int _ap, - int _mode, int _shift) { - ResetLastError(); - return Indi_Gator::iGator(_symbol, (ENUM_TIMEFRAMES)_tf, _jp, _js, _tp, _ts, _lp, _ls, (ENUM_MA_METHOD)_ma_method, - (ENUM_APPLIED_PRICE)_ap, (ENUM_GATOR_HISTOGRAM)_mode, _shift); -} -#endif +#include "../Indicators/Price/Indi_MA.h" #ifndef __MQLBUILD__ // Indicator constants. @@ -162,6 +158,7 @@ class Indi_Gator : public Indicator { int _teeth_shift, int _lips_period, int _lips_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, ENUM_GATOR_HISTOGRAM _mode, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iGator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift, _ma_method, _applied_price, _mode, _shift); @@ -169,6 +166,13 @@ class Indi_Gator : public Indicator { INDICATOR_BUILTIN_CALL_AND_RETURN(::iGator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift, _ma_method, _applied_price), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -327,3 +331,13 @@ class Indi_Gator : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iGator(string _symbol, int _tf, int _jp, int _js, int _tp, int _ts, int _lp, int _ls, int _ma_method, int _ap, + int _mode, int _shift) { + ResetLastError(); + return Indi_Gator::iGator(_symbol, (ENUM_TIMEFRAMES)_tf, _jp, _js, _tp, _ts, _lp, _ls, (ENUM_MA_METHOD)_ma_method, + (ENUM_APPLIED_PRICE)_ap, (ENUM_GATOR_HISTOGRAM)_mode, _shift); +} +#endif diff --git a/Indicators/Indi_HeikenAshi.mqh b/Indicators/Indi_HeikenAshi.mqh index 3c89e0fc6..9bf567a81 100644 --- a/Indicators/Indi_HeikenAshi.mqh +++ b/Indicators/Indi_HeikenAshi.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -27,6 +27,11 @@ * Doesn't give independent signals. Is used to define volatility (trend strength). */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" #include "../Storage/ValueStorage.all.h" @@ -127,6 +132,7 @@ class Indi_HeikenAshi : public Indicator { */ static double iCustomLegacyHeikenAshi(string _symbol, ENUM_TIMEFRAMES _tf, string _name, int _mode, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ // Low and High prices could be in reverse order when using MT4's built-in indicator, so we need to retrieve both // and return correct one. @@ -144,6 +150,13 @@ class Indi_HeikenAshi : public Indicator { return ::iCustom(_symbol, _tf, "Heiken Ashi", _mode, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iCustom(_symbol, _tf, "Examples\\Heiken_Ashi"), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -160,22 +173,23 @@ class Indi_HeikenAshi : public Indicator { * Calculates Heiken Ashi on the array of values. */ static double iHeikenAshiOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1 + 4); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1 + 4); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_HeikenAshi::Calculate( - INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _cache.GetBuffer(3), _cache.GetBuffer(4))); + _cache PTR_DEREF SetPrevCalculated( + Indi_HeikenAshi::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _cache PTR_DEREF GetBuffer(4))); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_Ichimoku.mqh b/Indicators/Indi_Ichimoku.mqh index 87ce9400e..158f8249c 100644 --- a/Indicators/Indi_Ichimoku.mqh +++ b/Indicators/Indi_Ichimoku.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iIchimoku(string _symbol, int _tf, int _ts, int _ks, int _ssb, int _mode, int _shift) { - ResetLastError(); - return Indi_Ichimoku::iIchimoku(_symbol, (ENUM_TIMEFRAMES)_tf, _ts, _ks, _ssb, _mode, _shift); -} -#endif - #ifndef __MQLBUILD__ // Indicator constants. // @docs @@ -133,11 +130,19 @@ class Indi_Ichimoku : public Indicator { */ static double iIchimoku(string _symbol, ENUM_TIMEFRAMES _tf, int _tenkan_sen, int _kijun_sen, int _senkou_span_b, int _mode, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iIchimoku(_symbol, _tf, _tenkan_sen, _kijun_sen, _senkou_span_b, _mode, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iIchimoku(_symbol, _tf, _tenkan_sen, _kijun_sen, _senkou_span_b), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -227,3 +232,11 @@ class Indi_Ichimoku : public Indicator { iparams.senkou_span_b = _senkou_span_b; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iIchimoku(string _symbol, int _tf, int _ts, int _ks, int _ssb, int _mode, int _shift) { + ResetLastError(); + return Indi_Ichimoku::iIchimoku(_symbol, (ENUM_TIMEFRAMES)_tf, _ts, _ks, _ssb, _mode, _shift); +} +#endif diff --git a/Indicators/Indi_Killzones.mqh b/Indicators/Indi_Killzones.mqh index 3f9dbe40a..5036b60ad 100644 --- a/Indicators/Indi_Killzones.mqh +++ b/Indicators/Indi_Killzones.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,6 +20,11 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" #include "../Market.struct.h" @@ -82,7 +87,7 @@ struct Indi_Killzones_Time : MarketTimeForex { }; /** - * Implements Pivot Detector. + * Implements Killzones indicator. */ class Indi_Killzones : public Indicator { protected: diff --git a/Indicators/Indi_MFI.mqh b/Indicators/Indi_MFI.mqh index 01aa9fc05..8984b08ab 100644 --- a/Indicators/Indi_MFI.mqh +++ b/Indicators/Indi_MFI.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iMFI(string _symbol, int _tf, int _period, int _shift) { - ResetLastError(); - return Indi_MFI::iMFI(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _shift); -} -#endif - // Structs. struct IndiMFIParams : IndicatorParams { unsigned int ma_period; @@ -80,19 +77,35 @@ class Indi_MFI : public Indicator { */ static double iMFI(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iMFI(_symbol, _tf, _period, _shift); #else // __MQL5__ return Indi_MFI::iMFI(_symbol, _tf, _period, VOLUME_TICK, _shift, _obj); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } static double iMFI(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_VOLUME _applied_volume, // Not used in MT4. int _shift = 0, Indi_MFI *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iMFI(_symbol, _tf, _period, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iMFI(_symbol, _tf, _period, VOLUME_TICK), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -161,3 +174,11 @@ class Indi_MFI : public Indicator { iparams.applied_volume = _applied_volume; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iMFI(string _symbol, int _tf, int _period, int _shift) { + ResetLastError(); + return Indi_MFI::iMFI(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _shift); +} +#endif diff --git a/Indicators/Indi_MassIndex.mqh b/Indicators/Indi_MassIndex.mqh index 3a82a39b1..0c8e4a07d 100644 --- a/Indicators/Indi_MassIndex.mqh +++ b/Indicators/Indi_MassIndex.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,11 +20,16 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" -#include "Indi_MA.mqh" +#include "Price/Indi_MA.h" // Structs. struct IndiMassIndexParams : IndicatorParams { @@ -98,22 +103,23 @@ class Indi_MassIndex : public Indicator { * Calculates Mass Index on the array of values. */ static double iMIOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _period, int _second_period, int _sum_period, int _mode, - int _abs_shift, IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + int _abs_shift, IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1 + 3); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1 + 3); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_MassIndex::Calculate( - INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _cache.GetBuffer(3), _period, _second_period, _sum_period)); + _cache PTR_DEREF SetPrevCalculated( + Indi_MassIndex::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _period, _second_period, _sum_period)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_Momentum.mqh b/Indicators/Indi_Momentum.mqh index 1ecdb366c..11c7d8ac3 100644 --- a/Indicators/Indi_Momentum.mqh +++ b/Indicators/Indi_Momentum.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -29,18 +29,15 @@ * In addition, it can help to identify when the price action is losing steam to prepare for a potential trend reversal. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" #include "Indi_PriceFeeder.mqh" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iMomentum(string _symbol, int _tf, int _period, int _ap, int _shift) { - ResetLastError(); - return Indi_Momentum::iMomentum(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); -} -#endif - // Structs. struct IndiMomentumParams : IndicatorParams { unsigned int period; @@ -95,10 +92,18 @@ class Indi_Momentum : public Indicator { */ static double iMomentum(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, ENUM_APPLIED_PRICE _ap, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iMomentum(_symbol, _tf, _period, _ap, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iMomentum(_symbol, _tf, _period, _ap), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -106,8 +111,8 @@ class Indi_Momentum : public Indicator { int _mode, int _shift = 0) { INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_indi, _period); - double _indi_value_buffer[]; - IndicatorDataEntry _entry(_indi.GetModeCount()); + ARRAY(double, _indi_value_buffer); + IndicatorDataEntry _entry(_indi PTR_DEREF GetModeCount()); ArrayResize(_indi_value_buffer, _period); @@ -122,12 +127,12 @@ class Indi_Momentum : public Indicator { return momentum; } - static double iMomentumOnArray(double &array[], int total, int period, int shift) { + static double iMomentumOnArray(CONST_ARRAY_REF(double, array), int total, int period, int shift) { #ifdef __MQL4__ return ::iMomentumOnArray(array, total, period, shift); #else Indi_PriceFeeder indi_price_feeder(array); - return iMomentumOnIndicator(&indi_price_feeder, NULL, NULL, period, /*unused*/ PRICE_OPEN, shift); + return iMomentumOnIndicator(&indi_price_feeder, NULL, PERIOD_CURRENT, period, /*unused*/ PRICE_OPEN, shift); #endif } @@ -146,7 +151,7 @@ class Indi_Momentum : public Indicator { // @fixit Somehow shift isn't used neither in MT4 nor MT5. _value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), iparams.shift + ToRelShift(_abs_shift)); - if (idparams.IsDrawing()) { + if (idparams.IsPloting()) { // draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + ToRelShift(_abs_shift)), _value, // 1); } @@ -161,7 +166,7 @@ class Indi_Momentum : public Indicator { // @fixit Somehow shift isn't used neither in MT4 nor MT5. _value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), iparams.shift + ToRelShift(_abs_shift)); - if (idparams.IsDrawing()) { + if (idparams.IsPloting()) { // draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + ToRelShift(_abs_shift)), _value, // 1); } @@ -211,3 +216,11 @@ class Indi_Momentum : public Indicator { iparams.applied_price = _ap; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iMomentum(string _symbol, int _tf, int _period, int _ap, int _shift) { + ResetLastError(); + return Indi_Momentum::iMomentum(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_APPLIED_PRICE)_ap, _shift); +} +#endif diff --git a/Indicators/Indi_OBV.mqh b/Indicators/Indi_OBV.mqh index 2d82a0001..1a5f0e62b 100644 --- a/Indicators/Indi_OBV.mqh +++ b/Indicators/Indi_OBV.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iOBV(string _symbol, int _tf, int _av, int _shift) { - ResetLastError(); - return Indi_OBV::iOBV(_symbol, (ENUM_TIMEFRAMES)_tf, (ENUM_APPLIED_VOLUME)_av, _shift); -} -#endif - // Structs. struct IndiOBVParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; // MT4 only. @@ -87,7 +84,7 @@ class Indi_OBV : public Indicator { } // Volume uses volume only. - return _ds PTR_DEREF HasSpecificValueStorage(INDI_VS_TYPE_VOLUME); + return _ds PTR_DEREF HasSpecificValueStorage(INDI_DATA_VS_TYPE_VOLUME); } /** @@ -104,10 +101,18 @@ class Indi_OBV : public Indicator { ENUM_APPLIED_VOLUME _applied = VOLUME_TICK, // MT5 only. #endif int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iOBV(_symbol, _tf, _applied, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iOBV(_symbol, _tf, _applied), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -174,3 +179,11 @@ class Indi_OBV : public Indicator { iparams.applied_volume = _applied_volume; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iOBV(string _symbol, int _tf, int _av, int _shift) { + ResetLastError(); + return Indi_OBV::iOBV(_symbol, (ENUM_TIMEFRAMES)_tf, (ENUM_APPLIED_VOLUME)_av, _shift); +} +#endif diff --git a/Indicators/Indi_OsMA.mqh b/Indicators/Indi_OsMA.mqh index 4c6e79dcb..d15cff845 100644 --- a/Indicators/Indi_OsMA.mqh +++ b/Indicators/Indi_OsMA.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,18 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iOsMA(string _symbol, int _tf, int _ema_fp, int _ema_sp, int _signal_period, int _ap, int _shift) { - ResetLastError(); - return Indi_OsMA::iOsMA(_symbol, (ENUM_TIMEFRAMES)_tf, _ema_fp, _ema_sp, _signal_period, (ENUM_APPLIED_PRICE)_ap, - _shift); -} -#endif - // Structs. struct IndiOsMAParams : IndicatorParams { int ema_fast_period; @@ -88,11 +84,19 @@ class Indi_OsMA : public Indicator { static double iOsMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ema_fast_period, int _ema_slow_period, int _signal_period, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iOsMA(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN( ::iOsMA(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -192,3 +196,12 @@ class Indi_OsMA : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iOsMA(string _symbol, int _tf, int _ema_fp, int _ema_sp, int _signal_period, int _ap, int _shift) { + ResetLastError(); + return Indi_OsMA::iOsMA(_symbol, (ENUM_TIMEFRAMES)_tf, _ema_fp, _ema_sp, _signal_period, (ENUM_APPLIED_PRICE)_ap, + _shift); +} +#endif diff --git a/Indicators/Indi_PriceChannel.mqh b/Indicators/Indi_PriceChannel.mqh index 4e365d2d9..9505141fd 100644 --- a/Indicators/Indi_PriceChannel.mqh +++ b/Indicators/Indi_PriceChannel.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "Indi_ZigZag.mqh" // Structs. @@ -73,7 +78,8 @@ class Indi_PriceChannel : public Indicator { } // PC uses high and low prices only. - return _ds PTR_DEREF HasSpecificAppliedPriceValueStorage(PRICE_HIGH | PRICE_LOW); + return _ds PTR_DEREF HasSpecificAppliedPriceValueStorage(PRICE_HIGH) && + _ds PTR_DEREF HasSpecificAppliedPriceValueStorage(PRICE_LOW); } /** @@ -90,22 +96,22 @@ class Indi_PriceChannel : public Indicator { * Calculates Price Channel on the array of values. */ static double iPriceChannelOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _period, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(3); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(3); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_PriceChannel::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, - _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _period)); + _cache PTR_DEREF SetPrevCalculated(Indi_PriceChannel::Calculate( + INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), _period)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_PriceFeeder.mqh b/Indicators/Indi_PriceFeeder.mqh index 8b1d6baf1..067a02acd 100644 --- a/Indicators/Indi_PriceFeeder.mqh +++ b/Indicators/Indi_PriceFeeder.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,14 +20,19 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" // Structs. struct IndiPriceFeederParams : IndicatorParams { ENUM_APPLIED_PRICE applied_price; - double price_data[]; + ARRAY(double, price_data); /** * Struct constructor. @@ -39,7 +44,7 @@ struct IndiPriceFeederParams : IndicatorParams { * * @todo Use more modes (full OHCL). */ - IndiPriceFeederParams(const double& _price_data[], int _total = 0) : IndicatorParams(INDI_PRICE_FEEDER) { + IndiPriceFeederParams(CONST_ARRAY_REF(double, _price_data), int _total = 0) : IndicatorParams(INDI_PRICE_FEEDER) { ArrayCopy(price_data, _price_data, 0, 0, _total == 0 ? WHOLE_ARRAY : _total); }; IndiPriceFeederParams(IndiPriceFeederParams& _params) { THIS_REF = _params; }; @@ -57,8 +62,9 @@ class Indi_PriceFeeder : public Indicator { IndicatorData* _indi_src = NULL, int _indi_src_mode = 0) : Indicator(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), _indi_src){}; - Indi_PriceFeeder(const double& _price_data[], int _total = 0, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, - IndicatorData* _indi_src = NULL, int _indi_src_mode = 0) + Indi_PriceFeeder(CONST_ARRAY_REF(double, _price_data), int _total = 0, + ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData* _indi_src = NULL, + int _indi_src_mode = 0) : Indicator(IndiPriceFeederParams(), IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), _indi_src) {} @@ -78,7 +84,9 @@ class Indi_PriceFeeder : public Indicator { */ unsigned int GetPossibleDataModes() override { return IDATA_BUILTIN; } - void SetPrices(const double& _price_data[], int _total = 0) { iparams = IndiPriceFeederParams(_price_data, _total); } + void SetPrices(CONST_ARRAY_REF(double, _price_data), int _total = 0) { + iparams = IndiPriceFeederParams(_price_data, _total); + } /** * Checks whether indicator has a valid value for a given shift. @@ -103,7 +111,7 @@ class Indi_PriceFeeder : public Indicator { bool OnTick(int _global_tick_index) override { bool _result = Indicator::OnTick(_global_tick_index); - if (idparams.IsDrawing()) { + if (idparams.IsPloting()) { int _max_modes = Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES)); IndicatorDataEntry _entry = GetEntry(0); for (int i = 0; i < _max_modes; ++i) { diff --git a/Indicators/Indi_PriceVolumeTrend.mqh b/Indicators/Indi_PriceVolumeTrend.mqh index bb101d2bb..0d646304a 100644 --- a/Indicators/Indi_PriceVolumeTrend.mqh +++ b/Indicators/Indi_PriceVolumeTrend.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,18 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. // 100 bars was originally specified by Indicators/Examples/PVT.mq5 #define INDI_PVT_MIN_BARS 2 // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" // Structs. @@ -85,21 +90,21 @@ class Indi_PriceVolumeTrend : public Indicator { * Calculates Price Volume Trend on the array of values. */ static double iPVTOnArray(INDICATOR_CALCULATE_PARAMS_LONG, ENUM_APPLIED_VOLUME _av, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated( - Indi_PriceVolumeTrend::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _av)); + _cache PTR_DEREF SetPrevCalculated(Indi_PriceVolumeTrend::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, + _cache PTR_DEREF GetBuffer(0), _av)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** @@ -133,7 +138,7 @@ class Indi_PriceVolumeTrend : public Indicator { } static void CalculatePVT(const int pos, const int rates_total, ValueStorage &close, - ValueStorage &volume, ValueStorage &ExtPVTBuffer) { + ValueStorage &volume, ValueStorage &ExtPVTBuffer) { for (int i = pos; i < rates_total && !IsStopped(); i++) { double prev_close = close[i - 1].Get(); // Calculate PVT value. diff --git a/Indicators/Indi_RS.mqh b/Indicators/Indi_RS.mqh index 3b7c513c4..e924cb741 100644 --- a/Indicators/Indi_RS.mqh +++ b/Indicators/Indi_RS.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "OHLC/Indi_OHLC.mqh" #include "Special/Indi_Math.mqh" @@ -110,7 +115,7 @@ class Indi_RS : public Indicator { // Updating Maths' data sources to be the same as RS data source. imath.GetByKey(0) REF_DEREF SetDataSource(GetDataSource()); imath.GetByKey(1) REF_DEREF SetDataSource(GetDataSource()); - return imath[_mode].Ptr().GetEntryValue(); + return imath[_mode] REF_DEREF GetEntryValue(); break; default: SetUserError(ERR_INVALID_PARAMETER); diff --git a/Indicators/Indi_RVI.mqh b/Indicators/Indi_RVI.mqh index f857a4694..a2791e97d 100644 --- a/Indicators/Indi_RVI.mqh +++ b/Indicators/Indi_RVI.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iRVI(string _symbol, int _tf, int _period, int _mode, int _shift) { - ResetLastError(); - return Indi_RVI::iRVI(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_SIGNAL_LINE)_mode, _shift); -} -#endif - // Structs. struct IndiRVIParams : IndicatorParams { unsigned int period; @@ -84,10 +81,18 @@ class Indi_RVI : public Indicator { string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 10, ENUM_SIGNAL_LINE _mode = LINE_MAIN, // (MT4/MT5): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iRVI(_symbol, _tf, _period, _mode, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iRVI(_symbol, _tf, _period), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -135,3 +140,11 @@ class Indi_RVI : public Indicator { iparams.period = _period; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iRVI(string _symbol, int _tf, int _period, int _mode, int _shift) { + ResetLastError(); + return Indi_RVI::iRVI(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_SIGNAL_LINE)_mode, _shift); +} +#endif diff --git a/Indicators/Indi_RateOfChange.mqh b/Indicators/Indi_RateOfChange.mqh index dda47c51c..73c426979 100644 --- a/Indicators/Indi_RateOfChange.mqh +++ b/Indicators/Indi_RateOfChange.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" // Structs. struct IndiRateOfChangeParams : IndicatorParams { @@ -79,21 +84,21 @@ class Indi_RateOfChange : public Indicator { * Calculates Rate of Change on the array of values. */ static double iROCOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, int _period, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_price); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated( - Indi_RateOfChange::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), _period)); + _cache PTR_DEREF SetPrevCalculated(Indi_RateOfChange::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, + _cache PTR_DEREF GetBuffer(0), _period)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_StdDev.mqh b/Indicators/Indi_StdDev.mqh index 2c3800559..25e29a7ce 100644 --- a/Indicators/Indi_StdDev.mqh +++ b/Indicators/Indi_StdDev.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -27,24 +27,16 @@ * It doesn't give independent signals. Is used to define volatility (trend strength). */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Indicator/Indicator.h" -#include "../Storage/ObjectsCache.h" -#include "Indi_MA.mqh" +#include "../Storage/Cache/ObjectsCache.h" #include "Indi_PriceFeeder.mqh" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iStdDev(string _symbol, int _tf, int _ma_period, int _ma_shift, int _ma_method, int _ap, int _shift) { - ResetLastError(); - return Indi_StdDev::iStdDev(_symbol, (ENUM_TIMEFRAMES)_tf, _ma_period, _ma_shift, (ENUM_MA_METHOD)_ma_method, - (ENUM_APPLIED_PRICE)_ap, _shift); -} -double iStdDevOnArray(double &_arr[], int _total, int _ma_period, int _ma_shift, int _ma_method, int _abs_shift) { - ResetLastError(); - return Indi_StdDev::iStdDevOnArray(_arr, _total, _ma_period, _ma_shift, (ENUM_MA_METHOD)_ma_method, _abs_shift); -} -#endif +#include "Price/Indi_MA.h" // Structs. struct IndiStdDevParams : IndicatorParams { @@ -104,11 +96,19 @@ class Indi_StdDev : public Indicator { */ static double iStdDev(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iStdDev(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iStdDev(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -120,7 +120,7 @@ class Indi_StdDev : public Indicator { Indi_StdDev *_obj = NULL) { INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_source, _ma_period + _ma_shift + _shift) - double _indi_value_buffer[]; + ARRAY(double, _indi_value_buffer); double _std_dev; int i; @@ -142,16 +142,17 @@ class Indi_StdDev : public Indicator { return _std_dev; } - static double iStdDevOnArray(const double &price[], double MAprice, int period) { + static double iStdDevOnArray(CONST_ARRAY_REF(double, price), double MAprice, int period) { double std_dev = 0; int i; - for (i = 0; i < period; ++i) std_dev += MathPow(price[i] - MAprice, 2); + for (i = 0; i < period; ++i) std_dev += MathPow(price[i] - MAprice, (double)2); return MathSqrt(std_dev / period); } - static double iStdDevOnArray(double &array[], int total, int ma_period, int ma_shift, int ma_method, int shift) { + static double iStdDevOnArray(ARRAY_REF(double, array), int total, int ma_period, int ma_shift, + ENUM_MA_METHOD ma_method, int shift) { #ifdef __MQL4__ return ::iStdDevOnArray(array, total, ma_period, ma_shift, ma_method, shift); #endif @@ -194,17 +195,17 @@ class Indi_StdDev : public Indicator { /** * Standard Deviation On Array is just a normal standard deviation over MA with a selected method. */ - static double iStdDevOnArray(const double &price[], int period, ENUM_MA_METHOD ma_method = MODE_SMA) { + static double iStdDevOnArray(CONST_ARRAY_REF(double, price), int period, ENUM_MA_METHOD ma_method = MODE_SMA) { string _key = "Indi_PriceFeeder"; Indi_PriceFeeder *_indi_price_feeder; if (!ObjectsCache::TryGet(_key, _indi_price_feeder)) { - IndiPriceFeederParams _params(); - IndicatorData *_indi_pf = new Indi_PriceFeeder(_params); + IndiPriceFeederParams _params; + Indi_PriceFeeder *_indi_pf = new Indi_PriceFeeder(_params); _indi_price_feeder = ObjectsCache::Set(_key, _indi_pf); } // Filling reused price feeder. - _indi_price_feeder.SetPrices(price); + _indi_price_feeder PTR_DEREF SetPrices(price); IndiMAParams ma_params(period, 0, ma_method, PRICE_OPEN); @@ -214,12 +215,12 @@ class Indi_StdDev : public Indicator { _indi_ma.SetDataSource(_indi_price_feeder, 0); // Using first and only mode from price feeder. double _result = iStdDevOnIndicator(_indi_ma, NULL, NULL, period, 0, PRICE_OPEN, 0); // Last parameter is unused. - // We don't want to store reference to indicator too long. + // We don't want to store reference to indicator too int64. _indi_ma.SetDataSource(NULL, 0); return _result; */ - Print(__FUNCTION__ + " must be refactored!"); + Print(string(__FUNCTION__) + " must be refactored!"); DebugBreak(); return 0; } @@ -321,3 +322,17 @@ class Indi_StdDev : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iStdDev(string _symbol, int _tf, int _ma_period, int _ma_shift, int _ma_method, int _ap, int _shift) { + ResetLastError(); + return Indi_StdDev::iStdDev(_symbol, (ENUM_TIMEFRAMES)_tf, _ma_period, _ma_shift, (ENUM_MA_METHOD)_ma_method, + (ENUM_APPLIED_PRICE)_ap, _shift); +} +double iStdDevOnArray(ARRAY_REF(double, _arr), int _total, int _ma_period, int _ma_shift, int _ma_method, + int _abs_shift) { + ResetLastError(); + return Indi_StdDev::iStdDevOnArray(_arr, _total, _ma_period, _ma_shift, (ENUM_MA_METHOD)_ma_method, _abs_shift); +} +#endif diff --git a/Indicators/Indi_TEMA.mqh b/Indicators/Indi_TEMA.mqh index 55c550fa3..563f3679b 100644 --- a/Indicators/Indi_TEMA.mqh +++ b/Indicators/Indi_TEMA.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,15 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" -#include "Indi_MA.mqh" +#include "../Storage/Dict/Buffer/BufferStruct.h" +#include "Price/Indi_MA.h" // Structs. struct IndiTEMAParams : IndicatorParams { @@ -76,9 +81,10 @@ class Indi_TEMA : public Indicator { */ static double iTEMA(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, int _ma_shift, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, Indi_TEMA *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iTEMA(_symbol, _tf, _ma_period, _ma_shift, _ap), _mode, _shift); -#else +#else // __MQL5__ if (_obj == nullptr) { Print( "Indi_TEMA::iTEMA() can work without supplying pointer to IndicatorData only in MQL5. In this platform " @@ -88,6 +94,13 @@ class Indi_TEMA : public Indicator { } return iTEMAOnIndicator(_obj, _ma_period, _ma_shift, _ap, _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -95,22 +108,23 @@ class Indi_TEMA : public Indicator { * Calculates iTEMA on the array of values. */ static double iTEMAOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, int _ma_period, int _ma_shift, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_price); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(4); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(4); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_TEMA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), - _cache.GetBuffer(1), _cache.GetBuffer(2), - _cache.GetBuffer(3), _ma_period, _ma_shift)); + _cache PTR_DEREF SetPrevCalculated( + Indi_TEMA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _ma_period, _ma_shift)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_TRIX.mqh b/Indicators/Indi_TRIX.mqh index f877fafa8..3c3c3964f 100644 --- a/Indicators/Indi_TRIX.mqh +++ b/Indicators/Indi_TRIX.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,15 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" -#include "Indi_MA.mqh" +#include "../Storage/Dict/Buffer/BufferStruct.h" +#include "Price/Indi_MA.h" // Structs. struct IndiTRIXParams : IndicatorParams { @@ -74,9 +79,10 @@ class Indi_TRIX : public Indicator { */ static double iTriX(string _symbol, ENUM_TIMEFRAMES _tf, int _ma_period, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iTriX(_symbol, _tf, _ma_period, _ap), _mode, _shift); -#else +#else // __MQL5__ if (_obj == nullptr) { Print( "Indi_TRIX::iTriX() can work without supplying pointer to IndicatorData only in MQL5. In this platform " @@ -86,6 +92,13 @@ class Indi_TRIX : public Indicator { } return iTriXOnIndicator(_obj, _ma_period, _ap, _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -93,22 +106,23 @@ class Indi_TRIX : public Indicator { * Calculates TriX on the array of values. */ static double iTriXOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, int _ma_period, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_price); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(4); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(4); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_TRIX::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), - _cache.GetBuffer(1), _cache.GetBuffer(2), - _cache.GetBuffer(3), _ma_period)); + _cache PTR_DEREF SetPrevCalculated( + Indi_TRIX::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _ma_period)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_UltimateOscillator.mqh b/Indicators/Indi_UltimateOscillator.mqh index 69160578e..22b5eb94f 100644 --- a/Indicators/Indi_UltimateOscillator.mqh +++ b/Indicators/Indi_UltimateOscillator.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,12 +20,17 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" #include "Indi_ATR.mqh" -#include "Indi_MA.mqh" +#include "Price/Indi_MA.h" // Structs. struct IndiUltimateOscillatorParams : IndicatorParams { @@ -107,9 +112,9 @@ class Indi_UltimateOscillator : public Indicator { _indi, Util::MakeKey(_fast_period, _middle_period, _slow_period, _fast_k, _middle_k, _slow_k)); // Will return Indi_ATRs with the same candles source as _indi's. - IndicatorData *_indi_atr_fast = Indi_ATR::GetCached(_indi, _fast_period); - IndicatorData *_indi_atr_middle = Indi_ATR::GetCached(_indi, _middle_period); - IndicatorData *_indi_atr_slow = Indi_ATR::GetCached(_indi, _slow_period); + Indi_ATR *_indi_atr_fast = Indi_ATR::GetCached(_indi, _fast_period); + Indi_ATR *_indi_atr_middle = Indi_ATR::GetCached(_indi, _middle_period); + Indi_ATR *_indi_atr_slow = Indi_ATR::GetCached(_indi, _slow_period); return iUOOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _fast_period, _middle_period, _slow_period, _fast_k, _middle_k, _slow_k, _mode, _shift, _cache, _indi_atr_fast, _indi_atr_middle, _indi_atr_slow); @@ -120,24 +125,25 @@ class Indi_UltimateOscillator : public Indicator { */ static double iUOOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _fast_period, int _middle_period, int _slow_period, int _fast_k, int _middle_k, int _slow_k, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, IndicatorData *_indi_atr_fast, - IndicatorData *_indi_atr_middle, IndicatorData *_indi_atr_slow, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, Indi_ATR *_indi_atr_fast, Indi_ATR *_indi_atr_middle, + Indi_ATR *_indi_atr_slow, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1 + 4); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1 + 4); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_UltimateOscillator::Calculate( - INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _cache.GetBuffer(3), _cache.GetBuffer(4), _fast_period, - _middle_period, _slow_period, _fast_k, _middle_k, _slow_k, _indi_atr_fast, _indi_atr_middle, _indi_atr_slow)); + _cache PTR_DEREF SetPrevCalculated(Indi_UltimateOscillator::Calculate( + INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _cache PTR_DEREF GetBuffer(4), _fast_period, _middle_period, + _slow_period, _fast_k, _middle_k, _slow_k, _indi_atr_fast, _indi_atr_middle, _indi_atr_slow)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_VIDYA.mqh b/Indicators/Indi_VIDYA.mqh index ebcc3b304..c2513a045 100644 --- a/Indicators/Indi_VIDYA.mqh +++ b/Indicators/Indi_VIDYA.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" // Structs. struct IndiVIDYAParams : IndicatorParams { @@ -79,9 +84,10 @@ class Indi_VIDYA : public Indicator { */ static double iVIDyA(string _symbol, ENUM_TIMEFRAMES _tf, int _cmo_period, int _ema_period, int _ma_shift, ENUM_APPLIED_PRICE _ap, int _mode = 0, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iVIDyA(_symbol, _tf, _cmo_period, _ema_period, _ma_shift, _ap), _mode, _shift); -#else +#else // __MQL5__ if (_obj == nullptr) { Print( "Indi_VIDYA::iVIDyA() can work without supplying pointer to IndicatorData only in MQL5. In this platform " @@ -91,6 +97,13 @@ class Indi_VIDYA : public Indicator { } return iVIDyAOnIndicator(_obj, _symbol, _tf, _cmo_period, _ema_period, _ma_shift, _ap, _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -98,22 +111,22 @@ class Indi_VIDYA : public Indicator { * Calculates iVIDyA on the array of values. */ static double iVIDyAOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, int _cmo_period, int _ema_period, int _ma_shift, - int _mode, int _abs_shift, IndicatorCalculateCache *_cache, - bool _recalculate = false) { - _cache.SetPriceBuffer(_price); + int _mode, int _abs_shift, IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_VIDYA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), - _cmo_period, _ema_period, _ma_shift)); + _cache PTR_DEREF SetPrevCalculated(Indi_VIDYA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, + _cache PTR_DEREF GetBuffer(0), _cmo_period, + _ema_period, _ma_shift)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_VROC.mqh b/Indicators/Indi_VROC.mqh index df21ac3a3..9f65e114f 100644 --- a/Indicators/Indi_VROC.mqh +++ b/Indicators/Indi_VROC.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" // Structs. @@ -71,7 +76,7 @@ class Indi_VROC : public Indicator { } // VROC uses volume only. - return _ds PTR_DEREF HasSpecificValueStorage(INDI_VS_TYPE_VOLUME); + return _ds PTR_DEREF HasSpecificValueStorage(INDI_DATA_VS_TYPE_VOLUME); } /** @@ -93,21 +98,21 @@ class Indi_VROC : public Indicator { * Calculates VROC on the array of values. */ static double iVROCOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _period, ENUM_APPLIED_VOLUME _av, int _mode, - int _abs_shift, IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + int _abs_shift, IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated( - Indi_VROC::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), _period, _av)); + _cache PTR_DEREF SetPrevCalculated( + Indi_VROC::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), _period, _av)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** @@ -139,7 +144,7 @@ class Indi_VROC : public Indicator { return (rates_total); } - static void CalculateVROC(const int pos, const int rates_total, ValueStorage &volume, + static void CalculateVROC(const int pos, const int rates_total, ValueStorage &volume, ValueStorage &ExtVROCBuffer, int ExtPeriodVROC) { for (int i = pos; i < rates_total && !IsStopped(); i++) { double prev_volume = (double)(volume[i - (ExtPeriodVROC - 1)].Get()); diff --git a/Indicators/Indi_Volumes.mqh b/Indicators/Indi_Volumes.mqh index 32dd51fa1..9d3551fa6 100644 --- a/Indicators/Indi_Volumes.mqh +++ b/Indicators/Indi_Volumes.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,18 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. // 2 bars was originally specified by Indicators/Examples/Volumes.mq5 #define INDI_VOLUMES_MIN_BARS 2 // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" // Structs. @@ -74,7 +79,7 @@ class Indi_Volumes : public Indicator { } // Volume uses volume only. - return _ds PTR_DEREF HasSpecificValueStorage(INDI_VS_TYPE_VOLUME); + return _ds PTR_DEREF HasSpecificValueStorage(INDI_DATA_VS_TYPE_VOLUME); } /** @@ -96,21 +101,22 @@ class Indi_Volumes : public Indicator { * Calculates AMVolumes on the array of values. */ static double iVolumesOnArray(INDICATOR_CALCULATE_PARAMS_LONG, ENUM_APPLIED_VOLUME _av, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1 + 1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1 + 1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_Volumes::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), - _cache.GetBuffer(1), _av)); + _cache PTR_DEREF SetPrevCalculated(Indi_Volumes::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, + _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _av)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** @@ -137,7 +143,7 @@ class Indi_Volumes : public Indicator { return (rates_total); } - static void CalculateVolume(const int pos, const int rates_total, ValueStorage &volume, + static void CalculateVolume(const int pos, const int rates_total, ValueStorage &volume, ValueStorage &ExtVolumesBuffer, ValueStorage &ExtColorsBuffer) { ExtVolumesBuffer[0] = (double)volume[0].Get(); ExtColorsBuffer[0] = 0.0; diff --git a/Indicators/Indi_WilliamsAD.mqh b/Indicators/Indi_WilliamsAD.mqh index af3893d88..3a81b4e5f 100644 --- a/Indicators/Indi_WilliamsAD.mqh +++ b/Indicators/Indi_WilliamsAD.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,19 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. // 2 bars was originally specified by Indicators/Examples/W_AD.mq5 #define INDI_WAD_MIN_BARS 100 // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Platform/Platform.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" // Structs. @@ -40,7 +46,7 @@ struct IndiWilliamsADParams : IndicatorParams { }; /** - * Implements the Volume Rate of Change indicator. + * Implements the Williams' AD indicator. */ class Indi_WilliamsAD : public Indicator { public: @@ -93,22 +99,22 @@ class Indi_WilliamsAD : public Indicator { /** * Calculates William's AD on the array of values. */ - static double iWADOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _abs_shift, - IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + static double iWADOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _mode, int _abs_shift, IndiBufferCache *_cache, + bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated( - Indi_WilliamsAD::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0))); + _cache PTR_DEREF SetPrevCalculated( + Indi_WilliamsAD::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0))); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_ZigZag.mqh b/Indicators/Indi_ZigZag.mqh index c33d5353a..0a830ea56 100644 --- a/Indicators/Indi_ZigZag.mqh +++ b/Indicators/Indi_ZigZag.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,12 +20,19 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. // 100 bars was originally specified by Indicators/Examples/ZigZag.mq5 #define INDI_ZIGZAG_MIN_BARS 100 // Includes. #include "../Indicator/Indicator.h" +#include "../Platform/Platform.h" +#include "../Platform/Terminal.h" #include "../Storage/ValueStorage.all.h" // Defines. @@ -114,9 +121,10 @@ class Indi_ZigZag : public Indicator { * Returns value for ZigZag indicator. */ static double iCustomZigZag(string _symbol, ENUM_TIMEFRAMES _tf, string _name, int _depth, int _deviation, - int _backstep, ENUM_ZIGZAG_LINE _mode = 0, int _shift = 0, IndicatorData *_obj = NULL) { + int _backstep, ENUM_ZIGZAG_LINE _mode = ZIGZAG_BUFFER, int _shift = 0, + IndicatorData *_obj = NULL) { #ifdef __MQL5__ - int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL; + int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorDataState::INDICATOR_DATA_STATE_PROP_HANDLE) : NULL; double _res[]; if (_handle == NULL || _handle == INVALID_HANDLE) { if ((_handle = ::iCustom(_symbol, _tf, _name, _depth, _deviation, _backstep)) == INVALID_HANDLE) { @@ -149,8 +157,8 @@ class Indi_ZigZag : public Indicator { /** * Returns value for ZigZag indicator. */ - static double iZigZag(IndicatorData *_indi, int _depth, int _deviation, int _backstep, ENUM_ZIGZAG_LINE _mode = 0, - int _rel_shift = 0) { + static double iZigZag(IndicatorData *_indi, int _depth, int _deviation, int _backstep, + ENUM_ZIGZAG_LINE _mode = ZIGZAG_BUFFER, int _rel_shift = 0) { INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_indi, INDI_ZIGZAG_MIN_BARS); INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_indi, Util::MakeKey(_depth, _deviation, _backstep)); return iZigZagOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _depth, _deviation, _backstep, _mode, @@ -161,22 +169,22 @@ class Indi_ZigZag : public Indicator { * Calculates ZigZag on the array of values. */ static double iZigZagOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _depth, int _deviation, int _backstep, int _mode, - int _abs_shift, IndicatorCalculateCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + int _abs_shift, IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(1 + 2); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(1 + 2); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_ZigZag::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache.GetBuffer(0), - _cache.GetBuffer(1), _cache.GetBuffer(2), _depth, - _deviation, _backstep)); + _cache PTR_DEREF SetPrevCalculated(Indi_ZigZag::Calculate( + INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), _depth, _deviation, _backstep)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/Indi_ZigZagColor.mqh b/Indicators/Indi_ZigZagColor.mqh index 537ca191d..e837964f5 100644 --- a/Indicators/Indi_ZigZagColor.mqh +++ b/Indicators/Indi_ZigZagColor.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,18 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. // 100 bars was originally specified by Indicators/Examples/ZigzagColor.mq5 #define INDI_ZIGZAG_COLOR_MIN_BARS 100 // Includes. -#include "../BufferStruct.mqh" #include "../Indicator/Indicator.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "../Storage/ValueStorage.all.h" #include "Indi_ZigZag.mqh" @@ -50,7 +55,7 @@ struct IndiZigZagColorParams : IndicatorParams { }; /** - * Implements the Volume Rate of Change indicator. + * Implements the ZigZag Color indicator. */ class Indi_ZigZagColor : public Indicator { public: @@ -97,7 +102,7 @@ class Indi_ZigZagColor : public Indicator { * Returns value for ZigZag Color indicator. */ static double iZigZagColor(IndicatorData *_indi, int _depth, int _deviation, int _backstep, - ENUM_ZIGZAG_LINE _mode = 0, int _rel_shift = 0) { + ENUM_ZIGZAG_LINE _mode = ZIGZAG_BUFFER, int _rel_shift = 0) { INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_indi, INDI_ZIGZAG_COLOR_MIN_BARS); INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(_indi, Util::MakeKey(_depth, _deviation, _backstep)); return iZigZagColorOnArray(INDICATOR_CALCULATE_POPULATED_PARAMS_LONG, _depth, _deviation, _backstep, _mode, @@ -108,24 +113,24 @@ class Indi_ZigZagColor : public Indicator { * Calculates ZigZag Color on the array of values. */ static double iZigZagColorOnArray(INDICATOR_CALCULATE_PARAMS_LONG, int _depth, int _deviation, int _backstep, - int _mode, int _abs_shift, IndicatorCalculateCache *_cache, + int _mode, int _abs_shift, IndiBufferCache *_cache, bool _recalculate = false) { - _cache.SetPriceBuffer(_open, _high, _low, _close); + _cache PTR_DEREF SetPriceBuffer(_open, _high, _low, _close); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(3 + 2); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(3 + 2); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_ZigZagColor::Calculate(INDICATOR_CALCULATE_GET_PARAMS_LONG, - _cache.GetBuffer(0), _cache.GetBuffer(1), - _cache.GetBuffer(2), _cache.GetBuffer(3), - _cache.GetBuffer(4), _depth, _deviation, _backstep)); + _cache PTR_DEREF SetPrevCalculated(Indi_ZigZagColor::Calculate( + INDICATOR_CALCULATE_GET_PARAMS_LONG, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _cache PTR_DEREF GetBuffer(4), _depth, _deviation, _backstep)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** diff --git a/Indicators/OHLC/Indi_OHLC.mqh b/Indicators/OHLC/Indi_OHLC.mqh index bf119cb41..0e491259c 100644 --- a/Indicators/OHLC/Indi_OHLC.mqh +++ b/Indicators/OHLC/Indi_OHLC.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../../BufferStruct.mqh" #include "../../Indicator/Indicator.h" +#include "../../Storage/Dict/Buffer/BufferStruct.h" #include "../../Storage/Objects.h" // Enums. diff --git a/Indicators/OHLC/README.md b/Indicators/OHLC/README.md new file mode 100644 index 000000000..68b1081b0 --- /dev/null +++ b/Indicators/OHLC/README.md @@ -0,0 +1,28 @@ +# OHLC indicators + +OHLC (Open-High-Low-Close) indicators are a specific category of technical indicators +used to generate values based on the open, high, low, and close prices of an asset. +The OHLC values can be used to construct candlestick charts, +which visually represent the price movements in the market. + +One example of an OHLC indicator is the Heikin-Ashi (HA) indicator. +Heikin-Ashi is known for its ability to filter out the noise +of day-to-day price fluctuations and provide a smoother representation of price data. +It achieves this by using a modified formula based on average price values. + +The Heikin-Ashi method calculates the open, high, low, and close values +based on the average of the previous candle's OHLC values. +This averaging technique helps to reduce the impact of sudden price spikes or gaps, +resulting in smoother candlestick patterns. +The modified candlestick charts generated by the Heikin-Ashi indicator +can provide clearer signals for identifying market trends and forecasting price movements. + +OHLC indicators, can be used in conjunction with other indicators or analysis techniques. +The OHLC values they produce can serve as input for other indicators +allowing traders to derive additional insights or develop trading strategies based on the price data. + +By utilizing OHLC indicators, traders can gain a better understanding of price dynamics, +identify key support and resistance levels, and recognize patterns +that may indicate potential trading opportunities. +The visual representation of OHLC values through candlestick charts +facilitates the interpretation of market sentiment and price action. diff --git a/Indicators/OHLC/indicators.h b/Indicators/OHLC/includes.h similarity index 80% rename from Indicators/OHLC/indicators.h rename to Indicators/OHLC/includes.h index be9752c28..8cf89dd84 100644 --- a/Indicators/OHLC/indicators.h +++ b/Indicators/OHLC/includes.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,5 +25,10 @@ * Include file to include all OHLC indicators. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // OHLC indicators. #include "Indi_OHLC.mqh" diff --git a/Indicators/OHLC/tests/Indi_OHLC.test.cpp b/Indicators/OHLC/tests/Indi_OHLC.test.cpp new file mode 100644 index 000000000..770ec0f86 --- /dev/null +++ b/Indicators/OHLC/tests/Indi_OHLC.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_OHLC indicator class. + */ + +// Includes. +#include "../Indi_OHLC.mqh" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_OHLC.test.mq4 b/Indicators/OHLC/tests/Indi_OHLC.test.mq4 similarity index 87% rename from Indicators/tests/Indi_OHLC.test.mq4 rename to Indicators/OHLC/tests/Indi_OHLC.test.mq4 index 841830833..8b452d441 100644 --- a/Indicators/tests/Indi_OHLC.test.mq4 +++ b/Indicators/OHLC/tests/Indi_OHLC.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_OHLC.test.mq5 b/Indicators/OHLC/tests/Indi_OHLC.test.mq5 similarity index 81% rename from Indicators/tests/Indi_OHLC.test.mq5 rename to Indicators/OHLC/tests/Indi_OHLC.test.mq5 index 6c2df2c08..4bb8c34d1 100644 --- a/Indicators/tests/Indi_OHLC.test.mq5 +++ b/Indicators/OHLC/tests/Indi_OHLC.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../OHLC/Indi_OHLC.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_OHLC.mqh" /** * @file diff --git a/Indicators/OHLC/tests/Makefile b/Indicators/OHLC/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/OHLC/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Indicators/Indi_MACD.mqh b/Indicators/Oscillator/Indi_MACD.h similarity index 92% rename from Indicators/Indi_MACD.mqh rename to Indicators/Oscillator/Indi_MACD.h index c7977ddd0..67460f4dd 100644 --- a/Indicators/Indi_MACD.mqh +++ b/Indicators/Oscillator/Indi_MACD.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,18 +20,19 @@ * */ -// Includes. -#include "../Indicator/Indicator.h" +/** + * @file + * Implements Moving Average Convergence Divergence (MACD) indicator. + */ -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iMACD(string _symbol, int _tf, int _ema_fp, int _ema_sp, int _signal_period, int _ap, int _mode, int _shift) { - ResetLastError(); - return Indi_MACD::iMACD(_symbol, (ENUM_TIMEFRAMES)_tf, _ema_fp, _ema_sp, _signal_period, (ENUM_APPLIED_PRICE)_ap, - (ENUM_SIGNAL_LINE)_mode, _shift); -} +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once #endif +// Includes. +#include "../../Indicator/Indicator.h" + // Structs. struct IndiMACDParams : IndicatorParams { unsigned int ema_fast_period; @@ -94,11 +95,19 @@ class Indi_MACD : public Indicator { unsigned int _signal_period, ENUM_APPLIED_PRICE _applied_price, ENUM_SIGNAL_LINE _mode = LINE_MAIN, // (MT4/MT5 _mode): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iMACD(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price, _mode, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN( ::iMACD(_symbol, _tf, _ema_fast_period, _ema_slow_period, _signal_period, _applied_price), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -203,3 +212,12 @@ class Indi_MACD : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iMACD(string _symbol, int _tf, int _ema_fp, int _ema_sp, int _signal_period, int _ap, int _mode, int _shift) { + ResetLastError(); + return Indi_MACD::iMACD(_symbol, (ENUM_TIMEFRAMES)_tf, _ema_fp, _ema_sp, _signal_period, (ENUM_APPLIED_PRICE)_ap, + (ENUM_SIGNAL_LINE)_mode, _shift); +} +#endif diff --git a/Indicators/Indi_RSI.mqh b/Indicators/Oscillator/Indi_RSI.h similarity index 94% rename from Indicators/Indi_RSI.mqh rename to Indicators/Oscillator/Indi_RSI.h index 1bc0dc454..8c494df7e 100644 --- a/Indicators/Indi_RSI.mqh +++ b/Indicators/Oscillator/Indi_RSI.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,20 @@ * */ +/** + * @file + * Implements Relative Strength Index (RSI) indicator. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../DictStruct.mqh" -#include "../Indicator/Indicator.h" -#include "Price/Indi_Price.mqh" +#include "../../Indicator/Indicator.h" +#include "../../Storage/Dict/DictStruct.h" +#include "../Price/Indi_Price.h" // Structs. struct IndiRSIParams : IndicatorParams { @@ -70,7 +80,7 @@ struct RSIGainLossData { * Implements the Relative Strength Index indicator. */ class Indi_RSI : public Indicator { - DictStruct aux_data; + DictStruct aux_data; public: /** @@ -110,17 +120,18 @@ class Indi_RSI : public Indicator { */ static double iRSI(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, ENUM_APPLIED_PRICE _applied_price = PRICE_CLOSE, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iRSI(_symbol, _tf, _period, _applied_price, _shift); -#else -#ifdef __MQL5__ +#else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iRSI(_symbol, _tf, _period, _applied_price), 0, _shift); -#else +#endif +#else // Non-MQL. + // @todo: Use Platform class. RUNTIME_ERROR( - "In C++ Indi_RSI::iRSI() method couldn't be used directly. Please use an On-Indicator mode and attach " + "Not implemented. Please use an On-Indicator mode and attach " "indicator via Platform::Add/AddWithDefaultBindings()."); return DBL_MAX; -#endif #endif } @@ -168,8 +179,8 @@ class Indi_RSI : public Indicator { ENUM_APPLIED_PRICE _ap = PRICE_CLOSE, int _shift = 0) { INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_target, _period + _shift + 1); // +1 because of _bar_time_prev. - long _bar_time_curr = _source PTR_DEREF GetBarTime(_shift); - long _bar_time_prev = _source PTR_DEREF GetBarTime(_shift + 1); + int64 _bar_time_curr = _source PTR_DEREF GetBarTime(_shift); + int64 _bar_time_prev = _source PTR_DEREF GetBarTime(_shift + 1); if (fmin(_bar_time_curr, _bar_time_prev) < 0) { // Return empty value on invalid bar time. return EMPTY_VALUE; diff --git a/Indicators/Indi_Stochastic.mqh b/Indicators/Oscillator/Indi_Stochastic.h similarity index 88% rename from Indicators/Indi_Stochastic.mqh rename to Indicators/Oscillator/Indi_Stochastic.h index d2cb81fe4..4d50863d7 100644 --- a/Indicators/Indi_Stochastic.mqh +++ b/Indicators/Oscillator/Indi_Stochastic.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,27 @@ * */ -// Includes. -#include "../Indicator/Indicator.h" +/** + * @file + * Implements Stochastic indicator. + */ -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iStochastic(string _symbol, int _tf, int _kperiod, int _dperiod, int _slowing, int _ma_method, int _pf, - int _mode, int _shift) { - ResetLastError(); - return Indi_Stochastic::iStochastic(_symbol, (ENUM_TIMEFRAMES)_tf, _kperiod, _dperiod, _slowing, - (ENUM_MA_METHOD)_ma_method, (ENUM_STO_PRICE)_pf, _mode, _shift); -} +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "../../Indicator/Indicator.h" +#include "../Price/Indi_MA.h" + +#ifndef __MQL__ +// Enums. +// @see: https://www.mql5.com/en/docs/constants/indicatorconstants/prices +enum ENUM_STO_PRICE { + STO_LOWHIGH = 0, // Calculation is based on Low/High prices. + STO_CLOSECLOSE, // Calculation is based on Close/Close prices. +}; #endif // Structs. @@ -99,11 +109,19 @@ class Indi_Stochastic : public Indicator { // (MT5 _price_field): STO_LOWHIGH - Low/High, STO_CLOSECLOSE - Close/Close int _mode, // (MT4): 0 - MODE_MAIN/MAIN_LINE, 1 - MODE_SIGNAL/SIGNAL_LINE int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iStochastic(_symbol, _tf, _kperiod, _dperiod, _slowing, _ma_method, _price_field, _mode, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN( ::iStochastic(_symbol, _tf, _kperiod, _dperiod, _slowing, _ma_method, _price_field), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -201,3 +219,13 @@ class Indi_Stochastic : public Indicator { iparams.price_field = _price_field; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iStochastic(string _symbol, int _tf, int _kperiod, int _dperiod, int _slowing, int _ma_method, int _pf, + int _mode, int _shift) { + ResetLastError(); + return Indi_Stochastic::iStochastic(_symbol, (ENUM_TIMEFRAMES)_tf, _kperiod, _dperiod, _slowing, + (ENUM_MA_METHOD)_ma_method, (ENUM_STO_PRICE)_pf, _mode, _shift); +} +#endif diff --git a/Indicators/Indi_WPR.mqh b/Indicators/Oscillator/Indi_WPR.h similarity index 88% rename from Indicators/Indi_WPR.mqh rename to Indicators/Oscillator/Indi_WPR.h index ff759aa64..1ac49fcd8 100644 --- a/Indicators/Indi_WPR.mqh +++ b/Indicators/Oscillator/Indi_WPR.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,20 @@ * */ -// Includes. -#include "../Indicator/Indicator.h" +/** + * @file + * Implements Williams Percent Range (WPR) indicator. + */ -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iWPR(string _symbol, int _tf, int _period, int _shift) { - ResetLastError(); - return Indi_WPR::iWPR(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _shift); -} +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once #endif +// Includes. +#include "../../Indicator/Indicator.h" +#include "../../Platform/Terminal.h" + // Structs. struct IndiWPRParams : IndicatorParams { unsigned int period; @@ -83,10 +86,11 @@ class Indi_WPR : public Indicator { */ static double iWPR(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, unsigned int _period = 14, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iWPR(_symbol, _tf, _period, _shift); #else // __MQL5__ - int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL; + int _handle = Object::IsValid(_obj) ? _obj.Get(IndicatorDataState::INDICATOR_DATA_STATE_PROP_HANDLE) : NULL; double _res[]; if (_handle == NULL || _handle == INVALID_HANDLE) { if ((_handle = ::iWPR(_symbol, _tf, _period)) == INVALID_HANDLE) { @@ -111,6 +115,13 @@ class Indi_WPR : public Indicator { return ArraySize(_res) > 0 ? _res[0] : EMPTY_VALUE; } return _res[0]; +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -150,3 +161,11 @@ class Indi_WPR : public Indicator { iparams.period = _period; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iWPR(string _symbol, int _tf, int _period, int _shift) { + ResetLastError(); + return Indi_WPR::iWPR(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _shift); +} +#endif diff --git a/Indicators/Oscillator/README.md b/Indicators/Oscillator/README.md new file mode 100644 index 000000000..6ef512086 --- /dev/null +++ b/Indicators/Oscillator/README.md @@ -0,0 +1,193 @@ +# Oscillator indicators + +Oscillators are a category of technical indicators used in financial markets analysis. +They are designed to identify overbought or oversold conditions and potential trend reversals. +Oscillators typically oscillate within a specific range or between certain values, +indicating the momentum or strength of a price movement. + +Oscillators are considered a subset of indicators since they are technical tools +used to analyze price data and generate signals. +They differ from other types of indicators +like trend-following or volume-based indicators +because oscillators are designed to provide information +about the short-term price behavior rather than long-term trends or volume patterns. + +Common examples of oscillators include the Relative Strength Index (RSI), +Stochastic Oscillator, Moving Average Convergence Divergence (MACD), and the Williams %R. +These indicators generate values that fluctuate within predefined boundaries, +typically between 0 and 100 or -100 and +100, +indicating the relative strength or weakness of price movements. + +Traders and analysts use oscillators to identify potential buying or selling opportunities, +divergences, and to gauge market conditions such as overbought or oversold levels. +They can be helpful in identifying potential trend reversals or determining the strength of an ongoing trend. + +In summary, oscillators are a type of indicator used in technical analysis +that measure price momentum and provide insights into overbought or oversold conditions. +They are considered a subset of indicators due to their specific function and characteristics. + +## AO (Awesome Oscillator) + +The Awesome Oscillator (AO) is a technical indicator designed to identify the +momentum of a market and potential trend reversals. It displays the difference +between a 34-period and a 5-period simple moving average (SMA) on a histogram. + +The calculation of the Awesome Oscillator involves subtracting the 34-period +SMA from the 5-period SMA. The resulting value is then plotted as a histogram, +with positive values indicating bullish momentum and negative values +indicating bearish momentum. + +The AO helps traders identify the strength and direction of a trend. When +the histogram bars are above the zero line, it suggests that bullish +momentum is dominant, signaling a potential uptrend. Conversely, when the +bars are below the zero line, it indicates bearish momentum, suggesting a +potential downtrend. + +The AO also provides signals for potential trend reversals. A change from +positive bars to negative bars or vice versa is considered a signal for a +potential trend reversal. Traders often look for these transitions to +generate buy or sell signals. + +Additionally, the Awesome Oscillator can be used to identify the divergence +between the indicator and price action. Divergence occurs when the +indicator's movement deviates from the price movement. Bullish divergence +occurs when the price forms lower lows while the AO forms higher lows, +suggesting a possible upward reversal. Conversely, bearish divergence +occurs when the price forms higher highs while the AO forms lower highs, +indicating a potential downward reversal. + +Traders often combine the Awesome Oscillator with other indicators or +analysis techniques to validate signals and strengthen their trading +strategies. It is a versatile tool that can be applied to various +timeframes and markets. + +In summary, the Awesome Oscillator (AO) is a technical indicator that +measures the momentum of a market and identifies potential trend reversals. +It displays the difference between a 34-period and a 5-period simple moving +average on a histogram. Positive histogram bars indicate bullish momentum, +negative bars indicate bearish momentum, and transitions can signal +potential trend reversals. The AO is often used in conjunction with other +indicators and analysis techniques to enhance trading decisions. + +## ASI (Accumulation Swing Index) indicator + +The Accumulation Swing Index (ASI) is a technical indicator that aims to gauge +the strength and direction of a market's price movement. +It combines price action and volume to provide insights into market trends +and potential reversals. The ASI calculates a running cumulative total, +incorporating the relationship between the current close, previous close, +and recent price ranges. + +The ASI starts with an initial value, typically zero, and then factors +in price and volume data. If the current close is higher than the previous close, +the indicator adds a fraction of the current range (high minus low) +to the prior ASI value. Conversely, if the current close is lower, +a fraction of the current range is subtracted. +The fraction is determined based on the volume and price relationship. + +The ASI's cumulative total fluctuates, reflecting the strength of price movements. +Rising ASI values indicate buying pressure and potential uptrends, +while falling values suggest selling pressure and potential downtrends. +Traders often analyze the ASI for divergences from price action, +which can signal shifts in market sentiment. + +The ASI is typically plotted as a line chart. +Positive values above zero indicate accumulation or buying pressure, +while negative values below zero indicate distribution or selling pressure. +The crossover of the ASI line with zero may be considered a signal +for potential trend reversals. + +It's important to note that the ASI does not provide specific +buy or sell signals on its own. Traders commonly use it in conjunction +with other technical analysis tools and indicators +to validate trading decisions and identify potential entry or exit points. + +In summary, it is a technical indicator that combines price action +and volume to assess market strength and direction. +It calculates a running cumulative total based on the relationship +between current and previous prices, incorporating price ranges. + +## ATR (Average True Range) + +The Average True Range (ATR) is a technical indicator used to measure and +quantify market volatility. It provides traders with information about the +average price range or volatility of an asset over a specified period. + +The ATR is calculated by taking the average of the true ranges of price +movements. The true range is the greatest of the following three values: the +difference between the current high and the current low, the absolute value of +the difference between the current high and the previous close, and the +absolute value of the difference between the current low and the previous +close. + +The ATR is typically displayed as a line chart or a histogram, indicating the +level of volatility in the market. Higher ATR values suggest greater +volatility, while lower values indicate lower volatility. + +Traders use the ATR in various ways. It helps determine the appropriate +placement of stop-loss orders by considering the average volatility of the +asset. A wider stop-loss may be used in more volatile markets to account for +larger price fluctuations, while a tighter stop-loss may be suitable for less +volatile markets. + +The ATR can also be used to identify potential trend reversals. A sudden +increase in the ATR may indicate a shift in market sentiment or the start of a +new trend. Traders may look for breakouts or changes in price behavior when the +ATR rises significantly. + +Additionally, the ATR can be used to compare volatility across different assets +or timeframes. By comparing ATR values, traders can assess which assets or +timeframes are experiencing higher or lower levels of volatility. + +In summary, the Average True Range (ATR) is a technical indicator that measures +market volatility by calculating the average price range over a specified +period. It helps traders determine stop-loss levels, identify potential trend +reversals, and compare volatility between assets or timeframes. The ATR +provides valuable insights into market conditions and assists traders in +managing risk and making informed trading decisions. + +## MACD (Moving Average Convergence Divergence) indicator + +MACD measures the relationship between two moving averages +of an asset's price. It consists of a MACD line and a signal line. +The MACD histogram represents the difference between the MACD line +and the signal line and provides insights into the momentum of the trend. + +## RSI (Relative Strength Index) indicator + +RSI compares the magnitude of recent price gains to recent price losses +to determine if an asset is overbought or oversold. +It oscillates between 0 and 100, +with values above 70 indicating overbought conditions +and values below 30 indicating oversold conditions. + +## Stochastic indicator + +The Stochastic Oscillator compares the closing price of an asset +to its price range over a specific period. +It generates values between 0 and 100, +where readings above 80 suggest overbought conditions, +and readings below 20 indicate oversold conditions. + +## WPR (Williams Percent Range) + +WPR indicator is a momentum oscillator developed by Larry Williams. +It is used to identify overbought and oversold conditions in the market +and potential trend reversals. +The WPR indicator oscillates between -100 and 0, +with readings above -20 considered overbought +and readings below -80 considered oversold. + +The WPR indicator calculates the percentage of the difference +between the current closing price and the highest high over a specified period, +relative to the difference between the highest high +and the lowest low over the same period. +The formula is then inverted and multiplied by -100 to obtain the WPR value. + +When the WPR indicator reaches or exceeds the -20 level, +it suggests that the market is overbought, +meaning the price may have risen too far too quickly, +and a reversal or correction may occur. +Conversely, when the WPR indicator falls to or below the -80 level, +it indicates oversold conditions, implying that the price may have declined +too rapidly and could potentially reverse to the upside. diff --git a/Indicators/Oscillator/includes.h b/Indicators/Oscillator/includes.h new file mode 100644 index 000000000..cb4fa953b --- /dev/null +++ b/Indicators/Oscillator/includes.h @@ -0,0 +1,37 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * @file + * Include file to include all oscillator indicators. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Oscillator indicators. +#include "Indi_MACD.h" +#include "Indi_RSI.h" +#include "Indi_Stochastic.h" +#include "Indi_WPR.h" diff --git a/Indicators/Oscillator/tests/Indi_MACD.test.cpp b/Indicators/Oscillator/tests/Indi_MACD.test.cpp new file mode 100644 index 000000000..4185d5d69 --- /dev/null +++ b/Indicators/Oscillator/tests/Indi_MACD.test.cpp @@ -0,0 +1,65 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_MACD class. + */ + +// Include enumerations. +#include "../../../Platform/Chart/Chart.enum.h" + +// Define external functions. + +// Calculates the Moving Averages Convergence/Divergence indicator and returns its value. +// @docs +// - https://docs.mql4.com/indicators/imacd +// - https://www.mql5.com/en/docs/indicators/imacd +/* +extern double iMACD( + string symbol, // Symbol. + int timeframe, // Timeframe> + int fast_ema_period, // Fast EMA period. + int slow_ema_period, // Slow EMA period. + int signal_period, // Signal line period. + int applied_price, // Applied price. + int mode, // Line index. + int shift // Shift. + ); +extern int iMACD( + string symbol, // Symbol name. + ENUM_TIMEFRAMES period, // Period. + int fast_ema_period, // Period for Fast average calculation. + int slow_ema_period, // Period for Slow average calculation. + int signal_period, // Period for their difference averaging. + ENUM_APPLIED_PRICE applied_price // Type of price or handle. + ); +*/ + +// Includes. +#include "../../../Platform/Platform.h" +#include "../Indi_MACD.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_MACD.test.mq4 b/Indicators/Oscillator/tests/Indi_MACD.test.mq4 similarity index 87% rename from Indicators/tests/Indi_MACD.test.mq4 rename to Indicators/Oscillator/tests/Indi_MACD.test.mq4 index b04cfc9e7..826f3b7e4 100644 --- a/Indicators/tests/Indi_MACD.test.mq4 +++ b/Indicators/Oscillator/tests/Indi_MACD.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_MACD.test.mq5 b/Indicators/Oscillator/tests/Indi_MACD.test.mq5 similarity index 81% rename from Indicators/tests/Indi_MACD.test.mq5 rename to Indicators/Oscillator/tests/Indi_MACD.test.mq5 index a1dcf9f17..79bf2f503 100644 --- a/Indicators/tests/Indi_MACD.test.mq5 +++ b/Indicators/Oscillator/tests/Indi_MACD.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_MACD.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_MACD.h" /** * @file diff --git a/Indicators/Oscillator/tests/Indi_RSI.test.cpp b/Indicators/Oscillator/tests/Indi_RSI.test.cpp new file mode 100644 index 000000000..f0c2b2e85 --- /dev/null +++ b/Indicators/Oscillator/tests/Indi_RSI.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_RSI class. + */ + +// Includes. +#include "../Indi_RSI.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_RSI.test.mq4 b/Indicators/Oscillator/tests/Indi_RSI.test.mq4 similarity index 87% rename from Indicators/tests/Indi_RSI.test.mq4 rename to Indicators/Oscillator/tests/Indi_RSI.test.mq4 index e8812ff2e..0eda037f2 100644 --- a/Indicators/tests/Indi_RSI.test.mq4 +++ b/Indicators/Oscillator/tests/Indi_RSI.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_RSI.test.mq5 b/Indicators/Oscillator/tests/Indi_RSI.test.mq5 similarity index 81% rename from Indicators/tests/Indi_RSI.test.mq5 rename to Indicators/Oscillator/tests/Indi_RSI.test.mq5 index d290e3b19..8f3c90c44 100644 --- a/Indicators/tests/Indi_RSI.test.mq5 +++ b/Indicators/Oscillator/tests/Indi_RSI.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_RSI.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_RSI.h" /** * @file diff --git a/Indicators/Oscillator/tests/Indi_Stochastic.test.cpp b/Indicators/Oscillator/tests/Indi_Stochastic.test.cpp new file mode 100644 index 000000000..d38039d0d --- /dev/null +++ b/Indicators/Oscillator/tests/Indi_Stochastic.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Stochastic class. + */ + +// Includes. +#include "../Indi_Stochastic.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Stochastic.test.mq4 b/Indicators/Oscillator/tests/Indi_Stochastic.test.mq4 similarity index 88% rename from Indicators/tests/Indi_Stochastic.test.mq4 rename to Indicators/Oscillator/tests/Indi_Stochastic.test.mq4 index d6b18b510..c0dd3e651 100644 --- a/Indicators/tests/Indi_Stochastic.test.mq4 +++ b/Indicators/Oscillator/tests/Indi_Stochastic.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Stochastic.test.mq5 b/Indicators/Oscillator/tests/Indi_Stochastic.test.mq5 similarity index 81% rename from Indicators/tests/Indi_Stochastic.test.mq5 rename to Indicators/Oscillator/tests/Indi_Stochastic.test.mq5 index abf62d07b..607ed5316 100644 --- a/Indicators/tests/Indi_Stochastic.test.mq5 +++ b/Indicators/Oscillator/tests/Indi_Stochastic.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_Stochastic.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Stochastic.h" /** * @file diff --git a/Indicators/Oscillator/tests/Indi_WPR.test.cpp b/Indicators/Oscillator/tests/Indi_WPR.test.cpp new file mode 100644 index 000000000..bc9bdff13 --- /dev/null +++ b/Indicators/Oscillator/tests/Indi_WPR.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_WPR class. + */ + +// Includes. +#include "../Indi_WPR.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_WPR.test.mq4 b/Indicators/Oscillator/tests/Indi_WPR.test.mq4 similarity index 87% rename from Indicators/tests/Indi_WPR.test.mq4 rename to Indicators/Oscillator/tests/Indi_WPR.test.mq4 index 2db21beba..8d064c8cc 100644 --- a/Indicators/tests/Indi_WPR.test.mq4 +++ b/Indicators/Oscillator/tests/Indi_WPR.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_WPR.test.mq5 b/Indicators/Oscillator/tests/Indi_WPR.test.mq5 similarity index 81% rename from Indicators/tests/Indi_WPR.test.mq5 rename to Indicators/Oscillator/tests/Indi_WPR.test.mq5 index 91b31f72f..7ee6e86bc 100644 --- a/Indicators/tests/Indi_WPR.test.mq5 +++ b/Indicators/Oscillator/tests/Indi_WPR.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_WPR.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_WPR.h" /** * @file diff --git a/Indicators/Oscillator/tests/Makefile b/Indicators/Oscillator/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/Oscillator/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Indicators/Indi_AppliedPrice.mqh b/Indicators/Price/Indi_AppliedPrice.h similarity index 88% rename from Indicators/Indi_AppliedPrice.mqh rename to Indicators/Price/Indi_AppliedPrice.h index ce0d688f6..18c9afd90 100644 --- a/Indicators/Indi_AppliedPrice.mqh +++ b/Indicators/Price/Indi_AppliedPrice.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,15 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" -#include "../Indicator/Indicator.h" -#include "OHLC/Indi_OHLC.mqh" +#include "../../Indicator/Indicator.h" +#include "../../Storage/Dict/Buffer/BufferStruct.h" +#include "../OHLC/Indi_OHLC.mqh" // Structs. struct IndiAppliedPriceParams : IndicatorParams { @@ -79,8 +84,8 @@ class Indi_AppliedPrice : public Indicator { unsigned int GetPossibleDataModes() override { return IDATA_INDICATOR; } static double iAppliedPriceOnIndicator(IndicatorData *_indi, ENUM_APPLIED_PRICE _applied_price, int _shift = 0) { - double _ohlc[4]; - _indi[_shift].GetArray(_ohlc, 4); + ARRAY(double, _ohlc); + PTR_TO_REF(_indi)[_shift].GetArray(_ohlc, 4); return BarOHLC::GetAppliedPrice(_applied_price, _ohlc[0], _ohlc[1], _ohlc[2], _ohlc[3]); } @@ -114,7 +119,7 @@ class Indi_AppliedPrice : public Indicator { switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_INDICATOR: if (!HasDataSource()) { - GetLogger().Error("Indi_AppliedPrice requires source indicator to be set via SetDataSource()!"); + logger REF_DEREF Error("Indi_AppliedPrice requires source indicator to be set via SetDataSource()!"); _is_valid &= false; } break; diff --git a/Indicators/Indi_MA.mqh b/Indicators/Price/Indi_MA.h similarity index 88% rename from Indicators/Indi_MA.mqh rename to Indicators/Price/Indi_MA.h index f3f1801ab..df7ae2fc8 100644 --- a/Indicators/Indi_MA.mqh +++ b/Indicators/Price/Indi_MA.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,34 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Prevents processing this includes file for the second time. #ifndef INDI_MA_MQH #define INDI_MA_MQH -#include "../Dict.mqh" -#include "../DictObject.mqh" -#include "../Indicator/Indicator.h" -#include "../Refs.mqh" -#include "../Storage/Singleton.h" -#include "../Storage/ValueStorage.h" -#include "../String.mqh" +// Includes. +#include "../../Indicator/Indicator.h" +#include "../../Refs.mqh" +#include "../../Storage/Dict/Dict.h" +#include "../../Storage/Dict/DictObject.h" +#include "../../Storage/Singleton.h" +#include "../../Storage/String.h" +#include "../../Storage/ValueStorage.h" + +#ifndef __MQL__ +// Enums. +// @see: https://www.mql5.com/en/docs/constants/indicatorconstants/enum_ma_method +enum ENUM_MA_METHOD { + MODE_SMA = 0, // Simple averaging. + MODE_EMA, // Exponential averaging. + MODE_SMMA, // Smoothed averaging. + MODE_LWMA, // Linear-weighted averaging. +}; +#endif // Structs. struct IndiMAParams : IndicatorParams { @@ -47,8 +64,14 @@ struct IndiMAParams : IndicatorParams { IndiMAParams(unsigned int _period = 13, int _ma_shift = 0, ENUM_MA_METHOD _ma_method = MODE_SMA, ENUM_APPLIED_PRICE _ap = PRICE_OPEN, int _shift = 10) : period(_period), ma_shift(_ma_shift), ma_method(_ma_method), applied_array(_ap), IndicatorParams(INDI_MA) { + if (custom_indi_name == "") { +#ifdef __MQL5__ + SetCustomIndicatorName("Examples\\Custom Moving Average"); +#else + SetCustomIndicatorName("Custom Moving Averages"); +#endif + } shift = _shift; - SetCustomIndicatorName("Examples\\Moving Average"); }; IndiMAParams(IndiMAParams &_params) { THIS_REF = _params; }; }; @@ -91,7 +114,7 @@ class Indi_MA : public Indicator { } // Volume uses volume only. - return _ds PTR_DEREF HasSpecificValueStorage(INDI_VS_TYPE_VOLUME); + return _ds PTR_DEREF HasSpecificValueStorage(INDI_DATA_VS_TYPE_VOLUME); } /** @@ -104,11 +127,19 @@ class Indi_MA : public Indicator { static double iMA(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _ma_period, unsigned int _ma_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iMA(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iMA(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _applied_price), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -116,56 +147,61 @@ class Indi_MA : public Indicator { * Calculates MA on another indicator. */ static double iMAOnIndicator(IndicatorData *_target, IndicatorData *_source, string symbol, ENUM_TIMEFRAMES tf, - unsigned int ma_period, unsigned int ma_shift, + int ma_period, int ma_shift, ENUM_MA_METHOD ma_method, // (MT4/MT5): MODE_SMA, MODE_EMA, MODE_SMMA, MODE_LWMA ENUM_APPLIED_PRICE _ap, int shift = 0) { // We need 1 bar more because MA methods assumes we have historic bars. INDI_REQUIRE_BARS_OR_RETURN_EMPTY(_source, int(ma_period + ma_shift + shift + 1)); - ValueStorage *_data = (ValueStorage *)_source.GetSpecificAppliedPriceValueStorage(_ap, _target); - return iMAOnArray(_data, 0, ma_period, ma_shift, ma_method, shift, _target PTR_DEREF GetCache()); + ValueStorage *_data = + (ValueStorage *)_source PTR_DEREF GetSpecificAppliedPriceValueStorage(_ap, _target); + return iMAOnArray(PTR_TO_REF(_data), 0, ma_period, ma_shift, ma_method, shift, _target PTR_DEREF GetCache()); } /** * Calculates MA on the array of values. Cache is optional. */ - static double iMAOnArray(double &price[], int total, int ma_period, int ma_shift, int ma_method, int shift, - IndicatorCalculateCache *cache = NULL) { + static double iMAOnArray(ARRAY_REF(double, price), int total, int ma_period, int ma_shift, ENUM_MA_METHOD ma_method, + int shift, IndiBufferCache *cache = NULL) { #ifdef __MQL4__ return ::iMAOnArray(price, total, ma_period, ma_shift, ma_method, shift); #else // We're reusing the same native array for each consecutive calculation. NativeValueStorage *_array_storage = Singleton>::Get(); - _array_storage.SetData(price); + _array_storage PTR_DEREF SetData(price); - return iMAOnArray((ValueStorage *)_array_storage, total, ma_period, ma_shift, ma_method, shift, cache); + return iMAOnArray(PTR_TO_REF((ValueStorage *)_array_storage), total, ma_period, ma_shift, ma_method, shift, + cache); #endif } /** * Calculates MA on the array of values. */ - static double iMAOnArray(ValueStorage &price, int total, int ma_period, int ma_shift, int ma_method, - int shift, IndicatorCalculateCache *_cache = NULL, bool recalculate = false) { + static double iMAOnArray(ValueStorage &price, int total, int ma_period, int ma_shift, + ENUM_MA_METHOD ma_method, int shift, IndiBufferCache *_cache = NULL, + bool recalculate = false) { if (_cache != NULL) { - _cache.SetPriceBuffer(price); + _cache PTR_DEREF SetPriceBuffer(price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(); } if (recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated( - Indi_MA::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), ma_method, ma_period)); + _cache PTR_DEREF SetPrevCalculated(Indi_MA::Calculate( + INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache PTR_DEREF GetBuffer(0), ma_method, ma_period)); // Returns value from the first calculation buffer. // Returns first value for as-series array or last value for non-as-series array. - return _cache.GetTailValue(0, shift + ma_shift); + return _cache PTR_DEREF GetTailValue(0, shift + ma_shift); } - double buf[], arr[], _result, pr, _array; + ARRAY(double, arr); + ARRAY(double, buf); + double _array, _result, pr; int pos, i, k, weight; double sum, lsum; if (total == 0) total = ArraySize(price); @@ -647,7 +683,7 @@ class Indi_MA : public Indicator { return (rates_total); } - static double SimpleMA(const int position, const int period, const double &price[]) { + static double SimpleMA(const int position, const int period, const ARRAY_REF(double, price)) { double result = 0.0; for (int i = 0; i < period; i++) { result += price[i]; @@ -681,13 +717,15 @@ class Indi_MA : public Indicator { break; case IDATA_ICUSTOM: _value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, /* [ */ GetPeriod(), - GetMAShift(), GetMAMethod(), GetAppliedPrice() /* ] */, 0, ToRelShift(_abs_shift)); + GetMAShift(), GetMAMethod() /* ] */, 0, ToRelShift(_abs_shift)); break; case IDATA_INDICATOR: // Calculating MA value from specified indicator. _value = Indi_MA::iMAOnIndicator(THIS_PTR, GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), GetMAShift(), GetMAMethod(), GetAppliedPrice(), ToRelShift(_abs_shift)); break; + default: + SetUserError(ERR_INVALID_PARAMETER); } return _value; @@ -705,7 +743,7 @@ class Indi_MA : public Indicator { IndiMAParams _p(_period, _ma_shift, _ma_method, _ap); _ptr = Objects::Set(_key, new Indi_MA(_p)); // Assigning the same candle indicator for MA as in _indi. - _ptr.SetDataSource(_indi PTR_DEREF GetCandle()); + _ptr PTR_DEREF SetDataSource(_indi PTR_DEREF GetCandle()); } return _ptr; } @@ -713,10 +751,10 @@ class Indi_MA : public Indicator { /** * Returns value storage of given kind. */ - IValueStorage *GetSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + IValueStorage *GetSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { switch (_type) { - case INDI_VS_TYPE_PRICE_ASK: - case INDI_VS_TYPE_PRICE_BID: + case INDI_DATA_VS_TYPE_PRICE_ASK: + case INDI_DATA_VS_TYPE_PRICE_BID: // We're returning the same buffer for ask and bid price, as target indicator probably won't bother. return GetValueStorage(0); default: @@ -728,10 +766,10 @@ class Indi_MA : public Indicator { /** * Checks whether indicator support given value storage type. */ - bool HasSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + bool HasSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { switch (_type) { - case INDI_VS_TYPE_PRICE_ASK: - case INDI_VS_TYPE_PRICE_BID: + case INDI_DATA_VS_TYPE_PRICE_ASK: + case INDI_DATA_VS_TYPE_PRICE_BID: return true; default: // Trying in parent class. @@ -820,13 +858,13 @@ int LinearWeightedMAOnBuffer(const int rates_total, const int prev_calculated, c } #else // !__MQL__4 // Defines global functions (for MQL4 backward compability). -double iMA(string _symbol, int _tf, int _ma_period, int _ma_shift, int _ma_method, int _ap, int _shift) { +double iMA(string _symbol, int _tf, int _ma_period, int _ma_shift, ENUM_MA_METHOD _ma_method, int _ap, int _shift) { ResetLastError(); - return Indi_MA::iMA(_symbol, (ENUM_TIMEFRAMES)_tf, _ma_period, _ma_shift, (ENUM_MA_METHOD)_ma_method, - (ENUM_APPLIED_PRICE)_ap, _shift); + return Indi_MA::iMA(_symbol, (ENUM_TIMEFRAMES)_tf, _ma_period, _ma_shift, _ma_method, (ENUM_APPLIED_PRICE)_ap, + _shift); } -double iMAOnArray(double &_arr[], int _total, int _period, int _ma_shift, int _ma_method, int _abs_shift, - IndicatorCalculateCache *_cache = NULL) { +double iMAOnArray(ARRAY_REF(double, _arr), int _total, int _period, int _ma_shift, ENUM_MA_METHOD _ma_method, + int _abs_shift, IndiBufferCache *_cache = NULL) { ResetLastError(); return Indi_MA::iMAOnArray(_arr, _total, _period, _ma_shift, _ma_method, _abs_shift, _cache); } diff --git a/Indicators/Price/Indi_Price.mqh b/Indicators/Price/Indi_Price.h similarity index 70% rename from Indicators/Price/Indi_Price.mqh rename to Indicators/Price/Indi_Price.h index 6edf53e1f..fe9a563ab 100644 --- a/Indicators/Price/Indi_Price.mqh +++ b/Indicators/Price/Indi_Price.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,20 +20,25 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../../BufferStruct.mqh" #include "../../Indicator/Indicator.h" -#include "../../Platform.h" +#include "../../Platform/Platform.h" +#include "../../Storage/Dict/Buffer/BufferStruct.h" #include "../../Storage/Objects.h" // Structs. -struct PriceIndiParams : IndicatorParams { +struct IndiPriceParams : IndicatorParams { ENUM_APPLIED_PRICE ap; // Struct constructor. - PriceIndiParams(ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0) : IndicatorParams(INDI_PRICE), ap(_ap) { + IndiPriceParams(ENUM_APPLIED_PRICE _ap = PRICE_TYPICAL, int _shift = 0) : IndicatorParams(INDI_PRICE), ap(_ap) { SetShift(_shift); }; - PriceIndiParams(PriceIndiParams &_params) : IndicatorParams() { THIS_REF = _params; }; + IndiPriceParams(IndiPriceParams &_params) : IndicatorParams() { THIS_REF = _params; }; // Getters. ENUM_APPLIED_PRICE GetAppliedPrice() { return ap; } // Setters. @@ -43,18 +48,18 @@ struct PriceIndiParams : IndicatorParams { /** * Price Indicator. */ -class Indi_Price : public Indicator { +class Indi_Price : public Indicator { public: /** * Class constructor. */ - Indi_Price(PriceIndiParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL, + Indi_Price(IndiPriceParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) : Indicator(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), _indi_src){}; Indi_Price(int _shift = 0, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) - : Indicator(PriceIndiParams(), + : Indicator(IndiPriceParams(), IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE, _indi_src_mode), _indi_src){}; /** @@ -90,7 +95,7 @@ class Indi_Price : public Indicator { string _key = _cache_key.ToString(); Indi_Price *_indi_price; if (!Objects::TryGet(_key, _indi_price)) { - PriceIndiParams _indi_price_params(_ap, _shift); + IndiPriceParams _indi_price_params(_ap, _shift); _indi_price = Objects::Set(_key, new Indi_Price(_indi_price_params)); if (_base_indi == nullptr) { @@ -105,51 +110,51 @@ class Indi_Price : public Indicator { /** * Returns value storage of given kind. */ - IValueStorage *GetSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + IValueStorage *GetSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { // Returning Price indicator which provides applied price in the only buffer #0. switch (_type) { - case INDI_VS_TYPE_PRICE_ASK: // Tick. - case INDI_VS_TYPE_PRICE_BID: // Tick. + case INDI_DATA_VS_TYPE_PRICE_ASK: // Tick. + case INDI_DATA_VS_TYPE_PRICE_BID: // Tick. return GetPlatformPrices(GetSymbol(), iparams.GetAppliedPrice(), GetTf(), iparams.GetShift()) PTR_DEREF GetValueStorage(0); - case INDI_VS_TYPE_PRICE_OPEN: // Candle. + case INDI_DATA_VS_TYPE_PRICE_OPEN: // Candle. return GetPlatformPrices(GetSymbol(), PRICE_OPEN, GetTf(), iparams.GetShift()) PTR_DEREF GetValueStorage(0); - case INDI_VS_TYPE_PRICE_HIGH: // Candle. + case INDI_DATA_VS_TYPE_PRICE_HIGH: // Candle. return GetPlatformPrices(GetSymbol(), PRICE_HIGH, GetTf(), iparams.GetShift()) PTR_DEREF GetValueStorage(0); - case INDI_VS_TYPE_PRICE_LOW: // Candle. + case INDI_DATA_VS_TYPE_PRICE_LOW: // Candle. return GetPlatformPrices(GetSymbol(), PRICE_LOW, GetTf(), iparams.GetShift()) PTR_DEREF GetValueStorage(0); - case INDI_VS_TYPE_PRICE_CLOSE: // Candle. + case INDI_DATA_VS_TYPE_PRICE_CLOSE: // Candle. return GetPlatformPrices(GetSymbol(), PRICE_CLOSE, GetTf(), iparams.GetShift()) PTR_DEREF GetValueStorage(0); - case INDI_VS_TYPE_PRICE_MEDIAN: // Candle. + case INDI_DATA_VS_TYPE_PRICE_MEDIAN: // Candle. return GetPlatformPrices(GetSymbol(), PRICE_MEDIAN, GetTf(), iparams.GetShift()) PTR_DEREF GetValueStorage(0); - case INDI_VS_TYPE_PRICE_TYPICAL: // Candle. + case INDI_DATA_VS_TYPE_PRICE_TYPICAL: // Candle. return GetPlatformPrices(GetSymbol(), PRICE_TYPICAL, GetTf(), iparams.GetShift()) PTR_DEREF GetValueStorage(0); - case INDI_VS_TYPE_PRICE_WEIGHTED: // Candle. + case INDI_DATA_VS_TYPE_PRICE_WEIGHTED: // Candle. return GetPlatformPrices(GetSymbol(), PRICE_WEIGHTED, GetTf(), iparams.GetShift()) PTR_DEREF GetValueStorage(0); default: // Trying in parent class. - return Indicator::GetSpecificValueStorage(_type); + return Indicator::GetSpecificValueStorage(_type); } } /** * Checks whether indicator support given value storage type. */ - bool HasSpecificValueStorage(ENUM_INDI_VS_TYPE _type) override { + bool HasSpecificValueStorage(ENUM_INDI_DATA_VS_TYPE _type) override { switch (_type) { - case INDI_VS_TYPE_PRICE_ASK: // Tick. - case INDI_VS_TYPE_PRICE_BID: // Tick. - case INDI_VS_TYPE_PRICE_OPEN: // Candle. - case INDI_VS_TYPE_PRICE_HIGH: // Candle. - case INDI_VS_TYPE_PRICE_LOW: // Candle. - case INDI_VS_TYPE_PRICE_CLOSE: // Candle. - case INDI_VS_TYPE_PRICE_MEDIAN: // Candle. - case INDI_VS_TYPE_PRICE_TYPICAL: // Candle. - case INDI_VS_TYPE_PRICE_WEIGHTED: // Candle. + case INDI_DATA_VS_TYPE_PRICE_ASK: // Tick. + case INDI_DATA_VS_TYPE_PRICE_BID: // Tick. + case INDI_DATA_VS_TYPE_PRICE_OPEN: // Candle. + case INDI_DATA_VS_TYPE_PRICE_HIGH: // Candle. + case INDI_DATA_VS_TYPE_PRICE_LOW: // Candle. + case INDI_DATA_VS_TYPE_PRICE_CLOSE: // Candle. + case INDI_DATA_VS_TYPE_PRICE_MEDIAN: // Candle. + case INDI_DATA_VS_TYPE_PRICE_TYPICAL: // Candle. + case INDI_DATA_VS_TYPE_PRICE_WEIGHTED: // Candle. return true; default: // Trying in parent class. - return Indicator::HasSpecificValueStorage(_type); + return Indicator::HasSpecificValueStorage(_type); } } }; diff --git a/Indicators/Price/README.md b/Indicators/Price/README.md new file mode 100644 index 000000000..52b716d38 --- /dev/null +++ b/Indicators/Price/README.md @@ -0,0 +1,147 @@ +# Price indicators + +Price indicators in Forex are a specific category of technical indicators that +generate a single price value as their output. +These indicators focus on analyzing and representing specific aspects of price data +to provide insights into market trends, momentum, or other relevant information. + +These price indicators are commonly used to identify trends, support and resistance levels, +and potential entry or exit points in the market. +By focusing on the single price value generated by these indicators, +traders can gain insights into the overall price direction +based on the average price over a specific period +and make informed trading decisions. + +Popular examples of price indicators include: + +- Moving Average (MA): + A widely used price indicator that calculates the average price over a specified period. + It smoothes out price fluctuations and provides a single value that represents the average price. + +- DEMA (Double Exponential Moving Average): + Similar to a traditional moving average, DEMA applies a double smoothing technique + to provide a single price value. + It aims to reduce lag and provide more responsive signals compared to standard moving averages. + +## AMA (Adaptive Moving Average) + +The Adaptive Moving Average (AMA) is a technical indicator designed to adjust +its sensitivity to market conditions. Unlike traditional moving averages that +use fixed periods, the AMA dynamically adapts to changing volatility, aiming +to provide more accurate signals. + +The AMA adjusts its smoothing factor based on market volatility. When the +market is more volatile, the indicator becomes more responsive and follows +price movements closely. Conversely, during periods of low volatility, the AMA +becomes less sensitive, reducing the impact of minor price fluctuations. + +The calculation of the AMA involves several steps. It begins with calculating +the Efficiency Ratio (ER), which measures the efficiency of price movement. +The ER compares the absolute value of the current price's change to the sum of +the absolute values of all price changes over a specified period. The ER +ranges between 0 and 1. + +Next, the Smoothing Constant (SC) is calculated by applying a formula to the +ER. The SC determines the degree of smoothing applied to the AMA. A higher SC +value results in less smoothing, making the AMA more responsive to recent +price changes. + +Finally, the AMA is computed by multiplying the current price's difference +from the previous AMA value by the SC and adding it to the previous AMA value. +This process is repeated for each subsequent data point. + +The Adaptive Moving Average aims to provide more accurate signals by adjusting +its responsiveness to prevailing market conditions. It can help traders +identify trends, support and resistance levels, and potential entry or exit +points. By adapting to changing market dynamics, the AMA attempts to minimize +false signals and enhance the effectiveness of moving average-based +strategies. + +It's worth noting that the specific formulas and parameters used in +calculating the AMA may vary based on the implementation and platform being +used. Traders should carefully review the settings and methodology of the +specific AMA indicator they intend to use. + +In summary, the Adaptive Moving Average (AMA) is a technical indicator that +dynamically adjusts its sensitivity to market conditions. It aims to provide +more accurate signals by adapting to changes in volatility. The AMA can assist +traders in identifying trends and potential entry or exit points. Its +flexibility makes it a popular choice among those seeking a moving average +that can adapt to varying market conditions. + +## DEMA (Double Exponential Moving Average) + +The Double Exponential Moving Average (DEMA) is a technical indicator that aims +to reduce lag and provide more responsive signals compared to traditional moving +averages. It accomplishes this by applying a double smoothing technique to the +price data. + +The calculation of the DEMA involves two steps. First, a regular exponential +moving average (EMA) is calculated using a specified period. The EMA calculates +the average price by assigning more weight to recent data points. + +Next, a second EMA is calculated on the previously calculated EMA values, again +using the same period. This second EMA smooths the EMA values further, resulting +in a double-smoothed average. + +The DEMA formula subtracts twice the second EMA from the first EMA to derive the +DEMA value. This calculation aims to provide a faster and more responsive moving +average line compared to traditional single-smoothed moving averages. + +The DEMA indicator attempts to identify trend reversals and generate trading +signals. When the DEMA line starts to rise, it suggests a bullish trend, while a +declining DEMA line indicates a bearish trend. Traders may look for crossovers +between the DEMA line and the price to generate buy or sell signals. + +The DEMA indicator is known for its ability to reduce lag and provide smoother +responses to price movements. However, it can also be more susceptible to false +signals during choppy or ranging market conditions. Traders often use the DEMA +in combination with other technical indicators or as part of a broader trading +strategy to confirm signals and enhance accuracy. + +In summary, the Double Exponential Moving Average (DEMA) is a technical +indicator that applies a double smoothing technique to price data. It aims to +reduce lag and provide more responsive signals compared to traditional moving +averages. The DEMA is used to identify trend reversals and generate trading +signals. Traders often use it in conjunction with other indicators and analysis +techniques to enhance their trading strategies. + +## MA (Moving Average) + +The Moving Average (MA) indicator is one of the most widely used and basic +technical analysis tools. It aims to smooth out price fluctuations and +identify trends by calculating the average price over a specified period. + +The MA indicator is calculated by adding up the closing prices of a financial +instrument over a designated number of periods and dividing the sum by the +number of periods. For example, a simple moving average (SMA) of 20 periods +would sum up the closing prices of the last 20 periods and divide the sum by 20. + +As new data points become available, the MA value is recalculated by dropping +the oldest data point and adding the most recent one. This process creates a +moving average line that trails the price action. + +The MA indicator helps traders visualize the overall direction and smooth out +short-term price fluctuations. It is commonly used to identify support and +resistance levels, as well as potential entry and exit points. When the price is +above the moving average, it suggests a bullish trend, and when the price is +below the moving average, it indicates a bearish trend. + +Different types of moving averages can be used, such as the simple moving +average (SMA) that evenly weighs all data points, or exponential moving average +(EMA) that places more weight on recent prices. Traders choose the type of +moving average based on their trading strategies and preferences. + +Crossovers between different moving averages are often analyzed to generate +trading signals. For example, a bullish signal may occur when a shorter-term +moving average crosses above a longer-term moving average, indicating a +potential upward trend reversal. Conversely, a bearish signal may occur when a +shorter-term moving average crosses below a longer-term moving average, +suggesting a potential downward trend reversal. + +In summary, the Moving Average (MA) indicator calculates the average price +over a specified period to smooth out price fluctuations and identify trends. +It is widely used to determine support and resistance levels, as well as +generate entry and exit signals. Traders often rely on moving averages in +combination with other indicators and analysis techniques to make informed +trading decisions. diff --git a/Indicators/Price/indicators.h b/Indicators/Price/includes.h similarity index 75% rename from Indicators/Price/indicators.h rename to Indicators/Price/includes.h index 2186dee41..edb2924b6 100644 --- a/Indicators/Price/indicators.h +++ b/Indicators/Price/includes.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,5 +25,12 @@ * Include file to include all price indicators. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Price indicators. -#include "Indi_Price.mqh" +#include "Indi_AppliedPrice.h" +#include "Indi_MA.h" +#include "Indi_Price.h" diff --git a/Indicators/Price/tests/Indi_AppliedPrice.test.cpp b/Indicators/Price/tests/Indi_AppliedPrice.test.cpp new file mode 100644 index 000000000..b918fd4d5 --- /dev/null +++ b/Indicators/Price/tests/Indi_AppliedPrice.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_AppliedPrice class. + */ + +// Includes. +#include "../Indi_AppliedPrice.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_AppliedPrice.test.mq4 b/Indicators/Price/tests/Indi_AppliedPrice.test.mq4 similarity index 88% rename from Indicators/tests/Indi_AppliedPrice.test.mq4 rename to Indicators/Price/tests/Indi_AppliedPrice.test.mq4 index a159a8e6d..313fe89ea 100644 --- a/Indicators/tests/Indi_AppliedPrice.test.mq4 +++ b/Indicators/Price/tests/Indi_AppliedPrice.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_AppliedPrice.test.mq5 b/Indicators/Price/tests/Indi_AppliedPrice.test.mq5 similarity index 79% rename from Indicators/tests/Indi_AppliedPrice.test.mq5 rename to Indicators/Price/tests/Indi_AppliedPrice.test.mq5 index c41210d81..697ce9d9f 100644 --- a/Indicators/tests/Indi_AppliedPrice.test.mq5 +++ b/Indicators/Price/tests/Indi_AppliedPrice.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,10 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_AppliedPrice.mqh" -#include "../Price/Indi_Price.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_AppliedPrice.h" +#include "../Indi_Price.h" /** * @file diff --git a/Indicators/Price/tests/Indi_MA.test.cpp b/Indicators/Price/tests/Indi_MA.test.cpp new file mode 100644 index 000000000..4d4c45d9e --- /dev/null +++ b/Indicators/Price/tests/Indi_MA.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_MA class. + */ + +// Includes. +#include "../Indi_MA.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_MA.test.mq4 b/Indicators/Price/tests/Indi_MA.test.mq4 similarity index 87% rename from Indicators/tests/Indi_MA.test.mq4 rename to Indicators/Price/tests/Indi_MA.test.mq4 index c221c8ab1..163739082 100644 --- a/Indicators/tests/Indi_MA.test.mq4 +++ b/Indicators/Price/tests/Indi_MA.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_MA.test.mq5 b/Indicators/Price/tests/Indi_MA.test.mq5 similarity index 81% rename from Indicators/tests/Indi_MA.test.mq5 rename to Indicators/Price/tests/Indi_MA.test.mq5 index 8fa7858ab..4fe2d1d93 100644 --- a/Indicators/tests/Indi_MA.test.mq5 +++ b/Indicators/Price/tests/Indi_MA.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_MA.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_MA.h" /** * @file diff --git a/Indicators/Price/tests/Indi_Price.test.cpp b/Indicators/Price/tests/Indi_Price.test.cpp new file mode 100644 index 000000000..f18a39de3 --- /dev/null +++ b/Indicators/Price/tests/Indi_Price.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Price indicator class. + */ + +// Includes. +#include "../Indi_Price.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Price.test.mq4 b/Indicators/Price/tests/Indi_Price.test.mq4 similarity index 87% rename from Indicators/tests/Indi_Price.test.mq4 rename to Indicators/Price/tests/Indi_Price.test.mq4 index eeaf181ab..834c59250 100644 --- a/Indicators/tests/Indi_Price.test.mq4 +++ b/Indicators/Price/tests/Indi_Price.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Price.test.mq5 b/Indicators/Price/tests/Indi_Price.test.mq5 similarity index 81% rename from Indicators/tests/Indi_Price.test.mq5 rename to Indicators/Price/tests/Indi_Price.test.mq5 index d8850076d..2e921001c 100644 --- a/Indicators/tests/Indi_Price.test.mq5 +++ b/Indicators/Price/tests/Indi_Price.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Price/Indi_Price.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Price.h" /** * @file diff --git a/Indicators/Price/tests/Makefile b/Indicators/Price/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/Price/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Indicators/Indi_Alligator.mqh b/Indicators/PriceMulti/Indi_Alligator.h similarity index 94% rename from Indicators/Indi_Alligator.mqh rename to Indicators/PriceMulti/Indi_Alligator.h index 6eaa59636..436474b74 100644 --- a/Indicators/Indi_Alligator.mqh +++ b/Indicators/PriceMulti/Indi_Alligator.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,20 +20,15 @@ * */ -// Includes. -#include "../Indicator/Indicator.h" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iAlligator(string _symbol, int _tf, int _jp, int _js, int _tp, int _ts, int _lp, int _ls, int _ma_method, - int _ap, int _mode, int _shift) { - ResetLastError(); - return Indi_Alligator::iAlligator(_symbol, (ENUM_TIMEFRAMES)_tf, _jp, _js, _tp, _ts, _lp, _ls, - (ENUM_MA_METHOD)_ma_method, (ENUM_APPLIED_PRICE)_ap, (ENUM_ALLIGATOR_LINE)_mode, - _shift); -} +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once #endif +// Includes. +#include "../../Indicator/Indicator.h" +#include "../Price/Indi_MA.h" + #ifndef __MQLBUILD__ // Defines. // Indicator constants. @@ -139,6 +134,7 @@ class Indi_Alligator : public Indicator { int _teeth_shift, int _lips_period, int _lips_shift, ENUM_MA_METHOD _ma_method, ENUM_APPLIED_PRICE _applied_price, ENUM_ALLIGATOR_LINE _mode, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iAlligator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift, _ma_method, _applied_price, _mode, _shift); @@ -146,6 +142,13 @@ class Indi_Alligator : public Indicator { INDICATOR_BUILTIN_CALL_AND_RETURN(::iAlligator(_symbol, _tf, _jaw_period, _jaw_shift, _teeth_period, _teeth_shift, _lips_period, _lips_shift, _ma_method, _applied_price), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -296,3 +299,14 @@ class Indi_Alligator : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iAlligator(string _symbol, int _tf, int _jp, int _js, int _tp, int _ts, int _lp, int _ls, int _ma_method, + int _ap, int _mode, int _shift) { + ResetLastError(); + return Indi_Alligator::iAlligator(_symbol, (ENUM_TIMEFRAMES)_tf, _jp, _js, _tp, _ts, _lp, _ls, + (ENUM_MA_METHOD)_ma_method, (ENUM_APPLIED_PRICE)_ap, (ENUM_ALLIGATOR_LINE)_mode, + _shift); +} +#endif diff --git a/Indicators/PriceMulti/README.md b/Indicators/PriceMulti/README.md new file mode 100644 index 000000000..6faa71a96 --- /dev/null +++ b/Indicators/PriceMulti/README.md @@ -0,0 +1,23 @@ +# Price Multi indicators + +Price multi indicators are a specific type of technical indicators in the Forex market +that generate multiple price values as their outputs. +These indicators go beyond providing a single value and offer a range of price information, +typically representing different aspects of price behavior. + +One example is the Alligator indicator developed by Bill Williams. +It consists of three lines, known as the jaw, teeth, and lips, +which mimic the structure of an alligator. +Each line represents a moving average with specific parameters and is shifted forward in time. +The values of these lines change as new price data is incorporated, +reflecting the dynamics of the market. + +These type of indicators provide traders with a more comprehensive perspective +on price movements by offering multiple price values instead of a single value. +This can help traders make more informed decisions +by considering different aspects of price behavior simultaneously. + +In summary, price multi indicators in Forex produce multiple price values as their outputs, +providing a broader view of price behavior. +These indicators offer traders a more comprehensive understanding of the market +and can assist in identifying trends and potential trading opportunities. diff --git a/Indicators/PriceMulti/includes.h b/Indicators/PriceMulti/includes.h new file mode 100644 index 000000000..295bcd4f4 --- /dev/null +++ b/Indicators/PriceMulti/includes.h @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * @file + * Include file to include all price multi indicators. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Price multi indicators. +#include "Indi_Alligator.h" diff --git a/Indicators/PriceMulti/tests/Indi_Alligator.test.cpp b/Indicators/PriceMulti/tests/Indi_Alligator.test.cpp new file mode 100644 index 000000000..f966ae735 --- /dev/null +++ b/Indicators/PriceMulti/tests/Indi_Alligator.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Alligator class. + */ + +// Includes. +#include "../Indi_Alligator.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Alligator.test.mq4 b/Indicators/PriceMulti/tests/Indi_Alligator.test.mq4 similarity index 87% rename from Indicators/tests/Indi_Alligator.test.mq4 rename to Indicators/PriceMulti/tests/Indi_Alligator.test.mq4 index 38a1166ec..23ad39592 100644 --- a/Indicators/tests/Indi_Alligator.test.mq4 +++ b/Indicators/PriceMulti/tests/Indi_Alligator.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Alligator.test.mq5 b/Indicators/PriceMulti/tests/Indi_Alligator.test.mq5 similarity index 81% rename from Indicators/tests/Indi_Alligator.test.mq5 rename to Indicators/PriceMulti/tests/Indi_Alligator.test.mq5 index 8ea327c47..b99ee3c95 100644 --- a/Indicators/tests/Indi_Alligator.test.mq5 +++ b/Indicators/PriceMulti/tests/Indi_Alligator.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_Alligator.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Alligator.h" /** * @file diff --git a/Indicators/PriceMulti/tests/Makefile b/Indicators/PriceMulti/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/PriceMulti/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Indicators/Indi_Bands.mqh b/Indicators/PriceRange/Indi_Bands.h similarity index 87% rename from Indicators/Indi_Bands.mqh rename to Indicators/PriceRange/Indi_Bands.h index fcd390dbd..ac3112a36 100644 --- a/Indicators/Indi_Bands.mqh +++ b/Indicators/PriceRange/Indi_Bands.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,26 +20,21 @@ * */ -// Includes. -#include "../Indicator/Indicator.h" -#include "Indi_CCI.mqh" -#include "Indi_Envelopes.mqh" -#include "Indi_MA.mqh" -#include "Indi_Momentum.mqh" -#include "Indi_RSI.mqh" -#include "Indi_StdDev.mqh" -#include "Price/Indi_Price.mqh" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iBands(string _symbol, int _tf, int _period, double _deviation, int _bands_shift, int _ap, int _mode, - int _shift) { - ResetLastError(); - return Indi_Bands::iBands(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _deviation, _bands_shift, (ENUM_APPLIED_PRICE)_ap, - (ENUM_BANDS_LINE)_mode, _shift); -} +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once #endif +// Includes. +#include "../../Indicator/Indicator.h" +#include "../Indi_CCI.mqh" +#include "../Indi_Momentum.mqh" +#include "../Indi_StdDev.mqh" +#include "../Oscillator/Indi_RSI.h" +#include "../Price/Indi_MA.h" +#include "../Price/Indi_Price.h" +#include "Indi_Envelopes.h" + // Indicator line identifiers used in Bands. enum ENUM_BANDS_LINE { #ifdef __MQL4__ @@ -128,11 +123,19 @@ class Indi_Bands : public Indicator { static double iBands(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, double _deviation, int _bands_shift, ENUM_APPLIED_PRICE _applied_price, ENUM_BANDS_LINE _mode = BAND_BASE, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iBands(_symbol, _tf, _period, _deviation, _bands_shift, _applied_price, _mode, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iBands(_symbol, _tf, _period, _bands_shift, _deviation, _applied_price), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -154,23 +157,23 @@ class Indi_Bands : public Indicator { } static double iBandsOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, int _period, double _deviation, int _bands_shift, - int _mode, int _abs_shift, IndicatorCalculateCache *_cache, - bool _recalculate = false) { - _cache.SetPriceBuffer(_price); + int _mode, int _abs_shift, IndiBufferCache *_cache, bool _recalculate = false) { + _cache PTR_DEREF SetPriceBuffer(_price); - if (!_cache.HasBuffers()) { - _cache.AddBuffer>(4); + if (!_cache PTR_DEREF HasBuffers()) { + _cache PTR_DEREF AddBuffer>(4); } if (_recalculate) { - _cache.ResetPrevCalculated(); + _cache PTR_DEREF ResetPrevCalculated(); } - _cache.SetPrevCalculated(Indi_Bands::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache.GetBuffer(0), - _cache.GetBuffer(1), _cache.GetBuffer(2), - _cache.GetBuffer(3), _period, _bands_shift, _deviation)); + _cache PTR_DEREF SetPrevCalculated( + Indi_Bands::Calculate(INDICATOR_CALCULATE_GET_PARAMS_SHORT, _cache PTR_DEREF GetBuffer(0), + _cache PTR_DEREF GetBuffer(1), _cache PTR_DEREF GetBuffer(2), + _cache PTR_DEREF GetBuffer(3), _period, _bands_shift, _deviation)); - return _cache.GetTailValue(_mode, _abs_shift); + return _cache PTR_DEREF GetTailValue(_mode, _abs_shift); } /** @@ -296,30 +299,30 @@ class Indi_Bands : public Indicator { virtual IndicatorData *FetchDataSource(ENUM_INDICATOR_TYPE _id) { IndicatorData *_result = NULL; if (_id == INDI_BANDS) { - IndiBandsParams bands_params(); - _result = Indi_Bands(bands_params); + IndiBandsParams bands_params; + _result = new Indi_Bands(bands_params); } else if (_id == INDI_CCI) { - IndiCCIParams cci_params(); + IndiCCIParams cci_params; _result = new Indi_CCI(cci_params); } else if (_id == INDI_ENVELOPES) { - IndiEnvelopesParams env_params(); + IndiEnvelopesParams env_params; _result = new Indi_Envelopes(env_params); } else if (_id == INDI_MOMENTUM) { - IndiMomentumParams mom_params(); + IndiMomentumParams mom_params; _result = new Indi_Momentum(mom_params); } else if (_id == INDI_MA) { - IndiMAParams ma_params(); + IndiMAParams ma_params; _result = new Indi_MA(ma_params); } else if (_id == INDI_RSI) { - IndiRSIParams _rsi_params(); + IndiRSIParams _rsi_params; _result = new Indi_RSI(_rsi_params); } else if (_id == INDI_STDDEV) { - IndiStdDevParams stddev_params(); + IndiStdDevParams stddev_params; _result = new Indi_StdDev(stddev_params); } if (_result != nullptr) { - _result.SetDataSource(GetCandle()); + _result PTR_DEREF SetDataSource(GetCandle()); return _result; } @@ -382,3 +385,13 @@ class Indi_Bands : public Indicator { iparams.applied_price = _applied_price; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iBands(string _symbol, int _tf, int _period, double _deviation, int _bands_shift, int _ap, int _mode, + int _shift) { + ResetLastError(); + return Indi_Bands::iBands(_symbol, (ENUM_TIMEFRAMES)_tf, _period, _deviation, _bands_shift, (ENUM_APPLIED_PRICE)_ap, + (ENUM_BANDS_LINE)_mode, _shift); +} +#endif diff --git a/Indicators/Indi_Envelopes.mqh b/Indicators/PriceRange/Indi_Envelopes.h similarity index 86% rename from Indicators/Indi_Envelopes.mqh rename to Indicators/PriceRange/Indi_Envelopes.h index 24527a7ee..ed6fa936f 100644 --- a/Indicators/Indi_Envelopes.mqh +++ b/Indicators/PriceRange/Indi_Envelopes.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,29 +20,18 @@ * */ -// Includes. -#include "../Indicator/Indicator.h" -#include "../Storage/Singleton.h" -#include "Indi_MA.mqh" -#include "Indi_PriceFeeder.mqh" -#include "Price/Indi_Price.mqh" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iEnvelopes(string _symbol, int _tf, int _period, int _ma_method, int _ma_shift, int _ap, double _deviation, - int _mode, int _shift) { - ResetLastError(); - return Indi_Envelopes::iEnvelopes(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_MA_METHOD)_ma_method, _ma_shift, - (ENUM_APPLIED_PRICE)_ap, _deviation, _mode, _shift); -} -double iEnvelopesOnArray(double &_arr[], int _total, int _ma_period, int _ma_method, int _ma_shift, double _deviation, - int _mode, int _shift) { - ResetLastError(); - return Indi_Envelopes::iEnvelopesOnArray(_arr, _total, _ma_period, (ENUM_MA_METHOD)_ma_method, _ma_shift, _deviation, - _mode, _shift); -} +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once #endif +// Includes. +#include "../../Indicator/Indicator.h" +#include "../../Storage/Singleton.h" +#include "../Indi_PriceFeeder.mqh" +#include "../Price/Indi_MA.h" +#include "../Price/Indi_Price.h" + // Structs. struct IndiEnvelopesParams : IndicatorParams { int ma_period; @@ -126,6 +115,7 @@ class Indi_Envelopes : public Indicator { int _mode, // (MT4 _mode): 0 - MODE_MAIN, 1 - MODE_UPPER, 2 - MODE_LOWER; (MT5 _mode): 0 - // UPPER_LINE, 1 - LOWER_LINE int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iEnvelopes(_symbol, _tf, _ma_period, _ma_method, _ma_shift, _ap, _deviation, _mode, _shift); #else // __MQL5__ @@ -140,6 +130,13 @@ class Indi_Envelopes : public Indicator { INDICATOR_BUILTIN_CALL_AND_RETURN(::iEnvelopes(_symbol, _tf, _ma_period, _ma_shift, _ma_method, _ap, _deviation), _mode, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -150,19 +147,19 @@ class Indi_Envelopes : public Indicator { int _mode, // (MT4 _mode): 0 - MODE_MAIN, 1 - MODE_UPPER, 2 - MODE_LOWER; (MT5 // _mode): 0 - UPPER_LINE, 1 - LOWER_LINE int _shift = 0) { - return iEnvelopesOnArray(_source.GetSpecificAppliedPriceValueStorage(_ap, _target), 0, _ma_period, _ma_method, - _ma_shift, _deviation, _mode, _shift, _target PTR_DEREF GetCache()); + return iEnvelopesOnArray(_source PTR_DEREF GetSpecificAppliedPriceValueStorage(_ap, _target), 0, _ma_period, + _ma_method, _ma_shift, _deviation, _mode, _shift, _target PTR_DEREF GetCache()); } - static double iEnvelopesOnArray(double &price[], int total, int ma_period, ENUM_MA_METHOD ma_method, int ma_shift, - double deviation, int mode, int shift, - IndicatorCalculateCache *_cache = NULL) { + static double iEnvelopesOnArray(CONST_ARRAY_REF(double, price), int total, int ma_period, ENUM_MA_METHOD ma_method, + int ma_shift, double deviation, int mode, int shift, + IndiBufferCache *_cache = NULL) { #ifdef __MQL4__ return iEnvelopesOnArray(price, total, ma_period, ma_method, ma_shift, deviation, mode, shift); #else // We're reusing the same native array for each consecutive calculation. NativeValueStorage *_price = Singleton >::Get(); - _price.SetData(price); + _price PTR_DEREF SetData(price); return iEnvelopesOnArray(_price, total, ma_period, ma_method, ma_shift, deviation, mode, shift); #endif @@ -170,19 +167,20 @@ class Indi_Envelopes : public Indicator { static double iEnvelopesOnArray(ValueStorage *_price, int _total, int _ma_period, ENUM_MA_METHOD _ma_method, int _ma_shift, double _deviation, int _mode, int _shift, - IndicatorCalculateCache *_cache = NULL) { + IndiBufferCache *_cache = NULL) { // We need 1 bar more because MA methods assumes we have historic bars. if (_price PTR_DEREF Size() < _shift + _ma_shift + _ma_period + 1) { return DBL_MIN; } - double _indi_value_buffer[]; + ARRAY(double, _indi_value_buffer); double _result; ArrayResize(_indi_value_buffer, _ma_period); // MA will use sub-cache of the given one. - _result = Indi_MA::iMAOnArray(_price, 0, _ma_period, _ma_shift, _ma_method, _shift, _cache.GetSubCache(0)); + _result = Indi_MA::iMAOnArray(PTR_TO_REF(_price), 0, _ma_period, _ma_shift, _ma_method, _shift, + _cache PTR_DEREF GetSubCache(0)); switch (_mode) { case LINE_UPPER: @@ -324,3 +322,19 @@ class Indi_Envelopes : public Indicator { iparams.deviation = _deviation; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iEnvelopes(string _symbol, int _tf, int _period, int _ma_method, int _ma_shift, int _ap, double _deviation, + int _mode, int _shift) { + ResetLastError(); + return Indi_Envelopes::iEnvelopes(_symbol, (ENUM_TIMEFRAMES)_tf, _period, (ENUM_MA_METHOD)_ma_method, _ma_shift, + (ENUM_APPLIED_PRICE)_ap, _deviation, _mode, _shift); +} +double iEnvelopesOnArray(CONST_ARRAY_REF(double, _arr), int _total, int _ma_period, int _ma_method, int _ma_shift, + double _deviation, int _mode, int _shift) { + ResetLastError(); + return Indi_Envelopes::iEnvelopesOnArray(_arr, _total, _ma_period, (ENUM_MA_METHOD)_ma_method, _ma_shift, _deviation, + _mode, _shift); +} +#endif diff --git a/Indicators/Indi_Pivot.mqh b/Indicators/PriceRange/Indi_Pivot.h similarity index 87% rename from Indicators/Indi_Pivot.mqh rename to Indicators/PriceRange/Indi_Pivot.h index 5a767296d..47d45cfe7 100644 --- a/Indicators/Indi_Pivot.mqh +++ b/Indicators/PriceRange/Indi_Pivot.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,11 +20,16 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../Bar.struct.h" -#include "../Indicator/Indicator.struct.h" -#include "../Serializer/Serializer.h" -#include "Special/Indi_Math.mqh" +#include "../../Bar.struct.h" +#include "../../Indicator/Indicator.struct.h" +#include "../../Serializer/Serializer.h" +#include "../Special/Indi_Math.mqh" // Structs. struct IndiPivotParams : IndicatorParams { @@ -38,7 +43,7 @@ struct IndiPivotParams : IndicatorParams { }; /** - * Implements Pivot Detector. + * Implements Pivot indicator. */ class Indi_Pivot : public Indicator { protected: @@ -100,7 +105,7 @@ class Indi_Pivot : public Indicator { * Returns IndicatorDataEntry struct filled with indicator values. */ virtual IndicatorDataEntry GetEntry(int _rel_shift = 0) { - long _bar_time = GetCandle() PTR_DEREF GetBarTime(_rel_shift); + int64 _bar_time = GetCandle() PTR_DEREF GetBarTime(_rel_shift); IndicatorDataEntry _entry = idata.GetByKey(_bar_time); if (_bar_time > 0 && !_entry.IsValid() && !_entry.CheckFlag(INDI_ENTRY_FLAG_INSUFFICIENT_DATA)) { ResetLastError(); @@ -157,10 +162,10 @@ class Indi_Pivot : public Indicator { // must have at least 4 buffers and define OHLC in the first 4 buffers. // Indi_Price is an example of such indicator. if (HasDataSource()) { - _ohlc.open = GetDataSource().GetValue(PRICE_OPEN, _shift); - _ohlc.high = GetDataSource().GetValue(PRICE_HIGH, _shift); - _ohlc.low = GetDataSource().GetValue(PRICE_LOW, _shift); - _ohlc.close = GetDataSource().GetValue(PRICE_CLOSE, _shift); + _ohlc.open = GetDataSource() PTR_DEREF GetValue(PRICE_OPEN, _shift); + _ohlc.high = GetDataSource() PTR_DEREF GetValue(PRICE_HIGH, _shift); + _ohlc.low = GetDataSource() PTR_DEREF GetValue(PRICE_LOW, _shift); + _ohlc.close = GetDataSource() PTR_DEREF GetValue(PRICE_CLOSE, _shift); } break; default: diff --git a/Indicators/Indi_SAR.mqh b/Indicators/PriceRange/Indi_SAR.h similarity index 89% rename from Indicators/Indi_SAR.mqh rename to Indicators/PriceRange/Indi_SAR.h index ecb2581c9..efd1ca987 100644 --- a/Indicators/Indi_SAR.mqh +++ b/Indicators/PriceRange/Indi_SAR.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,14 @@ * */ -// Includes. -#include "../Indicator/Indicator.h" - -#ifndef __MQL4__ -// Defines global functions (for MQL4 backward compability). -double iSAR(string _symbol, int _tf, double _step, double _max, int _shift) { - ResetLastError(); - return Indi_SAR::iSAR(_symbol, (ENUM_TIMEFRAMES)_tf, _step, _max, _shift); -} +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once #endif +// Includes. +#include "../../Indicator/Indicator.h" + // Structs. struct IndiSARParams : IndicatorParams { double step; @@ -80,10 +77,18 @@ class Indi_SAR : public Indicator { */ static double iSAR(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, double _step = 0.02, double _max = 0.2, int _shift = 0, IndicatorData *_obj = NULL) { +#ifdef __MQL__ #ifdef __MQL4__ return ::iSAR(_symbol, _tf, _step, _max, _shift); #else // __MQL5__ INDICATOR_BUILTIN_CALL_AND_RETURN(::iSAR(_symbol, _tf, _step, _max), 0, _shift); +#endif +#else // Non-MQL. + // @todo: Use Platform class. + RUNTIME_ERROR( + "Not implemented. Please use an On-Indicator mode and attach " + "indicator via Platform::Add/AddWithDefaultBindings()."); + return DBL_MAX; #endif } @@ -136,3 +141,11 @@ class Indi_SAR : public Indicator { iparams.max = _max; } }; + +#ifndef __MQL4__ +// Defines global functions (for MQL4 backward compability). +double iSAR(string _symbol, int _tf, double _step, double _max, int _shift) { + ResetLastError(); + return Indi_SAR::iSAR(_symbol, (ENUM_TIMEFRAMES)_tf, _step, _max, _shift); +} +#endif diff --git a/Indicators/PriceRange/README.md b/Indicators/PriceRange/README.md new file mode 100644 index 000000000..a952103a4 --- /dev/null +++ b/Indicators/PriceRange/README.md @@ -0,0 +1,174 @@ +# Price Range indicators + +Price range indicators are technical analysis tools that focus on generating +price range values. They provide information about the upper and lower levels +within which prices are likely to fluctuate. These indicators are useful for +identifying potential support and resistance levels, as well as assessing the +volatility of an asset. + +Price range indicators typically use statistical calculations or mathematical +formulas to determine the range values. These values are often based on factors +such as standard deviations, moving averages, or percentage deviations from a +central price line. + +One example of a price range indicator is Bollinger Bands. Bollinger Bands +consist of a central moving average line (usually a simple moving average) and +two outer bands that are a certain number of standard deviations away from the +moving average. The width of the bands expands or contracts based on market +volatility, indicating wider price ranges during periods of high volatility and +narrower ranges during periods of low volatility. + +Envelopes are another example of a price range indicator. They are constructed +by plotting two parallel lines above and below a moving average. The distance +between the upper and lower envelope lines is typically determined by a +percentage deviation from the moving average. Envelopes provide a visual +representation of the price range around the moving average, helping traders +identify overbought and oversold conditions. + +Price range indicators are valuable for identifying potential price reversal +points, as prices often encounter resistance or support near the upper and +lower ranges. They can also help traders assess the likelihood of price +breakouts or trend reversals when the price moves beyond the established range. + +Overall, price range indicators are useful tools for understanding the +potential price levels within which an asset is expected to trade. They assist +traders in identifying support and resistance levels, assessing market +volatility, and making informed decisions about entry and exit points. + +## Bollinger Bands + +Bollinger Bands (BB) is a popular technical indicator developed by John +Bollinger. It consists of three lines plotted on a price chart: a middle band, +an upper band, and a lower band. The indicator is designed to provide +information about the volatility and potential price levels of an asset. + +The middle band is typically a simple moving average (SMA) of a specified +period, often 20 periods. The upper band is calculated by adding a certain +number of standard deviations (usually 2) to the middle band, while the lower +band is obtained by subtracting the same number of standard deviations from +the middle band. + +The width of the Bollinger Bands expands and contracts based on the +volatility of the asset. During periods of high volatility, the bands widen, +indicating larger price ranges. Conversely, during low volatility periods, +the bands contract, suggesting smaller price ranges. + +Traders use Bollinger Bands in various ways. When the price approaches or +touches the upper band, it may indicate that the asset is overbought, +suggesting a potential reversal or a pause in the upward movement. +Conversely, when the price approaches or touches the lower band, it may +suggest that the asset is oversold, signaling a potential reversal or a pause +in the downward movement. + +Another popular strategy involves looking for price breakouts beyond the +bands. A breakout above the upper band is considered a bullish signal, +suggesting a potential continuation of the upward trend. Conversely, a +breakout below the lower band is seen as a bearish signal, indicating a +potential continuation of the downward trend. + +Traders may also pay attention to the interaction between the price and the +middle band. When the price crosses above the middle band from below, it +could indicate a bullish trend, while a cross below the middle band from +above may suggest a bearish trend. + +It's important to note that Bollinger Bands are not foolproof indicators and +should be used in conjunction with other technical analysis tools or +indicators to confirm signals. Traders should also consider the overall +market context and other relevant factors before making trading decisions +based solely on Bollinger Bands. + +In summary, Bollinger Bands (BB) is a widely used technical indicator that +consists of a middle band, upper band, and lower band. The bands adapt to +market volatility and provide insights into potential overbought and oversold +levels. Traders use Bollinger Bands to identify price reversals, breakouts, +and trends, but it's essential to use them in conjunction with other tools +and analysis techniques for better accuracy. + +## Envelopes + +The Envelopes indicator is a technical analysis tool that consists of two lines +plotted above and below a central moving average line. It helps traders +identify potential overbought and oversold levels and provides insights into +possible price reversals. + +The Envelopes indicator is constructed by defining a fixed percentage deviation +from a moving average. The moving average is typically a simple moving average +(SMA) of a specified period, such as 20 periods. The upper envelope line is +calculated by adding a certain percentage (usually a fixed number of percentage +points or a fixed percentage) above the moving average, while the lower +envelope line is derived by subtracting the same percentage below the moving +average. + +The Envelopes indicator provides visual boundaries or "envelopes" around the +moving average, representing potential price levels where the asset might +encounter resistance or support. When the price approaches or touches the upper +envelope line, it suggests that the asset may be overbought, indicating a +potential reversal or a pause in the upward movement. On the other hand, when +the price approaches or touches the lower envelope line, it suggests that the +asset may be oversold, signaling a potential reversal or a pause in the +downward movement. + +Traders can use the Envelopes indicator in various ways. They may look for +price bounces or reversals when the price reaches the upper or lower envelope +lines. A bounce from the upper envelope line back toward the moving average +could indicate a potential selling opportunity, while a bounce from the lower +envelope line toward the moving average could suggest a potential buying +opportunity. + +It's important to note that the Envelopes indicator is not a standalone +indicator and is often used in conjunction with other technical analysis tools +or indicators to confirm signals. Traders may combine it with other indicators, +such as oscillators or trend-following indicators, to enhance their trading +strategies. + +In summary, the Envelopes indicator is a technical tool that uses two lines +plotted above and below a central moving average to identify potential +overbought and oversold levels. It helps traders identify possible price +reversals and can be used to find selling or buying opportunities. However, +it should be used in combination with other indicators and analysis +techniques to validate signals and make well-informed trading decisions. + +## SAR + +The Parabolic SAR (Stop and Reverse) indicator is a technical analysis tool +that helps identify potential entry and exit points in a market trend. It is +particularly useful in trending markets where it can assist traders in +determining when to enter or exit a trade. + +The indicator is represented by a series of dots that appear either above or +below the price chart. These dots indicate potential stop and reverse points +for the price trend. When the dots are below the price, it suggests an upward +trend, while dots above the price indicate a downward trend. + +The calculation of the Parabolic SAR involves two key factors: the acceleration +factor (AF) and the extreme point (EP). The acceleration factor determines the +rate at which the SAR dots move closer to the price, while the extreme point +represents the highest or lowest price reached during the current trend. + +Initially, the SAR dots are placed below the price in an upward trend and above +the price in a downward trend. As the price continues to move in the same +direction, the dots gradually move closer to the price. The acceleration factor +determines how quickly this convergence occurs. + +When the price crosses above or below the SAR dot, it indicates a potential +trend reversal. At this point, the SAR dots switch sides, appearing on the +opposite side of the price chart. This reversal signal can be used by traders +to exit existing positions and potentially enter new positions in the opposite +direction. + +Traders often use the Parabolic SAR indicator in conjunction with other +technical analysis tools or indicators to confirm signals. For example, they +may look for confirmation from oscillators, moving averages, or chart patterns +to validate the potential trend reversal suggested by the SAR dots. + +It's important to note that the Parabolic SAR is most effective in trending +markets and may produce false signals or whipsaws in ranging or sideways +markets. Therefore, it is advisable to use the indicator in conjunction with +other tools to filter out false signals and improve overall trading decisions. + +In summary, the Parabolic SAR indicator is a technical tool that helps traders +identify potential entry and exit points in a trending market. It uses a series +of dots placed above or below the price chart to indicate potential stop and +reverse points. Traders can use these signals to determine trend reversals and +make informed trading decisions, but it is recommended to use the indicator +alongside other analysis techniques for better accuracy. diff --git a/Indicators/PriceRange/includes.h b/Indicators/PriceRange/includes.h new file mode 100644 index 000000000..095213f65 --- /dev/null +++ b/Indicators/PriceRange/includes.h @@ -0,0 +1,37 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +/** + * @file + * Include file to include all price range indicators. + */ + +// Price indicators. +#include "Indi_Bands.h" +#include "Indi_Envelopes.h" +#include "Indi_Pivot.h" +#include "Indi_SAR.h" diff --git a/Indicators/PriceRange/tests/Indi_Bands.test.cpp b/Indicators/PriceRange/tests/Indi_Bands.test.cpp new file mode 100644 index 000000000..266225f20 --- /dev/null +++ b/Indicators/PriceRange/tests/Indi_Bands.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Bands class. + */ + +// Includes. +#include "../Indi_Bands.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Bands.test.mq4 b/Indicators/PriceRange/tests/Indi_Bands.test.mq4 similarity index 87% rename from Indicators/tests/Indi_Bands.test.mq4 rename to Indicators/PriceRange/tests/Indi_Bands.test.mq4 index a5de70288..689050735 100644 --- a/Indicators/tests/Indi_Bands.test.mq4 +++ b/Indicators/PriceRange/tests/Indi_Bands.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Bands.test.mq5 b/Indicators/PriceRange/tests/Indi_Bands.test.mq5 similarity index 81% rename from Indicators/tests/Indi_Bands.test.mq5 rename to Indicators/PriceRange/tests/Indi_Bands.test.mq5 index dd91ac2a0..31c7bbe1c 100644 --- a/Indicators/tests/Indi_Bands.test.mq5 +++ b/Indicators/PriceRange/tests/Indi_Bands.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_Bands.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Bands.h" /** * @file diff --git a/Indicators/PriceRange/tests/Indi_Envelopes.test.cpp b/Indicators/PriceRange/tests/Indi_Envelopes.test.cpp new file mode 100644 index 000000000..244ffaea8 --- /dev/null +++ b/Indicators/PriceRange/tests/Indi_Envelopes.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Envelopes class. + */ + +// Includes. +#include "../Indi_Envelopes.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Envelopes.test.mq4 b/Indicators/PriceRange/tests/Indi_Envelopes.test.mq4 similarity index 87% rename from Indicators/tests/Indi_Envelopes.test.mq4 rename to Indicators/PriceRange/tests/Indi_Envelopes.test.mq4 index ef5521653..9ce8f0fd0 100644 --- a/Indicators/tests/Indi_Envelopes.test.mq4 +++ b/Indicators/PriceRange/tests/Indi_Envelopes.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Envelopes.test.mq5 b/Indicators/PriceRange/tests/Indi_Envelopes.test.mq5 similarity index 81% rename from Indicators/tests/Indi_Envelopes.test.mq5 rename to Indicators/PriceRange/tests/Indi_Envelopes.test.mq5 index ef72d25f5..ba694f061 100644 --- a/Indicators/tests/Indi_Envelopes.test.mq5 +++ b/Indicators/PriceRange/tests/Indi_Envelopes.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_Envelopes.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Envelopes.h" /** * @file diff --git a/Indicators/PriceRange/tests/Indi_Pivot.test.cpp b/Indicators/PriceRange/tests/Indi_Pivot.test.cpp new file mode 100644 index 000000000..407445ee1 --- /dev/null +++ b/Indicators/PriceRange/tests/Indi_Pivot.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Pivot class. + */ + +// Includes. +#include "../Indi_Pivot.h" +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Pivot.test.mq4 b/Indicators/PriceRange/tests/Indi_Pivot.test.mq4 similarity index 87% rename from Indicators/tests/Indi_Pivot.test.mq4 rename to Indicators/PriceRange/tests/Indi_Pivot.test.mq4 index 3cf7213c9..cbb408afe 100644 --- a/Indicators/tests/Indi_Pivot.test.mq4 +++ b/Indicators/PriceRange/tests/Indi_Pivot.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Pivot.test.mq5 b/Indicators/PriceRange/tests/Indi_Pivot.test.mq5 similarity index 81% rename from Indicators/tests/Indi_Pivot.test.mq5 rename to Indicators/PriceRange/tests/Indi_Pivot.test.mq5 index 1750b1685..a42355b6d 100644 --- a/Indicators/tests/Indi_Pivot.test.mq5 +++ b/Indicators/PriceRange/tests/Indi_Pivot.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_Pivot.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Pivot.h" /** * @file diff --git a/Indicators/PriceRange/tests/Indi_PriceRange.test.cpp b/Indicators/PriceRange/tests/Indi_PriceRange.test.cpp new file mode 100644 index 000000000..d6c820fed --- /dev/null +++ b/Indicators/PriceRange/tests/Indi_PriceRange.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of all price range classes. + */ + +// Includes. +#include "../../../Platform/Platform.h" +#include "../includes.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/PriceRange/tests/Indi_SAR.test.cpp b/Indicators/PriceRange/tests/Indi_SAR.test.cpp new file mode 100644 index 000000000..af7b0a987 --- /dev/null +++ b/Indicators/PriceRange/tests/Indi_SAR.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_SAR class. + */ + +// Includes. +#include "../Indi_SAR.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_SAR.test.mq4 b/Indicators/PriceRange/tests/Indi_SAR.test.mq4 similarity index 87% rename from Indicators/tests/Indi_SAR.test.mq4 rename to Indicators/PriceRange/tests/Indi_SAR.test.mq4 index a054079d6..b83b22103 100644 --- a/Indicators/tests/Indi_SAR.test.mq4 +++ b/Indicators/PriceRange/tests/Indi_SAR.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_SAR.test.mq5 b/Indicators/PriceRange/tests/Indi_SAR.test.mq5 similarity index 81% rename from Indicators/tests/Indi_SAR.test.mq5 rename to Indicators/PriceRange/tests/Indi_SAR.test.mq5 index e46ba8363..991174f2c 100644 --- a/Indicators/tests/Indi_SAR.test.mq5 +++ b/Indicators/PriceRange/tests/Indi_SAR.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_SAR.mqh" +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_SAR.h" /** * @file diff --git a/Indicators/PriceRange/tests/Makefile b/Indicators/PriceRange/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/PriceRange/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Indicators/Special/Indi_Custom.mqh b/Indicators/Special/Indi_Custom.mqh index 3d94d5ffa..3d0175c00 100644 --- a/Indicators/Special/Indi_Custom.mqh +++ b/Indicators/Special/Indi_Custom.mqh @@ -1,6 +1,7 @@ //+------------------------------------------------------------------+ -//| Copyright 2016-2022, EA31337 Ltd | -//| https://github.com/EA31337 | +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -19,9 +20,10 @@ * */ -// Prevents processing the same indicator file twice. -#ifndef INDI_CUSTOM_MQH -#define INDI_CUSTOM_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Defines #ifndef INDI_CUSTOM_PATH @@ -39,7 +41,7 @@ // Defines struct to store indicator parameter values. struct IndiCustomParams : public IndicatorParams { - DataParamEntry iargs[]; + ARRAY(DataParamEntry, iargs); // Struct constructors. IndiCustomParams(string _filepath = INDI_CUSTOM_PATH, int _shift = 0) : IndicatorParams(INDI_CUSTOM) { custom_indi_name = _filepath; @@ -60,7 +62,7 @@ struct IndiCustomParams : public IndicatorParams { } iargs[_index + 1] = _entry; } - void SetParams(DataParamEntry &_entries[]) { + void SetParams(CONST_ARRAY_REF(DataParamEntry, _entries)) { for (int i = 0; i < ArraySize(_entries); i++) { iargs[i] = _entries[i]; } @@ -126,5 +128,3 @@ class Indi_Custom : public Indicator { return _value; } }; - -#endif // INDI_CUSTOM_MQH diff --git a/Indicators/Special/Indi_Math.mqh b/Indicators/Special/Indi_Math.mqh index 56877b515..819f68803 100644 --- a/Indicators/Special/Indi_Math.mqh +++ b/Indicators/Special/Indi_Math.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,15 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../../BufferStruct.mqh" #include "../../Indicator/Indicator.h" -#include "../../Math.enum.h" +#include "../../Math/Math.enum.h" +#include "../../Storage/Dict/Buffer/BufferStruct.h" enum ENUM_MATH_OP_MODE { MATH_OP_MODE_BUILTIN, MATH_OP_MODE_CUSTOM_FUNCTION }; @@ -68,7 +73,7 @@ struct IndiMathParams : IndicatorParams { }; /** - * Implements the Volume Rate of Change indicator. + * Implements the Math indicator. */ class Indi_Math : public Indicator { public: @@ -119,7 +124,7 @@ class Indi_Math : public Indicator { switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { case IDATA_INDICATOR: if (!indi_src.IsSet()) { - GetLogger().Error( + GetLogger() PTR_DEREF Error( "In order use custom indicator as a source, you need to select one using SetIndicatorData() method, " "which is a part of IndiMathParams structure.", "Indi_Math"); @@ -133,12 +138,12 @@ class Indi_Math : public Indicator { case MATH_OP_MODE_BUILTIN: _value = Indi_Math::iMathOnIndicator(GetDataSource(), _Symbol, GetTf(), /*[*/ GetOpBuiltIn(), GetMode1(), GetMode2(), GetShift1(), - GetShift2() /*]*/, 0, ToRelShift(_abs_shift), &this); + GetShift2() /*]*/, 0, ToRelShift(_abs_shift), THIS_PTR); break; case MATH_OP_MODE_CUSTOM_FUNCTION: _value = Indi_Math::iMathOnIndicator(GetDataSource(), _Symbol, GetTf(), /*[*/ GetOpFunction(), GetMode1(), GetMode2(), GetShift1(), - GetShift2() /*]*/, 0, ToRelShift(_abs_shift), &this); + GetShift2() /*]*/, 0, ToRelShift(_abs_shift), THIS_PTR); break; } break; @@ -153,8 +158,8 @@ class Indi_Math : public Indicator { unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, unsigned int _shift_2, unsigned int _mode, int _shift, Indi_Math *_obj) { INDI_REQUIRE_SHIFT_OR_RETURN_EMPTY(_indi, MathMax(_shift_1, _shift_2)); - double _val_1 = _indi.GetValue(_mode_1, _shift_1); - double _val_2 = _indi.GetValue(_mode_2, _shift_2); + double _val_1 = _indi PTR_DEREF GetValue(_mode_1, _shift_1); + double _val_2 = _indi PTR_DEREF GetValue(_mode_2, _shift_2); return Math::Op(op, _val_1, _val_2); } @@ -162,8 +167,8 @@ class Indi_Math : public Indicator { unsigned int _mode_1, unsigned int _mode_2, unsigned int _shift_1, unsigned int _shift_2, unsigned int _mode, int _shift, Indi_Math *_obj) { INDI_REQUIRE_SHIFT_OR_RETURN_EMPTY(_indi, MathMax(_shift_1, _shift_2)); - double _val_1 = _indi.GetValue(_mode_1, _shift_1); - double _val_2 = _indi.GetValue(_mode_2, _shift_2); + double _val_1 = _indi PTR_DEREF GetValue(_mode_1, _shift_1); + double _val_2 = _indi PTR_DEREF GetValue(_mode_2, _shift_2); return _op(_val_1, _val_2); } diff --git a/Indicators/Special/Indi_Universal.h b/Indicators/Special/Indi_Universal.h new file mode 100644 index 000000000..ad9e44562 --- /dev/null +++ b/Indicators/Special/Indi_Universal.h @@ -0,0 +1,119 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +// Includes. +#include "../../Indicator/Indicator.h" +#include "../Price/Indi_Price.h" + +// Structs. +struct IndiUniversalParams : IndicatorParams { + unsigned int mode_1; + unsigned int shift_1; + + // Struct constructor. + IndiUniversalParams(unsigned int _mode_1 = 0, unsigned int _shift_1 = 0, int _shift = 0) + : IndicatorParams(INDI_SPECIAL_UNIVERSAL) { + mode_1 = _mode_1; + shift = _shift; + shift_1 = _shift_1; + }; + + IndiUniversalParams(IndiUniversalParams &_params) { THIS_REF = _params; }; +}; + +/** + * Implements the Universal indicator. + */ +class Indi_Universal : public Indicator { + protected: + /** + * Initialize. + */ + void Init() { + if (!indi_src.IsSet()) { + indi_src = new Indi_Price(); + } + } + + public: + /** + * Class constructor. + */ + Indi_Universal(IndiUniversalParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_INDICATOR, + IndicatorData *_indi_src = NULL, int _indi_src_mode = 0) + : Indicator(_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode), + _indi_src) { + Init(); + }; + Indi_Universal(int _shift = 0, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_INDICATOR, IndicatorData *_indi_src = NULL, + int _indi_src_mode = 0) + : Indicator(IndiUniversalParams(), + IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode), + _indi_src) { + Init(); + }; + + /** + * Returns possible data source types. It is a bit mask of ENUM_INDI_SUITABLE_DS_TYPE. + */ + unsigned int GetSuitableDataSourceTypes() override { return INDI_SUITABLE_DS_TYPE_EXPECT_ANY; } + + /** + * Returns possible data source modes. It is a bit mask of ENUM_IDATA_SOURCE_TYPE. + */ + unsigned int GetPossibleDataModes() override { return IDATA_INDICATOR; } + + /** + * Returns the indicator's value. + */ + virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _abs_shift = 0) { + IndicatorDataEntryValue _value = EMPTY_VALUE; + switch (Get(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) { + case IDATA_INDICATOR: + if (!indi_src.IsSet()) { + logger REF_DEREF Error( + "In order use custom indicator as a source, you need to select one using SetIndicatorData() method, " + "which is a part of IndiUniversalParams structure.", + "Indi_Universal"); + Alert( + "Indi_Universal: In order use custom indicator as a source, you need to select one using " + "SetIndicatorData() " + "method, which is a part of IndiUniversalParams structure."); + SetUserError(ERR_INVALID_PARAMETER); + return _value; + } + _value = indi_src REF_DEREF GetEntryValue(_mode, _abs_shift); + break; + default: + SetUserError(ERR_INVALID_PARAMETER); + break; + } + return _value; + } + + /* Getters */ + + /** + * Whether we can and have to select mode when specifying data source. + */ + virtual bool IsDataSourceModeSelectable() { return false; } +}; diff --git a/Indicators/Special/indicators.h b/Indicators/Special/includes.h similarity index 78% rename from Indicators/Special/indicators.h rename to Indicators/Special/includes.h index a99faecca..1465aa125 100644 --- a/Indicators/Special/indicators.h +++ b/Indicators/Special/includes.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,12 @@ * Include file to include all special indicators. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Special indicators. #include "Indi_Custom.mqh" #include "Indi_Math.mqh" +#include "Indi_Universal.h" diff --git a/Indicators/Special/tests/Indi_Custom.test.cpp b/Indicators/Special/tests/Indi_Custom.test.cpp new file mode 100644 index 000000000..26e5bf6b5 --- /dev/null +++ b/Indicators/Special/tests/Indi_Custom.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Custom indicator class. + */ + +// Includes. +#include "../Indi_Custom.mqh" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/Special/tests/Indi_Custom.test.mq4 b/Indicators/Special/tests/Indi_Custom.test.mq4 index bb3fffd61..1fd3962e9 100644 --- a/Indicators/Special/tests/Indi_Custom.test.mq4 +++ b/Indicators/Special/tests/Indi_Custom.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2022, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/Special/tests/Indi_Custom.test.mq5 b/Indicators/Special/tests/Indi_Custom.test.mq5 index 281fe217d..cc2ba4893 100644 --- a/Indicators/Special/tests/Indi_Custom.test.mq5 +++ b/Indicators/Special/tests/Indi_Custom.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2022, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../../Platform.h" +#include "../../../Platform/Platform.h" #include "../../../Test.mqh" #include "../Indi_Custom.mqh" diff --git a/Indicators/Special/tests/Indi_Universal.test.cpp b/Indicators/Special/tests/Indi_Universal.test.cpp new file mode 100644 index 000000000..ce9a1cd37 --- /dev/null +++ b/Indicators/Special/tests/Indi_Universal.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Universal indicator class. + */ + +// Includes. +#include "../Indi_Universal.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/Special/tests/Indi_Universal.test.mq4 b/Indicators/Special/tests/Indi_Universal.test.mq4 new file mode 100644 index 000000000..f2f3eca94 --- /dev/null +++ b/Indicators/Special/tests/Indi_Universal.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Universal indicator class. + */ + +#include "Indi_Universal.test.mq5" diff --git a/Indicators/Special/tests/Indi_Universal.test.mq5 b/Indicators/Special/tests/Indi_Universal.test.mq5 new file mode 100644 index 000000000..4e0560a30 --- /dev/null +++ b/Indicators/Special/tests/Indi_Universal.test.mq5 @@ -0,0 +1,31 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Includes. +#include "../../../Platform/Platform.h" +#include "../../../Test.mqh" +#include "../Indi_Universal.h" + +/** + * @file + * Test functionality of Universal indicator class. + */ +TEST_INDICATOR_DEFAULT_BINDINGS(Indi_Universal); diff --git a/Indicators/Special/tests/Makefile b/Indicators/Special/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/Special/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Indicators/Tick/Indi_TickMt.mqh b/Indicators/Tick/Indi_TickMt.h similarity index 94% rename from Indicators/Tick/Indi_TickMt.mqh rename to Indicators/Tick/Indi_TickMt.h index 0bd2f29a9..c2dcf44c8 100644 --- a/Indicators/Tick/Indi_TickMt.mqh +++ b/Indicators/Tick/Indi_TickMt.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,9 +31,9 @@ #endif // Includes. -#include "../../Chart.struct.static.h" #include "../../Indicator/IndicatorTick.h" #include "../../Indicator/IndicatorTick.provider.h" +#include "../../Platform/Chart/Chart.struct.static.h" // Structs. // Params for MT patform's tick-based indicator. @@ -97,7 +97,7 @@ class Indi_TickMt : public IndicatorTick= 0 ? (int)_index : iparams.GetShift(); - long _bar_time; + int64 _bar_time; _bar_time = GetBarTime(_ishift); TickAB _tick = itdata.GetByKey(_bar_time); @@ -127,12 +127,12 @@ class Indi_TickMt : public IndicatorTick, _out_ticks)) { + virtual bool FetchHistoryByTimeRange(int64 _from_ms, int64 _to_ms, ARRAY_REF(TickTAB, _out_ticks)) { ArrayResize(_out_ticks, 0); #ifdef __MQL5__ // In MQL5 we firstly try to fetch ticks by CopyTicksRange. - static MqlTick _tmp_ticks[]; + static ARRAY(MqlTick, _tmp_ticks); ArrayResize(_tmp_ticks, 0); int _tries = 10; @@ -217,12 +217,12 @@ class Indi_TickMt : public IndicatorTick _tick(_ask, _bid); IndicatorDataEntry _entry(TickToEntry(_time, _tick)); diff --git a/Indicators/Tick/Indi_TickProvider.h b/Indicators/Tick/Indi_TickProvider.h index 28e9b9f93..c592eb39b 100644 --- a/Indicators/Tick/Indi_TickProvider.h +++ b/Indicators/Tick/Indi_TickProvider.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -98,7 +98,7 @@ class Indi_TickProvider : public IndicatorTick, _out_ticks)) { + bool FetchHistoryByTimeRange(int64 _from_ms, int64 _to_ms, ARRAY_REF(TickTAB, _out_ticks)) { #ifdef __debug_indicator__ Print("Indi_TickProvider::FetchHistoryByTimeRange(from_ms = ", _from_ms, ", to_ms = ", _to_ms, ")"); #endif diff --git a/Indicators/Tick/Indi_TickRandom.mqh b/Indicators/Tick/Indi_TickRandom.h similarity index 93% rename from Indicators/Tick/Indi_TickRandom.mqh rename to Indicators/Tick/Indi_TickRandom.h index f44c7713f..f90f9c012 100644 --- a/Indicators/Tick/Indi_TickRandom.mqh +++ b/Indicators/Tick/Indi_TickRandom.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -85,7 +85,7 @@ class Indi_TickRandom : public IndicatorTick, _out_ticks)) { + bool FetchHistoryByTimeRange(int64 _from_ms, int64 _to_ms, ARRAY_REF(TickTAB, _out_ticks)) { // No history. return false; } diff --git a/Indicators/Tick/includes.h b/Indicators/Tick/includes.h new file mode 100644 index 000000000..d5962f22a --- /dev/null +++ b/Indicators/Tick/includes.h @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * @file + * Include file to include all tick indicators. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Tick indicators. +#include "Indi_TickMt.h" +//#include "Indi_TickProvider.h" // @fixme +#include "Indi_TickRandom.h" diff --git a/Indicators/Tick/tests/Indi_TickMt.test.cpp b/Indicators/Tick/tests/Indi_TickMt.test.cpp new file mode 100644 index 000000000..78cb8b856 --- /dev/null +++ b/Indicators/Tick/tests/Indi_TickMt.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_TickMt indicator class. + */ + +// Includes. +#include "../Indi_TickMt.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/Tick/tests/Indi_TickMt.test.mq4 b/Indicators/Tick/tests/Indi_TickMt.test.mq4 index 0ed26d3f7..892c0dc92 100644 --- a/Indicators/Tick/tests/Indi_TickMt.test.mq4 +++ b/Indicators/Tick/tests/Indi_TickMt.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/Tick/tests/Indi_TickMt.test.mq5 b/Indicators/Tick/tests/Indi_TickMt.test.mq5 index 903b56b52..3cb928dac 100644 --- a/Indicators/Tick/tests/Indi_TickMt.test.mq5 +++ b/Indicators/Tick/tests/Indi_TickMt.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,9 @@ */ // Includes. -#include "../../../Platform.h" +#include "../../../Platform/Platform.h" #include "../../../Test.mqh" -#include "../Indi_TickMt.mqh" +#include "../Indi_TickMt.h" /** * @file diff --git a/Indicators/Tick/tests/Makefile b/Indicators/Tick/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/Tick/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Indicators/indicators.h b/Indicators/includes.h similarity index 80% rename from Indicators/indicators.h rename to Indicators/includes.h index 027140284..915c350e6 100644 --- a/Indicators/indicators.h +++ b/Indicators/includes.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Include file to include all common indicators at once. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Standard indicators. #include "Indi_AC.mqh" #include "Indi_AD.mqh" @@ -34,26 +39,18 @@ #include "Indi_AO.mqh" #include "Indi_ASI.mqh" #include "Indi_ATR.mqh" -#include "Indi_Alligator.mqh" -#include "Indi_AppliedPrice.mqh" #include "Indi_BWMFI.mqh" #include "Indi_BWZT.mqh" -#include "Indi_Bands.mqh" #include "Indi_BearsPower.mqh" #include "Indi_BullsPower.mqh" #include "Indi_CCI.mqh" #include "Indi_CHO.mqh" #include "Indi_CHV.mqh" -#include "Indi_ColorBars.mqh" -#include "Indi_ColorCandlesDaily.mqh" -#include "Indi_ColorLine.mqh" -#include "Indi_CustomMovingAverage.mqh" #include "Indi_DEMA.mqh" #include "Indi_DeMarker.mqh" #include "Indi_Demo.mqh" #include "Indi_DetrendedPrice.mqh" #include "Indi_Drawer.mqh" -#include "Indi_Envelopes.mqh" #include "Indi_Force.mqh" #include "Indi_FractalAdaptiveMA.mqh" #include "Indi_Fractals.mqh" @@ -61,31 +58,33 @@ #include "Indi_HeikenAshi.mqh" #include "Indi_Ichimoku.mqh" #include "Indi_Killzones.mqh" -#include "Indi_MA.mqh" -#include "Indi_MACD.mqh" #include "Indi_MFI.mqh" #include "Indi_MassIndex.mqh" #include "Indi_Momentum.mqh" #include "Indi_OBV.mqh" #include "Indi_OsMA.mqh" -#include "Indi_Pivot.mqh" #include "Indi_PriceChannel.mqh" #include "Indi_PriceFeeder.mqh" #include "Indi_PriceVolumeTrend.mqh" #include "Indi_RS.mqh" -#include "Indi_RSI.mqh" #include "Indi_RVI.mqh" #include "Indi_RateOfChange.mqh" -#include "Indi_SAR.mqh" #include "Indi_StdDev.mqh" -#include "Indi_Stochastic.mqh" #include "Indi_TEMA.mqh" #include "Indi_TRIX.mqh" #include "Indi_UltimateOscillator.mqh" #include "Indi_VIDYA.mqh" #include "Indi_VROC.mqh" #include "Indi_Volumes.mqh" -#include "Indi_WPR.mqh" #include "Indi_WilliamsAD.mqh" #include "Indi_ZigZag.mqh" #include "Indi_ZigZagColor.mqh" + +// Includes indicators per each type. +#include "Bitwise/includes.h" +#include "OHLC/includes.h" +#include "Oscillator/includes.h" +#include "Price/includes.h" +#include "PriceMulti/includes.h" +#include "PriceRange/includes.h" +#include "Special/includes.h" diff --git a/Indicators/tests/DrawIndicator.test.cpp b/Indicators/tests/DrawIndicator.test.cpp new file mode 100644 index 000000000..0314a440b --- /dev/null +++ b/Indicators/tests/DrawIndicator.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of DrawIndicator class. + */ + +// Includes. +#include "../DrawIndicator.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/DrawIndicator.test.mq4 b/Indicators/tests/DrawIndicator.test.mq4 new file mode 100644 index 000000000..40b72d9e6 --- /dev/null +++ b/Indicators/tests/DrawIndicator.test.mq4 @@ -0,0 +1,27 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of DrawIndicator indicator class. + */ + +#include "DrawIndicator.test.mq5" diff --git a/tests/DrawIndicatorTest.mq5 b/Indicators/tests/DrawIndicator.test.mq5 similarity index 77% rename from tests/DrawIndicatorTest.mq5 rename to Indicators/tests/DrawIndicator.test.mq5 index 3e2c8c1bc..2ba022c68 100644 --- a/tests/DrawIndicatorTest.mq5 +++ b/Indicators/tests/DrawIndicator.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,15 +28,15 @@ //#define __debug_verbose__ // Includes. -#include "../DictStruct.mqh" +#include "../../Indicator/Indicator.struct.serialize.h" +#include "../../Storage/Dict/DictStruct.h" +#include "../../Test.mqh" #include "../DrawIndicator.mqh" -#include "../Indicator/Indicator.struct.serialize.h" -#include "../Indicators/Indi_Bands.mqh" -#include "../Indicators/Indi_Demo.mqh" -#include "../Indicators/Indi_MA.mqh" -#include "../Indicators/Indi_RSI.mqh" -#include "../Indicators/Price/Indi_Price.mqh" -#include "../Test.mqh" +#include "../Indi_Demo.mqh" +#include "../Oscillator/Indi_RSI.h" +#include "../Price/Indi_MA.h" +#include "../Price/Indi_Price.h" +#include "../PriceRange/Indi_Bands.h" // Global variables. Ref candles; @@ -67,12 +67,12 @@ void OnTick() { if (candles REF_DEREF IsNewBar()) { bar_processed++; - for (DictIterator> iter = Platform::GetIndicators() PTR_DEREF Begin(); iter.IsValid(); + for (DictIterator> iter = Platform::GetIndicators() PTR_DEREF Begin(); iter.IsValid(); ++iter) { IndicatorData *_indi = iter.Value().Ptr(); _indi.OnTick(Platform::GetGlobalTickIndex()); IndicatorDataEntry _entry = _indi.GetEntry(); - if (_indi.Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY)) && _entry.IsValid()) { + if (_indi.Get(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_IS_READY)) && _entry.IsValid()) { #ifdef __debug__ PrintFormat("%s: bar %d: %s", _indi.GetName(), bar_processed, _indi.ToString()); #endif @@ -113,45 +113,45 @@ bool InitIndicators() { #ifndef __MQL4__ // @fixme: Make it work for MT4. // Current Price (used by custom indicators) . - PriceIndiParams price_params(); - // price_params.SetDraw(clrGreenYellow); + IndiPriceParams price_params(); + // price_params.SetPlot(clrGreenYellow); Platform::AddWithDefaultBindings(new Indi_Price(price_params), "EURUSD", PERIOD_M1); #endif /* @fixme: Array out of range. // Bollinger Bands over Price indicator. /* - PriceIndiParams price_params_4_bands(); + IndiPriceParams price_params_4_bands(); IndicatorBase *indi_price_4_bands = new Indi_Price(price_params_4_bands); IndiBandsParams bands_on_price_params(); - bands_on_price_params.SetDraw(clrCadetBlue); + bands_on_price_params.SetPlot(clrCadetBlue); // bands_on_price_params.SetDataSource(indi_price_4_bands, true, INDI_PRICE_MODE_OPEN); Platform::AddWithDefaultBindings(new Indi_Bands(bands_on_price_params, indi_price_4_bands, true)); */ // Moving Average (MA) over Price indicator. /* - PriceIndiParams price_params_4_ma(); + IndiPriceParams price_params_4_ma(); IndicatorBase *indi_price_4_ma = new Indi_Price(price_params_4_ma); IndiMAParams ma_on_price_params(); - ma_on_price_params.SetDraw(clrYellowGreen); + ma_on_price_params.SetPlot(clrYellowGreen); // ma_on_price_params.SetDataSource(indi_price_4_ma, true, INDI_PRICE_MODE_OPEN); ma_on_price_params.SetIndicatorType(INDI_MA_ON_PRICE); Platform::AddWithDefaultBindings(new Indi_MA(ma_on_price_params, indi_price_4_ma)); // Relative Strength Index (RSI) over Price indicator. - PriceIndiParams price_params_4_rsi(); + IndiPriceParams price_params_4_rsi(); IndicatorData *indi_price_4_rsi = new Indi_Price(price_params_4_rsi); IndiRSIParams rsi_on_price_params(); - rsi_on_price_params.SetDraw(clrBisque, 1); + rsi_on_price_params.SetPlot(clrBisque, 1); IndicatorBase *indi_rsi_on_price = new Indi_RSI(rsi_on_price_params, IDATA_INDICATOR, indi_price_4_rsi); indis.Set(INDI_RSI_ON_PRICE, indi_rsi_on_price); */ // We'll be drawing all indicators' values on the chart. - for (DictIterator> iter = Platform::GetIndicators() PTR_DEREF Begin(); iter.IsValid(); + for (DictIterator> iter = Platform::GetIndicators() PTR_DEREF Begin(); iter.IsValid(); ++iter) { - // iter.Value() REF_DEREF SetDraw(true); // @fixme + // iter.Value() REF_DEREF SetPlot(true); // @fixme } return _LastError == ERR_NO_ERROR; @@ -162,10 +162,10 @@ bool InitIndicators() { */ bool PrintIndicators(string _prefix = "") { ResetLastError(); - for (DictIterator> iter = Platform::GetIndicators() PTR_DEREF Begin(); iter.IsValid(); + for (DictIterator> iter = Platform::GetIndicators() PTR_DEREF Begin(); iter.IsValid(); ++iter) { IndicatorData *_indi = iter.Value().Ptr(); - if (_indi.Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) { + if (_indi.Get(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_IS_READY))) { PrintFormat("%s: %s: %s", _prefix, _indi.GetName(), _indi.ToString()); } } diff --git a/Indicators/tests/Indi_AC.test.cpp b/Indicators/tests/Indi_AC.test.cpp new file mode 100644 index 000000000..cb31dbd00 --- /dev/null +++ b/Indicators/tests/Indi_AC.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_AC class. + */ + +// Includes. +#include "../Indi_AC.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_AC.test.mq4 b/Indicators/tests/Indi_AC.test.mq4 index f454573e4..a3f046b46 100644 --- a/Indicators/tests/Indi_AC.test.mq4 +++ b/Indicators/tests/Indi_AC.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_AC.test.mq5 b/Indicators/tests/Indi_AC.test.mq5 index d3167539f..00dc1c044 100644 --- a/Indicators/tests/Indi_AC.test.mq5 +++ b/Indicators/tests/Indi_AC.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_AC.mqh" diff --git a/Indicators/tests/Indi_AD.test.cpp b/Indicators/tests/Indi_AD.test.cpp new file mode 100644 index 000000000..e7f113dca --- /dev/null +++ b/Indicators/tests/Indi_AD.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_AD class. + */ + +// Includes. +#include "../Indi_AD.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_AD.test.mq4 b/Indicators/tests/Indi_AD.test.mq4 index 45e1076ae..53168a125 100644 --- a/Indicators/tests/Indi_AD.test.mq4 +++ b/Indicators/tests/Indi_AD.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_AD.test.mq5 b/Indicators/tests/Indi_AD.test.mq5 index 2880c6365..919abb3b0 100644 --- a/Indicators/tests/Indi_AD.test.mq5 +++ b/Indicators/tests/Indi_AD.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_AD.mqh" diff --git a/Indicators/tests/Indi_ADX.test.cpp b/Indicators/tests/Indi_ADX.test.cpp new file mode 100644 index 000000000..7f79f5bff --- /dev/null +++ b/Indicators/tests/Indi_ADX.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_ADX class. + */ + +// Includes. +#include "../Indi_ADX.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_ADX.test.mq4 b/Indicators/tests/Indi_ADX.test.mq4 index 4565cd9be..d34c089cc 100644 --- a/Indicators/tests/Indi_ADX.test.mq4 +++ b/Indicators/tests/Indi_ADX.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_ADX.test.mq5 b/Indicators/tests/Indi_ADX.test.mq5 index 5dd93ce28..e91ecee9f 100644 --- a/Indicators/tests/Indi_ADX.test.mq5 +++ b/Indicators/tests/Indi_ADX.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_ADX.mqh" diff --git a/Indicators/tests/Indi_ADXW.test.cpp b/Indicators/tests/Indi_ADXW.test.cpp new file mode 100644 index 000000000..6adc1c09a --- /dev/null +++ b/Indicators/tests/Indi_ADXW.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_ADXW class. + */ + +// Includes. +#include "../Indi_ADXW.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_ADXW.test.mq4 b/Indicators/tests/Indi_ADXW.test.mq4 index dc2497c9a..159f3290c 100644 --- a/Indicators/tests/Indi_ADXW.test.mq4 +++ b/Indicators/tests/Indi_ADXW.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_ADXW.test.mq5 b/Indicators/tests/Indi_ADXW.test.mq5 index 82edfafca..dd95d8999 100644 --- a/Indicators/tests/Indi_ADXW.test.mq5 +++ b/Indicators/tests/Indi_ADXW.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_ADXW.mqh" diff --git a/Indicators/tests/Indi_AMA.test.cpp b/Indicators/tests/Indi_AMA.test.cpp new file mode 100644 index 000000000..69e2a89c3 --- /dev/null +++ b/Indicators/tests/Indi_AMA.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_AMA class. + */ + +// Includes. +#include "../Indi_AMA.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_AMA.test.mq4 b/Indicators/tests/Indi_AMA.test.mq4 index 6398df899..f399ae5a5 100644 --- a/Indicators/tests/Indi_AMA.test.mq4 +++ b/Indicators/tests/Indi_AMA.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_AMA.test.mq5 b/Indicators/tests/Indi_AMA.test.mq5 index 4e0e1c9f4..1c9122621 100644 --- a/Indicators/tests/Indi_AMA.test.mq5 +++ b/Indicators/tests/Indi_AMA.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_AMA.mqh" diff --git a/Indicators/tests/Indi_AO.test.cpp b/Indicators/tests/Indi_AO.test.cpp new file mode 100644 index 000000000..d2c78c25e --- /dev/null +++ b/Indicators/tests/Indi_AO.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_AO class. + */ + +// Includes. +#include "../Indi_AO.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_AO.test.mq4 b/Indicators/tests/Indi_AO.test.mq4 index bcd4c9c74..529f5f8d3 100644 --- a/Indicators/tests/Indi_AO.test.mq4 +++ b/Indicators/tests/Indi_AO.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_AO.test.mq5 b/Indicators/tests/Indi_AO.test.mq5 index 14649e2da..bdba0dc8c 100644 --- a/Indicators/tests/Indi_AO.test.mq5 +++ b/Indicators/tests/Indi_AO.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_AO.mqh" diff --git a/Indicators/tests/Indi_ASI.test.cpp b/Indicators/tests/Indi_ASI.test.cpp new file mode 100644 index 000000000..77ce2b19b --- /dev/null +++ b/Indicators/tests/Indi_ASI.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_ASI class. + */ + +// Includes. +#include "../Indi_ASI.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_ASI.test.mq4 b/Indicators/tests/Indi_ASI.test.mq4 index 78d2a40cc..ea2e69fa4 100644 --- a/Indicators/tests/Indi_ASI.test.mq4 +++ b/Indicators/tests/Indi_ASI.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_ASI.test.mq5 b/Indicators/tests/Indi_ASI.test.mq5 index bae7205f2..1ee09fb35 100644 --- a/Indicators/tests/Indi_ASI.test.mq5 +++ b/Indicators/tests/Indi_ASI.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_ASI.mqh" diff --git a/Indicators/tests/Indi_ATR.test.cpp b/Indicators/tests/Indi_ATR.test.cpp new file mode 100644 index 000000000..7c1e7872a --- /dev/null +++ b/Indicators/tests/Indi_ATR.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_ATR class. + */ + +// Includes. +#include "../Indi_ATR.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_ATR.test.mq4 b/Indicators/tests/Indi_ATR.test.mq4 index e499dc3a7..84121c198 100644 --- a/Indicators/tests/Indi_ATR.test.mq4 +++ b/Indicators/tests/Indi_ATR.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_ATR.test.mq5 b/Indicators/tests/Indi_ATR.test.mq5 index 01bad4c9c..7375345f4 100644 --- a/Indicators/tests/Indi_ATR.test.mq5 +++ b/Indicators/tests/Indi_ATR.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_ATR.mqh" diff --git a/Indicators/tests/Indi_BWMFI.test.cpp b/Indicators/tests/Indi_BWMFI.test.cpp new file mode 100644 index 000000000..6591cc05d --- /dev/null +++ b/Indicators/tests/Indi_BWMFI.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_BWMFI class. + */ + +// Includes. +#include "../Indi_BWMFI.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_BWMFI.test.mq4 b/Indicators/tests/Indi_BWMFI.test.mq4 index aa966dfe6..80c391da3 100644 --- a/Indicators/tests/Indi_BWMFI.test.mq4 +++ b/Indicators/tests/Indi_BWMFI.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_BWMFI.test.mq5 b/Indicators/tests/Indi_BWMFI.test.mq5 index a57f75eeb..0d6b3887d 100644 --- a/Indicators/tests/Indi_BWMFI.test.mq5 +++ b/Indicators/tests/Indi_BWMFI.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_BWMFI.mqh" diff --git a/Indicators/tests/Indi_BWZT.test.cpp b/Indicators/tests/Indi_BWZT.test.cpp new file mode 100644 index 000000000..3c389116e --- /dev/null +++ b/Indicators/tests/Indi_BWZT.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_BWZT class. + */ + +// Includes. +#include "../Indi_BWZT.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_BWZT.test.mq4 b/Indicators/tests/Indi_BWZT.test.mq4 index 5aabf1566..b301c9936 100644 --- a/Indicators/tests/Indi_BWZT.test.mq4 +++ b/Indicators/tests/Indi_BWZT.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_BWZT.test.mq5 b/Indicators/tests/Indi_BWZT.test.mq5 index a5a66c0bb..81d370cd7 100644 --- a/Indicators/tests/Indi_BWZT.test.mq5 +++ b/Indicators/tests/Indi_BWZT.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_BWZT.mqh" diff --git a/Indicators/tests/Indi_BearsPower.test.cpp b/Indicators/tests/Indi_BearsPower.test.cpp new file mode 100644 index 000000000..a2247a51f --- /dev/null +++ b/Indicators/tests/Indi_BearsPower.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_BearsPower class. + */ + +// Includes. +#include "../Indi_BearsPower.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_BearsPower.test.mq4 b/Indicators/tests/Indi_BearsPower.test.mq4 index 05afff998..f60b114b9 100644 --- a/Indicators/tests/Indi_BearsPower.test.mq4 +++ b/Indicators/tests/Indi_BearsPower.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_BearsPower.test.mq5 b/Indicators/tests/Indi_BearsPower.test.mq5 index 02eca6d0a..59fb52ae2 100644 --- a/Indicators/tests/Indi_BearsPower.test.mq5 +++ b/Indicators/tests/Indi_BearsPower.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_BearsPower.mqh" diff --git a/Indicators/tests/Indi_BullsPower.test.cpp b/Indicators/tests/Indi_BullsPower.test.cpp new file mode 100644 index 000000000..dd4a059e0 --- /dev/null +++ b/Indicators/tests/Indi_BullsPower.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_BullsPower class. + */ + +// Includes. +#include "../Indi_BullsPower.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_BullsPower.test.mq4 b/Indicators/tests/Indi_BullsPower.test.mq4 index c44d4d96b..a52dd8ad7 100644 --- a/Indicators/tests/Indi_BullsPower.test.mq4 +++ b/Indicators/tests/Indi_BullsPower.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_BullsPower.test.mq5 b/Indicators/tests/Indi_BullsPower.test.mq5 index 08a26bb9f..62d8e8e19 100644 --- a/Indicators/tests/Indi_BullsPower.test.mq5 +++ b/Indicators/tests/Indi_BullsPower.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_BullsPower.mqh" diff --git a/Indicators/tests/Indi_CCI.test.cpp b/Indicators/tests/Indi_CCI.test.cpp new file mode 100644 index 000000000..1221be0f7 --- /dev/null +++ b/Indicators/tests/Indi_CCI.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_CCI class. + */ + +// Includes. +#include "../Indi_CCI.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_CCI.test.mq4 b/Indicators/tests/Indi_CCI.test.mq4 index 41d4ba5c8..ece9cde56 100644 --- a/Indicators/tests/Indi_CCI.test.mq4 +++ b/Indicators/tests/Indi_CCI.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_CCI.test.mq5 b/Indicators/tests/Indi_CCI.test.mq5 index f9073dfac..bd86c5b32 100644 --- a/Indicators/tests/Indi_CCI.test.mq5 +++ b/Indicators/tests/Indi_CCI.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_CCI.mqh" diff --git a/Indicators/tests/Indi_CHO.test.cpp b/Indicators/tests/Indi_CHO.test.cpp new file mode 100644 index 000000000..40bbd0702 --- /dev/null +++ b/Indicators/tests/Indi_CHO.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_CHO class. + */ + +// Includes. +#include "../Indi_CHO.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_CHO.test.mq4 b/Indicators/tests/Indi_CHO.test.mq4 index 5ab3e7a46..5d35bbbe5 100644 --- a/Indicators/tests/Indi_CHO.test.mq4 +++ b/Indicators/tests/Indi_CHO.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_CHO.test.mq5 b/Indicators/tests/Indi_CHO.test.mq5 index 75c104994..6f2828e7c 100644 --- a/Indicators/tests/Indi_CHO.test.mq5 +++ b/Indicators/tests/Indi_CHO.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_CHO.mqh" diff --git a/Indicators/tests/Indi_CHV.test.cpp b/Indicators/tests/Indi_CHV.test.cpp new file mode 100644 index 000000000..df51642ce --- /dev/null +++ b/Indicators/tests/Indi_CHV.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_CHV class. + */ + +// Includes. +#include "../Indi_CHV.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_CHV.test.mq4 b/Indicators/tests/Indi_CHV.test.mq4 index b3cdf4a59..c5504bf26 100644 --- a/Indicators/tests/Indi_CHV.test.mq4 +++ b/Indicators/tests/Indi_CHV.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_CHV.test.mq5 b/Indicators/tests/Indi_CHV.test.mq5 index 91423902b..6cf7b9c93 100644 --- a/Indicators/tests/Indi_CHV.test.mq5 +++ b/Indicators/tests/Indi_CHV.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_CHV.mqh" diff --git a/Indicators/tests/Indi_ColorBars.test.mq4 b/Indicators/tests/Indi_ColorBars.test.mq4 deleted file mode 100644 index cd735e9bd..000000000 --- a/Indicators/tests/Indi_ColorBars.test.mq4 +++ /dev/null @@ -1,27 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of Indi_ColorBars indicator class. - */ - -#include "Indi_ColorBars.test.mq5" diff --git a/Indicators/tests/Indi_ColorCandlesDaily.test.mq4 b/Indicators/tests/Indi_ColorCandlesDaily.test.mq4 deleted file mode 100644 index 984c0a9c4..000000000 --- a/Indicators/tests/Indi_ColorCandlesDaily.test.mq4 +++ /dev/null @@ -1,27 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of Indi_ColorCandlesDaily indicator class. - */ - -#include "Indi_ColorCandlesDaily.test.mq5" diff --git a/Indicators/tests/Indi_ColorLine.test.mq4 b/Indicators/tests/Indi_ColorLine.test.mq4 deleted file mode 100644 index c99cca1f4..000000000 --- a/Indicators/tests/Indi_ColorLine.test.mq4 +++ /dev/null @@ -1,27 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of Indi_ColorLine indicator class. - */ - -#include "Indi_ColorLine.test.mq5" diff --git a/Indicators/tests/Indi_CustomMovingAverage.test.mq4 b/Indicators/tests/Indi_CustomMovingAverage.test.mq4 deleted file mode 100644 index 33e0589c0..000000000 --- a/Indicators/tests/Indi_CustomMovingAverage.test.mq4 +++ /dev/null @@ -1,27 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of Indi_CustomMovingAverage indicator class. - */ - -#include "Indi_CustomMovingAverage.test.mq5" diff --git a/Indicators/tests/Indi_DEMA.test.cpp b/Indicators/tests/Indi_DEMA.test.cpp new file mode 100644 index 000000000..48118f6af --- /dev/null +++ b/Indicators/tests/Indi_DEMA.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_DEMA class. + */ + +// Includes. +#include "../Indi_DEMA.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_DEMA.test.mq4 b/Indicators/tests/Indi_DEMA.test.mq4 index cd0dd96d3..faec10887 100644 --- a/Indicators/tests/Indi_DEMA.test.mq4 +++ b/Indicators/tests/Indi_DEMA.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_DEMA.test.mq5 b/Indicators/tests/Indi_DEMA.test.mq5 index 99e30be4e..89c44d43c 100644 --- a/Indicators/tests/Indi_DEMA.test.mq5 +++ b/Indicators/tests/Indi_DEMA.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_DEMA.mqh" diff --git a/Indicators/tests/Indi_DeMarker.test.cpp b/Indicators/tests/Indi_DeMarker.test.cpp new file mode 100644 index 000000000..3193ef17a --- /dev/null +++ b/Indicators/tests/Indi_DeMarker.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_DeMarker class. + */ + +// Includes. +#include "../Indi_DeMarker.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_DeMarker.test.mq4 b/Indicators/tests/Indi_DeMarker.test.mq4 index 9f2e28a4f..cbee5b0f0 100644 --- a/Indicators/tests/Indi_DeMarker.test.mq4 +++ b/Indicators/tests/Indi_DeMarker.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_DeMarker.test.mq5 b/Indicators/tests/Indi_DeMarker.test.mq5 index e4085e164..eb020cc28 100644 --- a/Indicators/tests/Indi_DeMarker.test.mq5 +++ b/Indicators/tests/Indi_DeMarker.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_DeMarker.mqh" diff --git a/Indicators/tests/Indi_Demo.test.cpp b/Indicators/tests/Indi_Demo.test.cpp new file mode 100644 index 000000000..e4bbfc8b7 --- /dev/null +++ b/Indicators/tests/Indi_Demo.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Demo class. + */ + +// Includes. +#include "../Indi_Demo.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Demo.test.mq4 b/Indicators/tests/Indi_Demo.test.mq4 index f7bb53956..6b13c2cc7 100644 --- a/Indicators/tests/Indi_Demo.test.mq4 +++ b/Indicators/tests/Indi_Demo.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Demo.test.mq5 b/Indicators/tests/Indi_Demo.test.mq5 index e88ba7f3c..2dec72b1d 100644 --- a/Indicators/tests/Indi_Demo.test.mq5 +++ b/Indicators/tests/Indi_Demo.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Demo.mqh" diff --git a/Indicators/tests/Indi_ColorLine.test.mq5 b/Indicators/tests/Indi_DetrendedPrice.test.cpp similarity index 78% rename from Indicators/tests/Indi_ColorLine.test.mq5 rename to Indicators/tests/Indi_DetrendedPrice.test.cpp index 98a3bd5c3..a59478d75 100644 --- a/Indicators/tests/Indi_ColorLine.test.mq5 +++ b/Indicators/tests/Indi_DetrendedPrice.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,23 +9,28 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -// Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_ColorLine.mqh" - /** * @file - * Test functionality of Indi_ColorLine indicator class. + * Test C++ compilation of Indi_DetrendedPrice class. */ -TEST_INDICATOR_DEFAULT_BINDINGS(Indi_ColorLine); + +// Includes. +#include "../Indi_DetrendedPrice.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_DetrendedPrice.test.mq4 b/Indicators/tests/Indi_DetrendedPrice.test.mq4 index e2cf12d52..80e0b1e62 100644 --- a/Indicators/tests/Indi_DetrendedPrice.test.mq4 +++ b/Indicators/tests/Indi_DetrendedPrice.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_DetrendedPrice.test.mq5 b/Indicators/tests/Indi_DetrendedPrice.test.mq5 index 1d97e83fb..9aefad5da 100644 --- a/Indicators/tests/Indi_DetrendedPrice.test.mq5 +++ b/Indicators/tests/Indi_DetrendedPrice.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_DetrendedPrice.mqh" diff --git a/Indicators/tests/Indi_Drawer.test.cpp b/Indicators/tests/Indi_Drawer.test.cpp new file mode 100644 index 000000000..37f1fb554 --- /dev/null +++ b/Indicators/tests/Indi_Drawer.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Drawer class. + */ + +// Includes. +#include "../Indi_Drawer.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Drawer.test.mq4 b/Indicators/tests/Indi_Drawer.test.mq4 index 19086fd54..f3e6f26ae 100644 --- a/Indicators/tests/Indi_Drawer.test.mq4 +++ b/Indicators/tests/Indi_Drawer.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Drawer.test.mq5 b/Indicators/tests/Indi_Drawer.test.mq5 index 8ca3a93fe..b137c536d 100644 --- a/Indicators/tests/Indi_Drawer.test.mq5 +++ b/Indicators/tests/Indi_Drawer.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Drawer.mqh" diff --git a/Indicators/tests/Indi_Force.test.cpp b/Indicators/tests/Indi_Force.test.cpp new file mode 100644 index 000000000..0e9bd8d4c --- /dev/null +++ b/Indicators/tests/Indi_Force.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Force class. + */ + +// Includes. +#include "../Indi_Force.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Force.test.mq4 b/Indicators/tests/Indi_Force.test.mq4 index ccc628469..eab33526c 100644 --- a/Indicators/tests/Indi_Force.test.mq4 +++ b/Indicators/tests/Indi_Force.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Force.test.mq5 b/Indicators/tests/Indi_Force.test.mq5 index 2004b799f..5e8391ff4 100644 --- a/Indicators/tests/Indi_Force.test.mq5 +++ b/Indicators/tests/Indi_Force.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Force.mqh" diff --git a/Indicators/tests/Indi_FractalAdaptiveMA.test.cpp b/Indicators/tests/Indi_FractalAdaptiveMA.test.cpp new file mode 100644 index 000000000..669cb9da9 --- /dev/null +++ b/Indicators/tests/Indi_FractalAdaptiveMA.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_FractalAdaptiveMA class. + */ + +// Includes. +#include "../Indi_FractalAdaptiveMA.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_FractalAdaptiveMA.test.mq4 b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq4 index ac209b061..c71e62937 100644 --- a/Indicators/tests/Indi_FractalAdaptiveMA.test.mq4 +++ b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 index 38f5c80ea..f262d0c22 100644 --- a/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 +++ b/Indicators/tests/Indi_FractalAdaptiveMA.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_FractalAdaptiveMA.mqh" diff --git a/Indicators/tests/Indi_Fractals.test.cpp b/Indicators/tests/Indi_Fractals.test.cpp new file mode 100644 index 000000000..50d6950cb --- /dev/null +++ b/Indicators/tests/Indi_Fractals.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Fractals class. + */ + +// Includes. +#include "../Indi_Fractals.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Fractals.test.mq4 b/Indicators/tests/Indi_Fractals.test.mq4 index fb5ab315b..cfbbfe354 100644 --- a/Indicators/tests/Indi_Fractals.test.mq4 +++ b/Indicators/tests/Indi_Fractals.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Fractals.test.mq5 b/Indicators/tests/Indi_Fractals.test.mq5 index 0110e87e6..83749301b 100644 --- a/Indicators/tests/Indi_Fractals.test.mq5 +++ b/Indicators/tests/Indi_Fractals.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Fractals.mqh" diff --git a/Indicators/tests/Indi_Gator.test.cpp b/Indicators/tests/Indi_Gator.test.cpp new file mode 100644 index 000000000..f4be095c1 --- /dev/null +++ b/Indicators/tests/Indi_Gator.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Gator class. + */ + +// Includes. +#include "../Indi_Gator.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Gator.test.mq4 b/Indicators/tests/Indi_Gator.test.mq4 index 946003c00..063ea8488 100644 --- a/Indicators/tests/Indi_Gator.test.mq4 +++ b/Indicators/tests/Indi_Gator.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Gator.test.mq5 b/Indicators/tests/Indi_Gator.test.mq5 index f3cd03836..72ea0713c 100644 --- a/Indicators/tests/Indi_Gator.test.mq5 +++ b/Indicators/tests/Indi_Gator.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Gator.mqh" diff --git a/Indicators/tests/Indi_HeikenAshi.test.cpp b/Indicators/tests/Indi_HeikenAshi.test.cpp new file mode 100644 index 000000000..326731b08 --- /dev/null +++ b/Indicators/tests/Indi_HeikenAshi.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_HeikenAshi class. + */ + +// Includes. +#include "../Indi_HeikenAshi.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_HeikenAshi.test.mq4 b/Indicators/tests/Indi_HeikenAshi.test.mq4 index 028ca0ba3..f89cde4c2 100644 --- a/Indicators/tests/Indi_HeikenAshi.test.mq4 +++ b/Indicators/tests/Indi_HeikenAshi.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_HeikenAshi.test.mq5 b/Indicators/tests/Indi_HeikenAshi.test.mq5 index ccefa321f..fb214c269 100644 --- a/Indicators/tests/Indi_HeikenAshi.test.mq5 +++ b/Indicators/tests/Indi_HeikenAshi.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_HeikenAshi.mqh" diff --git a/Indicators/tests/Indi_Ichimoku.test.cpp b/Indicators/tests/Indi_Ichimoku.test.cpp new file mode 100644 index 000000000..60955e6af --- /dev/null +++ b/Indicators/tests/Indi_Ichimoku.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Ichimoku class. + */ + +// Includes. +#include "../Indi_Ichimoku.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Ichimoku.test.mq4 b/Indicators/tests/Indi_Ichimoku.test.mq4 index da6024286..0b8fc6950 100644 --- a/Indicators/tests/Indi_Ichimoku.test.mq4 +++ b/Indicators/tests/Indi_Ichimoku.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Ichimoku.test.mq5 b/Indicators/tests/Indi_Ichimoku.test.mq5 index 31267154f..09fee43b5 100644 --- a/Indicators/tests/Indi_Ichimoku.test.mq5 +++ b/Indicators/tests/Indi_Ichimoku.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Ichimoku.mqh" diff --git a/Indicators/tests/Indi_Killzones.test.cpp b/Indicators/tests/Indi_Killzones.test.cpp new file mode 100644 index 000000000..68be7807f --- /dev/null +++ b/Indicators/tests/Indi_Killzones.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Killzones class. + */ + +// Includes. +#include "../Indi_Killzones.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Killzones.test.mq4 b/Indicators/tests/Indi_Killzones.test.mq4 index bf0bf3b9b..4458d1e58 100644 --- a/Indicators/tests/Indi_Killzones.test.mq4 +++ b/Indicators/tests/Indi_Killzones.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Killzones.test.mq5 b/Indicators/tests/Indi_Killzones.test.mq5 index 11654c88e..8762aa093 100644 --- a/Indicators/tests/Indi_Killzones.test.mq5 +++ b/Indicators/tests/Indi_Killzones.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Killzones.mqh" diff --git a/Indicators/tests/Indi_MFI.test.cpp b/Indicators/tests/Indi_MFI.test.cpp new file mode 100644 index 000000000..b185f1b84 --- /dev/null +++ b/Indicators/tests/Indi_MFI.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_MFI class. + */ + +// Includes. +#include "../Indi_MFI.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_MFI.test.mq4 b/Indicators/tests/Indi_MFI.test.mq4 index 59e118b94..bc30069b1 100644 --- a/Indicators/tests/Indi_MFI.test.mq4 +++ b/Indicators/tests/Indi_MFI.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_MFI.test.mq5 b/Indicators/tests/Indi_MFI.test.mq5 index e86c7ae3a..89d2fa231 100644 --- a/Indicators/tests/Indi_MFI.test.mq5 +++ b/Indicators/tests/Indi_MFI.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_MFI.mqh" diff --git a/Indicators/tests/Indi_MassIndex.test.cpp b/Indicators/tests/Indi_MassIndex.test.cpp new file mode 100644 index 000000000..2cce413c3 --- /dev/null +++ b/Indicators/tests/Indi_MassIndex.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_MassIndex class. + */ + +// Includes. +#include "../Indi_MassIndex.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_MassIndex.test.mq4 b/Indicators/tests/Indi_MassIndex.test.mq4 index 9584d00a0..b338ce8e3 100644 --- a/Indicators/tests/Indi_MassIndex.test.mq4 +++ b/Indicators/tests/Indi_MassIndex.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_MassIndex.test.mq5 b/Indicators/tests/Indi_MassIndex.test.mq5 index 8c9f796ef..5a7ee0d3f 100644 --- a/Indicators/tests/Indi_MassIndex.test.mq5 +++ b/Indicators/tests/Indi_MassIndex.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_MassIndex.mqh" diff --git a/Indicators/tests/Indi_Momentum.test.cpp b/Indicators/tests/Indi_Momentum.test.cpp new file mode 100644 index 000000000..aa8dfee33 --- /dev/null +++ b/Indicators/tests/Indi_Momentum.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Momentum class. + */ + +// Includes. +#include "../Indi_Momentum.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Momentum.test.mq4 b/Indicators/tests/Indi_Momentum.test.mq4 index 5da496ca7..48dc5d032 100644 --- a/Indicators/tests/Indi_Momentum.test.mq4 +++ b/Indicators/tests/Indi_Momentum.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Momentum.test.mq5 b/Indicators/tests/Indi_Momentum.test.mq5 index 6321e3670..98c3ea158 100644 --- a/Indicators/tests/Indi_Momentum.test.mq5 +++ b/Indicators/tests/Indi_Momentum.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Momentum.mqh" diff --git a/Indicators/tests/Indi_OBV.test.cpp b/Indicators/tests/Indi_OBV.test.cpp new file mode 100644 index 000000000..c968c61d2 --- /dev/null +++ b/Indicators/tests/Indi_OBV.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_OBV class. + */ + +// Includes. +#include "../Indi_OBV.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_OBV.test.mq4 b/Indicators/tests/Indi_OBV.test.mq4 index 223d82439..6d11daa51 100644 --- a/Indicators/tests/Indi_OBV.test.mq4 +++ b/Indicators/tests/Indi_OBV.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_OBV.test.mq5 b/Indicators/tests/Indi_OBV.test.mq5 index 66f357b9e..66fbbff57 100644 --- a/Indicators/tests/Indi_OBV.test.mq5 +++ b/Indicators/tests/Indi_OBV.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_OBV.mqh" diff --git a/Indicators/tests/Indi_OHLC.test.cpp b/Indicators/tests/Indi_OHLC.test.cpp new file mode 100644 index 000000000..a1e45b926 --- /dev/null +++ b/Indicators/tests/Indi_OHLC.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_OHLC class. + */ + +// Includes. +#include "../../Indicators/OHLC/Indi_OHLC.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_OsMA.test.cpp b/Indicators/tests/Indi_OsMA.test.cpp new file mode 100644 index 000000000..81bef59ba --- /dev/null +++ b/Indicators/tests/Indi_OsMA.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_OsMA class. + */ + +// Includes. +#include "../Indi_OsMA.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_OsMA.test.mq4 b/Indicators/tests/Indi_OsMA.test.mq4 index 4867ee3c1..1358c7662 100644 --- a/Indicators/tests/Indi_OsMA.test.mq4 +++ b/Indicators/tests/Indi_OsMA.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_OsMA.test.mq5 b/Indicators/tests/Indi_OsMA.test.mq5 index 41ced79dd..615ff46a6 100644 --- a/Indicators/tests/Indi_OsMA.test.mq5 +++ b/Indicators/tests/Indi_OsMA.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_OsMA.mqh" diff --git a/Indicators/tests/Indi_Pattern.test.cpp b/Indicators/tests/Indi_Pattern.test.cpp new file mode 100644 index 000000000..888cbd60c --- /dev/null +++ b/Indicators/tests/Indi_Pattern.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Pattern class. + */ + +// Includes. +#include "../../Indicators/Bitwise/Indi_Pattern.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_ColorBars.test.mq5 b/Indicators/tests/Indi_Price.test.cpp similarity index 78% rename from Indicators/tests/Indi_ColorBars.test.mq5 rename to Indicators/tests/Indi_Price.test.cpp index 226bc7dce..203d9c372 100644 --- a/Indicators/tests/Indi_ColorBars.test.mq5 +++ b/Indicators/tests/Indi_Price.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,23 +9,28 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -// Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_ColorBars.mqh" - /** * @file - * Test functionality of Indi_ColorBars indicator class. + * Test C++ compilation of Indi_Price class. */ -TEST_INDICATOR_DEFAULT_BINDINGS(Indi_ColorBars); + +// Includes. +#include "../../Indicators/Price/Indi_Price.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_PriceChannel.test.cpp b/Indicators/tests/Indi_PriceChannel.test.cpp new file mode 100644 index 000000000..a4ceb1884 --- /dev/null +++ b/Indicators/tests/Indi_PriceChannel.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_PriceChannel class. + */ + +// Includes. +#include "../Indi_PriceChannel.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_PriceChannel.test.mq4 b/Indicators/tests/Indi_PriceChannel.test.mq4 index 52ab4fc26..87e21c89b 100644 --- a/Indicators/tests/Indi_PriceChannel.test.mq4 +++ b/Indicators/tests/Indi_PriceChannel.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_PriceChannel.test.mq5 b/Indicators/tests/Indi_PriceChannel.test.mq5 index ed7567358..d6f17d500 100644 --- a/Indicators/tests/Indi_PriceChannel.test.mq5 +++ b/Indicators/tests/Indi_PriceChannel.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_PriceChannel.mqh" diff --git a/Indicators/tests/Indi_PriceFeeder.test.cpp b/Indicators/tests/Indi_PriceFeeder.test.cpp new file mode 100644 index 000000000..fb28a6dd1 --- /dev/null +++ b/Indicators/tests/Indi_PriceFeeder.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_PriceFeeder class. + */ + +// Includes. +#include "../Indi_PriceFeeder.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_PriceFeeder.test.mq4 b/Indicators/tests/Indi_PriceFeeder.test.mq4 index b5158d9cd..2e3cc62a0 100644 --- a/Indicators/tests/Indi_PriceFeeder.test.mq4 +++ b/Indicators/tests/Indi_PriceFeeder.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_PriceFeeder.test.mq5 b/Indicators/tests/Indi_PriceFeeder.test.mq5 index a79c903a1..509c8c97d 100644 --- a/Indicators/tests/Indi_PriceFeeder.test.mq5 +++ b/Indicators/tests/Indi_PriceFeeder.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_PriceFeeder.mqh" diff --git a/Indicators/tests/Indi_PriceVolumeTrend.test.cpp b/Indicators/tests/Indi_PriceVolumeTrend.test.cpp new file mode 100644 index 000000000..1280eac1b --- /dev/null +++ b/Indicators/tests/Indi_PriceVolumeTrend.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_PriceVolumeTrend class. + */ + +// Includes. +#include "../Indi_PriceVolumeTrend.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_PriceVolumeTrend.test.mq4 b/Indicators/tests/Indi_PriceVolumeTrend.test.mq4 index 81517df61..c2e75d8b4 100644 --- a/Indicators/tests/Indi_PriceVolumeTrend.test.mq4 +++ b/Indicators/tests/Indi_PriceVolumeTrend.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_PriceVolumeTrend.test.mq5 b/Indicators/tests/Indi_PriceVolumeTrend.test.mq5 index 6546239fe..1d6da5062 100644 --- a/Indicators/tests/Indi_PriceVolumeTrend.test.mq5 +++ b/Indicators/tests/Indi_PriceVolumeTrend.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_PriceVolumeTrend.mqh" diff --git a/Indicators/tests/Indi_RS.test.cpp b/Indicators/tests/Indi_RS.test.cpp new file mode 100644 index 000000000..d81e396e1 --- /dev/null +++ b/Indicators/tests/Indi_RS.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_RS class. + */ + +// Includes. +#include "../Indi_RS.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_RS.test.mq4 b/Indicators/tests/Indi_RS.test.mq4 index ea3865532..0f1aa2535 100644 --- a/Indicators/tests/Indi_RS.test.mq4 +++ b/Indicators/tests/Indi_RS.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_RS.test.mq5 b/Indicators/tests/Indi_RS.test.mq5 index 355819ef9..8fff04d29 100644 --- a/Indicators/tests/Indi_RS.test.mq5 +++ b/Indicators/tests/Indi_RS.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_RS.mqh" diff --git a/Indicators/tests/Indi_RVI.test.cpp b/Indicators/tests/Indi_RVI.test.cpp new file mode 100644 index 000000000..9f15b1838 --- /dev/null +++ b/Indicators/tests/Indi_RVI.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_RVI class. + */ + +// Includes. +#include "../Indi_RVI.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_RVI.test.mq4 b/Indicators/tests/Indi_RVI.test.mq4 index 80e7bfa4b..f4c2fa78e 100644 --- a/Indicators/tests/Indi_RVI.test.mq4 +++ b/Indicators/tests/Indi_RVI.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_RVI.test.mq5 b/Indicators/tests/Indi_RVI.test.mq5 index 3200c1ad5..30d84c400 100644 --- a/Indicators/tests/Indi_RVI.test.mq5 +++ b/Indicators/tests/Indi_RVI.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_RVI.mqh" diff --git a/Indicators/tests/Indi_RateOfChange.test.cpp b/Indicators/tests/Indi_RateOfChange.test.cpp new file mode 100644 index 000000000..1bbec0188 --- /dev/null +++ b/Indicators/tests/Indi_RateOfChange.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_RateOfChange class. + */ + +// Includes. +#include "../Indi_RateOfChange.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_RateOfChange.test.mq4 b/Indicators/tests/Indi_RateOfChange.test.mq4 index 3842b5ae7..697496ea9 100644 --- a/Indicators/tests/Indi_RateOfChange.test.mq4 +++ b/Indicators/tests/Indi_RateOfChange.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_RateOfChange.test.mq5 b/Indicators/tests/Indi_RateOfChange.test.mq5 index a1b44e416..dc4ceb1a4 100644 --- a/Indicators/tests/Indi_RateOfChange.test.mq5 +++ b/Indicators/tests/Indi_RateOfChange.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_RateOfChange.mqh" diff --git a/Indicators/tests/Indi_StdDev.test.cpp b/Indicators/tests/Indi_StdDev.test.cpp new file mode 100644 index 000000000..8df779140 --- /dev/null +++ b/Indicators/tests/Indi_StdDev.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_StdDev class. + */ + +// Includes. +#include "../Indi_StdDev.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_StdDev.test.mq4 b/Indicators/tests/Indi_StdDev.test.mq4 index e0d32737d..91eef428f 100644 --- a/Indicators/tests/Indi_StdDev.test.mq4 +++ b/Indicators/tests/Indi_StdDev.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_StdDev.test.mq5 b/Indicators/tests/Indi_StdDev.test.mq5 index 358433006..53dfbc878 100644 --- a/Indicators/tests/Indi_StdDev.test.mq5 +++ b/Indicators/tests/Indi_StdDev.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_StdDev.mqh" diff --git a/Indicators/tests/Indi_TEMA.test.cpp b/Indicators/tests/Indi_TEMA.test.cpp new file mode 100644 index 000000000..9896fb162 --- /dev/null +++ b/Indicators/tests/Indi_TEMA.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_TEMA class. + */ + +// Includes. +#include "../Indi_TEMA.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_TEMA.test.mq4 b/Indicators/tests/Indi_TEMA.test.mq4 index 005f7d617..8f4975843 100644 --- a/Indicators/tests/Indi_TEMA.test.mq4 +++ b/Indicators/tests/Indi_TEMA.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_TEMA.test.mq5 b/Indicators/tests/Indi_TEMA.test.mq5 index 1b8e6447f..f1dadbaf8 100644 --- a/Indicators/tests/Indi_TEMA.test.mq5 +++ b/Indicators/tests/Indi_TEMA.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_TEMA.mqh" diff --git a/Indicators/tests/Indi_TRIX.test.cpp b/Indicators/tests/Indi_TRIX.test.cpp new file mode 100644 index 000000000..c8694d834 --- /dev/null +++ b/Indicators/tests/Indi_TRIX.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_TRIX class. + */ + +// Includes. +#include "../Indi_TRIX.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_TRIX.test.mq4 b/Indicators/tests/Indi_TRIX.test.mq4 index 6d118bdd0..d79696d26 100644 --- a/Indicators/tests/Indi_TRIX.test.mq4 +++ b/Indicators/tests/Indi_TRIX.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_TRIX.test.mq5 b/Indicators/tests/Indi_TRIX.test.mq5 index 7fe0ffc0a..a2cab206f 100644 --- a/Indicators/tests/Indi_TRIX.test.mq5 +++ b/Indicators/tests/Indi_TRIX.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_TRIX.mqh" diff --git a/Indicators/tests/Indi_UltimateOscillator.test.cpp b/Indicators/tests/Indi_UltimateOscillator.test.cpp new file mode 100644 index 000000000..4bbe6e77c --- /dev/null +++ b/Indicators/tests/Indi_UltimateOscillator.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_UltimateOscillator class. + */ + +// Includes. +#include "../Indi_UltimateOscillator.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_UltimateOscillator.test.mq4 b/Indicators/tests/Indi_UltimateOscillator.test.mq4 index 355bae804..ad7492ca8 100644 --- a/Indicators/tests/Indi_UltimateOscillator.test.mq4 +++ b/Indicators/tests/Indi_UltimateOscillator.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_UltimateOscillator.test.mq5 b/Indicators/tests/Indi_UltimateOscillator.test.mq5 index 58b574564..729c21b7c 100644 --- a/Indicators/tests/Indi_UltimateOscillator.test.mq5 +++ b/Indicators/tests/Indi_UltimateOscillator.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_UltimateOscillator.mqh" diff --git a/Indicators/tests/Indi_VIDYA.test.cpp b/Indicators/tests/Indi_VIDYA.test.cpp new file mode 100644 index 000000000..8a5820691 --- /dev/null +++ b/Indicators/tests/Indi_VIDYA.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_VIDYA class. + */ + +// Includes. +#include "../Indi_VIDYA.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_VIDYA.test.mq4 b/Indicators/tests/Indi_VIDYA.test.mq4 index 569fac9ef..45e9ab99f 100644 --- a/Indicators/tests/Indi_VIDYA.test.mq4 +++ b/Indicators/tests/Indi_VIDYA.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_VIDYA.test.mq5 b/Indicators/tests/Indi_VIDYA.test.mq5 index 5d22f6c5d..e69160d13 100644 --- a/Indicators/tests/Indi_VIDYA.test.mq5 +++ b/Indicators/tests/Indi_VIDYA.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_VIDYA.mqh" diff --git a/Indicators/tests/Indi_VROC.test.cpp b/Indicators/tests/Indi_VROC.test.cpp new file mode 100644 index 000000000..8f983e407 --- /dev/null +++ b/Indicators/tests/Indi_VROC.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_VROC class. + */ + +// Includes. +#include "../Indi_VROC.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_VROC.test.mq4 b/Indicators/tests/Indi_VROC.test.mq4 index d5e9eaa55..be4e0626c 100644 --- a/Indicators/tests/Indi_VROC.test.mq4 +++ b/Indicators/tests/Indi_VROC.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_VROC.test.mq5 b/Indicators/tests/Indi_VROC.test.mq5 index a7d5f0595..6b8187140 100644 --- a/Indicators/tests/Indi_VROC.test.mq5 +++ b/Indicators/tests/Indi_VROC.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_VROC.mqh" diff --git a/Indicators/tests/Indi_Volumes.test.cpp b/Indicators/tests/Indi_Volumes.test.cpp new file mode 100644 index 000000000..1c91cc7a4 --- /dev/null +++ b/Indicators/tests/Indi_Volumes.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_Volumes class. + */ + +// Includes. +#include "../Indi_Volumes.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_Volumes.test.mq4 b/Indicators/tests/Indi_Volumes.test.mq4 index bc13b7199..cbdebc7a5 100644 --- a/Indicators/tests/Indi_Volumes.test.mq4 +++ b/Indicators/tests/Indi_Volumes.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_Volumes.test.mq5 b/Indicators/tests/Indi_Volumes.test.mq5 index 05842b4b7..220d9dc6c 100644 --- a/Indicators/tests/Indi_Volumes.test.mq5 +++ b/Indicators/tests/Indi_Volumes.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_Volumes.mqh" diff --git a/Indicators/tests/Indi_WilliamsAD.test.cpp b/Indicators/tests/Indi_WilliamsAD.test.cpp new file mode 100644 index 000000000..0b014600a --- /dev/null +++ b/Indicators/tests/Indi_WilliamsAD.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_WilliamsAD class. + */ + +// Includes. +#include "../Indi_WilliamsAD.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_WilliamsAD.test.mq4 b/Indicators/tests/Indi_WilliamsAD.test.mq4 index c4498a22c..e3d5eb75e 100644 --- a/Indicators/tests/Indi_WilliamsAD.test.mq4 +++ b/Indicators/tests/Indi_WilliamsAD.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_WilliamsAD.test.mq5 b/Indicators/tests/Indi_WilliamsAD.test.mq5 index 7fbce1c5a..1496e7767 100644 --- a/Indicators/tests/Indi_WilliamsAD.test.mq5 +++ b/Indicators/tests/Indi_WilliamsAD.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_WilliamsAD.mqh" diff --git a/Indicators/tests/Indi_ZigZag.test.cpp b/Indicators/tests/Indi_ZigZag.test.cpp new file mode 100644 index 000000000..1e78a2a62 --- /dev/null +++ b/Indicators/tests/Indi_ZigZag.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_ZigZag class. + */ + +// Includes. +#include "../Indi_ZigZag.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_ZigZag.test.mq4 b/Indicators/tests/Indi_ZigZag.test.mq4 index 759590e9a..38d95397f 100644 --- a/Indicators/tests/Indi_ZigZag.test.mq4 +++ b/Indicators/tests/Indi_ZigZag.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_ZigZag.test.mq5 b/Indicators/tests/Indi_ZigZag.test.mq5 index 05c50c477..b1df0da6a 100644 --- a/Indicators/tests/Indi_ZigZag.test.mq5 +++ b/Indicators/tests/Indi_ZigZag.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_ZigZag.mqh" diff --git a/Indicators/tests/Indi_ZigZagColor.test.cpp b/Indicators/tests/Indi_ZigZagColor.test.cpp new file mode 100644 index 000000000..8a8f46ff6 --- /dev/null +++ b/Indicators/tests/Indi_ZigZagColor.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Indi_ZigZagColor class. + */ + +// Includes. +#include "../Indi_ZigZagColor.mqh" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_ZigZagColor.test.mq4 b/Indicators/tests/Indi_ZigZagColor.test.mq4 index 502937586..c3e46ab3d 100644 --- a/Indicators/tests/Indi_ZigZagColor.test.mq4 +++ b/Indicators/tests/Indi_ZigZagColor.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Indicators/tests/Indi_ZigZagColor.test.mq5 b/Indicators/tests/Indi_ZigZagColor.test.mq5 index f9e346de1..a4e8aa9af 100644 --- a/Indicators/tests/Indi_ZigZagColor.test.mq5 +++ b/Indicators/tests/Indi_ZigZagColor.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,7 +20,7 @@ */ // Includes. -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../Indi_ZigZagColor.mqh" diff --git a/Indicators/tests/Indicators.test.cpp b/Indicators/tests/Indicators.test.cpp new file mode 100644 index 000000000..2b8c62847 --- /dev/null +++ b/Indicators/tests/Indicators.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of all indicators. + */ + +// Includes. +#include "../../Platform/Platform.h" +#include "../includes.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/DatabaseTest.mq4 b/Indicators/tests/Indicators.test.mq4 similarity index 87% rename from tests/DatabaseTest.mq4 rename to Indicators/tests/Indicators.test.mq4 index 2bbe12cee..9da308ce3 100644 --- a/tests/DatabaseTest.mq4 +++ b/Indicators/tests/Indicators.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -21,8 +21,8 @@ /** * @file - * Test functionality of Database class. + * Test compilation of all indicators. */ // Includes. -#include "DatabaseTest.mq5" +#include "Indicators.test.mq5" diff --git a/Indicators/tests/Indicators.test.mq5 b/Indicators/tests/Indicators.test.mq5 new file mode 100644 index 000000000..55f42305a --- /dev/null +++ b/Indicators/tests/Indicators.test.mq5 @@ -0,0 +1,33 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test compilation of all indicators. + */ + +// Includes. +#include "../includes.h" + +/** + * Implements Init event handler. + */ +int OnInit() { return 0; } diff --git a/Indicators/tests/Makefile b/Indicators/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Indicators/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Inet.mqh b/Inet.mqh deleted file mode 100644 index 59020473c..000000000 --- a/Inet.mqh +++ /dev/null @@ -1,66 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef __no_dll__ -#import "wininet.dll" -// Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy. -#define INTERNET_FLAG_PRAGMA_NOCACHE 0x00000100 -// Does not add the returned entity to the cache. -#define INTERNET_FLAG_NO_CACHE_WRITE 0x04000000 -// Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. -#define INTERNET_FLAG_RELOAD 0x80000000 -int InternetOpenA(string agent, int access_type, string proxy_name, string proxy_bypass, int flags); -int InternetOpenUrlA(int internet, string url, string headers, int headers_length, int flags, int context); -int InternetReadFile(int handler, string buffer, int buffer_size, int& bytes_read[]); -int InternetCloseHandle(int handler); -#import "urlmon.dll" -int URLDownloadToFileW(int caller, string url, string filename, int reserved, int callback); -#import -#endif - -/** - * Class to provide methods that using the Internet Protocol (IP). - */ -class Inet { - -public: - - /** - * Read content from given URL. - */ - bool ReadFromURL(string url, string &output) { - #ifdef __no_dll__ - return (false); - #endif - int handler = InternetOpenUrlA(-1, url, "0", 0, -2080374528, 0); - if (handler == 0) { - return (false); - } - int out[] = {1}; - string buffer = "xxxxxxxxxx"; - int result = InternetReadFile(handler, buffer, 10, out); - if (handler != 0) InternetCloseHandle(handler); - output = buffer; - return (true); - } - -}; diff --git a/Instances.h b/Instances.h index 8f293a2bf..548aaa015 100644 --- a/Instances.h +++ b/Instances.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -34,13 +34,13 @@ #ifndef INSTANCES_H #define INSTANCES_H -#include "Dict.mqh" +#include "Storage/Dict/Dict.h" #include "Util.h" template class Instances { public: - static T* instances[]; + static ARRAY(T*, instances); Instances(T* _self) { Util::ArrayPush(instances, _self); } ~Instances() { @@ -49,6 +49,10 @@ class Instances { }; template +#ifdef __MQL__ T* Instances::instances[]; +#else +T* Instances::instances[]; +#endif #endif // INSTANCES_MQH diff --git a/Log.mqh b/Log.mqh index 262c93076..7123a2523 100644 --- a/Log.mqh +++ b/Log.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,24 +20,27 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef LOG_MQH -#define LOG_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Forward class declaration. template class DictStruct; // Includes. -#include "Array.mqh" -#include "DateTime.mqh" -#include "DictStruct.mqh" #include "File.mqh" -#include "Object.mqh" +#include "Std.h" +#include "Storage/Array.h" +#include "Storage/Collection.h" +#include "Storage/DateTime.h" +#include "Storage/Dict/DictStruct.h" +#include "Storage/Object.h" // Define assert macros. // Alias for function and line macros combined together. -#define __FUNCTION_LINE__ string(__FUNCTION__) + ":" + IntegerToString(__LINE__) +#define __FUNCTION_LINE__ C_STR(string(__FUNCTION__) + ":" + IntegerToString(__LINE__)) // Log verbosity level. enum ENUM_LOG_LEVEL { @@ -159,7 +162,7 @@ class Log : public Object { * Reports an last error. */ bool AddLastError(string prefix = "", string suffix = ""); - bool AddLastError(string prefix, long suffix); + bool AddLastError(string prefix, int64 suffix); /** * Reports an error. @@ -332,7 +335,7 @@ class Log : public Object { } }; -#include "Terminal.mqh" +#include "Platform/Terminal.h" /** * Reports last error. @@ -340,7 +343,7 @@ class Log : public Object { bool Log::AddLastError(string prefix, string suffix) { return Add(V_ERROR, Terminal::GetLastErrorText(), prefix, suffix); } -bool Log::AddLastError(string prefix, long suffix) { +bool Log::AddLastError(string prefix, int64 suffix) { return Add(V_ERROR, Terminal::GetLastErrorText(), prefix, StringFormat("%d", suffix)); } @@ -349,5 +352,3 @@ void StringToType(string _value, ENUM_LOG_LEVEL &_out) { // Maybe parse the string? _out = V_NONE; } - -#endif diff --git a/MD5.mqh b/MD5.mqh index c34fce753..bb1644eb9 100644 --- a/MD5.mqh +++ b/MD5.mqh @@ -42,9 +42,14 @@ @see: http://www.cnblogs.com/niniwzw/archive/2009/12/05/1617685.html */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "Array.mqh" #include "Convert.basic.h" +#include "Storage/Array.h" /** * Class to provide implementation of MD5 algorithm. @@ -60,7 +65,7 @@ class MD5 { int index = len % 64; // mod 64 int count = (len - index) / 64; - long a = 0x67452301, b = 0xEFCDAB89, c = 0x98BADCFE, d = 0x10325476; + int64 a = 0x67452301, b = 0xEFCDAB89, c = 0x98BADCFE, d = 0x10325476; int buff[16], last[16], i, k = 0, last_char[4], last_index; string item; for (i = 0; i < count; i++) { @@ -96,35 +101,35 @@ class MD5 { return result; } - static long F(long x, long y, long z) { return ((x & y) | ((~x) & z)); } + static int64 F(int64 x, int64 y, int64 z) { return ((x & y) | ((~x) & z)); } - static long G(long x, long y, long z) { return ((x & z) | (y & (~z))); } + static int64 G(int64 x, int64 y, int64 z) { return ((x & z) | (y & (~z))); } - static long H(long x, long y, long z) { return ((x ^ y ^ z)); } + static int64 H(int64 x, int64 y, int64 z) { return ((x ^ y ^ z)); } - static long I(long x, long y, long z) { return ((y ^ (x | (~z)))); } + static int64 I(int64 x, int64 y, int64 z) { return ((y ^ (x | (~z)))); } - static long AddUnsigned(long a, long b) { - long c = a + b; + static int64 AddUnsigned(int64 a, int64 b) { + int64 c = a + b; return (c); } - static long FF(long a, long b, long c, long d, long x, int s, long ac) { + static int64 FF(int64 a, int64 b, int64 c, int64 d, int64 x, int s, int64 ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac)); return (AddUnsigned(RotateLeft(a, s), b)); } - static long GG(long a, long b, long c, long d, long x, int s, long ac) { + static int64 GG(int64 a, int64 b, int64 c, int64 d, int64 x, int s, int64 ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac)); return (AddUnsigned(RotateLeft(a, s), b)); } - static long HH(long a, long b, long c, long d, long x, int s, long ac) { + static int64 HH(int64 a, int64 b, int64 c, int64 d, int64 x, int s, int64 ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac)); return (AddUnsigned(RotateLeft(a, s), b)); } - static long II(long a, long b, long c, long d, long x, int s, long ac) { + static int64 II(int64 a, int64 b, int64 c, int64 d, int64 x, int s, int64 ac) { a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac)); return (AddUnsigned(RotateLeft(a, s), b)); } @@ -133,17 +138,17 @@ class MD5 { * Implementation of right shift operation for unsigned int. * See: http://www.cnblogs.com/niniwzw/archive/2009/12/04/1617130.html */ - static long RotateLeft(long lValue, int iShiftBits) { + static int64 RotateLeft(int64 lValue, int iShiftBits) { if (iShiftBits == 32) return (lValue); - long result = (lValue << iShiftBits) | (((lValue >> 1) & 0x7fffffff) >> (31 - iShiftBits)); + int64 result = (lValue << iShiftBits) | (((lValue >> 1) & 0x7fffffff) >> (31 - iShiftBits)); return (result); } /** * Assume: ArraySize(x) == 16. */ - static void MD5Transform(long &a, long &b, long &c, long &d, int &x[]) { - long AA, BB, CC, DD; + static void MD5Transform(int64 &a, int64 &b, int64 &c, int64 &d, int &x[]) { + int64 AA, BB, CC, DD; int S11 = 7, S12 = 12, S13 = 17, S14 = 22; int S21 = 5, S22 = 9, S23 = 14, S24 = 20; int S31 = 4, S32 = 11, S33 = 16, S34 = 23; diff --git a/MQL4.mqh b/MQL4.mqh deleted file mode 100644 index 972bd3d16..000000000 --- a/MQL4.mqh +++ /dev/null @@ -1,1058 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * @file - * Provide backward compatibility for MQL4 in MT5/MQL5. - */ - -// Prevents processing this includes file for the second time. -#ifndef MQL4_MQH -#define MQL4_MQH - -//+------------------------------------------------------------------+ -//| Declaration of constants -//+------------------------------------------------------------------+ - -// Index in the order pool. -#ifndef SELECT_BY_POS -#define SELECT_BY_POS 0 -#endif - -// Some of standard MQL4 constants are absent in MQL5, therefore they should be declared as below. -#ifdef __MQL5__ -#define show_inputs script_show_inputs -// -- -#define extern input -// -- -#define init OnInit -// -- - -// Defines macros for MQL5. -/* @fixme: Conflicts with SymbolInfo::Ask() method. -#define Ask SymbolInfo::GetAsk(_Symbol) -#define Bid SymbolInfo::GetAsk(_Symbol) -//#define Bid (::SymbolInfoDouble(_Symbol, ::SYMBOL_BID)) -//#define Ask (::SymbolInfoDouble(_Symbol, ::SYMBOL_ASK)) -*/ - -// Defines macros for MQL5. -/* @fixme: error: macro too complex -#define Day(void) DateTime::Day() -#define DayOfWeek(void) SymbolInfo::DayOfWeek() -#define DayOfYear(void) SymbolInfo::DayOfYear() -*/ - -// Define boolean values. -#define True true -#define False false -#define TRUE true -#define FALSE false -// -- -/* @fixme: If this is defined, cannot call: DateTime::TimeToStr(). -#ifndef TimeToStr -#define TimeToStr(time_value, flags) TimeToString(time_value, flags) -#endif -*/ -// -- -#define CurTime TimeCurrent -// -- -#define LocalTime TimeLocal - -#ifndef TRADE_ACTION_CLOSE_BY -#define TRADE_ACTION_CLOSE_BY 1 -#endif - -//+------------------------------------------------------------------+ -//| Includes. -//+------------------------------------------------------------------+ - -/** - * Returns market data about securities. - */ -/* -#include "Market.mqh" -double MarketInfo(string _symbol, int _type) { - return Market::MarketInfo(_symbol, _type); -} -*/ - -//+------------------------------------------------------------------+ -//| | -//+------------------------------------------------------------------+ -string StringSetChar(const string &String_Var, const int iPos, const unsigned short Value) { - string Str = String_Var; - - ::StringSetCharacter(Str, iPos, Value); - - return (Str); -} - -#endif // __MQL5__ - -#ifdef __MQL5__ -#ifndef __MT4ORDERS__ - -#define __MT4ORDERS__ - -#define RESERVE_SIZE 1000 -#define DAY (24 * 3600) -#define HISTORY_PAUSE (MT4HISTORY::IsTester ? 0 : 5) - -class MT4HISTORY { - private: - static const bool IsTester; - - long Tickets[]; - unsigned int Amount; - - datetime LastTime; - - int LastTotalDeals; - int LastTotalOrders; - - datetime LastInitTime; - -#define GETNEXTPOS_FUNCTION(NAME) \ - static int GetNextPosMT4##NAME(int iPos) { \ - const int Total = ::History##NAME##sTotal(); \ - \ - while (iPos < Total) { \ - if (MT4HISTORY::IsMT4##NAME(::History##NAME##GetTicket(iPos))) break; \ - \ - iPos++; \ - } \ - \ - return (iPos); \ - } - - GETNEXTPOS_FUNCTION(Order) - GETNEXTPOS_FUNCTION(Deal) - -#undef GETNEXTPOS_FUNCTION - - bool RefreshHistory(void) { - bool Res = false; - - const datetime LastTimeCurrent = ::TimeCurrent(); - - if ((!MT4HISTORY::IsTester) && (LastTimeCurrent >= this PTR_DEREF LastInitTime + DAY)) { - this PTR_DEREF LastTime = 0; - - this PTR_DEREF LastTotalOrders = 0; - this PTR_DEREF LastTotalDeals = 0; - - this PTR_DEREF Amount = 0; - - ::ArrayResize(this PTR_DEREF Tickets, this PTR_DEREF Amount, RESERVE_SIZE); - - this PTR_DEREF LastInitTime = LastTimeCurrent; - } - - if (::HistorySelect(this PTR_DEREF LastTime, - ::MathMax(LastTimeCurrent, this PTR_DEREF LastTime) + DAY)) // Daily stock. - { - const int TotalOrders = ::HistoryOrdersTotal(); - const int TotalDeals = ::HistoryDealsTotal(); - - Res = ((TotalOrders != this PTR_DEREF LastTotalOrders) || (TotalDeals != this PTR_DEREF LastTotalDeals)); - - if (Res) { - int iOrder = MT4HISTORY::GetNextPosMT4Order(this PTR_DEREF LastTotalOrders); - int iDeal = MT4HISTORY::GetNextPosMT4Deal(this PTR_DEREF LastTotalDeals); - - long TimeOrder = (iOrder < TotalOrders) - ? ::HistoryOrderGetInteger(::HistoryOrderGetTicket(iOrder), ORDER_TIME_DONE /*_MSC*/) - : LONG_MAX; // ORDER_TIME_DONE_MSC returns zero in the tester (build 1470). - long TimeDeal = (iDeal < TotalDeals) - ? ::HistoryDealGetInteger(::HistoryDealGetTicket(iDeal), DEAL_TIME /*_MSC*/) - : LONG_MAX; - - while ((iDeal < TotalDeals) || (iOrder < TotalOrders)) - if (TimeOrder < TimeDeal) { - this PTR_DEREF Amount = ::ArrayResize(this PTR_DEREF Tickets, this PTR_DEREF Amount + 1, RESERVE_SIZE); - - this PTR_DEREF Tickets[this PTR_DEREF Amount - 1] = -(long)::HistoryOrderGetTicket(iOrder); - - iOrder = MT4HISTORY::GetNextPosMT4Order(iOrder + 1); - - TimeOrder = (iOrder < TotalOrders) - ? ::HistoryOrderGetInteger(::HistoryOrderGetTicket(iOrder), ORDER_TIME_DONE /*_MSC*/) - : LONG_MAX; // ORDER_TIME_DONE_MSC returns zero in the tester (build 1470). - } else { - this PTR_DEREF Amount = ::ArrayResize(this PTR_DEREF Tickets, this PTR_DEREF Amount + 1, RESERVE_SIZE); - - this PTR_DEREF Tickets[this PTR_DEREF Amount - 1] = (long)::HistoryDealGetTicket(iDeal); - - iDeal = MT4HISTORY::GetNextPosMT4Deal(iDeal + 1); - - TimeDeal = (iDeal < TotalDeals) ? ::HistoryDealGetInteger(::HistoryDealGetTicket(iDeal), DEAL_TIME /*_MSC*/) - : LONG_MAX; - } - - TimeOrder = (TotalOrders > 0) - ? ::HistoryOrderGetInteger(::HistoryOrderGetTicket(TotalOrders - 1), ORDER_TIME_DONE /*_MSC*/) - : 0; - TimeDeal = - (TotalDeals > 0) ? ::HistoryDealGetInteger(::HistoryDealGetTicket(TotalDeals - 1), DEAL_TIME /*_MSC*/) : 0; - - const long MaxTime = ::MathMax(TimeOrder, TimeDeal); - - this PTR_DEREF LastTotalOrders = 0; - this PTR_DEREF LastTotalDeals = 0; - - if (LastTimeCurrent - HISTORY_PAUSE > MaxTime) - this PTR_DEREF LastTime = LastTimeCurrent - HISTORY_PAUSE; - else { - this PTR_DEREF LastTime = (datetime)MaxTime; - - if (TimeOrder == MaxTime) - for (int i = TotalOrders - 1; i >= 0; i--) { - if (TimeOrder > ::HistoryOrderGetInteger(::HistoryOrderGetTicket(i), ORDER_TIME_DONE /*_MSC*/)) break; - - this PTR_DEREF LastTotalOrders++; - } - - if (TimeDeal == MaxTime) - for (int i = TotalDeals - 1; i >= 0; i--) { - if (TimeDeal != ::HistoryDealGetInteger(::HistoryDealGetTicket(TotalDeals - 1), DEAL_TIME /*_MSC*/)) - break; - - this PTR_DEREF LastTotalDeals++; - } - } - } else if (LastTimeCurrent - HISTORY_PAUSE > this PTR_DEREF LastTime) { - this PTR_DEREF LastTime = LastTimeCurrent - HISTORY_PAUSE; - - this PTR_DEREF LastTotalOrders = 0; - this PTR_DEREF LastTotalDeals = 0; - } - } - - return (Res); - } - - public: - static bool IsMT4Deal(const unsigned long Ticket) { - const ENUM_DEAL_TYPE Type = (ENUM_DEAL_TYPE)::HistoryDealGetInteger(Ticket, DEAL_TYPE); - - return (((Type != DEAL_TYPE_BUY) && (Type != DEAL_TYPE_SELL)) || - ((ENUM_DEAL_ENTRY)::HistoryDealGetInteger(Ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT)); - } - - static bool IsMT4Order(const unsigned long Ticket) { - return ((::HistoryOrderGetDouble(Ticket, ORDER_VOLUME_CURRENT) > 0) || - (::HistoryOrderGetInteger(Ticket, ORDER_POSITION_ID) == 0)); - } - - MT4HISTORY(void) : Amount(0), LastTime(0), LastTotalDeals(0), LastTotalOrders(0), LastInitTime(0) { - ::ArrayResize(this PTR_DEREF Tickets, this PTR_DEREF Amount, RESERVE_SIZE); - - this PTR_DEREF RefreshHistory(); - } - - int GetAmount(void) { - this PTR_DEREF RefreshHistory(); - - return ((int)this PTR_DEREF Amount); - } - - long operator[](const unsigned int Pos) { - long Res = 0; - - if (Pos >= this PTR_DEREF Amount) { - this PTR_DEREF RefreshHistory(); - - if (Pos < this PTR_DEREF Amount) Res = this PTR_DEREF Tickets[Pos]; - } else - Res = this PTR_DEREF Tickets[Pos]; - - return (Res); - } -}; - -static const bool MT4HISTORY::IsTester = (::MQLInfoInteger(MQL_TESTER) || ::MQLInfoInteger(MQL_OPTIMIZATION) || - ::MQLInfoInteger(MQL_VISUAL_MODE) || ::MQLInfoInteger(MQL_FRAME_MODE)); - -#undef HISTORY_PAUSE -#undef DAY -#undef RESERVE_SIZE - -struct MT4_ORDER { - int Ticket; - int Type; - - double Lots; - - string Symbol; - string Comment; - - double OpenPrice; - datetime OpenTime; - - double StopLoss; - double TakeProfit; - - double ClosePrice; - datetime CloseTime; - - datetime Expiration; - - int MagicNumber; - - double Profit; - - double Commission; - double Swap; - - string ToString(void) const { - static const string Types[] = {"buy", "sell", "buy limit", "sell limit", "buy stop", "sell stop", "balance"}; - const int digits = (int)::SymbolInfoInteger(this PTR_DEREF Symbol, SYMBOL_DIGITS); - - return ( - "#" + (string)this PTR_DEREF Ticket + " " + (string)this PTR_DEREF OpenTime + " " + - ((this PTR_DEREF Type < ::ArraySize(Types)) ? Types[this PTR_DEREF Type] : "unknown") + " " + - ::DoubleToString(this PTR_DEREF Lots, 2) + " " + this PTR_DEREF Symbol + " " + - ::DoubleToString(this PTR_DEREF OpenPrice, digits) + " " + ::DoubleToString(this PTR_DEREF StopLoss, digits) + - " " + ::DoubleToString(this PTR_DEREF TakeProfit, digits) + " " + - ((this PTR_DEREF CloseTime > 0) ? ((string)this PTR_DEREF CloseTime + " ") : "") + - ::DoubleToString(this PTR_DEREF ClosePrice, digits) + " " + ::DoubleToString(this PTR_DEREF Commission, 2) + - " " + ::DoubleToString(this PTR_DEREF Swap, 2) + " " + ::DoubleToString(this PTR_DEREF Profit, 2) + " " + - ((this PTR_DEREF Comment == "") ? "" : (this PTR_DEREF Comment + " ")) + (string)this PTR_DEREF MagicNumber + - (((this PTR_DEREF Expiration > 0) ? (" expiration " + (string)this PTR_DEREF Expiration) : ""))); - } -}; - -class MT4ORDERS { - private: - static MT4_ORDER Order; - static MT4HISTORY History; - - static const bool IsTester; - - static unsigned long GetPositionDealIn(const unsigned long PositionIdentifier = 0) { - unsigned long Ticket = 0; - - if ((PositionIdentifier == 0) ? ::HistorySelectByPosition(::PositionGetInteger(POSITION_IDENTIFIER)) - : ::HistorySelectByPosition(PositionIdentifier)) { - const int Total = ::HistoryDealsTotal(); - - for (int i = 0; i < Total; i++) { - const unsigned long TicketDeal = ::HistoryDealGetTicket(i); - - if (TicketDeal > 0) - if ((ENUM_DEAL_ENTRY)::HistoryDealGetInteger(TicketDeal, DEAL_ENTRY) == DEAL_ENTRY_IN) { - Ticket = TicketDeal; - - break; - } - } - } - - return (Ticket); - } - - static double GetPositionCommission(void) { - double Commission = ::PositionGetDouble(POSITION_COMMISSION); - - if (Commission == 0) { - const unsigned long Ticket = MT4ORDERS::GetPositionDealIn(); - - if (Ticket > 0) { - const double LotsIn = ::HistoryDealGetDouble(Ticket, DEAL_VOLUME); - - if (LotsIn > 0) - Commission = ::HistoryDealGetDouble(Ticket, DEAL_COMMISSION) * ::PositionGetDouble(POSITION_VOLUME) / LotsIn; - } - } - - return (Commission); - } - - static string GetPositionComment(void) { - string comment = ::PositionGetString(POSITION_COMMENT); - - if (comment == "") { - const unsigned long Ticket = MT4ORDERS::GetPositionDealIn(); - - if (Ticket > 0) comment = ::HistoryDealGetString(Ticket, DEAL_COMMENT); - } - - return (comment); - } - - static void GetPositionData(void) { - MT4ORDERS::Order.Ticket = (int)::PositionGetInteger(POSITION_TICKET); - MT4ORDERS::Order.Type = (int)::PositionGetInteger(POSITION_TYPE); - - MT4ORDERS::Order.Lots = ::PositionGetDouble(POSITION_VOLUME); - - MT4ORDERS::Order.Symbol = ::PositionGetString(POSITION_SYMBOL); - MT4ORDERS::Order.Comment = MT4ORDERS::GetPositionComment(); - - MT4ORDERS::Order.OpenPrice = ::PositionGetDouble(POSITION_PRICE_OPEN); - MT4ORDERS::Order.OpenTime = (datetime)::PositionGetInteger(POSITION_TIME); - - MT4ORDERS::Order.StopLoss = ::PositionGetDouble(POSITION_SL); - MT4ORDERS::Order.TakeProfit = ::PositionGetDouble(POSITION_TP); - - MT4ORDERS::Order.ClosePrice = ::PositionGetDouble(POSITION_PRICE_CURRENT); - MT4ORDERS::Order.CloseTime = 0; - - MT4ORDERS::Order.Expiration = 0; - - MT4ORDERS::Order.MagicNumber = (int)::PositionGetInteger(POSITION_MAGIC); - - MT4ORDERS::Order.Profit = ::PositionGetDouble(POSITION_PROFIT); - - MT4ORDERS::Order.Commission = MT4ORDERS::GetPositionCommission(); - MT4ORDERS::Order.Swap = ::PositionGetDouble(POSITION_SWAP); - - return; - } - - static void GetOrderData(void) { - MT4ORDERS::Order.Ticket = (int)::OrderGetInteger(ORDER_TICKET); - MT4ORDERS::Order.Type = (int)::OrderGetInteger(ORDER_TYPE); - - MT4ORDERS::Order.Lots = ::OrderGetDouble(ORDER_VOLUME_CURRENT); - - MT4ORDERS::Order.Symbol = ::OrderGetString(ORDER_SYMBOL); - MT4ORDERS::Order.Comment = ::OrderGetString(ORDER_COMMENT); - - MT4ORDERS::Order.OpenPrice = ::OrderGetDouble(ORDER_PRICE_OPEN); - MT4ORDERS::Order.OpenTime = (datetime)::OrderGetInteger(ORDER_TIME_SETUP); - - MT4ORDERS::Order.StopLoss = ::OrderGetDouble(ORDER_SL); - MT4ORDERS::Order.TakeProfit = ::OrderGetDouble(ORDER_TP); - - MT4ORDERS::Order.ClosePrice = ::OrderGetDouble(ORDER_PRICE_CURRENT); - MT4ORDERS::Order.CloseTime = (datetime)::OrderGetInteger(ORDER_TIME_DONE); - - MT4ORDERS::Order.Expiration = (datetime)::OrderGetInteger(ORDER_TIME_EXPIRATION); - - MT4ORDERS::Order.MagicNumber = (int)::OrderGetInteger(ORDER_MAGIC); - - MT4ORDERS::Order.Profit = 0; - - MT4ORDERS::Order.Commission = 0; - MT4ORDERS::Order.Swap = 0; - - return; - } - - static void GetHistoryOrderData(const unsigned long Ticket) { - MT4ORDERS::Order.Ticket = (int)::HistoryOrderGetInteger(Ticket, ORDER_TICKET); - MT4ORDERS::Order.Type = (int)::HistoryOrderGetInteger(Ticket, ORDER_TYPE); - - MT4ORDERS::Order.Lots = ::HistoryOrderGetDouble(Ticket, ORDER_VOLUME_CURRENT); - - if (MT4ORDERS::Order.Lots == 0) MT4ORDERS::Order.Lots = ::HistoryOrderGetDouble(Ticket, ORDER_VOLUME_INITIAL); - - MT4ORDERS::Order.Symbol = ::HistoryOrderGetString(Ticket, ORDER_SYMBOL); - MT4ORDERS::Order.Comment = ::HistoryOrderGetString(Ticket, ORDER_COMMENT); - - MT4ORDERS::Order.OpenPrice = ::HistoryOrderGetDouble(Ticket, ORDER_PRICE_OPEN); - MT4ORDERS::Order.OpenTime = (datetime)::HistoryOrderGetInteger(Ticket, ORDER_TIME_SETUP); - - MT4ORDERS::Order.StopLoss = ::HistoryOrderGetDouble(Ticket, ORDER_SL); - MT4ORDERS::Order.TakeProfit = ::HistoryOrderGetDouble(Ticket, ORDER_TP); - - MT4ORDERS::Order.ClosePrice = 0; - MT4ORDERS::Order.CloseTime = (datetime)::HistoryOrderGetInteger(Ticket, ORDER_TIME_DONE); - - MT4ORDERS::Order.Expiration = (datetime)::HistoryOrderGetInteger(Ticket, ORDER_TIME_EXPIRATION); - - MT4ORDERS::Order.MagicNumber = (int)::HistoryOrderGetInteger(Ticket, ORDER_MAGIC); - - MT4ORDERS::Order.Profit = 0; - - MT4ORDERS::Order.Commission = 0; - MT4ORDERS::Order.Swap = 0; - - return; - } - - static void GetHistoryPositionData(const unsigned long Ticket) { - MT4ORDERS::Order.Ticket = (int)::HistoryDealGetInteger(Ticket, DEAL_TICKET); - MT4ORDERS::Order.Type = (int)::HistoryDealGetInteger(Ticket, DEAL_TYPE); - - if ((MT4ORDERS::Order.Type > OP_SELL)) - MT4ORDERS::Order.Type += (OP_BALANCE - OP_SELL - 1); - else - MT4ORDERS::Order.Type = 1 - MT4ORDERS::Order.Type; - - MT4ORDERS::Order.Lots = ::HistoryDealGetDouble(Ticket, DEAL_VOLUME); - - MT4ORDERS::Order.Symbol = ::HistoryDealGetString(Ticket, DEAL_SYMBOL); - MT4ORDERS::Order.Comment = ::HistoryDealGetString(Ticket, DEAL_COMMENT); - - MT4ORDERS::Order.OpenPrice = ::HistoryDealGetDouble(Ticket, DEAL_PRICE); - MT4ORDERS::Order.OpenTime = (datetime)::HistoryDealGetInteger(Ticket, DEAL_TIME); - - MT4ORDERS::Order.StopLoss = 0; - MT4ORDERS::Order.TakeProfit = 0; - - MT4ORDERS::Order.ClosePrice = ::HistoryDealGetDouble(Ticket, DEAL_PRICE); - MT4ORDERS::Order.CloseTime = (datetime)::HistoryDealGetInteger(Ticket, DEAL_TIME); - ; - - MT4ORDERS::Order.Expiration = 0; - - MT4ORDERS::Order.MagicNumber = (int)::HistoryDealGetInteger(Ticket, DEAL_MAGIC); - - MT4ORDERS::Order.Profit = ::HistoryDealGetDouble(Ticket, DEAL_PROFIT); - - MT4ORDERS::Order.Commission = ::HistoryDealGetDouble(Ticket, DEAL_COMMISSION); - MT4ORDERS::Order.Swap = ::HistoryDealGetDouble(Ticket, DEAL_SWAP); - - const unsigned long OpenTicket = MT4ORDERS::GetPositionDealIn(::HistoryDealGetInteger(Ticket, DEAL_POSITION_ID)); - - if (OpenTicket > 0) { - MT4ORDERS::Order.OpenPrice = ::HistoryDealGetDouble(OpenTicket, DEAL_PRICE); - MT4ORDERS::Order.OpenTime = (datetime)::HistoryDealGetInteger(OpenTicket, DEAL_TIME); - - const double OpenLots = ::HistoryDealGetDouble(OpenTicket, DEAL_VOLUME); - - if (OpenLots > 0) - MT4ORDERS::Order.Commission += - ::HistoryDealGetDouble(OpenTicket, DEAL_COMMISSION) * MT4ORDERS::Order.Lots / OpenLots; - - if (MT4ORDERS::Order.MagicNumber == 0) - MT4ORDERS::Order.MagicNumber = (int)::HistoryDealGetInteger(OpenTicket, DEAL_MAGIC); - - if (MT4ORDERS::Order.Comment == "") MT4ORDERS::Order.Comment = ::HistoryDealGetString(OpenTicket, DEAL_COMMENT); - } - - return; - } - - static bool Waiting(const bool FlagInit = false) { - static unsigned long StartTime = 0; - - if (FlagInit) StartTime = ::GetMicrosecondCount(); - - const bool Res = (::GetMicrosecondCount() - StartTime < MT4ORDERS::OrderSend_MaxPause); - - if (Res) ::Sleep(0); - - return (Res); - } - - static bool EqualPrices(const double Price1, const double Price2, const int digits) { - return (::NormalizeDouble(Price1 - Price2, digits) == 0); - } - -#define WHILE(A) while (!(Res = (A)) && MT4ORDERS::Waiting()) - - static bool OrderSend(const MqlTradeRequest &Request, MqlTradeResult &Result) { - bool Res = ::OrderSend(Request, Result); - - if (Res && !MT4ORDERS::IsTester && (Result.retcode < TRADE_RETCODE_ERROR) && (MT4ORDERS::OrderSend_MaxPause > 0)) { - Res = (Result.retcode == TRADE_RETCODE_DONE); - MT4ORDERS::Waiting(true); - - if (Request.action == TRADE_ACTION_DEAL) { - WHILE(::HistoryOrderSelect(Result.order)); - - Res = Res && (((ENUM_ORDER_STATE)::HistoryOrderGetInteger(Result.order, ORDER_STATE) == ORDER_STATE_FILLED) || - ((ENUM_ORDER_STATE)::HistoryOrderGetInteger(Result.order, ORDER_STATE) == ORDER_STATE_PARTIAL)); - - if (Res) WHILE(::HistoryDealSelect(Result.deal)); - } else if (Request.action == TRADE_ACTION_PENDING) { - if (Res) - WHILE(::OrderSelect(Result.order)); - else { - WHILE(::HistoryOrderSelect(Result.order)); - - Res = false; - } - } else if (Request.action == TRADE_ACTION_SLTP) { - if (Res) { - bool EqualSL = false; - bool EqualTP = false; - - const int digits = (int)::SymbolInfoInteger(Request.symbol, SYMBOL_DIGITS); - - if ((Request.position == 0) ? ::PositionSelect(Request.symbol) : ::PositionSelectByTicket(Request.position)) { - EqualSL = MT4ORDERS::EqualPrices(::PositionGetDouble(POSITION_SL), Request.sl, digits); - EqualTP = MT4ORDERS::EqualPrices(::PositionGetDouble(POSITION_TP), Request.tp, digits); - } - - WHILE((EqualSL && EqualTP)) - if ((Request.position == 0) ? ::PositionSelect(Request.symbol) : ::PositionSelectByTicket(Request.position)) { - EqualSL = MT4ORDERS::EqualPrices(::PositionGetDouble(POSITION_SL), Request.sl, digits); - EqualTP = MT4ORDERS::EqualPrices(::PositionGetDouble(POSITION_TP), Request.tp, digits); - } - } - } else if (Request.action == TRADE_ACTION_MODIFY) { - if (Res) { - bool EqualSL = false; - bool EqualTP = false; - - const int digits = (int)::SymbolInfoInteger(Request.symbol, SYMBOL_DIGITS); - - if (::OrderSelect(Result.order)) { - EqualSL = MT4ORDERS::EqualPrices(::OrderGetDouble(ORDER_SL), Request.sl, digits); - EqualTP = MT4ORDERS::EqualPrices(::OrderGetDouble(ORDER_TP), Request.tp, digits); - } - - WHILE((EqualSL && EqualTP)) - if (::OrderSelect(Result.order)) { - EqualSL = MT4ORDERS::EqualPrices(::OrderGetDouble(ORDER_SL), Request.sl, digits); - EqualTP = MT4ORDERS::EqualPrices(::OrderGetDouble(ORDER_TP), Request.tp, digits); - } - } - } else if (Request.action == TRADE_ACTION_REMOVE) - if (Res) WHILE(::HistoryOrderSelect(Result.order)); - } - - return (Res); - } - -#undef WHILE - - static bool NewOrderSend(const MqlTradeRequest &Request) { - MqlTradeResult Result; - - return (MT4ORDERS::OrderSend(Request, Result) ? Result.retcode < TRADE_RETCODE_ERROR : false); - } - - static bool ModifyPosition(const unsigned long Ticket, MqlTradeRequest &Request) { - const bool Res = ::PositionSelectByTicket(Ticket); - - if (Res) { - Request.action = TRADE_ACTION_SLTP; - - Request.position = Ticket; - Request.symbol = ::PositionGetString(POSITION_SYMBOL); - } - - return (Res); - } - - static ENUM_ORDER_TYPE_FILLING GetFilling(const string Symb, const unsigned int Type = ORDER_FILLING_FOK) { - const ENUM_SYMBOL_TRADE_EXECUTION ExeMode = - (ENUM_SYMBOL_TRADE_EXECUTION)::SymbolInfoInteger(Symb, SYMBOL_TRADE_EXEMODE); - const int FillingMode = (int)::SymbolInfoInteger(Symb, SYMBOL_FILLING_MODE); - - return ((FillingMode == 0 || (Type >= ORDER_FILLING_RETURN) || ((FillingMode & (Type + 1)) != Type + 1)) - ? (((ExeMode == SYMBOL_TRADE_EXECUTION_EXCHANGE) || (ExeMode == SYMBOL_TRADE_EXECUTION_INSTANT)) - ? ORDER_FILLING_RETURN - : ((FillingMode == SYMBOL_FILLING_IOC) ? ORDER_FILLING_IOC : ORDER_FILLING_FOK)) - : (ENUM_ORDER_TYPE_FILLING)Type); - } - - static bool ModifyOrder(const unsigned long _ticket, const double _price, const datetime _expiration, - MqlTradeRequest &Request) { - const bool _res = ::OrderSelect(_ticket); - - if (_res) { - Request.action = TRADE_ACTION_MODIFY; - Request.order = _ticket; - - Request.price = _price; - - Request.symbol = ::OrderGetString(ORDER_SYMBOL); - - Request.type_filling = MT4ORDERS::GetFilling(Request.symbol); - - if (_expiration > 0) { - Request.type_time = ORDER_TIME_SPECIFIED; - Request.expiration = _expiration; - } - } - - return (_res); - } - - public: - static bool SelectByPosHistory(const int Index) { - const int Ticket = (int)MT4ORDERS::History[Index]; - const bool Res = - (Ticket > 0) ? ::HistoryDealSelect(Ticket) : ((Ticket < 0) ? ::HistoryOrderSelect(-Ticket) : false); - - if (Res) { - if (Ticket > 0) - MT4ORDERS::GetHistoryPositionData(Ticket); - else - MT4ORDERS::GetHistoryOrderData(-Ticket); - } - - return (Res); - } - - // position has higher priority - static bool SelectByPos(const int Index) { - const int Total = ::PositionsTotal(); - const bool Flag = (Index < Total); - - const bool Res = - (Flag) ? ::PositionSelectByTicket(::PositionGetTicket(Index)) : ::OrderSelect(::OrderGetTicket(Index - Total)); - - if (Res) { - if (Flag) - MT4ORDERS::GetPositionData(); - else - MT4ORDERS::GetOrderData(); - } - - return (Res); - } - - static bool SelectByHistoryTicket(const int Ticket) { - bool Res = ::HistoryDealSelect(Ticket) ? MT4HISTORY::IsMT4Deal(Ticket) : false; - - if (Res) - MT4ORDERS::GetHistoryPositionData(Ticket); - else { - Res = ::HistoryOrderSelect(Ticket) ? MT4HISTORY::IsMT4Order(Ticket) : false; - - if (Res) MT4ORDERS::GetHistoryOrderData(Ticket); - } - - return (Res); - } - - static bool SelectByExistingTicket(const int Ticket) { - bool Res = true; - - if (::PositionSelectByTicket(Ticket)) - MT4ORDERS::GetPositionData(); - else if (::OrderSelect(Ticket)) - MT4ORDERS::GetOrderData(); - else - Res = false; - - return (Res); - } - - // One Ticket priority: - // MODE_TRADES: exist position > exist order > deal > canceled order - // MODE_HISTORY: deal > canceled order > exist position > exist order - static bool SelectByTicket(const int Ticket, const int Pool = MODE_TRADES) { - return ((Pool == MODE_TRADES) - ? (MT4ORDERS::SelectByExistingTicket(Ticket) ? true : MT4ORDERS::SelectByHistoryTicket(Ticket)) - : (MT4ORDERS::SelectByHistoryTicket(Ticket) ? true : MT4ORDERS::SelectByExistingTicket(Ticket))); - } - - public: - static unsigned int OrderSend_MaxPause; - - static bool MT4OrderSelect(const int Index, const int Select, const int Pool = MODE_TRADES) { - return ((Select == SELECT_BY_POS) - ? ((Pool == MODE_TRADES) ? MT4ORDERS::SelectByPos(Index) : MT4ORDERS::SelectByPosHistory(Index)) - : MT4ORDERS::SelectByTicket(Index, Pool)); - } - - // MT5 OrderSelect - static bool MT4OrderSelect(const unsigned long Ticket) { return (::OrderSelect(Ticket)); } - - static int MT4OrdersTotal(void) { return (::OrdersTotal() + ::PositionsTotal()); } - - // MT5 OrdersTotal - static int MT4OrdersTotal(const bool MT5) { return (::OrdersTotal()); } - - static int MT4OrdersHistoryTotal(void) { return (MT4ORDERS::History.GetAmount()); } - - static int MT4OrderSend(const string Symb, const int Type, const double dVolume, const double _price, - const int SlipPage, const double SL, const double TP, const string comment = NULL, - const int magic = 0, const datetime dExpiration = 0, color arrow_color = clrNONE) { - MqlTradeRequest Request = {0}; - - Request.action = (((Type == OP_BUY) || (Type == OP_SELL)) ? TRADE_ACTION_DEAL : TRADE_ACTION_PENDING); - Request.magic = magic; - - Request.symbol = ((Symb == NULL) ? ::Symbol() : Symb); - Request.volume = dVolume; - Request.price = _price; - - Request.tp = TP; - Request.sl = SL; - Request.deviation = SlipPage; - Request.type = (ENUM_ORDER_TYPE)Type; - - Request.type_filling = MT4ORDERS::GetFilling(Request.symbol, (unsigned int)Request.deviation); - - if (dExpiration > 0) { - Request.type_time = ORDER_TIME_SPECIFIED; - Request.expiration = dExpiration; - } - - Request.comment = comment; - - MqlTradeResult Result; - - return (MT4ORDERS::OrderSend(Request, Result) - ? ((Request.action == TRADE_ACTION_DEAL) - ? (::HistoryDealSelect(Result.deal) ? (int)::HistoryDealGetInteger(Result.deal, DEAL_POSITION_ID) - : -1) - : (int)Result.order) - : -1); - } - - static bool MT4OrderModify(const unsigned long Ticket, const double _price, const double SL, const double TP, - const datetime Expiration, const color Arrow_Color = clrNONE) { - MqlTradeRequest Request = {0}; - - // considered case if order and position has the same ticket - bool Res = - ((Ticket != MT4ORDERS::Order.Ticket) || (MT4ORDERS::Order.Ticket <= OP_SELL)) - ? (MT4ORDERS::ModifyPosition(Ticket, Request) ? true - : MT4ORDERS::ModifyOrder(Ticket, _price, Expiration, Request)) - : (MT4ORDERS::ModifyOrder(Ticket, _price, Expiration, Request) - ? true - : MT4ORDERS::ModifyPosition(Ticket, Request)); - - if (Res) { - Request.tp = TP; - Request.sl = SL; - - Res = MT4ORDERS::NewOrderSend(Request); - } - - return (Res); - } - - static bool MT4OrderClose(const unsigned long Ticket, const double dLots, const double _price, const int SlipPage, - const color Arrow_Color = clrNONE) { - bool Res = ::PositionSelectByTicket(Ticket); - - if (Res) { - MqlTradeRequest Request = {0}; - - Request.action = TRADE_ACTION_DEAL; - Request.position = Ticket; - - Request.symbol = ::PositionGetString(POSITION_SYMBOL); - - Request.volume = dLots; - Request.price = _price; - - Request.deviation = SlipPage; - - Request.type = (ENUM_ORDER_TYPE)(1 - ::PositionGetInteger(POSITION_TYPE)); - - Request.type_filling = MT4ORDERS::GetFilling(Request.symbol, (unsigned int)Request.deviation); - - Res = MT4ORDERS::NewOrderSend(Request); - } - - return (Res); - } - - static bool MT4OrderCloseBy(const unsigned long Ticket, const int Opposite, const color Arrow_color) { - bool Res = ::PositionSelectByTicket(Ticket); - - if (Res) { - string _symbol = ::PositionGetString(POSITION_SYMBOL); - ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)::PositionGetInteger(POSITION_TYPE); - - if (!PositionSelectByTicket(Opposite)) return (false); - - string symbol_by = ::PositionGetString(POSITION_SYMBOL); - ENUM_POSITION_TYPE type_by = (ENUM_POSITION_TYPE)::PositionGetInteger(POSITION_TYPE); - - if (type == type_by) return (false); - if (_symbol != symbol_by) return (false); - - MqlTradeRequest Request = {0}; - - Request.action = TRADE_ACTION_CLOSE_BY; - Request.position = Ticket; - Request.position_by = Opposite; - - Res = MT4ORDERS::NewOrderSend(Request); - } - return (Res); - } - - static bool MT4OrderDelete(const unsigned long Ticket, const color Arrow_Color = clrNONE) { - bool Res = ::OrderSelect(Ticket); - - if (Res) { - MqlTradeRequest Request = {0}; - - Request.action = TRADE_ACTION_REMOVE; - Request.order = Ticket; - - Res = MT4ORDERS::NewOrderSend(Request); - } - - return (Res); - } -}; - -static MT4_ORDER MT4ORDERS::Order = {0}; - -static MT4HISTORY MT4ORDERS::History; - -static const bool MT4ORDERS::IsTester = (::MQLInfoInteger(MQL_TESTER) || ::MQLInfoInteger(MQL_OPTIMIZATION) || - ::MQLInfoInteger(MQL_VISUAL_MODE) || ::MQLInfoInteger(MQL_FRAME_MODE)); - -static unsigned int MT4ORDERS::OrderSend_MaxPause = 1000000; // Maximum time synchronization in microseconds. - -bool OrderClose(const unsigned long Ticket, const double dLots, const double _price, const int SlipPage, - const color Arrow_Color = clrNONE) { - return (MT4ORDERS::MT4OrderClose(Ticket, dLots, _price, SlipPage, Arrow_Color)); -} - -bool OrderModify(const unsigned long Ticket, const double _price, const double SL, const double TP, - const datetime Expiration, const color Arrow_Color = clrNONE) { - return (MT4ORDERS::MT4OrderModify(Ticket, _price, SL, TP, Expiration, Arrow_Color)); -} - -bool OrderDelete(const unsigned long Ticket, const color Arrow_Color = clrNONE) { - return (MT4ORDERS::MT4OrderDelete(Ticket, Arrow_Color)); -} - -bool OrderCloseBy(const unsigned long Ticket, const int Opposite, const color Arrow_color) { - return (MT4ORDERS::MT4OrderCloseBy(Ticket, Opposite, Arrow_color)); -} - -#endif // __MT4ORDERS__ -#endif // __MQL5__ - -/** - * MQL4 wrapper to work in MQL5. - */ -class MQL4 { - public: - /** - * Converts MQL4 time periods. - * - * As in MQL5 chart period constants changed, and some new time periods (M2, M3, M4, M6, M10, M12, H2, H3, H6, H8, - * H12) were added. - * - * Note: In MQL5 the numerical values of chart timeframe constants (from H1) - * are not equal to the number of minutes of a bar. - * E.g. In MQL5, the value of constant PERIOD_H1 is 16385, but in MQL4 PERIOD_H1=60. - * - * @see: https://www.mql5.com/en/articles/81 - */ - static ENUM_TIMEFRAMES TFMigrate(int _tf) { - switch (_tf) { - case 0: - return (PERIOD_CURRENT); - case 1: - return (PERIOD_M1); - case 2: - return (PERIOD_M2); - case 3: - return (PERIOD_M3); - case 4: - return (PERIOD_M4); - case 5: - return (PERIOD_M5); - case 6: - return (PERIOD_M6); - case 10: - return (PERIOD_M10); - case 12: - return (PERIOD_M12); - case 15: - return (PERIOD_M15); - case 30: - return (PERIOD_M30); - case 60: - return (PERIOD_H1); - case 240: - return (PERIOD_H4); - case 1440: - return (PERIOD_D1); - case 10080: - return (PERIOD_W1); - case 43200: - return (PERIOD_MN1); - case 16385: - return (PERIOD_H1); - case 16386: - return (PERIOD_H2); - case 16387: - return (PERIOD_H3); - case 16388: - return (PERIOD_H4); - case 16390: - return (PERIOD_H6); - case 16392: - return (PERIOD_H8); - case 16396: - return (PERIOD_H12); - case 16408: - return (PERIOD_D1); - case 32769: - return (PERIOD_W1); - case 49153: - return (PERIOD_MN1); - default: - return (PERIOD_CURRENT); - } - } - - ENUM_MA_METHOD MethodMigrate(int method) { - switch (method) { - case 0: - return (MODE_SMA); - case 1: - return (MODE_EMA); - case 2: - return (MODE_SMMA); - case 3: - return (MODE_LWMA); - default: - return (MODE_SMA); - } - } - - ENUM_APPLIED_PRICE PriceMigrate(int price) { - switch (price) { - case 1: - return (PRICE_CLOSE); - case 2: - return (PRICE_OPEN); - case 3: - return (PRICE_HIGH); - case 4: - return (PRICE_LOW); - case 5: - return (PRICE_MEDIAN); - case 6: - return (PRICE_TYPICAL); - case 7: - return (PRICE_WEIGHTED); - default: - return (PRICE_CLOSE); - } - } - - ENUM_STO_PRICE StoFieldMigrate(int field) { - switch (field) { - case 0: - return (STO_LOWHIGH); - case 1: - return (STO_CLOSECLOSE); - default: - return (STO_LOWHIGH); - } - } -}; -#endif // MQL4_MQH diff --git a/MQL5.mqh b/MQL5.mqh deleted file mode 100644 index 9bbf582a3..000000000 --- a/MQL5.mqh +++ /dev/null @@ -1,310 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * @file - * Provides forward compatibility for MQL5 in MT4/MQL4. - */ - -// Prevents processing this includes file for the second time. -#ifndef MQL5_MQH -#define MQL5_MQH - -//+------------------------------------------------------------------+ -//| Declaration of constants -//+------------------------------------------------------------------+ - -// Missing error handling constants in MQL4. -// @see: https://docs.mql4.com/constants/errorswarnings/errorcodes -// @see: https://www.mql5.com/en/docs/constants/errorswarnings -#ifdef __MQL4__ -// Return codes of the trade server. -#define TRADE_RETCODE_REQUOTE 10004 // Requote -#define TRADE_RETCODE_REJECT 10006 // Request rejected -#define TRADE_RETCODE_CANCEL 10007 // Request canceled by trader -#define TRADE_RETCODE_PLACED 10008 // Order placed -#define TRADE_RETCODE_DONE 10009 // Request completed -#define TRADE_RETCODE_DONE_PARTIAL 10010 // Only part of the request was completed -#define TRADE_RETCODE_ERROR 10011 // Request processing error -#define TRADE_RETCODE_TIMEOUT 10012 // Request canceled by timeout -#define TRADE_RETCODE_INVALID 10013 // Invalid request -#define TRADE_RETCODE_INVALID_VOLUME 10014 // Invalid volume in the request -#define TRADE_RETCODE_INVALID_PRICE 10015 // Invalid price in the request -#define TRADE_RETCODE_INVALID_STOPS 10016 // Invalid stops in the request -#define TRADE_RETCODE_TRADE_DISABLED 10017 // Trade is disabled -#define TRADE_RETCODE_MARKET_CLOSED 10018 // Market is closed -#define TRADE_RETCODE_NO_MONEY 10019 // There is not enough money to complete the request -#define TRADE_RETCODE_PRICE_CHANGED 10020 // Prices changed -#define TRADE_RETCODE_PRICE_OFF 10021 // There are no quotes to process the request -#define TRADE_RETCODE_INVALID_EXPIRATION 10022 // Invalid order expiration date in the request -#define TRADE_RETCODE_ORDER_CHANGED 10023 // Order state changed -#define TRADE_RETCODE_TOO_MANY_REQUESTS 10024 // Too frequent requests -#define TRADE_RETCODE_NO_CHANGES 10025 // No changes in request -#define TRADE_RETCODE_SERVER_DISABLES_AT 10026 // Autotrading disabled by server -#define TRADE_RETCODE_CLIENT_DISABLES_AT 10027 // Autotrading disabled by client terminal -#define TRADE_RETCODE_LOCKED 10028 // Request locked for processing -#define TRADE_RETCODE_FROZEN 10029 // Order or position frozen -#define TRADE_RETCODE_INVALID_FILL 10030 // Invalid order filling type -#define TRADE_RETCODE_CONNECTION 10031 // No connection with the trade server -#define TRADE_RETCODE_ONLY_REAL 10032 // Operation is allowed only for live accounts -#define TRADE_RETCODE_LIMIT_ORDERS 10033 // The number of pending orders has reached the limit -#define TRADE_RETCODE_LIMIT_VOLUME 10034 // The volume of orders and positions for the symbol has reached the limit -#define TRADE_RETCODE_INVALID_ORDER 10035 // Incorrect or prohibited order type -#define TRADE_RETCODE_POSITION_CLOSED 10036 // Position with the specified POSITION_IDENTIFIER has already been closed -#define TRADE_RETCODE_INVALID_CLOSE_VOLUME 10038 // A close volume exceeds the current position volume -#define TRADE_RETCODE_CLOSE_ORDER_EXIST 10039 // A close order already exists. -#define TRADE_RETCODE_LIMIT_POSITIONS 10040 // The number of open positions can be limited (e.g. Netting, Hedging). -#endif -// Runtime Errors (@see: https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes) -// General error codes. -#ifndef ERR_SUCCESS -#define ERR_SUCCESS 0 // The operation completed successfully. -#endif -#define ERR_NO_MQLERROR 4000 -#ifndef ERR_INTERNAL_ERROR -#define ERR_INTERNAL_ERROR 4001 // Operating system error. -#endif -#define ERR_WRONG_INTERNAL_PARAMETER 4002 // Wrong parameter in the inner call of the client terminal function. -//#define ERR_INVALID_PARAMETER 4003 // Wrong parameter when calling the system function. -#define ERR_NOT_ENOUGH_MEMORY 4004 // Not enough memory to perform the system function. -#define ERR_STRUCT_WITHOBJECTS_ORCLASS 4005 // The structure contains objects of strings and/or dynamic arrays and/or structure of such objects and/or classes. -#define ERR_INVALID_ARRAY 4006 // Array of a wrong type, wrong size, or a damaged object of a dynamic array. -#define ERR_ARRAY_RESIZE_ERROR 4007 // Not enough memory for the relocation of an array, or an attempt to change the size of a static array. -#define ERR_STRING_RESIZE_ERROR 4008 // Not enough memory for the relocation of string. -#define ERR_NOTINITIALIZED_STRING 4009 // Not initialized string. -#define ERR_INVALID_DATETIME 4010 // Invalid date and/or time. -#define ERR_ARRAY_BAD_SIZE 4011 // Requested array size exceeds 2 GB. -#ifndef ERR_INVALID_POINTER -#define ERR_INVALID_POINTER 4012 // Wrong pointer. -#endif -#define ERR_INVALID_POINTER_TYPE 4013 // Wrong type of pointer. -#define ERR_FUNCTION_NOT_ALLOWED 4014 // Function is not allowed for call. -#define ERR_RESOURCE_NAME_DUPLICATED 4015 // The names of the dynamic and the static resource match. -#ifndef ERR_RESOURCE_NOT_FOUND -#define ERR_RESOURCE_NOT_FOUND 4016 // Resource with this name has not been found in EX5. -#endif -#define ERR_RESOURCE_UNSUPPOTED_TYPE 4017 // Unsupported resource type or its size exceeds 16 Mb. -#define ERR_RESOURCE_NAME_IS_TOO_LONG 4018 // The resource name exceeds 63 characters. -// Charts. -#define ERR_CHART_WRONG_ID 4101 // Wrong chart ID. -#define ERR_CHART_NO_REPLY 4102 // Chart does not respond. -#ifndef ERR_CHART_NOT_FOUND -#define ERR_CHART_NOT_FOUND 4103 // Chart not found. -#endif -#define ERR_CHART_NO_EXPERT 4104 // No Expert Advisor in the chart that could handle the event. -#define ERR_CHART_CANNOT_OPEN 4105 // Chart opening error. -#define ERR_CHART_CANNOT_CHANGE 4106 // Failed to change chart symbol and period. -#define ERR_CHART_WRONG_PARAMETER 4107 // Error value of the parameter for the function of working with charts. -#define ERR_CHART_CANNOT_CREATE_TIMER 4108 // Failed to create timer. -#define ERR_CHART_WRONG_PROPERTY 4109 // Wrong chart property ID. -#define ERR_CHART_SCREENSHOT_FAILED 4110 // Error creating screenshots. -#define ERR_CHART_NAVIGATE_FAILED 4111 // Error navigating through chart. -#define ERR_CHART_TEMPLATE_FAILED 4112 // Error applying template. -#define ERR_CHART_WINDOW_NOT_FOUND 4113 // Subwindow containing the indicator was not found. -#define ERR_CHART_INDICATOR_CANNOT_ADD 4114 // Error adding an indicator to chart. -#define ERR_CHART_INDICATOR_CANNOT_DEL 4115 // Error deleting an indicator from the chart. -#define ERR_CHART_INDICATOR_NOT_FOUND 4116 // Indicator not found on the specified chart. -// Graphical Objects. -#define ERR_OBJECT_ERROR 4201 // Error working with a graphical object. -#define ERR_OBJECT_NOT_FOUND 4202 // Graphical object was not found. -#define ERR_OBJECT_WRONG_PROPERTY 4203 // Wrong ID of a graphical object property. -#define ERR_OBJECT_GETDATE_FAILED 4204 // Unable to get date corresponding to the value. -#define ERR_OBJECT_GETVALUE_FAILED 4205 // Unable to get value corresponding to the date. -// MarketInfo. -#define ERR_MARKET_UNKNOWN_SYMBOL 4301 // Unknown symbol. -#define ERR_MARKET_NOT_SELECTED 4302 // Symbol is not selected in MarketWatch. -#define ERR_MARKET_WRONG_PROPERTY 4303 // Wrong identifier of a symbol property. -#define ERR_MARKET_LASTTIME_UNKNOWN 4304 // Time of the last tick is not known (no ticks). -#define ERR_MARKET_SELECT_ERROR 4305 // Error adding or deleting a symbol in MarketWatch. -// History Access. -#define ERR_HISTORY_NOT_FOUND 4401 // Requested history not found. -#define ERR_HISTORY_WRONG_PROPERTY 4402 // Wrong ID of the history property. -#define ERR_HISTORY_TIMEOUT 4403 // Exceeded history request timeout. -#define ERR_HISTORY_BARS_LIMIT 4404 // Number of requested bars limited by terminal settings. -#define ERR_HISTORY_LOAD_ERRORS 4405 // Multiple errors when loading history. -#define ERR_HISTORY_SMALL_BUFFER 4407 // Receiving array is too small to store all requested data. -// Global_Variables. -#define ERR_GLOBALVARIABLE_NOT_FOUND 4501 // Global variable of the client terminal is not found. -#define ERR_GLOBALVARIABLE_EXISTS 4502 // Global variable of the client terminal with the same name already exists. -#define ERR_MAIL_SEND_FAILED 4510 // Email sending failed. -#define ERR_PLAY_SOUND_FAILED 4511 // Sound playing failed. -#define ERR_MQL5_WRONG_PROPERTY 4512 // Wrong identifier of the program property. -#define ERR_TERMINAL_WRONG_PROPERTY 4513 // Wrong identifier of the terminal property. -#define ERR_FTP_SEND_FAILED 4514 // File sending via ftp failed. -#define ERR_NOTIFICATION_SEND_FAILED 4515 // Failed to send a notification. -#define ERR_NOTIFICATION_WRONG_PARAMETER 4516 // Invalid parameter for sending a notification - an empty string or NULL has been passed to the SendNotification() function. -#define ERR_NOTIFICATION_WRONG_SETTINGS 4517 // Wrong settings of notifications in the terminal (ID is not specified or permission is not set). -#ifndef ERR_NOTIFICATION_TOO_FREQUENT -#define ERR_NOTIFICATION_TOO_FREQUENT 4518 // Too frequent sending of notifications. -#endif -#ifndef ERR_FTP_NOSERVER -#define ERR_FTP_NOSERVER 4519 // FTP server is not specified. -#endif -#ifndef ERR_FTP_NOLOGIN -#define ERR_FTP_NOLOGIN 4520 // FTP login is not specified. -#endif -#ifndef ERR_FTP_FILE_ERROR -#define ERR_FTP_FILE_ERROR 4521 // File not found in the MQL5\Files directory to send on FTP server. -#endif -#ifndef ERR_FTP_CONNECT_FAILED -#define ERR_FTP_CONNECT_FAILED 4522 // FTP connection failed. -#endif -#ifndef ERR_FTP_CHANGEDIR -#define ERR_FTP_CHANGEDIR 4523 // FTP path not found on server. -#endif -#ifndef ERR_FTP_CLOSED -#define ERR_FTP_CLOSED 4524 // FTP connection closed. -#endif -// Custom Indicator Buffers. -#define ERR_BUFFERS_NO_MEMORY 4601 // Not enough memory for the distribution of indicator buffers. -#define ERR_BUFFERS_WRONG_INDEX 4602 // Wrong indicator buffer index. -// Custom Indicator Properties. -#define ERR_CUSTOM_WRONG_PROPERTY 4603 // Wrong ID of the custom indicator property. -// Account. -#define ERR_ACCOUNT_WRONG_PROPERTY 4701 // Wrong account property ID. -#define ERR_TRADE_WRONG_PROPERTY 4751 // Wrong trade property ID. -#ifndef ERR_TRADE_DISABLED -#define ERR_TRADE_DISABLED 4752 // Trading by Expert Advisors prohibited. -#endif -#define ERR_TRADE_POSITION_NOT_FOUND 4753 // Position not found. -#define ERR_TRADE_ORDER_NOT_FOUND 4754 // Order not found. -#define ERR_TRADE_DEAL_NOT_FOUND 4755 // Deal not found. -#define ERR_TRADE_SEND_FAILED 4756 // Trade request sending failed. -// Indicators. -#define ERR_INDICATOR_UNKNOWN_SYMBOL 4801 // Unknown symbol. -#define ERR_INDICATOR_CANNOT_CREATE 4802 // Indicator cannot be created. -#define ERR_INDICATOR_NO_MEMORY 4803 // Not enough memory to add the indicator. -#define ERR_INDICATOR_CANNOT_APPLY 4804 // The indicator cannot be applied to another indicator. -#define ERR_INDICATOR_CANNOT_ADD 4805 // Error applying an indicator to chart. -#define ERR_INDICATOR_DATA_NOT_FOUND 4806 // Requested data not found. -#define ERR_INDICATOR_WRONG_HANDLE 4807 // Wrong indicator handle. -#define ERR_INDICATOR_WRONG_PARAMETERS 4808 // Wrong number of parameters when creating an indicator. -#define ERR_INDICATOR_PARAMETERS_MISSING 4809 // No parameters when creating an indicator. -#define ERR_INDICATOR_CUSTOM_NAME 4810 // The first parameter in the array must be the name of the custom indicator. -#define ERR_INDICATOR_PARAMETER_TYPE 4811 // Invalid parameter type in the array when creating an indicator. -#define ERR_INDICATOR_WRONG_INDEX 4812 // Wrong index of the requested indicator buffer. -// Depth of Market. -#define ERR_BOOKS_CANNOT_ADD 4901 // Depth Of Market can not be added. -#define ERR_BOOKS_CANNOT_DELETE 4902 // Depth Of Market can not be removed. -#define ERR_BOOKS_CANNOT_GET 4903 // The data from Depth Of Market can not be obtained. -#define ERR_BOOKS_CANNOT_SUBSCRIBE 4904 // Error in subscribing to receive new data from Depth Of Market. -// File Operations. -#define ERR_TOO_MANY_FILES 5001 // More than 64 files cannot be opened at the same time. -#define ERR_WRONG_FILENAME 5002 // Invalid file name. -#define ERR_TOO_LONG_FILENAME 5003 // Too long file name. -#ifndef ERR_CANNOT_OPEN_FILE -#define ERR_CANNOT_OPEN_FILE 5004 // File opening error. -#endif -#define ERR_FILE_CACHEBUFFER_ERROR 5005 // Not enough memory for cache to read. -#define ERR_CANNOT_DELETE_FILE 5006 // File deleting error. -#define ERR_INVALID_FILEHANDLE 5007 // A file with this handle was closed, or was not opening at all. -#define ERR_WRONG_FILEHANDLE 5008 // Wrong file handle. -#define ERR_FILE_NOTTOWRITE 5009 // The file must be opened for writing. -#define ERR_FILE_NOTTOREAD 5010 // The file must be opened for reading. -#define ERR_FILE_NOTBIN 5011 // The file must be opened as a binary one. -#define ERR_FILE_NOTTXT 5012 // The file must be opened as a text. -#define ERR_FILE_NOTTXTORCSV 5013 // The file must be opened as a text or CSV. -#define ERR_FILE_NOTCSV 5014 // The file must be opened as CSV. -#define ERR_FILE_READERROR 5015 // File reading error. -#define ERR_FILE_BINSTRINGSIZE 5016 // String size must be specified, because the file is opened as binary. -#define ERR_INCOMPATIBLE_FILE 5017 // A text file must be for string arrays, for other arrays - binary. -#ifndef ERR_FILE_IS_DIRECTORY -#define ERR_FILE_IS_DIRECTORY 5018 // This is not a file, this is a directory. -#endif -#ifndef ERR_FILE_NOT_EXIST -#define ERR_FILE_NOT_EXIST 5019 // File does not exist. -#endif -#ifndef ERR_FILE_CANNOT_REWRITE -#define ERR_FILE_CANNOT_REWRITE 5020 // File can not be rewritten. -#endif -#define ERR_WRONG_DIRECTORYNAME 5021 // Wrong directory name. -#define ERR_DIRECTORY_NOT_EXIST 5022 // Directory does not exist. -#define ERR_FILE_ISNOT_DIRECTORY 5023 // This is a file, not a directory. -#define ERR_CANNOT_DELETE_DIRECTORY 5024 // The directory cannot be removed. -#define ERR_CANNOT_CLEAN_DIRECTORY 5025 // Failed to clear the directory (probably one or more files are blocked and removal operation failed). -#define ERR_FILE_WRITEERROR 5026 // Failed to write a resource to a file. -#define ERR_FILE_ENDOFFILE 5027 // Unable to read the next piece of data from a CSV file (FileReadString, FileReadNumber, FileReadDatetime, FileReadBool), since the end of file is reached. -// String Casting. -#define ERR_NO_STRING_DATE 5030 // No date in the string. -#define ERR_WRONG_STRING_DATE 5031 // Wrong date in the string. -#define ERR_WRONG_STRING_TIME 5032 // Wrong time in the string. -#define ERR_STRING_TIME_ERROR 5033 // Error converting string to date. -#define ERR_STRING_OUT_OF_MEMORY 5034 // Not enough memory for the string. -#define ERR_STRING_SMALL_LEN 5035 // The string length is less than expected. -#define ERR_STRING_TOO_BIGNUMBER 5036 // Too large number, more than ULONG_MAX. -#define ERR_WRONG_FORMATSTRING 5037 // Invalid format string. -#define ERR_TOO_MANY_FORMATTERS 5038 // Amount of format specifiers more than the parameters. -#define ERR_TOO_MANY_PARAMETERS 5039 // Amount of parameters more than the format specifiers. -#define ERR_WRONG_STRING_PARAMETER 5040 // Damaged parameter of string type. -#define ERR_STRINGPOS_OUTOFRANGE 5041 // Position outside the string. -#define ERR_STRING_ZEROADDED 5042 // 0 added to the string end, a useless operation. -#define ERR_STRING_UNKNOWNTYPE 5043 // Unknown data type when converting to a string. -#define ERR_WRONG_STRING_OBJECT 5044 // Damaged string object. -// Operations with Array. -#ifndef ERR_INCOMPATIBLE_ARRAYS -#define ERR_INCOMPATIBLE_ARRAYS 5050 // Copying incompatible arrays. String array can be copied only to a string array, and a numeric array - in numeric array only. -#endif -#define ERR_SMALL_ASSERIES_ARRAY 5051 // The receiving array is declared as AS_SERIES, and it is of insufficient size. -#define ERR_SMALL_ARRAY 5052 // Too small array, the starting position is outside the array. -#define ERR_ZEROSIZE_ARRAY 5053 // An array of zero length. -#define ERR_NUMBER_ARRAYS_ONLY 5054 // Must be a numeric array. -#define ERR_ONEDIM_ARRAYS_ONLY 5055 // Must be a one-dimensional array. -#define ERR_SERIES_ARRAY 5056 // Timeseries cannot be used. -#define ERR_DOUBLE_ARRAY_ONLY 5057 // Must be an array of type double. -#define ERR_FLOAT_ARRAY_ONLY 5058 // Must be an array of type float. -#define ERR_LONG_ARRAY_ONLY 5059 // Must be an array of type long. -#define ERR_INT_ARRAY_ONLY 5060 // Must be an array of type int. -#define ERR_SHORT_ARRAY_ONLY 5061 // Must be an array of type short. -#define ERR_CHAR_ARRAY_ONLY 5062 // Must be an array of type char. -// Operations with OpenCL. -#define ERR_OPENCL_NOT_SUPPORTED 5100 // OpenCL functions are not supported on this computer. -#define ERR_OPENCL_INTERNAL 5101 // Internal error occurred when running OpenCL. -#define ERR_OPENCL_INVALID_HANDLE 5102 // Invalid OpenCL handle. -#define ERR_OPENCL_CONTEXT_CREATE 5103 // Error creating the OpenCL context. -#define ERR_OPENCL_QUEUE_CREATE 5104 // Failed to create a run queue in OpenCL. -#define ERR_OPENCL_PROGRAM_CREATE 5105 // Error occurred when compiling an OpenCL program. -#define ERR_OPENCL_TOO_LONG_KERNEL_NAME 5106 // Too long kernel name (OpenCL kernel). -#define ERR_OPENCL_KERNEL_CREATE 5107 // Error creating an OpenCL kernel. -#define ERR_OPENCL_SET_KERNEL_PARAMETER 5108 // Error occurred when setting parameters for the OpenCL kernel. -#define ERR_OPENCL_EXECUTE 5109 // OpenCL program runtime error. -#define ERR_OPENCL_WRONG_BUFFER_SIZE 5110 // Invalid size of the OpenCL buffer. -#define ERR_OPENCL_WRONG_BUFFER_OFFSET 5111 // Invalid offset in the OpenCL buffer. -#define ERR_OPENCL_BUFFER_CREATE 5112 // Failed to create an OpenCL buffer. -// Operations with WebRequest. -#ifndef ERR_WEBREQUEST_INVALID_ADDRESS -#define ERR_WEBREQUEST_INVALID_ADDRESS 5200 // Invalid URL. -#endif -#ifndef ERR_WEBREQUEST_CONNECT_FAILED -#define ERR_WEBREQUEST_CONNECT_FAILED 5201 // Failed to connect to specified URL. -#endif -#ifndef ERR_WEBREQUEST_TIMEOUT -#define ERR_WEBREQUEST_TIMEOUT 5202 // Timeout exceeded. -#endif -#ifndef ERR_WEBREQUEST_REQUEST_FAILED -#define ERR_WEBREQUEST_REQUEST_FAILED 5203 // HTTP request failed. -#endif -// User-Defined Errors. -#ifndef ERR_USER_ERROR_FIRST -#define ERR_USER_ERROR_FIRST 65536 // User defined errors start with this code. -#endif - -#endif // MQL5_MQH diff --git a/Mail.mqh b/Mail.mqh index f94c30382..984008967 100644 --- a/Mail.mqh +++ b/Mail.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,14 +20,15 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "Account/AccountMt.h" #include "Convert.mqh" -#include "Order.mqh" - -// Prevents processing this includes file for the second time. -#ifndef MAIL_MQH -#define MAIL_MQH +#include "Exchange/Account/AccountMt.h" +#include "Platform/Order.h" /** * Implements Mail class. @@ -136,4 +137,3 @@ class Mail { */ bool SendMailExecuteOrder() { return SendMail(GetMailSubjectExecuteOrder(), GetMailBodyExecuteOrder()); } }; -#endif diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..d8c1fdb97 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +EMCC_CFLAGS := $(CFLAGS) --bind -s ASSERTIONS=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s EXIT_RUNTIME=0 -s EXPORTED_FUNCTIONS="[]" -s WASM=1 -s MODULARIZE=1 -s NO_EXIT_RUNTIME=1 +MAKEFILES := $(wildcard **/tests/Makefile) + +.PHONY: all + +all: $(MAKEFILES) + @ret=0; \ + for makefile in $(MAKEFILES); do \ + $(MAKE) -C $$(dirname $$makefile) CFLAGS="$(CFLAGS)" EMCC_CFLAGS="$(EMCC_CFLAGS)" || { ret=$$?; }; \ + done; \ + exit $$ret + +clean: $(MAKEFILES) + @for makefile in $(MAKEFILES); do \ + echo "Cleaning $$makefile"; \ + $(MAKE) -C $$(dirname $$makefile) clean; \ + done diff --git a/Market.mqh b/Market.mqh index e57f9f3ca..441d7c580 100644 --- a/Market.mqh +++ b/Market.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,11 +25,12 @@ #define MARKET_MQH // Includes. +#include "Exchange/SymbolInfo/SymbolInfo.h" +#include "Exchange/SymbolInfo/SymbolInfo.struct.static.h" #include "Market.struct.h" -#include "Math.h" +#include "Math/Math.h" +#include "Platform/Chart/Chart.define.h" #include "Serializer/Serializer.h" -#include "SymbolInfo.mqh" -#include "SymbolInfo.struct.static.h" #include "Task/TaskCondition.enum.h" /** @@ -270,7 +271,7 @@ class Market : public SymbolInfo { case MARKET_COND_SPREAD_GT_20: return GetSpreadInPts() > 20; default: - GetLogger().Error(StringFormat("Invalid market condition: %s!", EnumToString(_cond), __FUNCTION_LINE__)); + logger.Error(StringFormat("Invalid market condition: %s!", EnumToString(_cond), __FUNCTION_LINE__)); return false; } } diff --git a/Market.struct.h b/Market.struct.h index 93f6e2e91..870bc337e 100644 --- a/Market.struct.h +++ b/Market.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,14 +25,19 @@ * Includes Market's structs. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Forward declaration. class Serializer; // Includes. -#include "DateTime.entry.h" -#include "DateTime.struct.h" #include "Serializer/SerializerNode.enum.h" #include "Std.h" +#include "Storage/DateTime.entry.h" +#include "Storage/DateTime.struct.h" // Market info. struct MarketData { diff --git a/Math.define.h b/Math/Math.define.h similarity index 87% rename from Math.define.h rename to Math/Math.define.h index b1f2e4e50..10b0ebdc8 100644 --- a/Math.define.h +++ b/Math/Math.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -37,6 +37,13 @@ #define fmin5(_v1, _v2, _v3, _v4, _v5) fmin(fmin(fmin(fmin(_v1, _v2), _v3), _v4), _v5) #define fmin6(_v1, _v2, _v3, _v4, _v5, _v6) fmin(fmin(fmin(fmin(fmin(_v1, _v2), _v3), _v4), _v5), _v6) +// Math errors. +#define MATH_ERR_OK 0 +#define MATH_ERR_ARGUMENTS_NAN 1 +#define MATH_ERR_ARGUMENTS_INVALID 2 +#define MATH_ERR_RESULT_INFINITE 3 +#define MATH_ERR_NON_CONVERGENCE 4 + #ifdef __cplusplus #include @@ -77,11 +84,11 @@ #endif #ifndef LONG_MIN -#define LONG_MIN std::numeric_limits::min() +#define LONG_MIN std::numeric_limits::min() #endif #ifndef LONG_MAX -#define LONG_MAX std::numeric_limits::max() +#define LONG_MAX std::numeric_limits::max() #endif #ifndef ULONG_MAX diff --git a/Math.enum.h b/Math/Math.enum.h similarity index 92% rename from Math.enum.h rename to Math/Math.enum.h index 1f324d917..2bc741e8e 100644 --- a/Math.enum.h +++ b/Math/Math.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Math.extern.h b/Math/Math.extern.h similarity index 68% rename from Math.extern.h rename to Math/Math.extern.h index c04c4215a..7b4f286d7 100644 --- a/Math.extern.h +++ b/Math/Math.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,10 +20,34 @@ * */ -// Define external global functions. #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once +#include +#include +#endif + +#ifdef __MQL__ +const double NaN = (double)"nan"; +#else +const double NaN = std::nan(""); +#endif + +#ifdef __MQL__ +const double POSINF = (double)"inf"; +#else +const double POSINF = std::numeric_limits::infinity(); +#endif + +#ifdef __MQL__ +const double NEGINF = (double)"-inf"; +#else +const double NEGINF = std::numeric_limits::infinity() * -1; +#endif + +// Define external global functions. +#ifndef __MQL__ #include #include @@ -44,6 +68,18 @@ T MathPow(T base, T exponent) { return std::pow(base, exponent); } template +T MathLog(T value) { + return std::log(value); +} +template +T MathExp(T value) { + return std::exp(value); +} +template +T MathSqrt(T value) { + return std::sqrt(value); +} +template T round(T value) { return std::round(value); } @@ -77,4 +113,7 @@ T log10(T value) { } int MathRand() { return std::rand() % 32768; } // int rand() { return std::rand() % 32768; } + +bool MathIsValidNumber(double _number) { return (_number != NaN && _number != NEGINF && _number != POSINF); } + #endif diff --git a/Math/Math.h b/Math/Math.h new file mode 100644 index 000000000..04d27f20b --- /dev/null +++ b/Math/Math.h @@ -0,0 +1,566 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "../Indicator/Indicator.struct.h" +#include "../Storage/Data.struct.h" +#include "Math.define.h" +#include "Math.enum.h" +#include "Math.extern.h" +#include "Math.normal.h" +#include "Math.struct.h" + +/** + * Class to provide math related methods. + */ +class Math { + protected: + public: + Math() {} + + /* Calculation */ + + template + static X ReLU(X _value) { + return (X)fmax(0, _value); + } + + /** + * Returns value changed by the given percentage. + * + * @param double _value + * Base value to change. + * @param float _pct + * Percentage to change (1 is 100%). + * + * @return + * Returns value after the change. + */ + static double ChangeByPct(double _v, float _pct) { return _v != 0 ? _v + (fabs(_v) * _pct) : 0; } + + /** + * Calculates change between 2 values in percentage. + * + * @docs: https://stackoverflow.com/a/65511594/55075 + * + * @param double _v1 + * First value. + * @param double _v2 + * Second value. + * @param bool _hundreds + * When true, 100% is 100, otherwise 1. + * @return + * Returns percentage change. + */ + static double ChangeInPct(double _v1, double _v2, bool _hundreds = false) { + double _result = 0; + if (_v1 != 0 && _v2 != 0) { + // If values are non-zero, use the standard formula. + _result = (_v2 / _v1) - 1; + } else if (_v1 == 0 || _v2 == 0) { + // Change is zero when both values are zeros, otherwise it's 1 (100%). + _result = _v1 == 0 && _v2 == 0 ? 0 : 1; + } + _result = _v2 > _v1 ? fabs(_result) : -fabs(_result); + return _hundreds ? _result * 100 : _result; + } + + /** + * Checks condition for 2 values based on the given comparison operator. + */ + template + static bool Compare(T1 _v1, T2 _v2, ENUM_MATH_CONDITION _op = MATH_COND_EQ) { + switch (_op) { + case MATH_COND_EQ: + return _v1 == _v2; + case MATH_COND_GT: + return _v1 > _v2; + case MATH_COND_LE: + return _v1 < _v2; + default: + break; + } + return false; + } + + /** + * Gets number of digits after decimal in a floating point number. + */ + template + static short FloatDigits(V _value) { + short _cnt = 0; + while ((int)_value != _value) { + _value *= 10; + _cnt++; + } + return _cnt; + } + + /** + * Returns a non-zero value. + * + * @return + * Returns a non-zero value. + */ + static double NonZero(double _v) { return _v == 0 ? DBL_MIN : _v; } + + static double RandomNonZero(void) { + double rnd = 0; + + while (rnd == 0.0 || rnd == 1.0) { + rnd = MathRand() / 32767.0; + } + + return rnd; + } + + static double TailLogProbability(const double probability, const bool tail, const bool log_mode) { + if (tail == true) { + if (log_mode) + return MathExp(probability); + else + return (probability); + } else { + if (log_mode) + return (1.0 - MathExp(probability)); + else + return (1.0 - probability); + } + } + + static double QuantileNormal(const double probability, const double mu, const double sigma, const bool tail, + const bool log_mode, int &error_code) { + // Check NaN. + if (!MathIsValidNumber(probability) || !MathIsValidNumber(mu) || !MathIsValidNumber(sigma)) { + error_code = MATH_ERR_ARGUMENTS_NAN; + return NaN; + } + //--- check sigma + if (sigma <= 0) { + error_code = MATH_ERR_ARGUMENTS_INVALID; + return NaN; + } + + // Calculate real probability. + double prob = TailLogProbability(probability, tail, log_mode); + + // Check probability range. + if (prob < 0.0 || prob > 1.0) { + error_code = MATH_ERR_ARGUMENTS_INVALID; + return NaN; + } + + // f(0)=-infinity + if (prob == 0.0) { + error_code = MATH_ERR_RESULT_INFINITE; + return NEGINF; + } + // f(1)=+infinity + if (prob == 1.0) { + error_code = MATH_ERR_RESULT_INFINITE; + return POSINF; + } + + error_code = MATH_ERR_OK; + + double q = prob - 0.5; + double r = 0; + double ppnd16 = 0.0; + + if (MathAbs(q) <= 0.425) { + r = 0.180625 - q * q; + ppnd16 = q * + (((((((normal_q_a7 * r + normal_q_a6) * r + normal_q_a5) * r + normal_q_a4) * r + normal_q_a3) * r + + normal_q_a2) * + r + + normal_q_a1) * + r + + normal_q_a0) / + (((((((normal_q_b7 * r + normal_q_b6) * r + normal_q_b5) * r + normal_q_b4) * r + normal_q_b3) * r + + normal_q_b2) * + r + + normal_q_b1) * + r + + 1.0); + + error_code = MATH_ERR_OK; + + return mu + sigma * ppnd16; + } else { + if (q < 0.0) + r = prob; + else + r = 1.0 - prob; + + r = MathSqrt(-MathLog(r)); + + if (r <= 5.0) { + r = r - 1.6; + ppnd16 = (((((((normal_q_c7 * r + normal_q_c6) * r + normal_q_c5) * r + normal_q_c4) * r + normal_q_c3) * r + + normal_q_c2) * + r + + normal_q_c1) * + r + + normal_q_c0) / + (((((((normal_q_d7 * r + normal_q_d6) * r + normal_q_d5) * r + normal_q_d4) * r + normal_q_d3) * r + + normal_q_d2) * + r + + normal_q_d1) * + r + + 1.0); + } else { + r = r - 5.0; + ppnd16 = (((((((normal_q_e7 * r + normal_q_e6) * r + normal_q_e5) * r + normal_q_e4) * r + normal_q_e3) * r + + normal_q_e2) * + r + + normal_q_e1) * + r + + normal_q_e0) / + (((((((normal_q_f7 * r + normal_q_f6) * r + normal_q_f5) * r + normal_q_f4) * r + normal_q_f3) * r + + normal_q_f2) * + r + + normal_q_f1) * + r + + 1.0); + } + + if (q < 0.0) ppnd16 = -ppnd16; + } + // Return rescaled/shifted value. + return mu + sigma * ppnd16; + } + + static bool QuantileNormal(CONST_ARRAY_REF(double, probability), const double mu, const double sigma, const bool tail, + const bool log_mode, ARRAY_REF(double, result)) { + //--- check NaN + if (!MathIsValidNumber(mu) || !MathIsValidNumber(sigma)) return false; + //--- check sigma + if (sigma < 0) return false; + + int data_count = ArraySize(probability); + if (data_count == 0) return false; + + int error_code = 0, i; + ArrayResize(result, data_count); + + //--- case sigma==0 + if (sigma == 0.0) { + for (i = 0; i < data_count; i++) result[i] = mu; + return true; + } + + for (i = 0; i < data_count; i++) { + //--- calculate real probability + double prob = TailLogProbability(probability[i], tail, log_mode); + //--- check probability range + if (prob < 0.0 || prob > 1.0) return false; + + //--- f(0)=-infinity, f(1)=+infinity + if (prob == 0.0 || prob == 1.0) { + if (prob == 0.0) + result[i] = NEGINF; + else + result[i] = POSINF; + } else { + double q = prob - 0.5; + double r = 0; + double ppnd16 = 0.0; + //--- + if (MathAbs(q) <= 0.425) { + r = 0.180625 - q * q; + ppnd16 = q * + (((((((normal_q_a7 * r + normal_q_a6) * r + normal_q_a5) * r + normal_q_a4) * r + normal_q_a3) * r + + normal_q_a2) * + r + + normal_q_a1) * + r + + normal_q_a0) / + (((((((normal_q_b7 * r + normal_q_b6) * r + normal_q_b5) * r + normal_q_b4) * r + normal_q_b3) * r + + normal_q_b2) * + r + + normal_q_b1) * + r + + 1.0); + //--- set rescaled/shifted value + result[i] = mu + sigma * ppnd16; + } else { + if (q < 0.0) + r = prob; + else + r = 1.0 - prob; + //--- + r = MathSqrt(-MathLog(r)); + //--- + if (r <= 5.0) { + r = r - 1.6; + ppnd16 = + (((((((normal_q_c7 * r + normal_q_c6) * r + normal_q_c5) * r + normal_q_c4) * r + normal_q_c3) * r + + normal_q_c2) * + r + + normal_q_c1) * + r + + normal_q_c0) / + (((((((normal_q_d7 * r + normal_q_d6) * r + normal_q_d5) * r + normal_q_d4) * r + normal_q_d3) * r + + normal_q_d2) * + r + + normal_q_d1) * + r + + 1.0); + } else { + r = r - 5.0; + ppnd16 = + (((((((normal_q_e7 * r + normal_q_e6) * r + normal_q_e5) * r + normal_q_e4) * r + normal_q_e3) * r + + normal_q_e2) * + r + + normal_q_e1) * + r + + normal_q_e0) / + (((((((normal_q_f7 * r + normal_q_f6) * r + normal_q_f5) * r + normal_q_f4) * r + normal_q_f3) * r + + normal_q_f2) * + r + + normal_q_f1) * + r + + 1.0); + } + //--- + if (q < 0.0) ppnd16 = -ppnd16; + } + //--- set rescaled/shifted value + result[i] = mu + sigma * ppnd16; + } + } + return true; + } + + static bool QuantileNormal(CONST_ARRAY_REF(double, probability), const double mu, const double sigma, + ARRAY_REF(double, result)) { + return QuantileNormal(probability, mu, sigma, true, false, result); + } + + static double RandomNormal(const double mu, const double sigma, int &error_code) { + if (!MathIsValidNumber(mu) || !MathIsValidNumber(sigma)) { + error_code = MATH_ERR_ARGUMENTS_NAN; + return NaN; + } + + if (sigma < 0) { + error_code = MATH_ERR_ARGUMENTS_INVALID; + return NaN; + } + + error_code = MATH_ERR_OK; + + if (sigma == 0.0) return mu; + + double rnd = RandomNonZero(); + + return QuantileNormal(rnd, mu, sigma, true, false, error_code); + } + + static bool RandomNormal(const double mu, const double sigma, const int data_count, ARRAY_REF(double, result)) { + int i; + + // Check NaN. + if (!MathIsValidNumber(mu) || !MathIsValidNumber(sigma)) { + return false; + } + + // Check sigma. + if (sigma < 0) { + return false; + } + + // Prepare output array and calculate random values. + ArrayResize(result, data_count); + + if (sigma == 0.0) { + for (i = 0; i < data_count; i++) result[i] = mu; + return true; + } + + int err_code = 0; + + for (i = 0; i < data_count; i++) { + result[i] = RandomNonZero(); + } + + // Return normal random array using quantile. + return QuantileNormal(result, mu, sigma, result); + } + + /* Conditions */ + + /** + * Checks for math condition. + * + * @param ENUM_MATH_CONDITION _cond + * Math condition. + * @param MqlParam[] _args + * Condition arguments. + * @return + * Returns true when the condition is met. + */ + /* + bool CheckCondition(ENUM_MATH_CONDITION _cond, DataParamEntry &_args[]) { + switch (_cond) { + case MATH_COND_EQ: + // @todo + return false; + case MATH_COND_GT: + // @todo + return false; + case MATH_COND_LE: + // @todo + return false; + default: + // logger.Error(StringFormat("Invalid math condition: %s!", EnumToString(_cond), __FUNCTION_LINE__)); + return false; + } + } + bool CheckCondition(ENUM_MATH_CONDITION _cond) { + DataParamEntry _args[] = {}; + return Math::CheckCondition(_cond, _args); + } + */ + + template + static T Add(T a, T b) { + return a + b; + } + template + static T Sub(T a, T b) { + return a - b; + } + template + static T Mul(T a, T b) { + return a * b; + } + template + static T Div(T a, T b) { + return a / b; + } + template + static T Sin(T a) { + return sin(a); + } + template + static T Cos(T a) { + return cos(a); + } + template + static T Tang(T a) { + return tan(a); + } + template + static T Min(T a, T b) { + return MathMin(a, b); + } + template + static T Min(T a, T b, T c) { + return MathMin(MathMin(a, b), c); + } + template + static T Min(T a, T b, T c, T d) { + return MathMin(MathMin(MathMin(a, b), c), d); + } + template + static T Max(T a, T b) { + return MathMax(a, b); + } + template + static T Max(T a, T b, T c) { + return MathMax(MathMax(a, b), c); + } + template + static T Max(T a, T b, T c, T d) { + return MathMax(MathMax(MathMax(a, b), c), d); + } + template + static T Avg(T a, T b) { + return (a + b) / 2; + } + template + static T Avg(T a, T b, T c) { + return (a + b + c) / 3; + } + template + static T Avg(T a, T b, T c, T d) { + return (a + b + c + d) / 4; + } + template + static T Abs(T a) { + return MathAbs(a); + } + + template + static T Op(ENUM_MATH_OP _op, T _val_1, T _val_2 = 0) { + switch (_op) { + case MATH_OP_ADD: + return Add(_val_1, _val_2); + case MATH_OP_SUB: + return Sub(_val_1, _val_2); + case MATH_OP_MUL: + return Mul(_val_1, _val_2); + case MATH_OP_DIV: + return Div(_val_1, _val_2); + case MATH_OP_SIN: + return Sin(_val_1); + case MATH_OP_COS: + return Cos(_val_2); + case MATH_OP_TAN: + return Tang(_val_2); + case MATH_OP_MIN: + return Min(_val_1, _val_2); + case MATH_OP_MAX: + return Max(_val_1, _val_2); + case MATH_OP_AVG: + return Avg(_val_1, _val_2); + case MATH_OP_RELU: + return ReLU(_val_1); + case MATH_OP_ABS: + return Abs(_val_1); + case MATH_OP_ABS_DIFF: + return Abs(_val_1 - _val_2); + default: + return EMPTY_VALUE; + } + } +}; + +#ifdef __MQL__ + +/** + * Specialization of MQL's Round() to support int64 input. + */ +int64 MathRound(int64 _value) { return _value; } + +/** + * Specialization of MQL's round() to support int64 input. + */ +int64 round(int64 _value) { return MathRound(_value); } + +#endif diff --git a/Math/Math.normal.h b/Math/Math.normal.h new file mode 100644 index 000000000..6ceabd2c8 --- /dev/null +++ b/Math/Math.normal.h @@ -0,0 +1,92 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +const static double normal_cdf_a[5] = {2.2352520354606839287E00, 1.6102823106855587881E02, 1.0676894854603709582E03, + 1.8154981253343561249E04, 6.5682337918207449113E-2}; +const static double normal_cdf_b[4] = {4.7202581904688241870E01, 9.7609855173777669322E02, 1.0260932208618978205E04, + 4.5507789335026729956E04}; +//--- coefficients for approximation in second interval +const static double normal_cdf_c[9] = {3.9894151208813466764E-1, 8.8831497943883759412E00, 9.3506656132177855979E01, + 5.9727027639480026226E02, 2.4945375852903726711E03, 6.8481904505362823326E03, + 1.1602651437647350124E04, 9.8427148383839780218E03, 1.0765576773720192317E-8}; +const static double normal_cdf_d[8] = {2.2266688044328115691E01, 2.3538790178262499861E02, 1.5193775994075548050E03, + 6.4855582982667607550E03, 1.8615571640885098091E04, 3.4900952721145977266E04, + 3.8912003286093271411E04, 1.9685429676859990727E04}; +//--- coefficients for approximation in third interval +const static double normal_cdf_p[6] = {2.1589853405795699E-1, 1.274011611602473639E-1, 2.2235277870649807E-2, + 1.421619193227893466E-3, 2.9112874951168792E-5, 2.307344176494017303E-2}; +const static double normal_cdf_q[5] = {1.28426009614491121E00, 4.68238212480865118E-1, 6.59881378689285515E-2, + 3.78239633202758244E-3, 7.29751555083966205E-5}; + +//--- coefficients for p close to 0.5 +const double normal_q_a0 = 3.3871328727963666080; +const double normal_q_a1 = 1.3314166789178437745E+2; +const double normal_q_a2 = 1.9715909503065514427E+3; +const double normal_q_a3 = 1.3731693765509461125E+4; +const double normal_q_a4 = 4.5921953931549871457E+4; +const double normal_q_a5 = 6.7265770927008700853E+4; +const double normal_q_a6 = 3.3430575583588128105E+4; +const double normal_q_a7 = 2.5090809287301226727E+3; +const double normal_q_b1 = 4.2313330701600911252E+1; +const double normal_q_b2 = 6.8718700749205790830E+2; +const double normal_q_b3 = 5.3941960214247511077E+3; +const double normal_q_b4 = 2.1213794301586595867E+4; +const double normal_q_b5 = 3.9307895800092710610E+4; +const double normal_q_b6 = 2.8729085735721942674E+4; +const double normal_q_b7 = 5.2264952788528545610E+3; +//--- coefficients for p not close to 0, 0.5 or 1 +const double normal_q_c0 = 1.42343711074968357734; +const double normal_q_c1 = 4.63033784615654529590; +const double normal_q_c2 = 5.76949722146069140550; +const double normal_q_c3 = 3.64784832476320460504; +const double normal_q_c4 = 1.27045825245236838258; +const double normal_q_c5 = 2.41780725177450611770E-1; +const double normal_q_c6 = 2.27238449892691845833E-2; +const double normal_q_c7 = 7.74545014278341407640E-4; +const double normal_q_d1 = 2.05319162663775882187; +const double normal_q_d2 = 1.67638483018380384940; +const double normal_q_d3 = 6.89767334985100004550E-1; +const double normal_q_d4 = 1.48103976427480074590E-1; +const double normal_q_d5 = 1.51986665636164571966E-2; +const double normal_q_d6 = 5.47593808499534494600E-4; +const double normal_q_d7 = 1.05075007164441684324E-9; +//--- coefficients for p near 0 or 1. +const double normal_q_e0 = 6.65790464350110377720E0; +const double normal_q_e1 = 5.46378491116411436990E0; +const double normal_q_e2 = 1.78482653991729133580E0; +const double normal_q_e3 = 2.96560571828504891230E-1; +const double normal_q_e4 = 2.65321895265761230930E-2; +const double normal_q_e5 = 1.24266094738807843860E-3; +const double normal_q_e6 = 2.71155556874348757815E-5; +const double normal_q_e7 = 2.01033439929228813265E-7; +const double normal_q_f1 = 5.99832206555887937690E-1; +const double normal_q_f2 = 1.36929880922735805310E-1; +const double normal_q_f3 = 1.48753612908506148525E-2; +const double normal_q_f4 = 7.86869131145613259100E-4; +const double normal_q_f5 = 1.84631831751005468180E-5; +const double normal_q_f6 = 1.42151175831644588870E-7; +const double normal_q_f7 = 2.04426310338993978564E-15; diff --git a/Math.struct.h b/Math/Math.struct.h similarity index 87% rename from Math.struct.h rename to Math/Math.struct.h index 8b2b0009c..c4894e5f2 100644 --- a/Math.struct.h +++ b/Math/Math.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -29,7 +29,7 @@ #pragma once #endif -#include "Data.struct.h" +#include "../Storage/Data.struct.h" // Prevents processing this includes file for the second time. #ifndef MATH_STRUCT_H diff --git a/Matrix.mqh b/Math/Matrix.h similarity index 99% rename from Matrix.mqh rename to Math/Matrix.h index 63d8ad054..898bddc94 100644 --- a/Matrix.mqh +++ b/Math/Matrix.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,6 +24,12 @@ #ifndef MATRIX_MQH #define MATRIX_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + + #ifdef __MQL5__ #define MATRIX_USE_OPENCL #endif @@ -34,6 +40,7 @@ #endif #endif +// Includes. #include "Math.h" #ifdef MATRIX_USE_OPENCL @@ -1776,24 +1783,19 @@ class Matrix { */ void FillRandomUniform(X _min, X _max, int _seed = -1) { FillRandom(_min, _max, _seed); } -#ifdef USE_MQL_MATH_STAT /** * Initializer that generates tensors with a normal distribution. */ void FillRandomNormal(X _mean, X _stddev, int _seed = -1) { -#ifdef __MQL5__ if (_seed != -1) { Print("Matrix::FillRandomNormal(): _seed parameter is not yet implemented! Please use -1 as _seed."); } - double _values[]; - MathRandomNormal(_mean, _stddev, GetSize(), _values); + ARRAY(double, _values); + int _size = GetSize(); + Math::RandomNormal(_mean, _stddev, _size, _values); FillFromArray(_values); -#else - Print("Matrix::FillRandomNormal() is implemented only in MQL5!"); -#endif } -#endif /** * Fills matrix with the flattened data. Also fill flattened data cache. diff --git a/Matrix.matmul.cl b/Math/Matrix.matmul.cl similarity index 100% rename from Matrix.matmul.cl rename to Math/Matrix.matmul.cl diff --git a/Matrix.matmul.naive.cl b/Math/Matrix.matmul.naive.cl similarity index 100% rename from Matrix.matmul.naive.cl rename to Math/Matrix.matmul.naive.cl diff --git a/Matrix.matmul.test.cl b/Math/Matrix.matmul.test.cl similarity index 100% rename from Matrix.matmul.test.cl rename to Math/Matrix.matmul.test.cl diff --git a/MiniMatrix.h b/Math/MatrixMini.h similarity index 78% rename from MiniMatrix.h rename to Math/MatrixMini.h index 50adb9653..a2e1bd59f 100644 --- a/MiniMatrix.h +++ b/Math/MatrixMini.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,19 +20,23 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef MINIMATRIX_MQH -#define MINIMATRIX_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "../Platform/Platform.extern.h" template -class MiniMatrix2d { +class MatrixMini2d { public: ARRAY(T, data); int size_x; int size_y; - MiniMatrix2d() {} - MiniMatrix2d(int _size_x, int _size_y) : size_x(_size_x), size_y(_size_y) { Resize(_size_x, _size_y); } + MatrixMini2d() {} + MatrixMini2d(int _size_x, int _size_y) : size_x(_size_x), size_y(_size_y) { Resize(_size_x, _size_y); } void Resize(int _size_x, int _size_y) { ArrayResize(data, _size_x * _size_y); @@ -56,5 +60,3 @@ class MiniMatrix2d { int SizeY() { return size_y; } }; - -#endif diff --git a/OpenCL.h b/Math/OpenCL.h similarity index 99% rename from OpenCL.h rename to Math/OpenCL.h index b6aa15303..8626fba40 100644 --- a/OpenCL.h +++ b/Math/OpenCL.h @@ -2,7 +2,7 @@ #pragma once #endif -#include "DictStruct.mqh" +#include "../Storage/Dict/DictStruct.h" // Defines. #define OPENCL_PROGRAM_MAX_ARGS 8 diff --git a/Math/tests/Makefile b/Math/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Math/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Math/tests/Math.test.cpp b/Math/tests/Math.test.cpp new file mode 100644 index 000000000..863e00e42 --- /dev/null +++ b/Math/tests/Math.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Math class. + */ + +// Includes. +#include "../Math.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/MathTest.mq4 b/Math/tests/Math.test.mq4 similarity index 85% rename from tests/MathTest.mq4 rename to Math/tests/Math.test.mq4 index a24c55a36..53d935173 100644 --- a/tests/MathTest.mq4 +++ b/Math/tests/Math.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "MathTest.mq5" +#include "Math.test.mq5" diff --git a/tests/MathTest.mq5 b/Math/tests/Math.test.mq5 similarity index 94% rename from tests/MathTest.mq5 rename to Math/tests/Math.test.mq5 index 7f985b4ee..df76add49 100644 --- a/tests/MathTest.mq5 +++ b/Math/tests/Math.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,7 +26,7 @@ // Includes. #include "../Math.h" -#include "../Test.mqh" +#include "../../Test.mqh" /** * Implements initialization function. diff --git a/Math/tests/Matrix.test.cpp b/Math/tests/Matrix.test.cpp new file mode 100644 index 000000000..929cef6ba --- /dev/null +++ b/Math/tests/Matrix.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Matrix class. + */ + +// Includes. +#include "../Matrix.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/MatrixTest.mq4 b/Math/tests/Matrix.test.mq4 similarity index 85% rename from tests/MatrixTest.mq4 rename to Math/tests/Matrix.test.mq4 index 93394e04f..b99931119 100644 --- a/tests/MatrixTest.mq4 +++ b/Math/tests/Matrix.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "MatrixTest.mq5" +#include "Matrix.test.mq5" diff --git a/tests/MatrixTest.mq5 b/Math/tests/Matrix.test.mq5 similarity index 99% rename from tests/MatrixTest.mq5 rename to Math/tests/Matrix.test.mq5 index 72af18d8c..161a813a4 100644 --- a/tests/MatrixTest.mq5 +++ b/Math/tests/Matrix.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,8 +28,8 @@ #define USE_MQL_MATH_STAT // Includes. -#include "../Matrix.mqh" -#include "../Test.mqh" +#include "../Matrix.h" +#include "../../Test.mqh" /** * Implements Init event handler. diff --git a/Math/tests/MatrixMini.test.cpp b/Math/tests/MatrixMini.test.cpp new file mode 100644 index 000000000..d6370b8bf --- /dev/null +++ b/Math/tests/MatrixMini.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of MatrixMini class. + */ + +// Includes. +#include "../MatrixMini.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Trade/tests/TradeSignalTest.mq4 b/Math/tests/MatrixMini.test.mq4 similarity index 86% rename from Trade/tests/TradeSignalTest.mq4 rename to Math/tests/MatrixMini.test.mq4 index 84a7ee94e..7287c57fc 100644 --- a/Trade/tests/TradeSignalTest.mq4 +++ b/Math/tests/MatrixMini.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,20 +9,20 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * @file - * Test functionality of TradeSignal class. + * Test functionality of MatrixMini class. */ // Includes. -#include "TradeSignalTest.mq5" +#include "MatrixMini.test.mq5" diff --git a/Math/tests/MatrixMini.test.mq5 b/Math/tests/MatrixMini.test.mq5 new file mode 100644 index 000000000..4ffe5f337 --- /dev/null +++ b/Math/tests/MatrixMini.test.mq5 @@ -0,0 +1,41 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of MatrixMini class. + */ + +// Includes. +#include "../MatrixMini.h" +#include "../../Test.mqh" + +/** + * Implements Init event handler. + */ +int OnInit() { + + // @todo: Write some tests. + + // MatrixMini _matrix(2, 3, 20); + + return INIT_SUCCEEDED; +} diff --git a/Msg.mqh b/Msg.mqh deleted file mode 100644 index fb11fcb2c..000000000 --- a/Msg.mqh +++ /dev/null @@ -1,97 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/* - * Class to provide methods to deal with the messages. - */ -class Msg { -public: - - string last_msg; - - /* - * Display a text message. - * - * @param string text Text of the message. - * @param string type Type of the message. - * @param string subtype Subtype of the message. - * @param int no Number of the message. - * @param bool print Condition whether to print as a standard message. - * @param bool comment Condition whether to print as a comment. - * @param bool alert Condition whether to print as an alert. - * @param bool dups When true, ignore the duplicates. - * - * @return - * Return text if the message is shown, otherwise NULL. - * - */ - static string ShowText( - string text, - string type = "", - string subtype = "", - int no = 0, - bool print = true, - bool comment = false, - bool alert = false, - bool dups = true, - string sep = ": " - ) { - - static string _last_msg; - bool shown = false; - - string msg = ""; - - if (type != "") { - msg += type; - if (no > 0) { - msg += " (" + IntegerToString(no) + ")"; - } - msg += sep; - } - if (subtype != "") { - msg += subtype + sep; - } - msg += text; - - if (msg != _last_msg || !dups) { - if (print) { - Print(msg); - shown = true; - } - if (comment) { - Comment(msg); - shown = true; - } - if (alert) { - Alert(msg); - shown = true; - } - if (shown) { - _last_msg = msg; - return msg; - } - } - return NULL; - } - -}; diff --git a/Pattern.enum.h b/Pattern.enum.h index 0a35cb5e1..6484e5d13 100644 --- a/Pattern.enum.h +++ b/Pattern.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Pattern.mqh b/Pattern.mqh index 60935d6b8..d191c2c99 100644 --- a/Pattern.mqh +++ b/Pattern.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,6 +24,11 @@ * Provides functionality for detecting candle patterns. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "Pattern.struct.h" diff --git a/Pattern.struct.h b/Pattern.struct.h index fae8dd84e..f8aebe7d8 100644 --- a/Pattern.struct.h +++ b/Pattern.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -32,12 +32,12 @@ // Includes. #include "Bar.struct.h" -#include "Math.define.h" +#include "Math/Math.define.h" #include "Pattern.enum.h" // Defines structure for bitwise pattern values. struct PatternBitwise { - unsigned int v[]; + ARRAY(unsigned int, v); // Operator methods. unsigned int operator[](const int _index) const { return v[_index]; } // Adds new value to the end of the array. @@ -52,7 +52,7 @@ struct PatternBitwise { * @return * Returns array of counts. */ - void GetBitCount(short& _depths[]) { + void GetBitCount(ARRAY_REF(short, _depths)) { int _size = sizeof(int) * 8; for (int _bi = 0; _bi < _size; _bi++) { _depths[_bi] = GetBitCount(_bi); @@ -125,7 +125,7 @@ struct PatternBitwise { * @return * Returns array of depths. */ - void GetBitDepth(short& _depths[]) { + void GetBitDepth(ARRAY_REF(short, _depths)) { int _size = sizeof(int) * 8; for (int _bi = 0; _bi < _size; _bi++) { _depths[_bi] = GetBitDepth(_bi); @@ -163,7 +163,7 @@ struct PatternCandle { int _size = sizeof(int) * 8; for (int i = 0; i < _size; i++) { int _value = CheckPattern(1 << i) ? 1 : 0; - _s.Pass(THIS_REF, (string)(i + 1), _value, SERIALIZER_FIELD_FLAG_DYNAMIC); + _s.Pass(THIS_REF, IntegerToString(i + 1), _value, SERIALIZER_FIELD_FLAG_DYNAMIC); } return SerializerNodeObject; } @@ -296,14 +296,23 @@ struct PatternCandle1 : PatternCandle { // Struct for calculating and storing 2-candlestick patterns. struct PatternCandle2 : PatternCandle { PatternCandle2(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle2(const BarOHLC& _c[]) : PatternCandle(PATTERN_2CANDLE_NONE) { + PatternCandle2(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_2CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_2CANDLE _enum = (ENUM_PATTERN_2CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle2(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_2CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_2CANDLE _enum = (ENUM_PATTERN_2CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#endif // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_2CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_2CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { switch (_enum) { case PATTERN_2CANDLE_BEARS: // Two bear candles. @@ -405,14 +414,23 @@ struct PatternCandle2 : PatternCandle { // Struct for calculating and storing 3-candlestick patterns. struct PatternCandle3 : PatternCandle { PatternCandle3(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle3(const BarOHLC& _c[]) : PatternCandle(PATTERN_3CANDLE_NONE) { + PatternCandle3(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_3CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_3CANDLE _enum = (ENUM_PATTERN_3CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle3(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_3CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_3CANDLE _enum = (ENUM_PATTERN_3CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#endif // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_3CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_3CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { switch (_enum) { case PATTERN_3CANDLE_BEARS: // Three bear candles. @@ -521,14 +539,23 @@ struct PatternCandle3 : PatternCandle { // Struct for calculating and storing 4-candlestick patterns. struct PatternCandle4 : PatternCandle { PatternCandle4(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle4(const BarOHLC& _c[]) : PatternCandle(PATTERN_4CANDLE_NONE) { + PatternCandle4(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_4CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_4CANDLE _enum = (ENUM_PATTERN_4CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle4(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_4CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_4CANDLE _enum = (ENUM_PATTERN_4CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#endif // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_4CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_4CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { PatternCandle3 _c3(_c); switch (_enum) { case PATTERN_4CANDLE_BEARS: @@ -539,7 +566,7 @@ struct PatternCandle4 : PatternCandle { return /* Bear 0 cont. */ _c[0].open > _c[0].close && /* Bear 0 is low */ _c[0].low < _c[3].low && - /* Bear 0 body is large */ _c3.CheckPattern(PATTERN_3CANDLE_BODY0_GT_SUM) && + /* Bear 0 body is large */ _c3.CheckPattern(PATTERN_3CANDLE_BODY0_GT_SUM, _c) && /* Bull 1 */ _c[1].open < _c[1].close && /* Bull 2 */ _c[2].open < _c[2].close && /* Bear 3 */ _c[3].open > _c[3].close && @@ -575,7 +602,7 @@ struct PatternCandle4 : PatternCandle { return /* Bull 0 cont. */ _c[0].open < _c[0].close && /* Bull 0 is high */ _c[0].high > _c[3].high && - /* Bull 0 body is large */ _c3.CheckPattern(PATTERN_3CANDLE_BODY0_GT_SUM) && + /* Bull 0 body is large */ _c3.CheckPattern(PATTERN_3CANDLE_BODY0_GT_SUM, _c) && /* Bear 1 */ _c[1].open > _c[1].close && /* Bear 2 */ _c[2].open > _c[2].close && /* Bull 3 */ _c[3].open < _c[3].close && @@ -687,14 +714,24 @@ struct PatternCandle4 : PatternCandle { // Struct for calculating and storing 4-candlestick patterns. struct PatternCandle5 : PatternCandle { PatternCandle5(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle5(const BarOHLC& _c[]) : PatternCandle(PATTERN_5CANDLE_NONE) { + PatternCandle5(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_5CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_5CANDLE _enum = (ENUM_PATTERN_5CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle5(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_5CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_5CANDLE _enum = (ENUM_PATTERN_5CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#endif + // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_5CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_5CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { switch (_enum) { case PATTERN_5CANDLE_BODY0_DIFF_PEAK: // Diff of the last two bodies is at a peak. @@ -838,14 +875,24 @@ struct PatternCandle5 : PatternCandle { // Struct for calculating and storing 4-candlestick patterns. struct PatternCandle6 : PatternCandle { PatternCandle6(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle6(const BarOHLC& _c[]) : PatternCandle(PATTERN_6CANDLE_NONE) { + PatternCandle6(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_6CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_6CANDLE _enum = (ENUM_PATTERN_6CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle6(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_6CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_6CANDLE _enum = (ENUM_PATTERN_6CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#endif + // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_6CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_6CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { switch (_enum) { case PATTERN_6CANDLE_NONE: return false; @@ -857,14 +904,24 @@ struct PatternCandle6 : PatternCandle { // Struct for calculating and storing 4-candlestick patterns. struct PatternCandle7 : PatternCandle { PatternCandle7(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle7(const BarOHLC& _c[]) : PatternCandle(PATTERN_7CANDLE_NONE) { + PatternCandle7(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_7CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_7CANDLE _enum = (ENUM_PATTERN_7CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle7(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_7CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_7CANDLE _enum = (ENUM_PATTERN_7CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#endif + // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_7CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_7CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { switch (_enum) { case PATTERN_7CANDLE_NONE: return false; @@ -876,14 +933,24 @@ struct PatternCandle7 : PatternCandle { // Struct for calculating and storing 4-candlestick patterns. struct PatternCandle8 : PatternCandle { PatternCandle8(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle8(const BarOHLC& _c[]) : PatternCandle(PATTERN_8CANDLE_NONE) { + PatternCandle8(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_8CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_8CANDLE _enum = (ENUM_PATTERN_8CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle8(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_8CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_8CANDLE _enum = (ENUM_PATTERN_8CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#endif + // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_8CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_8CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { switch (_enum) { case PATTERN_8CANDLE_NONE: return false; @@ -895,14 +962,24 @@ struct PatternCandle8 : PatternCandle { // Struct for calculating and storing 4-candlestick patterns. struct PatternCandle9 : PatternCandle { PatternCandle9(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle9(const BarOHLC& _c[]) : PatternCandle(PATTERN_9CANDLE_NONE) { + PatternCandle9(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_9CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_9CANDLE _enum = (ENUM_PATTERN_9CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle9(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_9CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_9CANDLE _enum = (ENUM_PATTERN_9CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#endif + // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_9CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_9CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { switch (_enum) { case PATTERN_9CANDLE_NONE: return false; @@ -914,14 +991,24 @@ struct PatternCandle9 : PatternCandle { // Struct for calculating and storing 4-candlestick patterns. struct PatternCandle10 : PatternCandle { PatternCandle10(unsigned int _pattern = 0) : PatternCandle(_pattern) {} - PatternCandle10(const BarOHLC& _c[]) : PatternCandle(PATTERN_10CANDLE_NONE) { + PatternCandle10(CONST_ARRAY_REF(BarOHLC, _c)) : PatternCandle(PATTERN_10CANDLE_NONE) { for (int i = 0; i < sizeof(int) * 8; i++) { ENUM_PATTERN_10CANDLE _enum = (ENUM_PATTERN_10CANDLE)(1 << i); SetPattern(_enum, CheckPattern(_enum, _c)); } } +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternCandle10(CONST_FIXED_ARRAY_REF(BarOHLC, _c, 8)) : PatternCandle(PATTERN_10CANDLE_NONE) { + for (int i = 0; i < sizeof(int) * 8; i++) { + ENUM_PATTERN_10CANDLE _enum = (ENUM_PATTERN_10CANDLE)(1 << i); + SetPattern(_enum, CheckPattern(_enum, _c)); + } + } +#endif + // Calculation methods. - static bool CheckPattern(ENUM_PATTERN_10CANDLE _enum, const BarOHLC& _c[]) { + static bool CheckPattern(ENUM_PATTERN_10CANDLE _enum, CONST_ARRAY_REF(BarOHLC, _c)) { switch (_enum) { case PATTERN_10CANDLE_NONE: return false; @@ -954,7 +1041,20 @@ struct PatternEntry { pattern8(0), pattern9(0), pattern10(0) {} - PatternEntry(BarOHLC& _c[]) + PatternEntry(ARRAY_REF(BarOHLC, _c)) + : pattern1(_c[0]), + pattern2(_c), + pattern3(_c), + pattern4(_c), + pattern5(_c), + pattern6(_c), + pattern7(_c), + pattern8(_c), + pattern9(_c), + pattern10(_c) {} +#ifndef __MQL__ + // In MQL we use non-fixed-array constructor. + PatternEntry(FIXED_ARRAY_REF(BarOHLC, _c, 8)) : pattern1(_c[0]), pattern2(_c), pattern3(_c), @@ -965,6 +1065,8 @@ struct PatternEntry { pattern8(_c), pattern9(_c), pattern10(_c) {} +#endif + // Operator methods. unsigned int operator[](const int _index) const { switch (_index) { diff --git a/Chart.define.h b/Platform/Chart/Chart.define.h similarity index 92% rename from Chart.define.h rename to Platform/Chart/Chart.define.h index 3d7ae8d32..653898359 100644 --- a/Chart.define.h +++ b/Platform/Chart/Chart.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Terminal's defines. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + /* Defines */ // Define type of timeframe periods using bitwise values. diff --git a/Chart.enum.h b/Platform/Chart/Chart.enum.h similarity index 95% rename from Chart.enum.h rename to Platform/Chart/Chart.enum.h index 3e6af773f..e3f1d3bc8 100644 --- a/Chart.enum.h +++ b/Platform/Chart/Chart.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -55,8 +55,8 @@ enum ENUM_APPLIED_PRICE { enum ENUM_CHART_PARAM { CHART_PARAM_NONE = 0, // None CHART_PARAM_ID, // Chart ID - // CHART_PARAM_SYMBOL, // Symbol - // CHART_PARAM_TF, // Timeframe + CHART_PARAM_SYMBOL, // Symbol + CHART_PARAM_TF, // Timeframe CHART_PARAM_TFI, // Timeframe index FINAL_ENUM_CHART_PARAM }; diff --git a/Chart.mqh b/Platform/Chart/Chart.h similarity index 82% rename from Chart.mqh rename to Platform/Chart/Chart.h index f8080c2a1..d6eef3209 100644 --- a/Chart.mqh +++ b/Platform/Chart/Chart.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -29,19 +29,20 @@ * - https://www.mql5.com/en/docs/series */ -// Prevents processing this includes file for the second time. -#ifndef CHART_MQH -#define CHART_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. +#include "../../Convert.mqh" +#include "../../Market.mqh" +#include "../../Serializer/Serializer.h" +#include "../../Task/TaskCondition.enum.h" #include "Chart.define.h" #include "Chart.enum.h" #include "Chart.struct.h" #include "Chart.struct.serialize.h" -#include "Convert.mqh" -#include "Market.mqh" -#include "Serializer/Serializer.h" -#include "Task/TaskCondition.enum.h" // Forward class declaration. class Chart; @@ -65,21 +66,18 @@ ChartPriceOpen Open; int iBarShift(string _symbol, int _tf, datetime _time, bool _exact = false) { return ChartStatic::iBarShift(_symbol, (ENUM_TIMEFRAMES)_tf, _time, _exact); } -double iClose(string _symbol, int _tf, int _shift) { - return ChartStatic::iClose(_symbol, (ENUM_TIMEFRAMES)_tf, _shift); -} #endif #ifndef __MQL__ struct MqlRates { - datetime time; // Period start time - double open; // Open price - double high; // The highest price of the period - double low; // The lowest price of the period - double close; // Close price - long tick_volume; // Tick volume - int spread; // Spread - long real_volume; // Trade volume + datetime time; // Period start time + double open; // Open price + double high; // The highest price of the period + double low; // The lowest price of the period + double close; // Close price + int64 tick_volume; // Tick volume + int spread; // Spread + int64 real_volume; // Trade volume }; #endif @@ -98,7 +96,7 @@ class Chart : public Market { // Stores indicator instances. // @todo - // Dict indis; + // Dict indis; // Variables. datetime last_bar_time; @@ -123,10 +121,12 @@ class Chart : public Market { * _hide bool Flag for hiding indicators when testing. Set true to hide created indicators, otherwise false. */ static void HideTestIndicators(bool _hide = false) { +#ifdef __MQL__ #ifdef __MQL4__ ::HideTestIndicators(_hide); #else // __MQL5__ ::TesterHideIndicators(_hide); +#endif #endif } @@ -180,5 +180,3 @@ class Chart : public Market { void SerializeStub(int _n1 = 1, int _n2 = 1, int _n3 = 1, int _n4 = 1, int _n5 = 1) {} }; - -#endif diff --git a/Chart.struct.h b/Platform/Chart/Chart.struct.h similarity index 84% rename from Chart.struct.h rename to Platform/Chart/Chart.struct.h index bb17302ba..ef0d2e3f0 100644 --- a/Chart.struct.h +++ b/Platform/Chart/Chart.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -35,15 +35,16 @@ class Class; struct ChartTf; // Includes. -#include "Array.mqh" -#include "Bar.struct.h" +#include "../../Bar.struct.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/SerializerNode.enum.h" +#include "../../Std.h" +#include "../../Storage/Array.h" +#include "../Terminal.define.h" #include "Chart.define.h" #include "Chart.enum.h" #include "Chart.struct.static.h" #include "Chart.struct.tf.h" -#include "Serializer/Serializer.h" -#include "Serializer/SerializerNode.enum.h" -#include "Terminal.define.h" /* Defines struct to store bar entries. */ struct ChartEntry { @@ -54,7 +55,7 @@ struct ChartEntry { ChartEntry(const ChartEntry& _r) { SetBar(_r.bar); } // Getters. BarEntry GetBar() { return bar; } - string ToCSV() { return StringFormat("%s", bar.ToCSV()); } + string ToCSV() { return StringFormat("%s", C_STR(bar.ToCSV())); } // Setters. void SetBar(const BarEntry& _bar) { bar = _bar; } // Serializers. @@ -64,15 +65,15 @@ struct ChartEntry { /* Defines struct for chart parameters. */ struct ChartParams { - long id; + int64 id; string symbol; ChartTf tf; // Copy constructor. ChartParams(ChartParams& _cparams) : symbol(_cparams.symbol), tf(_cparams.tf) {} // Constructors. - ChartParams(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL, long _id = 0) + ChartParams(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL, int64 _id = 0) : id(_id), symbol(_symbol), tf(_tf){}; - ChartParams(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL, long _id = 0) : id(_id), symbol(_symbol), tf(_tfi){}; + ChartParams(ENUM_TIMEFRAMES_INDEX _tfi, string _symbol = NULL, int64 _id = 0) : id(_id), symbol(_symbol), tf(_tfi){}; // Getters. template T Get(ENUM_CHART_PARAM _param) { @@ -97,7 +98,7 @@ struct ChartParams { void Set(ENUM_CHART_PARAM _param, T _value) { switch (_param) { case CHART_PARAM_ID: - id = (long)_value; + id = (int64)_value; return; case CHART_PARAM_SYMBOL: symbol = (string)_value; @@ -113,4 +114,4 @@ struct ChartParams { } // Serializers. SerializerNodeType Serialize(Serializer& s); -} chart_params_defaults(PERIOD_CURRENT, _Symbol); +} chart_params_defaults(PERIOD_CURRENT, Symbol()); diff --git a/Chart.struct.serialize.h b/Platform/Chart/Chart.struct.serialize.h similarity index 81% rename from Chart.struct.serialize.h rename to Platform/Chart/Chart.struct.serialize.h index 1c436f916..e95408df5 100644 --- a/Chart.struct.serialize.h +++ b/Platform/Chart/Chart.struct.serialize.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,12 +25,17 @@ * Includes Chart's struct serializers. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Forward class declaration. class Serializer; // Includes. -#include "Serializer/Serializer.h" -#include "Serializer/SerializerNode.enum.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/SerializerNode.enum.h" /* Method to serialize ChartEntry structure. */ SerializerNodeType ChartEntry::Serialize(Serializer& _s) { diff --git a/Chart.struct.static.h b/Platform/Chart/Chart.struct.static.h similarity index 95% rename from Chart.struct.static.h rename to Platform/Chart/Chart.struct.static.h index 2e7f8d65b..efed99fa4 100644 --- a/Chart.struct.static.h +++ b/Platform/Chart/Chart.struct.static.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,10 +31,10 @@ #endif // Includes. +#include "../Platform.extern.h" +#include "../Terminal.define.h" #include "Chart.define.h" #include "Chart.symboltf.h" -#include "Platform.extern.h" -#include "Terminal.define.h" /* Defines struct for chart static methods. */ struct ChartStatic { @@ -320,10 +320,10 @@ struct ChartStatic { * * If local history is empty (not loaded), function returns 0. */ - static long iVolume(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) { + static int64 iVolume(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) { #ifdef __MQL4__ ResetLastError(); - long _volume = ::iVolume(_symbol, _tf, _shift); // Same as: Volume[_shift] + int64 _volume = ::iVolume(_symbol, _tf, _shift); // Same as: Volume[_shift] if (_LastError != ERR_NO_ERROR) { _volume = EMPTY_VALUE; ResetLastError(); @@ -341,7 +341,7 @@ struct ChartStatic { * * If local history is empty (not loaded), function returns 0. */ - static datetime GetBarTime(CONST_REF_TO(string) _symbol, ENUM_TIMEFRAMES _tf, unsigned int _shift = 0) { + static datetime GetBarTime(CONST_REF_TO_SIMPLE(string) _symbol, ENUM_TIMEFRAMES _tf, unsigned int _shift = 0) { #ifdef __MQL4__ datetime _time = ::iTime(_symbol, _tf, _shift); // Same as: Time[_shift] @@ -370,5 +370,5 @@ struct ChartStatic { /** * Gets Chart ID. */ - static long ID() { return ::ChartID(); } + static int64 ID() { return ::ChartID(); } }; diff --git a/Chart.struct.tf.h b/Platform/Chart/Chart.struct.tf.h similarity index 97% rename from Chart.struct.tf.h rename to Platform/Chart/Chart.struct.tf.h index 0acc2d8f5..da66aaf0f 100644 --- a/Chart.struct.tf.h +++ b/Platform/Chart/Chart.struct.tf.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,7 +28,7 @@ #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once -#include "Platform.extern.h" +#include "../Platform.extern.h" #endif // Forward declarations. @@ -36,9 +36,9 @@ class Serializer; // Includes. #include "Chart.enum.h" -#include "Serializer/Serializer.h" -#include "Serializer/SerializerNode.enum.h" -#include "Terminal.define.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/SerializerNode.enum.h" +#include "../Terminal.define.h" /* Defines struct for chart timeframe. */ struct ChartTf { diff --git a/Chart.symboltf.h b/Platform/Chart/Chart.symboltf.h similarity index 81% rename from Chart.symboltf.h rename to Platform/Chart/Chart.symboltf.h index 52411498d..e3b9c2f9f 100644 --- a/Chart.symboltf.h +++ b/Platform/Chart/Chart.symboltf.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,7 +31,8 @@ #endif // Includes. -#include "Std.h" +#include "../../Std.h" +#include "../../Storage/String.extern.h" /** * Represents symbol and timeframe. To be used by IndicatorBase and ChartBase classes. @@ -41,8 +42,8 @@ struct SymbolTf { const ENUM_TIMEFRAMES tf; const string symbol_tf_key; - CONST_REF_TO(string) Key() const { return symbol_tf_key; } - CONST_REF_TO(string) Symbol() const { return symbol; } + RETURN_CONST_REF_TO_SIMPLE(string) Key() const { return symbol_tf_key; } + RETURN_CONST_REF_TO_SIMPLE(string) Symbol() const { return symbol; } ENUM_TIMEFRAMES Tf() const { return tf; } SymbolTf(string _symbol, ENUM_TIMEFRAMES _tf) diff --git a/ChartBase.h b/Platform/Chart/ChartBase.h similarity index 97% rename from ChartBase.h rename to Platform/Chart/ChartBase.h index 99010949a..1b4a049c7 100644 --- a/ChartBase.h +++ b/Platform/Chart/ChartBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -38,9 +38,9 @@ #include "Chart.struct.h" #include "Chart.symboltf.h" #include "Data.define.h" -#include "Dict.mqh" #include "Log.mqh" #include "Refs.mqh" +#include "Storage/Dict/Dict.h" #include "Task/TaskCondition.enum.h" /** @@ -133,7 +133,7 @@ class ChartBase : public Dynamic { /** * Return symbol bound to chart. */ - CONST_REF_TO(string) GetSymbol() { return cparams.Get(CHART_PARAM_SYMBOL); } + CONST_REF_TO_SIMPLE(string) GetSymbol() { return cparams.Get(CHART_PARAM_SYMBOL); } /** * Return time-frame bound to chart. @@ -193,7 +193,7 @@ class ChartBase : public Dynamic { * * If local history is empty (not loaded), function returns 0. */ - virtual long GetVolume(int _shift = 0) = 0; + virtual int64 GetVolume(int _shift = 0) = 0; /** * Returns the shift of the maximum value over a specific number of periods depending on type. @@ -386,10 +386,10 @@ class ChartBase : public Dynamic { int nBarsInNearPr = 0; ENUM_TIMEFRAMES TimeNearPr = PERIOD_M1; double ModellingQuality = 0; - long StartGen = 0; - long StartBar = 0; - long StartGenM1 = 0; - long HistoryTotal = 0; + int64 StartGen = 0; + int64 StartBar = 0; + int64 StartGenM1 = 0; + int64 HistoryTotal = 0; datetime x = StrToTime("1971.01.01 00:00"); datetime modeling_start_time = StrToTime("1971.01.01 00:00"); @@ -697,7 +697,7 @@ class ChartBase : public Dynamic { /** * Return size of BarOHLC array. */ - unsigned long SizeChartEntry() { return ArraySize(chart_saves); } + uint64 SizeChartEntry() { return ArraySize(chart_saves); } /* Serializers */ diff --git a/ChartMt.h b/Platform/Chart/ChartMt.h similarity index 95% rename from ChartMt.h rename to Platform/Chart/ChartMt.h index 5f32f0230..d98b4c8e1 100644 --- a/ChartMt.h +++ b/Platform/Chart/ChartMt.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,9 +31,9 @@ #endif // Includes. +#include "../Terminal.define.h" #include "Chart.struct.static.h" #include "Chart.symboltf.h" -#include "Terminal.define.h" #ifdef __DISABLED @@ -214,7 +214,7 @@ class ChartMt : public ChartBase { * * If local history is empty (not loaded), function returns 0. */ - virtual long GetVolume(int _shift = 0) override { return ::iVolume(GetSymbol(), GetTf(), _shift); } + virtual int64 GetVolume(int _shift = 0) override { return ::iVolume(GetSymbol(), GetTf(), _shift); } }; #endif @@ -300,6 +300,8 @@ struct ChartBarTime { ChartBarTime() : symbol_tf(Symbol(), PERIOD_CURRENT) {} datetime operator[](const int _shift) const { return Get(symbol_tf, _shift); } static datetime Get(const SymbolTf& _symbol_tf, const int _shift) { - return ChartStatic::GetBarTime(_symbol_tf.Symbol(), _symbol_tf.Tf(), _shift); + string _symbol = _symbol_tf.Symbol(); + ENUM_TIMEFRAMES _tf = _symbol_tf.Tf(); + return ChartStatic::GetBarTime(_symbol, _tf, _shift); } }; diff --git a/Platform/Chart/README.md b/Platform/Chart/README.md new file mode 100644 index 000000000..fdb99daea --- /dev/null +++ b/Platform/Chart/README.md @@ -0,0 +1 @@ +# Chart diff --git a/Platform/Chart/tests/Chart.test.cpp b/Platform/Chart/tests/Chart.test.cpp new file mode 100644 index 000000000..a74173e9b --- /dev/null +++ b/Platform/Chart/tests/Chart.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Chart class. + */ + +// Includes. +#include "../Chart.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Platform/Chart/tests/Chart.test.mq4 b/Platform/Chart/tests/Chart.test.mq4 new file mode 100644 index 000000000..c08dd84a1 --- /dev/null +++ b/Platform/Chart/tests/Chart.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Chart class. + */ + +// Includes. +#include "Chart.test.mq5" diff --git a/tests/ChartTest.mq5 b/Platform/Chart/tests/Chart.test.mq5 similarity index 92% rename from tests/ChartTest.mq5 rename to Platform/Chart/tests/Chart.test.mq5 index 5fd95b1f0..f3b9f9779 100644 --- a/tests/ChartTest.mq5 +++ b/Platform/Chart/tests/Chart.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,9 +25,9 @@ */ // Includes. -#include "../Chart.mqh" -#include "../Convert.mqh" -#include "../Test.mqh" +#include "../Chart.h" +#include "../../../Convert.mqh" +#include "../../../Test.mqh" /** * Implements OnInit(). diff --git a/Platform/Chart/tests/ChartMt.test.cpp b/Platform/Chart/tests/ChartMt.test.cpp new file mode 100644 index 000000000..e2bad718e --- /dev/null +++ b/Platform/Chart/tests/ChartMt.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of ChartMt class. + */ + +// Includes. +#include "../ChartMt.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/ChartTest.mq4 b/Platform/Chart/tests/ChartMt.test.mq4 similarity index 87% rename from tests/ChartTest.mq4 rename to Platform/Chart/tests/ChartMt.test.mq4 index 8498ca7c7..e431ba656 100644 --- a/tests/ChartTest.mq4 +++ b/Platform/Chart/tests/ChartMt.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,20 +9,20 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * @file - * Test functionality of Chart class. + * Test functionality of ChartMt class. */ // Includes. -#include "ChartTest.mq5" +#include "ChartMt.test.mq5" diff --git a/Platform/Chart/tests/ChartMt.test.mq5 b/Platform/Chart/tests/ChartMt.test.mq5 new file mode 100644 index 000000000..db7e0f9c0 --- /dev/null +++ b/Platform/Chart/tests/ChartMt.test.mq5 @@ -0,0 +1,39 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of ChartMt class. + */ + +// Includes. +#include "../ChartMt.h" +#include "../../../Test.mqh" + +/** + * Implements OnInit(). + */ +int OnInit() { + + // @todo: Write some tests... + + return (INIT_SUCCEEDED); +} diff --git a/Platform/Chart/tests/Makefile b/Platform/Chart/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Platform/Chart/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/3D/Chart3D.h b/Platform/Chart3D/Chart3D.h similarity index 92% rename from 3D/Chart3D.h rename to Platform/Chart3D/Chart3D.h index 692c60f71..4f9cbcd64 100644 --- a/3D/Chart3D.h +++ b/Platform/Chart3D/Chart3D.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,13 +25,18 @@ * 3D Chart. */ -#include "../Bar.struct.h" -#include "../Indicator/IndicatorData.h" -#include "../Indicators/Indi_MA.mqh" -#include "../Instances.h" -#include "../Refs.mqh" -#include "../Serializer/SerializerConverter.h" -#include "../Serializer/SerializerJson.h" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Bar.struct.h" +#include "../../Indicator/IndicatorData.h" +#include "../../Indicators/Price/Indi_MA.h" +#include "../../Instances.h" +#include "../../Refs.mqh" +#include "../../Serializer/SerializerConverter.h" +#include "../../Serializer/SerializerJson.h" #include "Chart3DCandles.h" #include "Chart3DType.h" #include "Cube.h" diff --git a/3D/Chart3DCandles.h b/Platform/Chart3D/Chart3DCandles.h similarity index 92% rename from 3D/Chart3DCandles.h rename to Platform/Chart3D/Chart3DCandles.h index 4df50d599..606f88b77 100644 --- a/3D/Chart3DCandles.h +++ b/Platform/Chart3D/Chart3DCandles.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,12 @@ * 3D chart candles renderer. */ -#include "../Chart.define.h" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../Chart/Chart.define.h" #include "Chart3DType.h" #include "Cube.h" #include "Device.h" diff --git a/3D/Chart3DType.h b/Platform/Chart3D/Chart3DType.h similarity index 83% rename from 3D/Chart3DType.h rename to Platform/Chart3D/Chart3DType.h index 51e6b66d3..66a4da897 100644 --- a/3D/Chart3DType.h +++ b/Platform/Chart3D/Chart3DType.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,12 @@ * 3D chart type renderer. */ -#include "../Refs.mqh" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Refs.mqh" #include "Device.h" class Chart3D; diff --git a/3D/Cube.h b/Platform/Chart3D/Cube.h similarity index 92% rename from 3D/Cube.h rename to Platform/Chart3D/Cube.h index 85ba8c1dc..9ac3d8e89 100644 --- a/3D/Cube.h +++ b/Platform/Chart3D/Cube.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Cube mesh. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "Face.h" #include "Mesh.h" diff --git a/3D/Device.h b/Platform/Chart3D/Device.h similarity index 96% rename from 3D/Device.h rename to Platform/Chart3D/Device.h index 61de259fa..741561a51 100644 --- a/3D/Device.h +++ b/Platform/Chart3D/Device.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,14 +25,20 @@ * Generic graphics device. */ -#include "../Refs.mqh" -#include "../Util.h" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Refs.mqh" +#include "../../Util.h" #include "Frontend.h" #include "IndexBuffer.h" #include "Material.h" #include "Math.h" #include "Mesh.h" #include "Shader.h" +#include "ShaderVertexLayout.struct.h" #include "VertexBuffer.h" enum GFX_DRAW_TEXT_FLAGS { GFX_DRAW_TEXT_FLAG_NONE, GFX_DRAW_TEXT_FLAG_2D_COORD_X, GFX_DRAW_TEXT_FLAG_2D_COORD_Y }; diff --git a/3D/Devices/MTDX/MTDXDevice.h b/Platform/Chart3D/Devices/MTDX/MTDXDevice.h similarity index 94% rename from 3D/Devices/MTDX/MTDXDevice.h rename to Platform/Chart3D/Devices/MTDX/MTDXDevice.h index 33c60df26..aa82926c8 100644 --- a/3D/Devices/MTDX/MTDXDevice.h +++ b/Platform/Chart3D/Devices/MTDX/MTDXDevice.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * MetaTrader DX-targeted graphics device. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "../../Device.h" class MTDXDevice : public Device { diff --git a/3D/Devices/MTDX/MTDXIndexBuffer.h b/Platform/Chart3D/Devices/MTDX/MTDXIndexBuffer.h similarity index 88% rename from 3D/Devices/MTDX/MTDXIndexBuffer.h rename to Platform/Chart3D/Devices/MTDX/MTDXIndexBuffer.h index 057f3306c..dc615894b 100644 --- a/3D/Devices/MTDX/MTDXIndexBuffer.h +++ b/Platform/Chart3D/Devices/MTDX/MTDXIndexBuffer.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * MetaTrader DX-targeted graphics device's index buffer. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "../../IndexBuffer.h" class MTDXIndexBuffer : public IndexBuffer { diff --git a/3D/Devices/MTDX/MTDXShader.h b/Platform/Chart3D/Devices/MTDX/MTDXShader.h similarity index 95% rename from 3D/Devices/MTDX/MTDXShader.h rename to Platform/Chart3D/Devices/MTDX/MTDXShader.h index 2cf97f95b..f09e4dc3c 100644 --- a/3D/Devices/MTDX/MTDXShader.h +++ b/Platform/Chart3D/Devices/MTDX/MTDXShader.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * MetaTrader DX-targeted unversal graphics shader. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "../../Shader.h" class MTDXShader : public Shader { diff --git a/3D/Devices/MTDX/MTDXVertexBuffer.h b/Platform/Chart3D/Devices/MTDX/MTDXVertexBuffer.h similarity index 87% rename from 3D/Devices/MTDX/MTDXVertexBuffer.h rename to Platform/Chart3D/Devices/MTDX/MTDXVertexBuffer.h index 9b9332962..5e514a73e 100644 --- a/3D/Devices/MTDX/MTDXVertexBuffer.h +++ b/Platform/Chart3D/Devices/MTDX/MTDXVertexBuffer.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * MetaTrader DX-targeted graphics vertex buffer. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "../../VertexBuffer.h" class MTDXVertexBuffer : public VertexBuffer { diff --git a/3D/Face.h b/Platform/Chart3D/Face.h similarity index 91% rename from 3D/Face.h rename to Platform/Chart3D/Face.h index 9bd841b76..59f394b26 100644 --- a/3D/Face.h +++ b/Platform/Chart3D/Face.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Generic graphics face object. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "Math.h" // Face flags. diff --git a/3D/Frontend.h b/Platform/Chart3D/Frontend.h similarity index 89% rename from 3D/Frontend.h rename to Platform/Chart3D/Frontend.h index 173a26c87..a5bc188eb 100644 --- a/3D/Frontend.h +++ b/Platform/Chart3D/Frontend.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,12 @@ * Generic graphics front-end (display buffer target). */ -#include "../Refs.mqh" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Refs.mqh" struct DrawTextQueueItem { float x; @@ -40,7 +45,7 @@ struct DrawTextQueueItem { */ class Frontend : public Dynamic { protected: - DrawTextQueueItem draw_text_queue[]; + ARRAY(DrawTextQueueItem, draw_text_queue); public: /** diff --git a/3D/Frontends/MT5Frontend.h b/Platform/Chart3D/Frontends/MT5Frontend.h similarity index 95% rename from 3D/Frontends/MT5Frontend.h rename to Platform/Chart3D/Frontends/MT5Frontend.h index 39962aaad..c6878aa32 100644 --- a/3D/Frontends/MT5Frontend.h +++ b/Platform/Chart3D/Frontends/MT5Frontend.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * MT5 graphics front-end (display buffer target). */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "../Frontend.h" /** diff --git a/3D/IndexBuffer.h b/Platform/Chart3D/IndexBuffer.h similarity index 78% rename from 3D/IndexBuffer.h rename to Platform/Chart3D/IndexBuffer.h index 3c0153802..7392f7731 100644 --- a/3D/IndexBuffer.h +++ b/Platform/Chart3D/IndexBuffer.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,12 @@ * Generic graphics index buffer. */ -#include "../Refs.mqh" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Refs.mqh" class Device; @@ -49,12 +54,12 @@ class IndexBuffer : public Dynamic { /** * Creates index buffer. */ - virtual bool Create(void*& _data[]) = NULL; + virtual bool Create(VOID_DATA(_data)) = NULL; /** * Fills index buffer with indices. */ - virtual void Fill(unsigned int& _indices[]) = NULL; + virtual void Fill(ARRAY_REF(unsigned int, _indices)) = NULL; /** * Activates index buffer for rendering. diff --git a/3D/Interface.h b/Platform/Chart3D/Interface.h similarity index 89% rename from 3D/Interface.h rename to Platform/Chart3D/Interface.h index df041a9d8..e387ffa79 100644 --- a/3D/Interface.h +++ b/Platform/Chart3D/Interface.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,12 @@ * Chart events. */ -#include "../Util.h" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Util.h" enum ENUM_INTERFACE_EVENT { INTERFACE_EVENT_NONE, @@ -53,7 +58,7 @@ struct InterfaceEvent { * * Invoked when the ChartEvent event occurs. */ -void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) { +void OnChartEvent(const int id, const int64& lparam, const double& dparam, const string& sparam) { datetime _dt; double _mp; int _window = 0; diff --git a/Platform/Chart3D/Material.h b/Platform/Chart3D/Material.h new file mode 100644 index 000000000..43c5313a3 --- /dev/null +++ b/Platform/Chart3D/Material.h @@ -0,0 +1,45 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "Math.h" + +/** + * Generic vertex to be used by meshes. + */ +class Material { + public: + DXColor Color; + + Material(unsigned int _color = 0xFFFFFFFF) { Color = DXColor(_color); } + + Material(const Material& _r) { Color = _r.Color; } + + Material* SetColor(unsigned int _color) { + Color = DXColor(_color); + return &this; + } +}; diff --git a/3D/Math.h b/Platform/Chart3D/Math.h similarity index 99% rename from 3D/Math.h rename to Platform/Chart3D/Math.h index 651741a88..25cd12e1d 100644 --- a/3D/Math.h +++ b/Platform/Chart3D/Math.h @@ -1,10 +1,17 @@ //+------------------------------------------------------------------+ //| DXMath.mqh | -//| Copyright 2019,MetaQuotes Software Corp. | +//| Copyright 2019,MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#ifdef __MQL__ #property copyright "Copyright 2019,MetaQuotes Software Corp." #property link "https://www.mql5.com" +#endif //+------------------------------------------------------------------+ //| DirectX Math Routines | //+------------------------------------------------------------------+ @@ -209,10 +216,10 @@ struct DXQuaternion { //| DViewport | //+------------------------------------------------------------------+ struct DViewport { - unsigned long x; - unsigned long y; - unsigned long width; - unsigned long height; + uint64 x; + uint64 y; + uint64 width; + uint64 height; float minz; float maxz; }; diff --git a/3D/Mesh.h b/Platform/Chart3D/Mesh.h similarity index 92% rename from 3D/Mesh.h rename to Platform/Chart3D/Mesh.h index 95cbf8ce3..07417fcf6 100644 --- a/3D/Mesh.h +++ b/Platform/Chart3D/Mesh.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,9 +25,14 @@ * Generic graphics mesh. */ -#include "../Dict.mqh" -#include "../Refs.mqh" -#include "../Util.h" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Refs.mqh" +#include "../../Storage/Dict/Dict.h" +#include "../../Util.h" #include "Face.h" #include "IndexBuffer.h" #include "Material.h" @@ -43,7 +48,7 @@ class Device; template struct PointEntry { T point; - long key; + int64 key; // Default constructor. PointEntry() {} @@ -61,9 +66,9 @@ struct PointEntry { return key == MakeKey(_r.point.Position.x, _r.point.Position.y, _r.point.Position.z); } - static long MakeKey(float x, float y, float z) { - return long(x / GFX_MESH_LOOKUP_PRECISION) + 4194304 * long(y / GFX_MESH_LOOKUP_PRECISION) + - 17592186044416 * long(z / GFX_MESH_LOOKUP_PRECISION); + static int64 MakeKey(float x, float y, float z) { + return int64(x / GFX_MESH_LOOKUP_PRECISION) + 4194304 * int64(y / GFX_MESH_LOOKUP_PRECISION) + + 17592186044416 * int64(z / GFX_MESH_LOOKUP_PRECISION); } }; diff --git a/Platform/Chart3D/README.md b/Platform/Chart3D/README.md new file mode 100644 index 000000000..2c8882790 --- /dev/null +++ b/Platform/Chart3D/README.md @@ -0,0 +1 @@ +# Chart3D diff --git a/3D/Shader.h b/Platform/Chart3D/Shader.h similarity index 84% rename from 3D/Shader.h rename to Platform/Chart3D/Shader.h index 104bc0c85..8bfc3de25 100644 --- a/3D/Shader.h +++ b/Platform/Chart3D/Shader.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,12 @@ * Generic graphics shader. */ -#include "../Refs.mqh" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Refs.mqh" // Shader type. enum ENUM_SHADER_TYPE { @@ -55,17 +60,6 @@ struct MVPBuffer { // char _unused2[1]; }; -// Vertex layout used for Vertex Shaders. -struct ShaderVertexLayout { - string name; - unsigned int index; - ENUM_GFX_VAR_TYPE_FLOAT type; - unsigned int num_components; - bool clamped; - unsigned int stride; - unsigned int offset; -}; - /** * Unified vertex/pixel shader. */ diff --git a/Platform/Chart3D/ShaderVertexLayout.struct.h b/Platform/Chart3D/ShaderVertexLayout.struct.h new file mode 100644 index 000000000..026d2d8a6 --- /dev/null +++ b/Platform/Chart3D/ShaderVertexLayout.struct.h @@ -0,0 +1,42 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * @file + * Defines ShaderVertexLayout structure. + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Vertex layout used for Vertex Shaders. +struct ShaderVertexLayout { + string name; + unsigned int index; + ENUM_GFX_VAR_TYPE_FLOAT type; + unsigned int num_components; + bool clamped; + unsigned int stride; + unsigned int offset; +}; diff --git a/3D/Shaders/chart3d_ps.hlsl b/Platform/Chart3D/Shaders/chart3d_ps.hlsl similarity index 100% rename from 3D/Shaders/chart3d_ps.hlsl rename to Platform/Chart3D/Shaders/chart3d_ps.hlsl diff --git a/3D/Shaders/chart3d_vs.hlsl b/Platform/Chart3D/Shaders/chart3d_vs.hlsl similarity index 100% rename from 3D/Shaders/chart3d_vs.hlsl rename to Platform/Chart3D/Shaders/chart3d_vs.hlsl diff --git a/3D/Shaders/cube_ps.hlsl b/Platform/Chart3D/Shaders/cube_ps.hlsl similarity index 100% rename from 3D/Shaders/cube_ps.hlsl rename to Platform/Chart3D/Shaders/cube_ps.hlsl diff --git a/3D/Shaders/cube_vs.hlsl b/Platform/Chart3D/Shaders/cube_vs.hlsl similarity index 100% rename from 3D/Shaders/cube_vs.hlsl rename to Platform/Chart3D/Shaders/cube_vs.hlsl diff --git a/3D/TSR.h b/Platform/Chart3D/TSR.h similarity index 89% rename from 3D/TSR.h rename to Platform/Chart3D/TSR.h index 61ab08371..4ed42dd48 100644 --- a/3D/TSR.h +++ b/Platform/Chart3D/TSR.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Translations, scale and rotation matrices. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "Math.h" class TSR { diff --git a/Platform/Chart3D/Vertex.h b/Platform/Chart3D/Vertex.h new file mode 100644 index 000000000..65e9248b0 --- /dev/null +++ b/Platform/Chart3D/Vertex.h @@ -0,0 +1,58 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Refs.mqh" + +/** + * Generic vertex to be used by meshes. + */ +struct Vertex { + DXVector3 Position; + DXVector3 Normal; + DXColor Color; + + // Default constructor. + Vertex(float r = 1, float g = 1, float b = 1, float a = 1) { + Color.r = r; + Color.g = g; + Color.b = b; + Color.a = a; + } + + Vertex(const Vertex &r) { + Position = r.Position; + Normal = r.Normal; + Color = r.Color; + } + + static const ShaderVertexLayout Layout[3]; +}; + +const ShaderVertexLayout Vertex::Layout[3] = { + {"POSITION", 0, GFX_VAR_TYPE_FLOAT, 3, false, sizeof(Vertex), 0}, + {"NORMAL", 0, GFX_VAR_TYPE_FLOAT, 3, false, sizeof(Vertex), sizeof(float) * 3}, + {"COLOR", 0, GFX_VAR_TYPE_FLOAT, 4, false, sizeof(Vertex), sizeof(float) * 6}}; diff --git a/3D/VertexBuffer.h b/Platform/Chart3D/VertexBuffer.h similarity index 82% rename from 3D/VertexBuffer.h rename to Platform/Chart3D/VertexBuffer.h index a892fc4a4..3b3f9916d 100644 --- a/3D/VertexBuffer.h +++ b/Platform/Chart3D/VertexBuffer.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,12 @@ * Generic graphics vertex buffer. */ -#include "../Refs.mqh" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../../Refs.mqh" class VertexBuffer : public Dynamic { // Reference to graphics device. diff --git a/Platform/Chart3D/tests/Chart3D.test.cpp b/Platform/Chart3D/tests/Chart3D.test.cpp new file mode 100644 index 000000000..1d7c0be3e --- /dev/null +++ b/Platform/Chart3D/tests/Chart3D.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Chart3D class. + */ + +// Includes. +#include "../Chart3D.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Platform/Chart3D/tests/Chart3D.test.mq4 b/Platform/Chart3D/tests/Chart3D.test.mq4 new file mode 100644 index 000000000..9f34bcfa4 --- /dev/null +++ b/Platform/Chart3D/tests/Chart3D.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Chart3D class. + */ + +// Includes. +#include "Chart3D.test.mq5" diff --git a/tests/3DTest.mq5 b/Platform/Chart3D/tests/Chart3D.test.mq5 similarity index 78% rename from tests/3DTest.mq5 rename to Platform/Chart3D/tests/Chart3D.test.mq5 index 01f9dbe9b..22d2552d5 100644 --- a/tests/3DTest.mq5 +++ b/Platform/Chart3D/tests/Chart3D.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -29,22 +29,22 @@ //#define __debug__ // Resources. -#resource "3D/Shaders/vertex.hlsl" as string ShaderSourceVS; -#resource "3D/Shaders/pixel.hlsl" as string ShaderSourcePS; +#resource "Shaders/vertex.hlsl" as string ShaderSourceVS; +#resource "Shaders/pixel.hlsl" as string ShaderSourcePS; // Includes. -#include "../3D/Chart3D.h" -#include "../3D/Cube.h" -#include "../3D/Devices/MTDX/MTDXDevice.h" -#include "../3D/Devices/MTDX/MTDXIndexBuffer.h" -#include "../3D/Devices/MTDX/MTDXShader.h" -#include "../3D/Devices/MTDX/MTDXVertexBuffer.h" -#include "../3D/Frontends/MT5Frontend.h" -#include "../BufferStruct.mqh" -#include "../Chart.mqh" -#include "../Platform.h" -#include "../Serializer/Serializer.h" -#include "../Test.mqh" +#include "../Chart3D.h" +#include "../Cube.h" +#include "../Devices/MTDX/MTDXDevice.h" +#include "../Devices/MTDX/MTDXIndexBuffer.h" +#include "../Devices/MTDX/MTDXShader.h" +#include "../Devices/MTDX/MTDXVertexBuffer.h" +#include "../Frontends/MT5Frontend.h" +#include "../../../Storage/Dict/Buffer/BufferStruct.h" +#include "../../Chart/Chart.h" +#include "../../Platform.h" +#include "../../../Serializer/Serializer.h" +#include "../../../Test.mqh" /** * Implements OnInit(). diff --git a/Platform/Chart3D/tests/Makefile b/Platform/Chart3D/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Platform/Chart3D/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/tests/3D/Shaders/pixel.hlsl b/Platform/Chart3D/tests/Shaders/pixel.hlsl similarity index 100% rename from tests/3D/Shaders/pixel.hlsl rename to Platform/Chart3D/tests/Shaders/pixel.hlsl diff --git a/tests/3D/Shaders/vertex.hlsl b/Platform/Chart3D/tests/Shaders/vertex.hlsl similarity index 100% rename from tests/3D/Shaders/vertex.hlsl rename to Platform/Chart3D/tests/Shaders/vertex.hlsl diff --git a/Deal.enum.h b/Platform/Deal.enum.h similarity index 94% rename from Deal.enum.h rename to Platform/Deal.enum.h index fa7cb4a19..2f904f637 100644 --- a/Deal.enum.h +++ b/Platform/Deal.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Platform/MQL5.mqh b/Platform/MQL5.mqh new file mode 100644 index 000000000..293d6056a --- /dev/null +++ b/Platform/MQL5.mqh @@ -0,0 +1,314 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * @file + * Provides forward compatibility for MQL5 in MT4/MQL4. + */ + +// Prevents processing this includes file for the second time. +#ifndef MQL5_MQH +#define MQL5_MQH + +//+------------------------------------------------------------------+ +//| Declaration of constants +//+------------------------------------------------------------------+ + +// Missing error handling constants in MQL4. +// @see: https://docs.mql4.com/constants/errorswarnings/errorcodes +// @see: https://www.mql5.com/en/docs/constants/errorswarnings +#ifdef __MQL4__ +// Return codes of the trade server. +#define TRADE_RETCODE_REQUOTE 10004 // Requote +#define TRADE_RETCODE_REJECT 10006 // Request rejected +#define TRADE_RETCODE_CANCEL 10007 // Request canceled by trader +#define TRADE_RETCODE_PLACED 10008 // Order placed +#define TRADE_RETCODE_DONE 10009 // Request completed +#define TRADE_RETCODE_DONE_PARTIAL 10010 // Only part of the request was completed +#define TRADE_RETCODE_ERROR 10011 // Request processing error +#define TRADE_RETCODE_TIMEOUT 10012 // Request canceled by timeout +#define TRADE_RETCODE_INVALID 10013 // Invalid request +#define TRADE_RETCODE_INVALID_VOLUME 10014 // Invalid volume in the request +#define TRADE_RETCODE_INVALID_PRICE 10015 // Invalid price in the request +#define TRADE_RETCODE_INVALID_STOPS 10016 // Invalid stops in the request +#define TRADE_RETCODE_TRADE_DISABLED 10017 // Trade is disabled +#define TRADE_RETCODE_MARKET_CLOSED 10018 // Market is closed +#define TRADE_RETCODE_NO_MONEY 10019 // There is not enough money to complete the request +#define TRADE_RETCODE_PRICE_CHANGED 10020 // Prices changed +#define TRADE_RETCODE_PRICE_OFF 10021 // There are no quotes to process the request +#define TRADE_RETCODE_INVALID_EXPIRATION 10022 // Invalid order expiration date in the request +#define TRADE_RETCODE_ORDER_CHANGED 10023 // Order state changed +#define TRADE_RETCODE_TOO_MANY_REQUESTS 10024 // Too frequent requests +#define TRADE_RETCODE_NO_CHANGES 10025 // No changes in request +#define TRADE_RETCODE_SERVER_DISABLES_AT 10026 // Autotrading disabled by server +#define TRADE_RETCODE_CLIENT_DISABLES_AT 10027 // Autotrading disabled by client terminal +#define TRADE_RETCODE_LOCKED 10028 // Request locked for processing +#define TRADE_RETCODE_FROZEN 10029 // Order or position frozen +#define TRADE_RETCODE_INVALID_FILL 10030 // Invalid order filling type +#define TRADE_RETCODE_CONNECTION 10031 // No connection with the trade server +#define TRADE_RETCODE_ONLY_REAL 10032 // Operation is allowed only for live accounts +#define TRADE_RETCODE_LIMIT_ORDERS 10033 // The number of pending orders has reached the limit +#define TRADE_RETCODE_LIMIT_VOLUME 10034 // The volume of orders and positions for the symbol has reached the limit +#define TRADE_RETCODE_INVALID_ORDER 10035 // Incorrect or prohibited order type +#define TRADE_RETCODE_POSITION_CLOSED 10036 // Position with the specified POSITION_IDENTIFIER has already been closed +#define TRADE_RETCODE_INVALID_CLOSE_VOLUME 10038 // A close volume exceeds the current position volume +#define TRADE_RETCODE_CLOSE_ORDER_EXIST 10039 // A close order already exists. +#define TRADE_RETCODE_LIMIT_POSITIONS 10040 // The number of open positions can be limited (e.g. Netting, Hedging). +#endif +// Runtime Errors (@see: https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes) +// General error codes. +#ifndef ERR_SUCCESS +#define ERR_SUCCESS 0 // The operation completed successfully. +#endif +#define ERR_NO_MQLERROR 4000 +#ifndef ERR_INTERNAL_ERROR +#define ERR_INTERNAL_ERROR 4001 // Operating system error. +#endif +#define ERR_WRONG_INTERNAL_PARAMETER 4002 // Wrong parameter in the inner call of the client terminal function. +//#define ERR_INVALID_PARAMETER 4003 // Wrong parameter when calling the system function. +#define ERR_NOT_ENOUGH_MEMORY 4004 // Not enough memory to perform the system function. +// The structure contains objects of strings and/or dynamic arrays and/or structure of such objects and/or classes. +#define ERR_STRUCT_WITHOBJECTS_ORCLASS 4005 +#define ERR_INVALID_ARRAY 4006 // Array of a wrong type, wrong size, or a damaged object of a dynamic array. +#define ERR_ARRAY_RESIZE_ERROR 4007 // Not enough memory for the relocation of an array. +#define ERR_STRING_RESIZE_ERROR 4008 // Not enough memory for the relocation of string. +#define ERR_NOTINITIALIZED_STRING 4009 // Not initialized string. +#define ERR_INVALID_DATETIME 4010 // Invalid date and/or time. +#define ERR_ARRAY_BAD_SIZE 4011 // Requested array size exceeds 2 GB. +#ifndef ERR_INVALID_POINTER +#define ERR_INVALID_POINTER 4012 // Wrong pointer. +#endif +#define ERR_INVALID_POINTER_TYPE 4013 // Wrong type of pointer. +#define ERR_FUNCTION_NOT_ALLOWED 4014 // Function is not allowed for call. +#define ERR_RESOURCE_NAME_DUPLICATED 4015 // The names of the dynamic and the static resource match. +#ifndef ERR_RESOURCE_NOT_FOUND +#define ERR_RESOURCE_NOT_FOUND 4016 // Resource with this name has not been found in EX5. +#endif +#define ERR_RESOURCE_UNSUPPOTED_TYPE 4017 // Unsupported resource type or its size exceeds 16 Mb. +#define ERR_RESOURCE_NAME_IS_TOO_LONG 4018 // The resource name exceeds 63 characters. +// Charts. +#define ERR_CHART_WRONG_ID 4101 // Wrong chart ID. +#define ERR_CHART_NO_REPLY 4102 // Chart does not respond. +#ifndef ERR_CHART_NOT_FOUND +#define ERR_CHART_NOT_FOUND 4103 // Chart not found. +#endif +#define ERR_CHART_NO_EXPERT 4104 // No Expert Advisor in the chart that could handle the event. +#define ERR_CHART_CANNOT_OPEN 4105 // Chart opening error. +#define ERR_CHART_CANNOT_CHANGE 4106 // Failed to change chart symbol and period. +#define ERR_CHART_WRONG_PARAMETER 4107 // Error value of the parameter for the function of working with charts. +#define ERR_CHART_CANNOT_CREATE_TIMER 4108 // Failed to create timer. +#define ERR_CHART_WRONG_PROPERTY 4109 // Wrong chart property ID. +#define ERR_CHART_SCREENSHOT_FAILED 4110 // Error creating screenshots. +#define ERR_CHART_NAVIGATE_FAILED 4111 // Error navigating through chart. +#define ERR_CHART_TEMPLATE_FAILED 4112 // Error applying template. +#define ERR_CHART_WINDOW_NOT_FOUND 4113 // Subwindow containing the indicator was not found. +#define ERR_CHART_INDICATOR_CANNOT_ADD 4114 // Error adding an indicator to chart. +#define ERR_CHART_INDICATOR_CANNOT_DEL 4115 // Error deleting an indicator from the chart. +#define ERR_CHART_INDICATOR_NOT_FOUND 4116 // Indicator not found on the specified chart. +// Graphical Objects. +#define ERR_OBJECT_ERROR 4201 // Error working with a graphical object. +#define ERR_OBJECT_NOT_FOUND 4202 // Graphical object was not found. +#define ERR_OBJECT_WRONG_PROPERTY 4203 // Wrong ID of a graphical object property. +#define ERR_OBJECT_GETDATE_FAILED 4204 // Unable to get date corresponding to the value. +#define ERR_OBJECT_GETVALUE_FAILED 4205 // Unable to get value corresponding to the date. +// MarketInfo. +#define ERR_MARKET_UNKNOWN_SYMBOL 4301 // Unknown symbol. +#define ERR_MARKET_NOT_SELECTED 4302 // Symbol is not selected in MarketWatch. +#define ERR_MARKET_WRONG_PROPERTY 4303 // Wrong identifier of a symbol property. +#define ERR_MARKET_LASTTIME_UNKNOWN 4304 // Time of the last tick is not known (no ticks). +#define ERR_MARKET_SELECT_ERROR 4305 // Error adding or deleting a symbol in MarketWatch. +// History Access. +#define ERR_HISTORY_NOT_FOUND 4401 // Requested history not found. +#define ERR_HISTORY_WRONG_PROPERTY 4402 // Wrong ID of the history property. +#define ERR_HISTORY_TIMEOUT 4403 // Exceeded history request timeout. +#define ERR_HISTORY_BARS_LIMIT 4404 // Number of requested bars limited by terminal settings. +#define ERR_HISTORY_LOAD_ERRORS 4405 // Multiple errors when loading history. +#define ERR_HISTORY_SMALL_BUFFER 4407 // Receiving array is too small to store all requested data. +// Global_Variables. +#define ERR_GLOBALVARIABLE_NOT_FOUND 4501 // Global variable of the client terminal is not found. +#define ERR_GLOBALVARIABLE_EXISTS 4502 // Global variable of the client terminal with the same name already exists. +#define ERR_MAIL_SEND_FAILED 4510 // Email sending failed. +#define ERR_PLAY_SOUND_FAILED 4511 // Sound playing failed. +#define ERR_MQL5_WRONG_PROPERTY 4512 // Wrong identifier of the program property. +#define ERR_TERMINAL_WRONG_PROPERTY 4513 // Wrong identifier of the terminal property. +#define ERR_FTP_SEND_FAILED 4514 // File sending via ftp failed. +#define ERR_NOTIFICATION_SEND_FAILED 4515 // Failed to send a notification. +#define ERR_NOTIFICATION_WRONG_PARAMETER 4516 // Invalid parameter for sending a notification. +#define ERR_NOTIFICATION_WRONG_SETTINGS 4517 // Wrong settings of notifications in the terminal +#ifndef ERR_NOTIFICATION_TOO_FREQUENT +#define ERR_NOTIFICATION_TOO_FREQUENT 4518 // Too frequent sending of notifications. +#endif +#ifndef ERR_FTP_NOSERVER +#define ERR_FTP_NOSERVER 4519 // FTP server is not specified. +#endif +#ifndef ERR_FTP_NOLOGIN +#define ERR_FTP_NOLOGIN 4520 // FTP login is not specified. +#endif +#ifndef ERR_FTP_FILE_ERROR +#define ERR_FTP_FILE_ERROR 4521 // File not found in the MQL5\Files directory to send on FTP server. +#endif +#ifndef ERR_FTP_CONNECT_FAILED +#define ERR_FTP_CONNECT_FAILED 4522 // FTP connection failed. +#endif +#ifndef ERR_FTP_CHANGEDIR +#define ERR_FTP_CHANGEDIR 4523 // FTP path not found on server. +#endif +#ifndef ERR_FTP_CLOSED +#define ERR_FTP_CLOSED 4524 // FTP connection closed. +#endif +// Custom Indicator Buffers. +#define ERR_BUFFERS_NO_MEMORY 4601 // Not enough memory for the distribution of indicator buffers. +#define ERR_BUFFERS_WRONG_INDEX 4602 // Wrong indicator buffer index. +// Custom Indicator Properties. +#define ERR_CUSTOM_WRONG_PROPERTY 4603 // Wrong ID of the custom indicator property. +// Account. +#define ERR_ACCOUNT_WRONG_PROPERTY 4701 // Wrong account property ID. +#define ERR_TRADE_WRONG_PROPERTY 4751 // Wrong trade property ID. +#ifndef ERR_TRADE_DISABLED +#define ERR_TRADE_DISABLED 4752 // Trading by Expert Advisors prohibited. +#endif +#define ERR_TRADE_POSITION_NOT_FOUND 4753 // Position not found. +#define ERR_TRADE_ORDER_NOT_FOUND 4754 // Order not found. +#define ERR_TRADE_DEAL_NOT_FOUND 4755 // Deal not found. +#define ERR_TRADE_SEND_FAILED 4756 // Trade request sending failed. +// Indicators. +#define ERR_INDICATOR_UNKNOWN_SYMBOL 4801 // Unknown symbol. +#define ERR_INDICATOR_CANNOT_CREATE 4802 // Indicator cannot be created. +#define ERR_INDICATOR_NO_MEMORY 4803 // Not enough memory to add the indicator. +#define ERR_INDICATOR_CANNOT_APPLY 4804 // The indicator cannot be applied to another indicator. +#define ERR_INDICATOR_CANNOT_ADD 4805 // Error applying an indicator to chart. +#define ERR_INDICATOR_DATA_NOT_FOUND 4806 // Requested data not found. +#define ERR_INDICATOR_WRONG_HANDLE 4807 // Wrong indicator handle. +#define ERR_INDICATOR_WRONG_PARAMETERS 4808 // Wrong number of parameters when creating an indicator. +#define ERR_INDICATOR_PARAMETERS_MISSING 4809 // No parameters when creating an indicator. +#define ERR_INDICATOR_CUSTOM_NAME 4810 // The first parameter in the array must be the name of the custom indicator. +#define ERR_INDICATOR_PARAMETER_TYPE 4811 // Invalid parameter type in the array when creating an indicator. +#define ERR_INDICATOR_WRONG_INDEX 4812 // Wrong index of the requested indicator buffer. +// Depth of Market. +#define ERR_BOOKS_CANNOT_ADD 4901 // Depth Of Market can not be added. +#define ERR_BOOKS_CANNOT_DELETE 4902 // Depth Of Market can not be removed. +#define ERR_BOOKS_CANNOT_GET 4903 // The data from Depth Of Market can not be obtained. +#define ERR_BOOKS_CANNOT_SUBSCRIBE 4904 // Error in subscribing to receive new data from Depth Of Market. +// File Operations. +#define ERR_TOO_MANY_FILES 5001 // More than 64 files cannot be opened at the same time. +#define ERR_WRONG_FILENAME 5002 // Invalid file name. +#define ERR_TOO_LONG_FILENAME 5003 // Too long file name. +#ifndef ERR_CANNOT_OPEN_FILE +#define ERR_CANNOT_OPEN_FILE 5004 // File opening error. +#endif +#define ERR_FILE_CACHEBUFFER_ERROR 5005 // Not enough memory for cache to read. +#define ERR_CANNOT_DELETE_FILE 5006 // File deleting error. +#define ERR_INVALID_FILEHANDLE 5007 // A file with this handle was closed, or was not opening at all. +#define ERR_WRONG_FILEHANDLE 5008 // Wrong file handle. +#define ERR_FILE_NOTTOWRITE 5009 // The file must be opened for writing. +#define ERR_FILE_NOTTOREAD 5010 // The file must be opened for reading. +#define ERR_FILE_NOTBIN 5011 // The file must be opened as a binary one. +#define ERR_FILE_NOTTXT 5012 // The file must be opened as a text. +#define ERR_FILE_NOTTXTORCSV 5013 // The file must be opened as a text or CSV. +#define ERR_FILE_NOTCSV 5014 // The file must be opened as CSV. +#define ERR_FILE_READERROR 5015 // File reading error. +#define ERR_FILE_BINSTRINGSIZE 5016 // String size must be specified, because the file is opened as binary. +#define ERR_INCOMPATIBLE_FILE 5017 // A text file must be for string arrays, for other arrays - binary. +#ifndef ERR_FILE_IS_DIRECTORY +#define ERR_FILE_IS_DIRECTORY 5018 // This is not a file, this is a directory. +#endif +#ifndef ERR_FILE_NOT_EXIST +#define ERR_FILE_NOT_EXIST 5019 // File does not exist. +#endif +#ifndef ERR_FILE_CANNOT_REWRITE +#define ERR_FILE_CANNOT_REWRITE 5020 // File can not be rewritten. +#endif +#define ERR_WRONG_DIRECTORYNAME 5021 // Wrong directory name. +#define ERR_DIRECTORY_NOT_EXIST 5022 // Directory does not exist. +#define ERR_FILE_ISNOT_DIRECTORY 5023 // This is a file, not a directory. +#define ERR_CANNOT_DELETE_DIRECTORY 5024 // The directory cannot be removed. + +#define ERR_CANNOT_CLEAN_DIRECTORY 5025 // Failed to clear the directory (probably one or more files are blocked and removal operation failed). +#define ERR_FILE_WRITEERROR 5026 // Failed to write a resource to a file. +#define ERR_FILE_ENDOFFILE 5027 // Unable to read the next piece of data from a file. +// String Casting. +#define ERR_NO_STRING_DATE 5030 // No date in the string. +#define ERR_WRONG_STRING_DATE 5031 // Wrong date in the string. +#define ERR_WRONG_STRING_TIME 5032 // Wrong time in the string. +#define ERR_STRING_TIME_ERROR 5033 // Error converting string to date. +#define ERR_STRING_OUT_OF_MEMORY 5034 // Not enough memory for the string. +#define ERR_STRING_SMALL_LEN 5035 // The string length is less than expected. +#define ERR_STRING_TOO_BIGNUMBER 5036 // Too large number, more than ULONG_MAX. +#define ERR_WRONG_FORMATSTRING 5037 // Invalid format string. +#define ERR_TOO_MANY_FORMATTERS 5038 // Amount of format specifiers more than the parameters. +#define ERR_TOO_MANY_PARAMETERS 5039 // Amount of parameters more than the format specifiers. +#define ERR_WRONG_STRING_PARAMETER 5040 // Damaged parameter of string type. +#define ERR_STRINGPOS_OUTOFRANGE 5041 // Position outside the string. +#define ERR_STRING_ZEROADDED 5042 // 0 added to the string end, a useless operation. +#define ERR_STRING_UNKNOWNTYPE 5043 // Unknown data type when converting to a string. +#define ERR_WRONG_STRING_OBJECT 5044 // Damaged string object. +// Operations with Array. +#ifndef ERR_INCOMPATIBLE_ARRAYS +#define ERR_INCOMPATIBLE_ARRAYS \ + 5050 // Copying incompatible arrays. String array can be copied only to a string array, and a numeric array - in + // numeric array only. +#endif +#define ERR_SMALL_ASSERIES_ARRAY 5051 // The receiving array is declared as AS_SERIES, and it is of insufficient size. +#define ERR_SMALL_ARRAY 5052 // Too small array, the starting position is outside the array. +#define ERR_ZEROSIZE_ARRAY 5053 // An array of zero length. +#define ERR_NUMBER_ARRAYS_ONLY 5054 // Must be a numeric array. +#define ERR_ONEDIM_ARRAYS_ONLY 5055 // Must be a one-dimensional array. +#define ERR_SERIES_ARRAY 5056 // Timeseries cannot be used. +#define ERR_DOUBLE_ARRAY_ONLY 5057 // Must be an array of type double. +#define ERR_FLOAT_ARRAY_ONLY 5058 // Must be an array of type float. +#define ERR_LONG_ARRAY_ONLY 5059 // Must be an array of type int64. +#define ERR_INT_ARRAY_ONLY 5060 // Must be an array of type int. +#define ERR_SHORT_ARRAY_ONLY 5061 // Must be an array of type short. +#define ERR_CHAR_ARRAY_ONLY 5062 // Must be an array of type char. +// Operations with OpenCL. +#define ERR_OPENCL_NOT_SUPPORTED 5100 // OpenCL functions are not supported on this computer. +#define ERR_OPENCL_INTERNAL 5101 // Internal error occurred when running OpenCL. +#define ERR_OPENCL_INVALID_HANDLE 5102 // Invalid OpenCL handle. +#define ERR_OPENCL_CONTEXT_CREATE 5103 // Error creating the OpenCL context. +#define ERR_OPENCL_QUEUE_CREATE 5104 // Failed to create a run queue in OpenCL. +#define ERR_OPENCL_PROGRAM_CREATE 5105 // Error occurred when compiling an OpenCL program. +#define ERR_OPENCL_TOO_LONG_KERNEL_NAME 5106 // Too long kernel name (OpenCL kernel). +#define ERR_OPENCL_KERNEL_CREATE 5107 // Error creating an OpenCL kernel. +#define ERR_OPENCL_SET_KERNEL_PARAMETER 5108 // Error occurred when setting parameters for the OpenCL kernel. +#define ERR_OPENCL_EXECUTE 5109 // OpenCL program runtime error. +#define ERR_OPENCL_WRONG_BUFFER_SIZE 5110 // Invalid size of the OpenCL buffer. +#define ERR_OPENCL_WRONG_BUFFER_OFFSET 5111 // Invalid offset in the OpenCL buffer. +#define ERR_OPENCL_BUFFER_CREATE 5112 // Failed to create an OpenCL buffer. +// Operations with WebRequest. +#ifndef ERR_WEBREQUEST_INVALID_ADDRESS +#define ERR_WEBREQUEST_INVALID_ADDRESS 5200 // Invalid URL. +#endif +#ifndef ERR_WEBREQUEST_CONNECT_FAILED +#define ERR_WEBREQUEST_CONNECT_FAILED 5201 // Failed to connect to specified URL. +#endif +#ifndef ERR_WEBREQUEST_TIMEOUT +#define ERR_WEBREQUEST_TIMEOUT 5202 // Timeout exceeded. +#endif +#ifndef ERR_WEBREQUEST_REQUEST_FAILED +#define ERR_WEBREQUEST_REQUEST_FAILED 5203 // HTTP request failed. +#endif +// User-Defined Errors. +#ifndef ERR_USER_ERROR_FIRST +#define ERR_USER_ERROR_FIRST 65536 // User defined errors start with this code. +#endif + +#endif // MQL5_MQH diff --git a/Order.define.h b/Platform/Order.define.h similarity index 85% rename from Order.define.h rename to Platform/Order.define.h index 0e1ec61ee..ff953d369 100644 --- a/Order.define.h +++ b/Platform/Order.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 | -//| https://github.com/EA31337 | +//| Copyright 201642023, EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Includes Order's defines. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #ifndef __MQL4__ // Mode constants. #define MODE_TRADES 0 diff --git a/Order.enum.h b/Platform/Order.enum.h similarity index 99% rename from Order.enum.h rename to Platform/Order.enum.h index 0bf12814b..ca53f9b69 100644 --- a/Order.enum.h +++ b/Platform/Order.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Order.mqh b/Platform/Order.h similarity index 93% rename from Order.mqh rename to Platform/Order.h index 5f4dabd30..026d0e7d4 100644 --- a/Order.mqh +++ b/Platform/Order.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,30 +25,31 @@ * Implements class for managing orders. */ -// Prevents processing this includes file for the second time. -#ifndef ORDER_MQH -#define ORDER_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Forward declaration. class SymbolInfo; // Includes. -#include "Convert.basic.h" -#include "Data.define.h" -#include "Data.struct.h" -#include "Deal.enum.h" -#include "Log.mqh" +#include "../Convert.basic.h" +#include "../Storage/Data.define.h" +#include "../Storage/Data.struct.h" +#include "../Platform/Deal.enum.h" +#include "../Log.mqh" #include "Order.define.h" #include "Order.enum.h" #include "Order.struct.h" -#include "Serializer/Serializer.define.h" -#include "Serializer/Serializer.h" -#include "Serializer/SerializerConverter.h" -#include "Serializer/SerializerJson.h" -#include "Std.h" -#include "String.mqh" -#include "SymbolInfo.mqh" -#include "Task/TaskAction.enum.h" +#include "../Serializer/Serializer.define.h" +#include "../Serializer/Serializer.h" +#include "../Serializer/SerializerConverter.h" +#include "../Serializer/SerializerJson.h" +#include "../Std.h" +#include "../Storage/String.h" +#include "../Exchange/SymbolInfo/SymbolInfo.h" +#include "../Task/TaskAction.enum.h" #include "Terminal.define.h" /* Defines for backward compatibility. */ @@ -117,7 +118,7 @@ class Order : public SymbolInfo { #ifndef __MQL4__ // Used for order selection in MQL5 & C++. - static unsigned long selected_ticket_id; + static uint64 selected_ticket_id; static ENUM_ORDER_SELECT_TYPE selected_ticket_type; #endif @@ -126,7 +127,7 @@ class Order : public SymbolInfo { * Class constructors. */ Order() {} - Order(long _ticket_no) { + Order(int64 _ticket_no) { odata.Set(ORDER_PROP_TICKET, _ticket_no); Refresh(true); } @@ -265,7 +266,7 @@ class Order : public SymbolInfo { /** * Sets an order property integer value. */ - void Set(ENUM_ORDER_PROPERTY_INTEGER _prop, long _value) { odata.Set(_prop, _value); } + void Set(ENUM_ORDER_PROPERTY_INTEGER _prop, int64 _value) { odata.Set(_prop, _value); } /** * Sets an order property string value. @@ -278,15 +279,15 @@ class Order : public SymbolInfo { * Is order is open. */ bool IsClosed(bool _refresh = false) { - if (odata.Get(ORDER_PROP_TIME_CLOSED) == 0) { + if (odata.Get(ORDER_PROP_TIME_CLOSED) == 0) { if (_refresh || ShouldRefresh()) { if (Order::TryOrderSelect(Order::OrderTicket(), SELECT_BY_TICKET, MODE_HISTORY)) { - odata.Set(ORDER_PROP_TIME_CLOSED, Order::OrderCloseTime()); + odata.Set(ORDER_PROP_TIME_CLOSED, Order::OrderCloseTime()); odata.Set(ORDER_PROP_REASON_CLOSE, ORDER_REASON_CLOSED_UNKNOWN); } } } - return odata.Get(ORDER_PROP_TIME_CLOSED) > 0; + return odata.Get(ORDER_PROP_TIME_CLOSED) > 0; } /** @@ -307,7 +308,7 @@ class Order : public SymbolInfo { for (int _ci = 0; _ci < _num; _ci++) { ENUM_ORDER_CONDITION _cond = oparams.Get(ORDER_PARAM_COND_CLOSE, _ci); ARRAY(DataParamEntry, _cond_args); - DataParamEntry _item0 = oparams.Get(ORDER_PARAM_COND_CLOSE_ARG_VALUE, _ci); + DataParamEntry _item0 = oparams.Get(ORDER_PARAM_COND_CLOSE_ARG_VALUE, _ci); ArrayPushObject(_cond_args, _item0); _result |= Order::CheckCondition(_cond, _cond_args); } @@ -322,7 +323,7 @@ class Order : public SymbolInfo { * Returns true when order values can be refreshed, otherwise false. */ bool ShouldRefresh() { - return odata.Get(ORDER_PROP_TIME_LAST_REFRESH) + oparams.Get(ORDER_PARAM_REFRESH_FREQ) <= + return odata.Get(ORDER_PROP_TIME_LAST_REFRESH) + oparams.Get(ORDER_PARAM_REFRESH_FREQ) <= TimeCurrent(); } @@ -333,7 +334,7 @@ class Order : public SymbolInfo { * Returns true when order stops can be updated, otherwise false. */ bool ShouldUpdate() { - return odata.Get(ORDER_PROP_TIME_LAST_UPDATE) + oparams.Get(ORDER_PARAM_UPDATE_FREQ) <= + return odata.Get(ORDER_PROP_TIME_LAST_UPDATE) + oparams.Get(ORDER_PARAM_UPDATE_FREQ) <= TimeCurrent(); } @@ -343,13 +344,13 @@ class Order : public SymbolInfo { * Check whether order is selected and it is same as the class one. */ bool IsSelected() { - unsigned long ticket_id = Order::OrderTicket(); + uint64 ticket_id = Order::OrderTicket(); bool is_selected; if (IsDummy()) { is_selected = true; } else { - is_selected = (odata.Get(ORDER_PROP_TICKET) > 0 && ticket_id == odata.Get(ORDER_PROP_TICKET)); + is_selected = (odata.Get(ORDER_PROP_TICKET) > 0 && ticket_id == odata.Get(ORDER_PROP_TICKET)); } ResetLastError(); @@ -374,7 +375,7 @@ class Order : public SymbolInfo { // and only for the symbols with Market or Exchange execution. // In case of partial filling a market or limit order with remaining volume is not canceled but processed further. ENUM_ORDER_TYPE_FILLING _result = ORDER_FILLING_RETURN; - const long _filling_mode = SymbolInfoStatic::GetFillingMode(_symbol); + const int64 _filling_mode = SymbolInfoStatic::GetFillingMode(_symbol); if ((_filling_mode & SYMBOL_FILLING_IOC) == SYMBOL_FILLING_IOC) { // Execute a deal with the volume maximally available in the market within that indicated in the order. // In case the order cannot be filled completely, the available volume of the order will be filled, and the @@ -401,10 +402,10 @@ class Order : public SymbolInfo { /** * Get allowed order filling modes. */ - static ENUM_ORDER_TYPE_FILLING GetOrderFilling(const string _symbol, const long _type) { + static ENUM_ORDER_TYPE_FILLING GetOrderFilling(const string _symbol, const int64 _type) { const ENUM_SYMBOL_TRADE_EXECUTION _exe_mode = (ENUM_SYMBOL_TRADE_EXECUTION)SymbolInfoStatic::SymbolInfoInteger(_symbol, SYMBOL_TRADE_EXEMODE); - const long _filling_mode = SymbolInfoStatic::GetFillingMode(_symbol); + const int64 _filling_mode = SymbolInfoStatic::GetFillingMode(_symbol); return ((_filling_mode == 0 || (_type >= ORDER_FILLING_RETURN) || ((_filling_mode & (_type + 1)) != _type + 1)) ? (((_exe_mode == SYMBOL_TRADE_EXECUTION_EXCHANGE) || (_exe_mode == SYMBOL_TRADE_EXECUTION_INSTANT)) ? ORDER_FILLING_RETURN @@ -431,7 +432,7 @@ class Order : public SymbolInfo { if (Order::TryOrderSelect(Order::OrderTicket(), SELECT_BY_TICKET, MODE_HISTORY)) { for (int i = HistoryDealsTotal() - 1; i >= 0; i--) { // https://www.mql5.com/en/docs/trading/historydealgetticket - const unsigned long _deal_ticket = HistoryDealGetTicket(i); + const uint64 _deal_ticket = HistoryDealGetTicket(i); const ENUM_DEAL_ENTRY _deal_entry = (ENUM_DEAL_ENTRY)HistoryDealGetInteger(_deal_ticket, DEAL_ENTRY); if (_deal_entry == DEAL_ENTRY_OUT || _deal_entry == DEAL_ENTRY_OUT_BY) { _result = HistoryDealGetDouble(_deal_ticket, DEAL_PRICE); @@ -456,11 +457,11 @@ class Order : public SymbolInfo { // http://docs.mql4.com/trading/orderopentime return (datetime)Order::OrderGetInteger(ORDER_TIME_SETUP); #else - long _result = 0; + int64 _result = 0; if (Order::TryOrderSelect(Order::OrderTicket(), SELECT_BY_TICKET, MODE_HISTORY)) { for (int i = HistoryDealsTotal() - 1; i >= 0; i--) { // https://www.mql5.com/en/docs/trading/historydealgetticket - const unsigned long _deal_ticket = HistoryDealGetTicket(i); + const uint64 _deal_ticket = HistoryDealGetTicket(i); const ENUM_DEAL_ENTRY _deal_entry = (ENUM_DEAL_ENTRY)HistoryDealGetInteger(_deal_ticket, DEAL_ENTRY); if (_deal_entry == DEAL_ENTRY_IN) { _result = HistoryDealGetInteger(_deal_ticket, DEAL_TIME); @@ -490,11 +491,11 @@ class Order : public SymbolInfo { return ::OrderCloseTime(); #else // __MQL5__ // @docs https://www.mql5.com/en/docs/trading/historydealgetinteger - long _result = 0; + int64 _result = 0; if (Order::TryOrderSelect(Order::OrderTicket(), SELECT_BY_TICKET, MODE_HISTORY)) { for (int i = HistoryDealsTotal() - 1; i >= 0; i--) { // https://www.mql5.com/en/docs/trading/historydealgetticket - const unsigned long _deal_ticket = HistoryDealGetTicket(i); + const uint64 _deal_ticket = HistoryDealGetTicket(i); const ENUM_DEAL_ENTRY _deal_entry = (ENUM_DEAL_ENTRY)HistoryDealGetInteger(_deal_ticket, DEAL_ENTRY); if (_deal_entry == DEAL_ENTRY_OUT || _deal_entry == DEAL_ENTRY_OUT_BY) { _result = HistoryDealGetInteger(_deal_ticket, DEAL_TIME); @@ -531,7 +532,7 @@ class Order : public SymbolInfo { if (Order::TryOrderSelect(Order::OrderTicket(), SELECT_BY_TICKET, MODE_HISTORY)) { for (int i = HistoryDealsTotal() - 1; i >= 0; i--) { // https://www.mql5.com/en/docs/trading/historydealgetticket - const unsigned long _deal_ticket = HistoryDealGetTicket(i); + const uint64 _deal_ticket = HistoryDealGetTicket(i); _result += _deal_ticket > 0 ? HistoryDealGetDouble(_deal_ticket, DEAL_COMMISSION) : 0; } } @@ -559,7 +560,7 @@ class Order : public SymbolInfo { if (Order::TryOrderSelect(Order::OrderTicket(), SELECT_BY_TICKET, MODE_HISTORY)) { for (int i = HistoryDealsTotal() - 1; i >= 0; i--) { // https://www.mql5.com/en/docs/trading/historydealgetticket - const unsigned long _deal_ticket = HistoryDealGetTicket(i); + const uint64 _deal_ticket = HistoryDealGetTicket(i); if (_deal_ticket > 0) { _result += HistoryDealGetDouble(_deal_ticket, DEAL_COMMISSION); _result += HistoryDealGetDouble(_deal_ticket, DEAL_FEE); @@ -613,8 +614,8 @@ class Order : public SymbolInfo { * - http://docs.mql4.com/trading/ordermagicnumber * - https://www.mql5.com/en/docs/trading/ordergetinteger */ - static long OrderMagicNumber() { return Order::OrderGetInteger(ORDER_MAGIC); } - unsigned long GetMagicNumber() { return orequest.magic; } + static int64 OrderMagicNumber() { return Order::OrderGetInteger(ORDER_MAGIC); } + uint64 GetMagicNumber() { return orequest.magic; } /** * Returns open price of the currently selected order/position. @@ -646,7 +647,7 @@ class Order : public SymbolInfo { if (Order::TryOrderSelect(Order::OrderTicket(), SELECT_BY_TICKET, MODE_HISTORY)) { for (int i = HistoryDealsTotal() - 1; i >= 0; i--) { // https://www.mql5.com/en/docs/trading/historydealgetticket - const unsigned long _deal_ticket = HistoryDealGetTicket(i); + const uint64 _deal_ticket = HistoryDealGetTicket(i); _result += _deal_ticket > 0 ? HistoryDealGetDouble(_deal_ticket, DEAL_PROFIT) : 0; } } @@ -714,7 +715,7 @@ class Order : public SymbolInfo { if (Order::TryOrderSelect(Order::OrderTicket(), SELECT_BY_TICKET, MODE_HISTORY)) { for (int i = HistoryDealsTotal() - 1; i >= 0; i--) { // https://www.mql5.com/en/docs/trading/historydealgetticket - const unsigned long _deal_ticket = HistoryDealGetTicket(i); + const uint64 _deal_ticket = HistoryDealGetTicket(i); _result += _deal_ticket > 0 ? HistoryDealGetDouble(_deal_ticket, DEAL_SWAP) : 0; } } @@ -755,14 +756,14 @@ class Order : public SymbolInfo { * @see https://docs.mql4.com/trading/orderticket * @see https://www.mql5.com/en/docs/trading/ordergetticket */ - static unsigned long OrderTicket() { + static uint64 OrderTicket() { #ifdef __MQL4__ return ::OrderTicket(); #else return selected_ticket_id; #endif } - // unsigned long GetTicket() const { return odata.Get(ORDER_PROP_TICKET); } + // uint64 GetTicket() const { return odata.Get(ORDER_PROP_TICKET); } /** * Returns order operation type of the currently selected order/position. @@ -798,9 +799,9 @@ class Order : public SymbolInfo { * Each executed order results in a deal that opens or modifies an already existing position. * The identifier of exactly this position is set to the executed order at this moment. */ - static unsigned long OrderGetPositionID() { + static uint64 OrderGetPositionID() { #ifdef __MQL4__ - unsigned long _ticket = ::OrderTicket(); + uint64 _ticket = ::OrderTicket(); for (int _pos = 0; _pos < OrdersTotal(); _pos++) { if (::OrderSelect(_pos, SELECT_BY_POS, MODE_TRADES) && ::OrderTicket() == _ticket) { return _pos; @@ -812,14 +813,14 @@ class Order : public SymbolInfo { #endif } /* @todo - unsigned long GetPositionID() { + uint64 GetPositionID() { #ifdef ORDER_POSITION_ID if (odata.position_id == 0) { OrderSelect(); Refresh(ORDER_POSITION_ID); } #endif - return odata.Get(ORDER_POSITION_ID); + return odata.Get(ORDER_POSITION_ID); } */ @@ -832,7 +833,7 @@ class Order : public SymbolInfo { * - https://www.mql5.com/en/docs/constants/structures/mqltraderequest * - https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties */ - static unsigned long OrderGetPositionBy() { + static uint64 OrderGetPositionBy() { #ifdef __MQL4__ // @todo /* @@ -848,14 +849,14 @@ class Order : public SymbolInfo { #endif } /* @todo - unsigned long GetOrderPositionBy() { + uint64 GetOrderPositionBy() { #ifdef ORDER_POSITION_BY_ID if (odata.position_by_id == 0) { OrderSelect(); Refresh(ORDER_POSITION_BY_ID); } #endif - return odata.Get(ORDER_POSITION_BY_ID); + return odata.Get(ORDER_POSITION_BY_ID); } */ @@ -864,7 +865,7 @@ class Order : public SymbolInfo { * * @see https://www.mql5.com/en/docs/trading/positiongetticket */ - unsigned long PositionGetTicket(int _index) { + uint64 PositionGetTicket(int _index) { #ifdef __MQL4__ if (::OrderSelect(_index, SELECT_BY_POS, MODE_TRADES)) { return ::OrderTicket(); @@ -888,9 +889,9 @@ class Order : public SymbolInfo { * Returns true if successful, otherwise false. * To get details about error, call the GetLastError() function. */ - static bool OrderClose(unsigned long _ticket, // Unique number of the order ticket. - double _lots, // Number of lots. - double _price, // Closing price. + static bool OrderClose(uint64 _ticket, // Unique number of the order ticket. + double _lots, // Number of lots. + double _price, // Closing price. int _deviation, // Maximal possible deviation/slippage from the requested price (in points). color _arrow_color = CLR_NONE // Color of the closing arrow on the chart. ) { @@ -991,7 +992,7 @@ class Order : public SymbolInfo { /** * Closes a position by an opposite one. */ - static bool OrderCloseBy(long _ticket, long _opposite, color _color) { + static bool OrderCloseBy(int64 _ticket, int64 _opposite, color _color) { #ifdef __MQL4__ return ::OrderCloseBy((int)_ticket, (int)_opposite, _color); #else @@ -1014,8 +1015,8 @@ class Order : public SymbolInfo { /** * Closes a position by an opposite one. */ - bool OrderCloseBy(long _opposite, color _color) { - bool _result = OrderCloseBy(odata.Get(ORDER_PROP_TICKET), _opposite, _color); + bool OrderCloseBy(int64 _opposite, color _color) { + bool _result = OrderCloseBy(odata.Get(ORDER_PROP_TICKET), _opposite, _color); if (_result) { odata.Set(ORDER_PROP_REASON_CLOSE, ORDER_REASON_CLOSED_BY_OPPOSITE); } @@ -1027,7 +1028,7 @@ class Order : public SymbolInfo { * * @see: https://docs.mql4.com/trading/orderdelete */ - static bool OrderDelete(unsigned long _ticket, color _color = color()) { + static bool OrderDelete(uint64 _ticket, color _color = color()) { #ifdef __MQL4__ return ::OrderDelete((int)_ticket, _color); #else @@ -1042,7 +1043,7 @@ class Order : public SymbolInfo { #endif } bool OrderDelete(ENUM_ORDER_REASON_CLOSE _reason = ORDER_REASON_CLOSED_UNKNOWN) { - bool _result = Order::OrderDelete(odata.Get(ORDER_PROP_TICKET)); + bool _result = Order::OrderDelete(odata.Get(ORDER_PROP_TICKET)); if (_result) { odata.Set(ORDER_PROP_REASON_CLOSE, _reason); } @@ -1054,7 +1055,7 @@ class Order : public SymbolInfo { * * @see http://docs.mql4.com/trading/ordermodify */ - static bool OrderModify(unsigned long _ticket, // Ticket of the position. + static bool OrderModify(uint64 _ticket, // Ticket of the position. double _price, // Price. double _stoploss, // Stop loss. double _takeprofit, // Take profit. @@ -1083,7 +1084,7 @@ class Order : public SymbolInfo { #endif } bool OrderModify(double _sl, double _tp, double _price = 0, datetime _expiration = 0) { - if (odata.Get(ORDER_PROP_TIME_CLOSED) > 0) { + if (odata.Get(ORDER_PROP_TIME_CLOSED) > 0) { // Ignore change for already closed orders. return false; } else if (_sl == odata.Get(ORDER_SL) && _tp == odata.Get(ORDER_TP) && @@ -1091,8 +1092,8 @@ class Order : public SymbolInfo { // Ignore change for the same values. return false; } - bool _result = Order::OrderModify(odata.Get(ORDER_PROP_TICKET), _price, _sl, _tp, _expiration); - long _last_error = GetLastError(); + bool _result = Order::OrderModify(odata.Get(ORDER_PROP_TICKET), _price, _sl, _tp, _expiration); + int64 _last_error = GetLastError(); if (_result && OrderSelect()) { // Updating expected values. odata.Set(ORDER_SL, _sl); @@ -1106,9 +1107,10 @@ class Order : public SymbolInfo { if (IsClosed()) { Refresh(); } else { - GetLogger() PTR_DEREF Warning(StringFormat("Failed to modify order (#%d/p:%g/sl:%g/tp:%g/code:%d).", - odata.Get(ORDER_PROP_TICKET), _price, _sl, _tp, _last_error), - __FUNCTION_LINE__, ToCSV()); + GetLogger() + PTR_DEREF Warning(StringFormat("Failed to modify order (#%d/p:%g/sl:%g/tp:%g/code:%d).", + odata.Get(ORDER_PROP_TICKET), _price, _sl, _tp, _last_error), + __FUNCTION_LINE__, ToCSV()); Refresh(ORDER_SL); Refresh(ORDER_TP); // TODO: Refresh(ORDER_PRI) @@ -1120,7 +1122,7 @@ class Order : public SymbolInfo { _result = false; } else { ologger.Error(StringFormat("Error: %d! Failed to modify non-existing order (#%d/p:%g/sl:%g/tp:%g).", - _last_error, odata.Get(ORDER_PROP_TICKET), _price, _sl, _tp), + _last_error, odata.Get(ORDER_PROP_TICKET), _price, _sl, _tp), __FUNCTION_LINE__, ToCSV()); } } @@ -1184,17 +1186,17 @@ class Order : public SymbolInfo { * Returns number of the ticket assigned to the order by the trade server * or -1 if it fails. */ - static long OrderSend(string _symbol, // Symbol. - int _cmd, // Operation. - double _volume, // Volume. - double _price, // Price. - unsigned long _deviation, // Deviation. - double _stoploss, // Stop loss. - double _takeprofit, // Take profit. - string _comment = NULL, // Comment. - unsigned long _magic = 0, // Magic number. - datetime _expiration = 0, // Pending order expiration. - color _arrow_color = clrNONE // Color. + static int64 OrderSend(string _symbol, // Symbol. + int _cmd, // Operation. + double _volume, // Volume. + double _price, // Price. + uint64 _deviation, // Deviation. + double _stoploss, // Stop loss. + double _takeprofit, // Take profit. + string _comment = NULL_STRING, // Comment. + uint64 _magic = 0, // Magic number. + datetime _expiration = 0, // Pending order expiration. + color _arrow_color = clrNONE // Color. ) { #ifdef __MQL4__ #ifdef __debug__ @@ -1234,7 +1236,7 @@ class Order : public SymbolInfo { if (!Order::OrderSend(_request, _result)) { return -1; } - return (long)_result.order; + return (int64)_result.order; #endif } static bool OrderSend(const MqlTradeRequest &_request, MqlTradeResult &_result, MqlTradeCheckResult &_result_check, @@ -1360,8 +1362,8 @@ class Order : public SymbolInfo { MqlTradeCheckResult _result_check = {0}; return Order::OrderSend(_request, _result, _result_check); } - long OrderSend() { - long _result = -1; + int64 OrderSend() { + int64 _result = -1; odata.ResetError(); oresult.retcode = ERR_NO_ERROR; oresult_check.retcode = ERR_NO_ERROR; @@ -1394,8 +1396,8 @@ class Order : public SymbolInfo { // However, this is not a sign of successful execution of a trade operation. // @see: https://www.mql5.com/en/docs/trading/ordersend // In order to obtain information about the error, call the GetLastError() function. - odata.Set(ORDER_PROP_TICKET, oresult.order); - _result = (long)oresult.order; + odata.Set(ORDER_PROP_TICKET, oresult.order); + _result = (int64)oresult.order; } else { // The function execution result is placed to structure MqlTradeResult, // whose retcode field contains the trade server return code. @@ -1450,7 +1452,7 @@ class Order : public SymbolInfo { * @return * Returns number of the fake ticket assigned to the order. */ - long OrderSendDummy() { + int64 OrderSendDummy() { static int _dummy_order_id = 0; odata.ResetError(); orequest.type_filling = orequest.type_filling ? orequest.type_filling : GetOrderFilling(orequest.symbol); @@ -1469,13 +1471,13 @@ class Order : public SymbolInfo { oresult.retcode = TRADE_RETCODE_DONE; // Mark trade operation as done. oresult.comment = orequest.comment; // Order comment. oresult.order = ++_dummy_order_id; // Assign sequential order id. Starts from 1. - odata.Set(ORDER_PROP_TICKET, oresult.order); + odata.Set(ORDER_PROP_TICKET, oresult.order); RefreshDummy(); odata.Set(ORDER_PROP_LAST_ERROR, oresult.retcode); // @todo Register order in a static dictionary order_id -> order for further select. - return (long)oresult.order; + return (int64)oresult.order; } /** @@ -1532,7 +1534,7 @@ class Order : public SymbolInfo { * * @see http://docs.mql4.com/trading/orderselect */ - static bool OrderSelect(unsigned long _index, int select, int pool = MODE_TRADES) { + static bool OrderSelect(uint64 _index, int select, int pool = MODE_TRADES) { ResetLastError(); #ifdef __MQL4__ return ::OrderSelect((int)_index, select, pool); @@ -1554,7 +1556,7 @@ class Order : public SymbolInfo { // HistoryOrderSelect(ticket) function, which clears the cache and re-fill it with only one order, in the // case of success. Recall that the value, returned from HistoryOrdersTotal() depends on the number of orders // in the cache. - unsigned long _ticket_id = HistoryOrderGetTicket((int)_index); + uint64 _ticket_id = HistoryOrderGetTicket((int)_index); if (_ticket_id != 0) { selected_ticket_type = ORDER_SELECT_TYPE_HISTORY; } else if (::HistoryOrderSelect(_ticket_id)) { @@ -1616,27 +1618,27 @@ class Order : public SymbolInfo { * * @see http://docs.mql4.com/trading/orderselect */ - static bool TryOrderSelect(unsigned long _index, int select, int pool = MODE_TRADES) { + static bool TryOrderSelect(uint64 _index, int select, int pool = MODE_TRADES) { bool result = OrderSelect(_index, select, pool); ResetLastError(); return result; } - static bool OrderSelectByTicket(unsigned long _ticket) { + static bool OrderSelectByTicket(uint64 _ticket) { return Order::OrderSelect(_ticket, SELECT_BY_TICKET, MODE_TRADES) || Order::OrderSelect(_ticket, SELECT_BY_TICKET, MODE_HISTORY); } - static bool TryOrderSelectByTicket(unsigned long _ticket) { + static bool TryOrderSelectByTicket(uint64 _ticket) { return Order::TryOrderSelect(_ticket, SELECT_BY_TICKET, MODE_TRADES) || Order::TryOrderSelect(_ticket, SELECT_BY_TICKET, MODE_HISTORY); } - bool OrderSelect() { return !IsSelected() ? Order::OrderSelectByTicket(odata.Get(ORDER_PROP_TICKET)) : true; } + bool OrderSelect() { return !IsSelected() ? Order::OrderSelectByTicket(odata.Get(ORDER_PROP_TICKET)) : true; } bool TryOrderSelect() { - return !IsSelected() ? Order::TryOrderSelectByTicket(odata.Get(ORDER_PROP_TICKET)) : true; + return !IsSelected() ? Order::TryOrderSelectByTicket(odata.Get(ORDER_PROP_TICKET)) : true; } - bool OrderSelectHistory() { return OrderSelect(odata.Get(ORDER_PROP_TICKET), MODE_HISTORY); } + bool OrderSelectHistory() { return OrderSelect(odata.Get(ORDER_PROP_TICKET), MODE_HISTORY); } /* Setters */ @@ -1659,7 +1661,7 @@ class Order : public SymbolInfo { ResetLastError(); // Checks if order is updated for the first time. - bool _is_init = odata.Get(ORDER_PRICE_OPEN) == 0 || odata.Get(ORDER_TIME_SETUP) == 0; + bool _is_init = odata.Get(ORDER_PRICE_OPEN) == 0 || odata.Get(ORDER_TIME_SETUP) == 0; // Update integer values. if (_is_init) { @@ -1692,9 +1694,9 @@ class Order : public SymbolInfo { } // Updates whether order is open or closed. - if (odata.Get(ORDER_PROP_TIME_CLOSED) == 0) { + if (odata.Get(ORDER_PROP_TIME_CLOSED) == 0) { // Updates close time. - odata.Set(ORDER_PROP_TIME_CLOSED, Order::OrderCloseTime()); + odata.Set(ORDER_PROP_TIME_CLOSED, Order::OrderCloseTime()); } if (IsOpen()) { @@ -1728,7 +1730,7 @@ class Order : public SymbolInfo { odata.ProcessLastError(); ResetLastError(); } - odata.Set(ORDER_PROP_TIME_LAST_REFRESH, TimeCurrent()); + odata.Set(ORDER_PROP_TIME_LAST_REFRESH, TimeCurrent()); return _result && _last_error == ERR_NO_ERROR; } @@ -1763,7 +1765,7 @@ class Order : public SymbolInfo { // @todo: More RefreshDummy(XXX); odata.ResetError(); - odata.Set(ORDER_PROP_TIME_LAST_REFRESH, TimeCurrent()); + odata.Set(ORDER_PROP_TIME_LAST_REFRESH, TimeCurrent()); odata.ProcessLastError(); return _result && GetLastError() == ERR_NO_ERROR; } @@ -1920,7 +1922,7 @@ class Order : public SymbolInfo { */ bool Refresh(ENUM_ORDER_PROPERTY_INTEGER _prop_id) { bool _result = false; - long _value = WRONG_VALUE; + int64 _value = WRONG_VALUE; ResetLastError(); switch (_prop_id) { case ORDER_MAGIC: @@ -2134,9 +2136,9 @@ class Order : public SymbolInfo { * - https://www.mql5.com/en/docs/trading/ordergetinteger * */ - static long OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id) { + static int64 OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id) { ResetLastError(); - long _result = 0; + int64 _result = 0; #ifdef __MQL4__ #ifdef __debug__ Print("OrderGetInteger(", EnumToString(property_id), ")..."); @@ -2225,9 +2227,9 @@ class Order : public SymbolInfo { return OrderGetParam(property_id, selected_ticket_type, ORDER_SELECT_DATA_TYPE_INTEGER, _result); #endif } - static bool OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id, long &_out) { + static bool OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id, int64 &_out) { #ifdef __MQL4__ - _out = (long)OrderGetInteger(property_id); + _out = (int64)OrderGetInteger(property_id); return true; #else return OrderGetParam(property_id, selected_ticket_type, ORDER_SELECT_DATA_TYPE_INTEGER, _out) >= 0; @@ -2376,15 +2378,15 @@ class Order : public SymbolInfo { * @param ENUM_ORDER_SELECT_TYPE type * Identifier of a property. * - * @param long& _out + * @param int64& _out * Reference to output value (the same as returned from the function). * - * @return long + * @return int64 * Returns the value of the property (same as for `_out` variable). * In case of error, information can be obtained using GetLastError() function. * */ - static long OrderGetValue(int property_id, ENUM_ORDER_SELECT_TYPE type, long &_out) { + static int64 OrderGetValue(int property_id, ENUM_ORDER_SELECT_TYPE type, int64 &_out) { switch (type) { case ORDER_SELECT_TYPE_NONE: return 0; @@ -2504,7 +2506,7 @@ class Order : public SymbolInfo { template static X OrderGetParam(int _prop_id, ENUM_ORDER_SELECT_TYPE _type, ENUM_ORDER_SELECT_DATA_TYPE _data_type, X &_out) { #ifndef __MQL4__ - long _long; + int64 _long; string _string; switch (selected_ticket_type) { case ORDER_SELECT_TYPE_NONE: @@ -2746,12 +2748,12 @@ class Order : public SymbolInfo { * Returns true when the condition is met. */ bool CheckCondition(ENUM_ORDER_CONDITION _cond, ARRAY_REF(DataParamEntry, _args)) { - // float _profit = (float)Get(ORDER_PROP_PROFIT_PIPS); + // float _profit = (float)Get(ORDER_PROP_PROFIT_PIPS); switch (_cond) { case ORDER_COND_IN_LOSS: - return Get(ORDER_PROP_PROFIT_PIPS) < (ArraySize(_args) > 0 ? -DataParamEntry::ToDouble(_args[0]) : 0); + return Get(ORDER_PROP_PROFIT_PIPS) < (ArraySize(_args) > 0 ? -DataParamEntry::ToDouble(_args[0]) : 0); case ORDER_COND_IN_PROFIT: - return Get(ORDER_PROP_PROFIT_PIPS) > (ArraySize(_args) > 0 ? DataParamEntry::ToDouble(_args[0]) : 0); + return Get(ORDER_PROP_PROFIT_PIPS) > (ArraySize(_args) > 0 ? DataParamEntry::ToDouble(_args[0]) : 0); case ORDER_COND_IS_CLOSED: return IsClosed(); case ORDER_COND_IS_OPEN: @@ -2759,7 +2761,7 @@ class Order : public SymbolInfo { case ORDER_COND_LIFETIME_GT_ARG: case ORDER_COND_LIFETIME_LT_ARG: if (ArraySize(_args) > 0) { - long _arg_value = DataParamEntry::ToInteger(_args[0]); + int64 _arg_value = DataParamEntry::ToInteger(_args[0]); switch (_cond) { case ORDER_COND_LIFETIME_GT_ARG: return TimeCurrent() - odata.Get(ORDER_TIME_SETUP) > _arg_value; @@ -2774,7 +2776,7 @@ class Order : public SymbolInfo { case ORDER_COND_PROP_LT_ARG: { if (ArraySize(_args) >= 2) { // First argument is enum value (order property). - long _prop_id = _args[0].integer_value; + int64 _prop_id = _args[0].integer_value; // Second argument is the actual value with compare with. switch (_args[1].type) { case TYPE_DOUBLE: @@ -2895,7 +2897,7 @@ class Order : public SymbolInfo { /** * Returns order details in text. */ - string ToString(ARRAY_REF(long, _props), ENUM_DATATYPE _type = TYPE_DOUBLE, string _dlm = ";") { + string ToString(ARRAY_REF(int64, _props), ENUM_DATATYPE _type = TYPE_DOUBLE, string _dlm = ";") { int i = 0; string _output = ""; switch (_type) { @@ -2906,7 +2908,7 @@ class Order : public SymbolInfo { break; case TYPE_LONG: for (i = 0; i < Array::ArraySize(_props); i++) { - _output += StringFormat("%d%s", odata.Get((ENUM_ORDER_PROPERTY_INTEGER)_props[i]), C_STR(_dlm)); + _output += StringFormat("%d%s", odata.Get((ENUM_ORDER_PROPERTY_INTEGER)_props[i]), C_STR(_dlm)); } break; case TYPE_STRING: @@ -2951,7 +2953,5 @@ class Order : public SymbolInfo { #ifdef __MQL5__ // Assigns values to static variables. ENUM_ORDER_SELECT_TYPE Order::selected_ticket_type = ORDER_SELECT_TYPE_NONE; -unsigned long Order::selected_ticket_id = 0; +uint64 Order::selected_ticket_id = 0; #endif - -#endif // ORDER_MQH diff --git a/Order.struct.h b/Platform/Order.struct.h similarity index 95% rename from Order.struct.h rename to Platform/Order.struct.h index 563871e63..1b83a8010 100644 --- a/Order.struct.h +++ b/Platform/Order.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,12 +31,12 @@ #endif // Includes. -#include "Data.struct.h" +#include "../Exchange/SymbolInfo/SymbolInfo.struct.static.h" +#include "../Serializer/Serializer.h" +#include "../Storage/Data.struct.h" #include "Order.enum.h" #include "Platform.extern.h" -#include "Serializer/Serializer.h" -#include "SymbolInfo.struct.static.h" -#include "Terminal.mqh" +#include "Terminal.h" #ifndef __MQL5__ /** @@ -59,29 +59,29 @@ struct MqlTradeCheckResult { // @see: https://www.mql5.com/en/docs/constants/structures/mqltraderequest struct MqlTradeRequest { ENUM_TRADE_REQUEST_ACTIONS action; // Trade operation type. - unsigned long magic; // Expert Advisor ID (magic number). - unsigned long order; // Order ticket. + uint64 magic; // Expert Advisor ID (magic number). + uint64 order; // Order ticket. string symbol; // Trade symbol. double volume; // Requested volume for a deal in lots. double price; // Price. double stoplimit; // StopLimit level of the order. double sl; // Stop Loss level of the order. double tp; // Take Profit level of the order. - unsigned long deviation; // Maximal possible deviation from the requested price. + uint64 deviation; // Maximal possible deviation from the requested price. ENUM_ORDER_TYPE type; // Order type. ENUM_ORDER_TYPE_FILLING type_filling; // Order execution type. ENUM_ORDER_TYPE_TIME type_time; // Order expiration type. datetime expiration; // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type. string comment; // Order comment. - unsigned long position; // Position ticket. - unsigned long position_by; // The ticket of an opposite position. + uint64 position; // Position ticket. + uint64 position_by; // The ticket of an opposite position. }; // @see: https://www.mql5.com/en/docs/constants/structures/mqltraderesult struct MqlTradeResult { unsigned int retcode; // Operation return code. - unsigned long deal; // Deal ticket, if it is performed. - unsigned long order; // Order ticket, if it is placed. + uint64 deal; // Deal ticket, if it is performed. + uint64 order; // Order ticket, if it is placed. double volume; // Deal volume, confirmed by broker. double price; // Deal price, confirmed by broker. double bid; // Current Bid price. @@ -130,7 +130,7 @@ struct OrderParams { bool _result = true; int _size = ArraySize(_cond_close); if (_size <= _index) { - _result &= ArrayResize(_cond_close, _size + 1); + _result &= ArrayResize(_cond_close, _size + 1) == _size + 1; } return _result; } @@ -232,10 +232,10 @@ struct OrderParams { */ struct OrderData { protected: - unsigned long magic; // Magic number. - unsigned long position_id; // Position ID. - unsigned long position_by_id; // Position By ID. - unsigned long ticket; // Ticket number. + uint64 magic; // Magic number. + uint64 position_id; // Position ID. + uint64 position_by_id; // Position By ID. + uint64 ticket; // Ticket number. ENUM_ORDER_STATE state; // State. string comment; // Comment. double commission; // Commission. @@ -248,12 +248,12 @@ struct OrderData { double swap; // Order cumulative swap. datetime time_closed; // Closed time. datetime time_done; // Execution/cancellation time. - long time_done_msc; // The time of execution/cancellation time (in msc). + int64 time_done_msc; // The time of execution/cancellation time (in msc). datetime time_expiration; // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type). datetime time_last_refresh; // Last refresh of order values. datetime time_last_update; // Last update of order stops. datetime time_setup; // Setup time. - long time_setup_msc; // The time of placing the order (in msc). + int64 time_setup_msc; // The time of placing the order (in msc). double total_fees; // Total fees. double sl; // Current Stop loss level of the order. double tp; // Current Take Profit level of the order. @@ -377,13 +377,13 @@ struct OrderData { case ORDER_STATE: return (T)state; case ORDER_TIME_EXPIRATION: - return (T)(long)time_expiration; + return (T)(int64)time_expiration; case ORDER_TIME_DONE: - return (T)(long)time_done; + return (T)(int64)time_done; case ORDER_TIME_DONE_MSC: return (T)time_done_msc; case ORDER_TIME_SETUP: - return (T)(long)time_setup; + return (T)(int64)time_setup; case ORDER_TIME_SETUP_MSC: return (T)time_setup_msc; case ORDER_TYPE_FILLING: @@ -539,10 +539,10 @@ struct OrderData { profit = (double)_value; return; case ORDER_PROP_REASON_CLOSE: - reason_close = (ENUM_ORDER_REASON_CLOSE)(long)_value; + reason_close = (ENUM_ORDER_REASON_CLOSE)(int64)_value; return; case ORDER_PROP_TICKET: - ticket = (unsigned long)_value; + ticket = (uint64)_value; return; case ORDER_PROP_TIME_CLOSED: time_closed = (datetime)_value; @@ -592,7 +592,7 @@ struct OrderData { } SetUserError(ERR_INVALID_PARAMETER); } - void Set(ENUM_ORDER_PROPERTY_INTEGER _prop_name, long _value) { + void Set(ENUM_ORDER_PROPERTY_INTEGER _prop_name, int64 _value) { switch (_prop_name) { case ORDER_TYPE: type = (ENUM_ORDER_TYPE)_value; @@ -659,7 +659,7 @@ struct OrderData { } /* template - T Set(long _prop_name) { + T Set(int64 _prop_name) { // MQL4 back-compatibility version for non-enum properties. return Set((ENUM_ORDER_PROPERTY_INTEGER)_prop_name); } @@ -913,7 +913,7 @@ struct OrderStatic { * @return * Identifying (magic) number of the currently selected order/position. */ - static long MagicNumber() { + static int64 MagicNumber() { #ifdef __MQL4__ return ::OrderMagicNumber(); #else @@ -980,7 +980,7 @@ struct OrderStatic { * - https://docs.mql4.com/trading/orderticket * - https://www.mql5.com/en/docs/trading/positiongetticket */ - static unsigned long Ticket() { + static uint64 Ticket() { #ifdef __MQL4__ return ::OrderTicket(); #else diff --git a/OrderQuery.h b/Platform/OrderQuery.h similarity index 85% rename from OrderQuery.h rename to Platform/OrderQuery.h index b81bf9799..ff6492839 100644 --- a/OrderQuery.h +++ b/Platform/OrderQuery.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,15 +25,20 @@ * Implements class for querying list of orders. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "DictStruct.mqh" -#include "Order.mqh" -#include "Refs.mqh" -#include "Std.h" +#include "../Refs.mqh" +#include "../Std.h" +#include "../Storage/Dict/DictStruct.h" +#include "Order.h" class OrderQuery : public Dynamic { protected: - DictStruct> *orders; + DictStruct> *orders; public: // Enumeration of comparison operators. @@ -48,7 +53,7 @@ class OrderQuery : public Dynamic { }; OrderQuery() {} - OrderQuery(DictStruct> &_orders) : orders(GET_PTR(_orders)) {} + OrderQuery(DictStruct> &_orders) : orders(GET_PTR(_orders)) {} /** * Calculates sum of order's value based on the property's enum. @@ -62,7 +67,7 @@ class OrderQuery : public Dynamic { template T CalcSumByProp(E _prop) { T _sum = 0; - for (DictStructIterator> iter = orders PTR_DEREF Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders PTR_DEREF Begin(); iter.IsValid(); ++iter) { _sum += iter.Value() REF_DEREF Get(_prop); } return _sum; @@ -77,7 +82,7 @@ class OrderQuery : public Dynamic { template T CalcSumByPropWithCond(E _prop, ECT _prop_cond_type, ECV _prop_cond_value) { T _sum = 0; - for (DictStructIterator> iter = orders PTR_DEREF Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders PTR_DEREF Begin(); iter.IsValid(); ++iter) { Order *_order = iter.Value().Ptr(); if (_order PTR_DEREF Get(_prop_cond_type) == _prop_cond_value) { _sum += _order PTR_DEREF Get(_prop); @@ -100,7 +105,7 @@ class OrderQuery : public Dynamic { return _order_ref_found; } _order_ref_found = orders PTR_DEREF Begin().Value(); - for (DictStructIterator> iter = orders PTR_DEREF Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders PTR_DEREF Begin(); iter.IsValid(); ++iter) { Ref _order_ref = iter.Value(); if (Compare(_order_ref REF_DEREF Get(_prop), _op, _order_ref_found REF_DEREF Get(_prop))) { _order_ref_found = _order_ref; @@ -122,7 +127,7 @@ class OrderQuery : public Dynamic { if (orders PTR_DEREF Size() == 0) { return _order_ref_found; } - for (DictStructIterator> iter = orders PTR_DEREF Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders PTR_DEREF Begin(); iter.IsValid(); ++iter) { Ref _order_ref = iter.Value(); if (Compare(_order_ref REF_DEREF Get(_prop), _op, _value)) { _order_ref_found = _order_ref; @@ -192,5 +197,5 @@ class OrderQuery : public Dynamic { * @return * Returns a pointer to the new instance. */ - static OrderQuery *GetInstance(DictStruct> &_orders) { return new OrderQuery(_orders); } + static OrderQuery *GetInstance(DictStruct> &_orders) { return new OrderQuery(_orders); } }; diff --git a/Orders.mqh b/Platform/Orders.h similarity index 95% rename from Orders.mqh rename to Platform/Orders.h index 2872f261d..3b95b2b17 100644 --- a/Orders.mqh +++ b/Platform/Orders.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,23 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Forward declarations. class Orders; // Includes. -#include "Account/Account.h" -#include "Chart.struct.static.h" -#include "Log.mqh" -#include "Math.h" -#include "Order.mqh" -#include "Terminal.mqh" -#include "Trade.struct.h" +#include "../Exchange/Account/Account.h" +#include "../Exchange/SymbolInfo/SymbolInfo.struct.static.h" +#include "../Log.mqh" +#include "../Math/Math.h" +#include "../Trade.struct.h" +#include "Chart/Chart.struct.static.h" +#include "Order.h" +#include "Terminal.h" /* Defines */ @@ -118,9 +124,9 @@ class Orders { /** * Finds order in the selected pool. */ - Order *SelectOrder(unsigned long _ticket) { + Order *SelectOrder(uint64 _ticket) { for (unsigned int _pos = ArraySize(orders); _pos >= 0; _pos--) { - if (orders[_pos] PTR_DEREF Get(ORDER_PROP_TICKET) == _ticket) { + if (orders[_pos] PTR_DEREF Get(ORDER_PROP_TICKET) == _ticket) { return orders[_pos]; } } @@ -130,7 +136,7 @@ class Orders { /** * Select order object by ticket. */ - Order *SelectByTicket(unsigned long _ticket) { + Order *SelectByTicket(uint64 _ticket) { Order *_order = SelectOrder(_ticket); if (_order != NULL) { return _order; @@ -149,7 +155,7 @@ class Orders { /** * Calculate number of lots for open positions. */ - static double GetOpenLots(string _symbol = NULL_STRING, long magic_number = 0, int magic_range = 0) { + static double GetOpenLots(string _symbol = NULL_STRING, int64 magic_number = 0, int magic_range = 0) { double total_lots = 0; // @todo: Convert to MQL5. _symbol = _symbol != NULL_STRING ? _symbol : _Symbol; diff --git a/Platform.define.h b/Platform/Platform.define.h similarity index 88% rename from Platform.define.h rename to Platform/Platform.define.h index 31d4919e3..d3ff58339 100644 --- a/Platform.define.h +++ b/Platform/Platform.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Platform/Platform.enum.h b/Platform/Platform.enum.h new file mode 100644 index 000000000..8c8b75309 --- /dev/null +++ b/Platform/Platform.enum.h @@ -0,0 +1,44 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#ifndef __MQL4__ +// @note Values differ from the documentation at +// https://www.mql5.com/en/docs/matrix/matrix_initialization/matrix_copyticks +// @see https://www.mql5.com/en/forum/448933 +enum ENUM_COPY_TICKS { + COPY_TICKS_INFO = 1, + COPY_TICKS_TRADE = 2, + COPY_TICKS_ALL = 3, + COPY_TICKS_VERTICAL = 32768, + COPY_TICKS_TIME_MS = 65536, + COPY_TICKS_BID = 131072, + COPY_TICKS_ASK = 262144, + COPY_TICKS_LAST = 524288, + COPY_TICKS_VOLUME = 1048576, + COPY_TICKS_FLAGS = 2097152 +}; +#endif diff --git a/Platform.extern.h b/Platform/Platform.extern.h similarity index 70% rename from Platform.extern.h rename to Platform/Platform.extern.h index 11edea715..f5b62bd7f 100644 --- a/Platform.extern.h +++ b/Platform/Platform.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,17 +25,23 @@ #pragma once // Includes. -#include "Account/Account.enum.h" -#include "Data.define.h" +#include + +#include "../Exchange/Account/Account.enum.h" +#include "../Storage/Data.define.h" +#include "../Storage/DateTime.h" +#include "../Storage/Object.extern.h" #include "Deal.enum.h" -#include "Object.extern.h" #include "Order.define.h" +#include "Order.enum.h" +#include "Platform.enum.h" #include "Terminal.enum.h" // Forward declarations. struct MqlTradeRequest; struct MqlTradeResult; struct MqlTradeCheckResult; +struct MqlTick; template double iCustom(string symbol, int timeframe, string name, Args... args) { @@ -43,10 +49,17 @@ double iCustom(string symbol, int timeframe, string name, Args... args) { return 0; } +/** + * Displays a message in a separate window. + * @docs: https://www.mql5.com/en/docs/common/alert + */ +extern void Alert(char* argument); +extern void Alert(string argument); + /** * Returns number of candles for a given symbol and time-frame. */ -extern int Bars(CONST_REF_TO(string) _symbol, ENUM_TIMEFRAMES _tf); +extern int Bars(CONST_REF_TO_SIMPLE(string) _symbol, ENUM_TIMEFRAMES _tf); /** * Returns the number of calculated data for the specified indicator. @@ -67,7 +80,12 @@ extern int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, extern int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, ARRAY_REF(double, close_array)); -extern unsigned int64 PositionGetTicket(int _index); +extern double iOpen(string symbol, int timeframe, int shift); +extern double iHigh(string symbol, int timeframe, int shift); +extern double iLow(string symbol, int timeframe, int shift); +extern double iClose(string symbol, int timeframe, int shift); + +extern uint64 PositionGetTicket(int _index); extern int64 PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id); @@ -77,13 +95,13 @@ extern string PositionGetString(ENUM_POSITION_PROPERTY_STRING property_id); extern int HistoryDealsTotal(); -extern unsigned int64 HistoryDealGetTicket(int index); +extern uint64 HistoryDealGetTicket(int index); -extern int64 HistoryDealGetInteger(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id); +extern int64 HistoryDealGetInteger(uint64 ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id); -extern double HistoryDealGetDouble(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id); +extern double HistoryDealGetDouble(uint64 ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id); -extern string HistoryDealGetString(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_STRING property_id); +extern string HistoryDealGetString(uint64 ticket_number, ENUM_DEAL_PROPERTY_STRING property_id); extern bool OrderSelect(int index); @@ -95,25 +113,25 @@ extern bool OrderSend(const MqlTradeRequest& request, MqlTradeResult& result); extern bool OrderCheck(const MqlTradeRequest& request, MqlTradeCheckResult& result); -extern unsigned int64 OrderGetTicket(int index); +extern uint64 OrderGetTicket(int index); -extern unsigned int64 HistoryOrderGetTicket(int index); +extern uint64 HistoryOrderGetTicket(int index); extern bool HistorySelectByPosition(int64 position_id); -extern bool HistoryDealSelect(unsigned int64 ticket); +extern bool HistoryDealSelect(uint64 ticket); extern int64 OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id); -extern int64 HistoryOrderGetInteger(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id); +extern int64 HistoryOrderGetInteger(uint64 ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id); extern double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE property_id); -extern double HistoryOrderGetDouble(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id); +extern double HistoryOrderGetDouble(uint64 ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id); string OrderGetString(ENUM_ORDER_PROPERTY_STRING property_id); -string HistoryOrderGetString(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_STRING property_id); +string HistoryOrderGetString(uint64 ticket_number, ENUM_ORDER_PROPERTY_STRING property_id); extern int PositionsTotal(); @@ -169,4 +187,16 @@ extern bool ObjectDelete(int64 chart_id, string name); extern int ObjectFind(int64 chart_id, string name); +int GetLastError() { return _LastError; } + +void ResetLastError() { _LastError = 0; } + +int CopyTicks(const string symbol_name, ARRAY_REF(MqlTick, ticks_array), unsigned int flags = COPY_TICKS_ALL, + int64 from = 0, unsigned int count = 0); + +int CopyTicksRange(const string symbol_name, ARRAY_REF(MqlTick, ticks_array), unsigned int flags = COPY_TICKS_ALL, + int64 from_msc = 0, int64 to_msc = 0); + +void Sleep(int milliseconds) { std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); } + #endif diff --git a/Platform.h b/Platform/Platform.h similarity index 83% rename from Platform.h rename to Platform/Platform.h index 8acf63a4e..101208e38 100644 --- a/Platform.h +++ b/Platform/Platform.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -36,7 +36,7 @@ /** * Returns number of candles for a given symbol and time-frame. */ -extern int Bars(CONST_REF_TO(string) _symbol, ENUM_TIMEFRAMES _tf); +extern int Bars(CONST_REF_TO_SIMPLE(string) _symbol, ENUM_TIMEFRAMES _tf); #endif @@ -46,23 +46,23 @@ extern int Bars(CONST_REF_TO(string) _symbol, ENUM_TIMEFRAMES _tf); * Current platform's static methods. */ -#include "DrawIndicator.mqh" -#include "Flags.h" -#include "Indicator/IndicatorData.h" -#include "Indicator/tests/classes/IndicatorTfDummy.h" -#include "Std.h" +#include "../Indicator/IndicatorData.h" +#include "../Indicator/tests/classes/IndicatorTfDummy.h" +#include "../Indicators/DrawIndicator.mqh" +#include "../Std.h" +#include "../Storage/Flags.struct.h" #ifdef __MQLBUILD__ - #include "Indicators/Tf/Indi_TfMt.h" - #include "Indicators/Tick/Indi_TickMt.mqh" + #include "../Indicators/Tf/Indi_TfMt.h" + #include "../Indicators/Tick/Indi_TickMt.h" #define PLATFORM_DEFAULT_INDICATOR_TICK Indi_TickMt #define PLATFORM_DEFAULT_INDICATOR_TF Indi_TfMt #else - #include "Indicators/Tick/Indi_TickProvider.h" + #include "../Indicators/Tick/Indi_TickProvider.h" #define PLATFORM_DEFAULT_INDICATOR_TICK Indi_TickRandom #define PLATFORM_DEFAULT_INDICATOR_TF IndicatorTfDummy #endif -#include "SymbolInfo.struct.static.h" +#include "../Exchange/SymbolInfo/SymbolInfo.struct.static.h" class Platform { // Whether Init() was already called. @@ -84,10 +84,10 @@ class Platform { static bool emitted_history; // List of added indicators. - static DictStruct> indis; + static DictStruct> indis; // List of default Candle/Tick indicators. - static DictStruct> indis_dflt; + static DictStruct> indis_dflt; // Result of the last tick. static bool last_tick_result; @@ -127,7 +127,7 @@ class Platform { // Checking starting periods and updating time to current one. time_flags = time.GetStartedPeriods(); - DictStructIterator> _iter; + DictStructIterator> _iter; last_tick_result = false; @@ -186,7 +186,7 @@ class Platform { /** * Returns dictionary of added indicators (keyed by unique id). */ - static DictStruct> *GetIndicators() { return &indis; } + static DictStruct> *GetIndicators() { return &indis; } /** * Adds indicator to be processed by platform. @@ -194,7 +194,7 @@ class Platform { static void Add(IndicatorData *_indi) { Ref _ref = _indi; - DictStructIterator> _iter; + DictStructIterator> _iter; for (_iter = indis_dflt.Begin(); _iter.IsValid(); ++_iter) { if (_iter.Value() == _ref) { Alert("Warning: ", _indi PTR_DEREF GetFullName(), @@ -210,7 +210,7 @@ class Platform { /** * Adds indicator to be processed by platform and tries to initialize its data source(s). */ - static void AddWithDefaultBindings(IndicatorData *_indi, CONST_REF_TO(string) _symbol, ENUM_TIMEFRAMES _tf) { + static void AddWithDefaultBindings(IndicatorData *_indi, string _symbol, ENUM_TIMEFRAMES _tf) { Add(_indi); BindDefaultDataSource(_indi, _symbol, _tf); } @@ -268,7 +268,7 @@ class Platform { /** * Returns number of candles for a given symbol and time-frame. */ - static int Bars(CONST_REF_TO(string) _symbol, ENUM_TIMEFRAMES _tf) { + static int Bars(CONST_REF_TO_SIMPLE(string) _symbol, ENUM_TIMEFRAMES _tf) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -295,7 +295,7 @@ class Platform { * Note that some indicators may work on custom set of buffers required from data source and not on Candle or Tick * indicator. */ - static void BindDefaultDataSource(IndicatorData *_indi, CONST_REF_TO(string) _symbol, ENUM_TIMEFRAMES _tf) { + static void BindDefaultDataSource(IndicatorData *_indi, CONST_REF_TO_SIMPLE(string) _symbol, ENUM_TIMEFRAMES _tf) { Flags _suitable_ds_types = _indi PTR_DEREF GetSuitableDataSourceTypes(); IndicatorData *_default_indi_candle = FetchDefaultCandleIndicator(_symbol, _tf); @@ -396,7 +396,7 @@ class Platform { /** * Returns default properties for given symbol for current platform. */ - static SymbolInfoProp FetchDefaultSymbolProps(CONST_REF_TO(string) _symbol) { + static SymbolInfoProp FetchDefaultSymbolProps(CONST_REF_TO_SIMPLE(string) _symbol) { SymbolInfoProp props; #ifdef __MQLBUILD__ props.pip_value = SymbolInfoStatic::GetPipValue(_symbol); @@ -424,7 +424,7 @@ class Platform { */ static string IndicatorsToString(int _shift = 0) { string _result; - for (DictStructIterator> _iter = indis.Begin(); _iter.IsValid(); ++_iter) { + for (DictStructIterator> _iter = indis.Begin(); _iter.IsValid(); ++_iter) { IndicatorDataEntry _entry = _iter.Value() REF_DEREF GetEntry(_shift); _result += _iter.Value() REF_DEREF GetFullName() + " = " + _entry.ToString() + "\n"; } @@ -453,6 +453,38 @@ class Platform { return period; } + /** + * Returns the point size of the current symbol in the quote currency. + * @see https://docs.mql4.com/check/point + */ + static double GetPoint() { + if (symbol == PLATFORM_WRONG_SYMBOL) { + RUNTIME_ERROR( + "Retrieving _Point variable or calling Point() outside the OnTick() of the currently ticking indicator is " + "prohibited!"); + } + + Alert("Error: Platform::GetPoint() is not yet implemented! Returning 0.01."); + DebugBreak(); + return 0.01; + } + + /** + * Returns the number of decimal digits determining the accuracy of price of the current chart symbol. + * @see https://docs.mql4.com/check/digits + */ + static int GetDigits() { + if (symbol == PLATFORM_WRONG_SYMBOL) { + RUNTIME_ERROR( + "Retrieving _Digits variable or calling Digits() outside the OnTick() of the currently ticking indicator is " + "prohibited!"); + } + + Alert("Error: Platform::GetDigits() is not yet implemented! Returning 2."); + DebugBreak(); + return 2; + } + private: /** * Sets symbol of the currently ticking indicator. @@ -473,8 +505,8 @@ bool Platform::time_clear_flags = true; int Platform::global_tick_index = 0; string Platform::symbol = PLATFORM_WRONG_SYMBOL; ENUM_TIMEFRAMES Platform::period = PLATFORM_WRONG_TIMEFRAME; -DictStruct> Platform::indis; -DictStruct> Platform::indis_dflt; +DictStruct> Platform::indis; +DictStruct> Platform::indis_dflt; #ifndef __MQL__ // Following methods must be there are they're externed in Platform.extern.h @@ -483,7 +515,7 @@ DictStruct> Platform::indis_dflt; /** * Returns number of candles for a given symbol and time-frame. */ -int Bars(CONST_REF_TO(string) _symbol, ENUM_TIMEFRAMES _tf) { return Platform::Bars(_symbol, _tf); } +int Bars(CONST_REF_TO_SIMPLE(string) _symbol, ENUM_TIMEFRAMES _tf) { return Platform::Bars(_symbol, _tf); } /** * Returns the number of calculated data for the specified indicator. @@ -498,7 +530,7 @@ int CopyBuffer(int indicator_handle, int buffer_num, int start_pos, int count, A return 0; } -unsigned int64 PositionGetTicket(int _index) { +uint64 PositionGetTicket(int _index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -523,22 +555,22 @@ int HistoryDealsTotal() { return 0; } -unsigned int64 HistoryDealGetTicket(int index) { +uint64 HistoryDealGetTicket(int index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -int64 HistoryDealGetInteger(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id) { +int64 HistoryDealGetInteger(uint64 ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -double HistoryDealGetDouble(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id) { +double HistoryDealGetDouble(uint64 ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -string HistoryDealGetString(unsigned int64 ticket_number, ENUM_DEAL_PROPERTY_STRING property_id) { +string HistoryDealGetString(uint64 ticket_number, ENUM_DEAL_PROPERTY_STRING property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns empty string."); return 0; } @@ -568,12 +600,12 @@ bool OrderCheck(const MqlTradeRequest &request, MqlTradeCheckResult &result) { return false; } -unsigned int64 OrderGetTicket(int index) { +uint64 OrderGetTicket(int index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } -unsigned int64 HistoryOrderGetTicket(int index) { +uint64 HistoryOrderGetTicket(int index) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -583,7 +615,7 @@ bool HistorySelectByPosition(int64 position_id) { return false; } -bool HistoryDealSelect(unsigned int64 ticket) { +bool HistoryDealSelect(uint64 ticket) { Print("Not yet implemented: ", __FUNCTION__, " returns false."); return false; } @@ -593,7 +625,7 @@ int64 OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id) { return 0; } -int64 HistoryOrderGetInteger(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id) { +int64 HistoryOrderGetInteger(uint64 ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -603,7 +635,7 @@ double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE property_id) { return 0; } -double HistoryOrderGetDouble(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id) { +double HistoryOrderGetDouble(uint64 ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } @@ -613,7 +645,7 @@ string OrderGetString(ENUM_ORDER_PROPERTY_STRING property_id) { return 0; } -string HistoryOrderGetString(unsigned int64 ticket_number, ENUM_ORDER_PROPERTY_STRING property_id) { +string HistoryOrderGetString(uint64 ticket_number, ENUM_ORDER_PROPERTY_STRING property_id) { Print("Not yet implemented: ", __FUNCTION__, " returns empty string."); return 0; } @@ -668,6 +700,26 @@ int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, return 0; } +double iOpen(string symbol, int timeframe, int shift) { + Print("Not yet implemented: ", __FUNCTION__, " returns 1.0."); + return 1.0; +} + +double iHigh(string symbol, int timeframe, int shift) { + Print("Not yet implemented: ", __FUNCTION__, " returns 1.0."); + return 1.0; +} + +double iLow(string symbol, int timeframe, int shift) { + Print("Not yet implemented: ", __FUNCTION__, " returns 1.0."); + return 1.0; +} + +double iClose(string symbol, int timeframe, int shift) { + Print("Not yet implemented: ", __FUNCTION__, " returns 1.0."); + return 1.0; +} + int ChartID() { return Platform::ChartID(); } bool OrderCalcMargin(ENUM_ORDER_TYPE _action, string _symbol, double _volume, double _price, double &_margin) { @@ -758,10 +810,6 @@ bool ObjectDelete(int64 chart_id, string name) { return false; } -int GetLastError() { return _LastError; } - -void ResetLastError() { _LastError = 0; } - int ObjectFind(int64 chart_id, string name) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; @@ -821,6 +869,12 @@ SymbolGetter::operator string() const { return Platform::GetSymbol(); } ENUM_TIMEFRAMES Period() { return Platform::GetPeriod(); } +double Point() { return Platform::GetPoint(); } +#define _Point (Point()) + +int Digits() { return Platform::GetDigits(); } +#define _Digits (Digits()) + datetime StructToTime(MqlDateTime &dt_struct) { tm ltm; ltm.tm_mday = dt_struct.day; @@ -840,29 +894,29 @@ datetime StructToTime(MqlDateTime &dt_struct) { /** * Will test given indicator class with platform-default data source bindings. */ -#define TEST_INDICATOR_DEFAULT_BINDINGS_PARAMS(C, PARAMS) \ - Ref indi = new C(PARAMS); \ - \ - int OnInit() { \ - Platform::Init(); \ - Platform::AddWithDefaultBindings(indi.Ptr(), "EURUSD", PERIOD_M1); \ - bool _result = true; \ - assertTrueOrFail(indi REF_DEREF IsValid(), "Error on IsValid!"); \ - return (_result && _LastError == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED); \ - } \ - \ - void OnTick() { \ - Platform::Tick(); \ - if (Platform::IsNewHour()) { \ - IndicatorDataEntry _entry = indi REF_DEREF GetEntry(); \ - bool _is_ready = indi REF_DEREF Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY)); \ - bool _is_valid = _entry.IsValid(); \ - Print(indi REF_DEREF ToString(), _is_ready ? " (Ready)" : " (Not yet ready)"); \ - if (_is_ready && !_is_valid) { \ - Print(indi REF_DEREF ToString(), " (Invalid entry!)"); \ - assertTrueOrExit(_entry.IsValid(), "Invalid entry!"); \ - } \ - } \ +#define TEST_INDICATOR_DEFAULT_BINDINGS_PARAMS(C, PARAMS) \ + Ref indi = new C(PARAMS); \ + \ + int OnInit() { \ + Platform::Init(); \ + Platform::AddWithDefaultBindings(indi.Ptr(), "EURUSD", PERIOD_M1); \ + bool _result = true; \ + assertTrueOrFail(indi REF_DEREF IsValid(), "Error on IsValid!"); \ + return (_result && _LastError == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED); \ + } \ + \ + void OnTick() { \ + Platform::Tick(); \ + if (Platform::IsNewHour()) { \ + IndicatorDataEntry _entry = indi REF_DEREF GetEntry(); \ + bool _is_ready = indi REF_DEREF Get(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_IS_READY)); \ + bool _is_valid = _entry.IsValid(); \ + Print(indi REF_DEREF ToString(), _is_ready ? " (Ready)" : " (Not yet ready)"); \ + if (_is_ready && !_is_valid) { \ + Print(indi REF_DEREF ToString(), " (Invalid entry!)"); \ + assertTrueOrExit(_entry.IsValid(), "Invalid entry!"); \ + } \ + } \ } #define TEST_INDICATOR_DEFAULT_BINDINGS(C) TEST_INDICATOR_DEFAULT_BINDINGS_PARAMS(C, ) diff --git a/PlatformTime.h b/Platform/PlatformTime.h similarity index 89% rename from PlatformTime.h rename to Platform/PlatformTime.h index 5cad5dd3c..73e16008c 100644 --- a/PlatformTime.h +++ b/Platform/PlatformTime.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2022, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,24 +20,28 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "DateTime.enum.h" +#include "../Storage/DateTime.enum.h" +#include "../Storage/DateTime.struct.h" /** * @file * Platform time retrieval. */ #ifndef __MQL__ -#pragma once // Includes. #include #include -#include "DateTime.struct.h" #endif -#include "Std.h" +#include "../Std.h" class PlatformTime { static MqlDateTime current_time; diff --git a/Draw.mqh b/Platform/Plot.h similarity index 72% rename from Draw.mqh rename to Platform/Plot.h index 1074333cd..7b36aa0ca 100644 --- a/Draw.mqh +++ b/Platform/Plot.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,13 +25,23 @@ * Group of functions intended for working with graphic objects relating to any specified chart. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Class dependencies. class Chart; -class Draw; +class Plot; // Includes. -#include "Chart.mqh" -#include "Data.define.h" +#include "../Storage/Data.define.h" +#include "../Storage/Object.extern.h" +#include "../Storage/Object.h" +#include "Platform.extern.h" +#include "Terminal.define.h" +#include "Terminal.enum.h" +#include "Terminal.extern.h" #ifndef __MQL4__ // Defines macros (for MQL4 backward compatibility). @@ -44,18 +54,18 @@ class Draw; #ifndef __MQL4__ // Defines global functions (for MQL4 backward compatibility). bool ObjectCreate(string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1) { - return Draw::ObjectCreate(0, _name, _otype, _swindow, _t1, _p1); + return Plot::ObjectCreate(0, _name, _otype, _swindow, _t1, _p1); } bool ObjectCreate(string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1, datetime _t2, double _p2) { - return Draw::ObjectCreate(0, _name, _otype, _swindow, _t1, _p1, _t2, _p2); + return Plot::ObjectCreate(0, _name, _otype, _swindow, _t1, _p1, _t2, _p2); } -bool ObjectDelete(string _name) { return Draw::ObjectDelete(_name); } -bool ObjectSet(string _name, int _prop_id, double _value) { return Draw::ObjectSet(_name, _prop_id, _value); } -int ObjectsTotal(int _type = EMPTY) { return Draw::ObjectsTotal(); } -string ObjectName(int _index) { return Draw::ObjectName(_index); } -void SetIndexLabel(int _index, string _text) { Draw::SetIndexLabel(_index, _text); } +bool ObjectDelete(string _name) { return Plot::ObjectDelete(_name); } +bool ObjectSet(string _name, int _prop_id, double _value) { return Plot::ObjectSet(_name, _prop_id, _value); } +int ObjectsTotal(int _type = EMPTY) { return Plot::ObjectsTotal(); } +string ObjectName(int _index) { return Plot::ObjectName(_index); } +void SetIndexLabel(int _index, string _text) { Plot::SetIndexLabel(_index, _text); } void SetIndexStyle(int _index, int _type, int _style = EMPTY, int _width = EMPTY, color _clr = CLR_NONE) { - Draw::SetIndexStyle(_index, _type, _style, _width, _clr); + Plot::SetIndexStyle(_index, _type, _style, _width, _clr); } #endif @@ -76,19 +86,19 @@ void SetIndexStyle(int _index, int _type, int _style = EMPTY, int _width = EMPTY #endif /** - * Class to provide drawing methods working with graphic objects. + * Class to provide plotting methods working with graphic objects. */ -class Draw : public Object { +class Plot : public Object { protected: // Variables. - long chart_id; + int64 chart_id; // Class variables. public: /** * Class constructor. */ - Draw(long _chart_id = 0) : chart_id(_chart_id != 0 ? _chart_id : ChartID()) {} + Plot(int64 _chart_id = 0) : chart_id(_chart_id != 0 ? _chart_id : ::ChartID()) {} /* Graphic object related methods */ @@ -100,10 +110,10 @@ class Draw : public Object { * @return * Name of the object is returned in case of success. */ - static string ObjectName(long _chart_id, int _pos, int _sub_window = -1, int _type = -1) { + static string ObjectName(int64 _chart_id, int _pos, int _sub_window = -1, int _type = -1) { return ::ObjectName(_chart_id, _pos, _sub_window, _type); } - static string ObjectName(int _index) { return Draw::ObjectName(0, _index); } + static string ObjectName(int _index) { return Plot::ObjectName(0, _index); } /** * Returns the number of objects in the specified chart, @@ -112,19 +122,19 @@ class Draw : public Object { * @return * The number of objects. */ - static int ObjectsTotal(long chart_id, int type = EMPTY, int window = -1) { + static int ObjectsTotal(int64 chart_id, int type = EMPTY, int window = -1) { #ifdef __MQL4__ return ::ObjectsTotal(chart_id, window, type); #else return ::ObjectsTotal(chart_id, window, type); #endif } - static int ObjectsTotal() { return Draw::ObjectsTotal(0); } + static int ObjectsTotal() { return Plot::ObjectsTotal(0); } /* Setters */ /** - * Sets drawing line description for showing in the DataWindow and in the tooltip. + * Sets plotting line description for showing in the DataWindow and in the tooltip. * * @return * If successful, returns true, otherwise false. @@ -167,7 +177,7 @@ class Draw : public Object { * - https://docs.mql4.com/objects/objectset * - https://docs.mql4.com/constants/objectconstants/enum_object_property */ - static bool ObjectSet(string name, int prop_id, double prop_value, long chart_id = 0) { + static bool ObjectSet(string name, int prop_id, double prop_value, int64 chart_id = 0) { #ifdef __MQL4__ return ::ObjectSet(name, prop_id, prop_value); #else // __MQL5__ @@ -196,10 +206,10 @@ class Draw : public Object { return ObjectSetDouble(chart_id, name, (ENUM_OBJECT_PROPERTY_DOUBLE)prop_id, (double)prop_value); case OBJPROP_RAY: // Boolean value to set/get ray flag of object. - return ObjectSetInteger(chart_id, name, OBJPROP_RAY_RIGHT, (long)prop_value); + return ObjectSetInteger(chart_id, name, OBJPROP_RAY_RIGHT, (int64)prop_value); case OBJPROP_FIBOLEVELS: // Integer value to set/get Fibonacci object level count. Can be from 0 to 32. - return ObjectSetInteger(chart_id, name, OBJPROP_LEVELS, (long)prop_value); + return ObjectSetInteger(chart_id, name, OBJPROP_LEVELS, (int64)prop_value); case OBJPROP_ARROWCODE: // Arrow code for the Arrow object (char). case OBJPROP_BACK: // Boolean value to set/get background drawing flag for object. case OBJPROP_COLOR: // Color value to set/get object color. @@ -214,10 +224,33 @@ class Draw : public Object { case OBJPROP_WIDTH: // Integer value to set/get object line width. Can be from 1 to 5. case OBJPROP_XDISTANCE: // The distance in pixels along the X axis from the binding corner (int). case OBJPROP_YDISTANCE: // The distance in pixels along the Y axis from the binding corner (int). - return ObjectSetInteger(chart_id, name, (ENUM_OBJECT_PROPERTY_INTEGER)prop_id, (long)prop_value); + return ObjectSetInteger(chart_id, name, (ENUM_OBJECT_PROPERTY_INTEGER)prop_id, (int64)prop_value); default: break; } + + // MQL4 enum values. + switch (prop_id) { + // Datetime value to set/get first coordinate time part. + case OBJPROP_TIME1: + return ObjectSetInteger(chart_id, name, OBJPROP_TIME, (int64)prop_value); + // Datetime value to set/get second coordinate time part. + case OBJPROP_TIME2: + return ObjectSetInteger(chart_id, name, OBJPROP_TIME, 1, (int64)prop_value); + // Datetime value to set/get third coordinate time part. + case OBJPROP_TIME3: + return ObjectSetInteger(chart_id, name, OBJPROP_TIME, 2, (int64)prop_value); + // Double value to set/get first coordinate price part. + case OBJPROP_PRICE1: + return ObjectSetDouble(chart_id, name, OBJPROP_PRICE, (double)prop_value); + // Double value to set/get second coordinate price part. + case OBJPROP_PRICE2: + return ObjectSetDouble(chart_id, name, OBJPROP_PRICE, 1, prop_value); + // Double value to set/get third coordinate price part. + case OBJPROP_PRICE3: + return ObjectSetDouble(chart_id, name, OBJPROP_PRICE, 2, prop_value); + } + return (false); #endif } @@ -227,7 +260,7 @@ class Draw : public Object { /** * Creates an object with the specified name, type, and the initial coordinates. */ - static bool ObjectCreate(long _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1) { + static bool ObjectCreate(int64 _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1) { #ifdef __MQL4__ // https://docs.mql4.com/objects/objectcreate return ::ObjectCreate(_name, _otype, _swindow, _t1, _p1); @@ -236,7 +269,7 @@ class Draw : public Object { return ::ObjectCreate(_cid, _name, _otype, _swindow, _t1, _p1); #endif } - static bool ObjectCreate(long _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1, + static bool ObjectCreate(int64 _cid, string _name, ENUM_OBJECT _otype, int _swindow, datetime _t1, double _p1, datetime _t2, double _p2) { #ifdef __MQL4__ // https://docs.mql4.com/objects/objectcreate @@ -261,7 +294,7 @@ class Draw : public Object { /** * Deletes object via name. */ - static bool ObjectDelete(long chart_id, string name) { + static bool ObjectDelete(int64 chart_id, string name) { #ifdef __MQL4__ // https://docs.mql4.com/objects/objectdelete return ::ObjectDelete(name); @@ -270,22 +303,22 @@ class Draw : public Object { return ::ObjectDelete(chart_id, name); #endif } - static bool ObjectDelete(string name) { return Draw::ObjectDelete(0, name); } + static bool ObjectDelete(string name) { return Plot::ObjectDelete(0, name); } /** - * Draw a vertical line. + * Plot a vertical line. */ bool DrawVLine(string oname, datetime tm) { - bool result = Draw::ObjectCreate(NULL, oname, OBJ_VLINE, 0, tm, 0); + bool result = Plot::ObjectCreate(NULL, oname, OBJ_VLINE, 0, tm, 0); if (!result) PrintFormat("%(): Can't create vertical line! code #", __FUNCTION__, GetLastError()); return (result); } /** - * Draw a horizontal line. + * Plot a horizontal line. */ bool DrawHLine(string oname, double value) { - bool result = Draw::ObjectCreate(NULL, oname, OBJ_HLINE, 0, 0, value); + bool result = Plot::ObjectCreate(NULL, oname, OBJ_HLINE, 0, 0, value); if (!result) PrintFormat("%(): Can't create horizontal line! code #", __FUNCTION__, GetLastError()); return (result); } @@ -294,30 +327,30 @@ class Draw : public Object { * Delete a vertical line. */ bool DeleteVertLine(string oname) { - bool result = Draw::ObjectDelete(NULL, oname); + bool result = Plot::ObjectDelete(NULL, oname); if (!result) PrintFormat("%(): Can't delete vertical line! code #", __FUNCTION__, GetLastError()); return (result); } /** - * Draw a line given the price. + * Plot a line given the price. */ void ShowLine(string oname, double price, int _colour = Yellow) { /** @TODO - Draw::ObjectCreate(chart_id, oname, OBJ_HLINE, 0, GetBarTime(), price); - Draw::ObjectSet(oname, OBJPROP_COLOR, _colour); - Draw::ObjectMove(oname, 0, GetBarTime(), price); + Plot::ObjectCreate(chart_id, oname, OBJ_HLINE, 0, GetBarTime(), price); + Plot::ObjectSet(oname, OBJPROP_COLOR, _colour); + Plot::ObjectMove(oname, 0, GetBarTime(), price); */ } /** - * Draw a trend line. + * Plot a trend line. */ bool TLine(string name, double p1, double p2, datetime d1, datetime d2, color clr = clrYellow, bool ray = false, int window = WINDOW_MAIN) { - if (ObjectFind(chart_id, name) >= 0 && Draw::ObjectMove(name, 0, d1, p1)) { - Draw::ObjectMove(name, 1, d2, p2); - } else if (!Draw::ObjectCreate(chart_id, name, OBJ_TREND, window, d1, p1, d2, p2)) { + if (ObjectFind(chart_id, name) >= 0 && Plot::ObjectMove(name, 0, d1, p1)) { + Plot::ObjectMove(name, 1, d2, p2); + } else if (!Plot::ObjectCreate(chart_id, name, OBJ_TREND, window, d1, p1, d2, p2)) { // Note: In case of error, check the message by GetLastError(). if (GetLastError() == 4206) { // No specified subwindow. @@ -326,11 +359,11 @@ class Draw : public Object { return false; } - if (!Draw::ObjectSet(name, OBJPROP_RAY, ray)) { + if (!Plot::ObjectSet(name, OBJPROP_RAY, ray)) { return false; } - if (clr && !Draw::ObjectSet(name, OBJPROP_COLOR, clr)) { + if (clr && !Plot::ObjectSet(name, OBJPROP_COLOR, clr)) { return false; } diff --git a/Terminal.define.h b/Platform/Terminal.define.h similarity index 98% rename from Terminal.define.h rename to Platform/Terminal.define.h index fcdc5e646..61ef792c3 100644 --- a/Terminal.define.h +++ b/Platform/Terminal.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Terminal's defines. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + /* Defines */ // Codepages. @@ -98,6 +103,7 @@ #define clrLightBlue 0x00ADD8E6 #define clrLightCoral 0x00F08080 #define clrLightCyan 0x00E0FFFF +#define clrLightGoldenrod 0x00EEDC82 #define clrLightGoldenrodYellow 0x00FAFAD2 #define clrLightGreen 0x0090EE90 #define clrLightGrey 0x00D3D3D3 diff --git a/Terminal.enum.h b/Platform/Terminal.enum.h similarity index 98% rename from Terminal.enum.h rename to Platform/Terminal.enum.h index a79712f4c..7a6f481f1 100644 --- a/Terminal.enum.h +++ b/Platform/Terminal.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,7 +31,7 @@ #endif // Includes. -#include "Indicator/Indicator.define.h" +#include "../Indicator/Indicator.define.h" // Defines user error enumeration. enum ENUM_USER_ERR { USER_ERR_INVALID_ARGUMENT }; diff --git a/Terminal.extern.h b/Platform/Terminal.extern.h similarity index 92% rename from Terminal.extern.h rename to Platform/Terminal.extern.h index e97e33ff0..937942ac7 100644 --- a/Terminal.extern.h +++ b/Platform/Terminal.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ #pragma once // Includes. -#include "String.mqh" +#include "../Storage/String.h" #include "Terminal.define.h" #include "Terminal.enum.h" diff --git a/Terminal.mqh b/Platform/Terminal.h similarity index 97% rename from Terminal.mqh rename to Platform/Terminal.h index a55001967..e78d1f125 100644 --- a/Terminal.mqh +++ b/Platform/Terminal.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -29,28 +29,26 @@ * - https://www.mql5.com/en/docs/chart_operations */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Forward declaration. class Terminal; -// Prevents processing this includes file for the second time. -#ifndef TERMINAL_MQH -#define TERMINAL_MQH - // Includes. -#include "Convert.mqh" -#include "Data.struct.h" -#include "Object.mqh" -#include "Refs.mqh" -#include "String.mqh" +#include "../Convert.mqh" +#include "../Refs.mqh" +#include "../Storage/Data.struct.h" +#include "../Storage/Object.h" +#include "../Storage/String.h" #include "Terminal.define.h" #include "Terminal.enum.h" #include "Terminal.extern.h" #include "Terminal.struct.h" -#ifdef __MQL5__ -// Provide backward compatibility for MQL4 in MQL5. -//#include "MQL4.mqh" -#else +#ifdef __MQL4__ // Provides forward compatibility for MQL5 in MQL4. #include "MQL5.mqh" #endif @@ -997,8 +995,8 @@ class Terminal : public Object { * Returns true when the condition is met. */ bool CheckCondition(ENUM_TERMINAL_CONDITION _cond, ARRAY_REF(DataParamEntry, _args)) { - // long _arg1l = ArraySize(_args) > 0 ? DataParamEntry::ToInteger(_args[0]) : WRONG_VALUE; - // long _arg2l = ArraySize(_args) > 1 ? DataParamEntry::ToInteger(_args[1]) : WRONG_VALUE; + // int64 _arg1l = ArraySize(_args) > 0 ? DataParamEntry::ToInteger(_args[0]) : WRONG_VALUE; + // int64 _arg2l = ArraySize(_args) > 1 ? DataParamEntry::ToInteger(_args[1]) : WRONG_VALUE; switch (_cond) { case TERMINAL_COND_IS_CONNECTED: return !IsConnected(); @@ -1007,7 +1005,7 @@ class Terminal : public Object { return false; } } - bool CheckCondition(ENUM_TERMINAL_CONDITION _cond, long _arg1) { + bool CheckCondition(ENUM_TERMINAL_CONDITION _cond, int64 _arg1) { ARRAY(DataParamEntry, _args); DataParamEntry _param1 = _arg1; ArrayPushObject(_args, _param1); @@ -1031,9 +1029,9 @@ class Terminal : public Object { * Returns true when the condition is met. */ bool ExecuteAction(ENUM_TERMINAL_ACTION _action, ARRAY_REF(MqlParam, _args)) { - // long _arg1l = ArraySize(_args) > 0 ? DataParamEntry::ToInteger(_args[0]) : WRONG_VALUE; - // long _arg2l = ArraySize(_args) > 1 ? DataParamEntry::ToInteger(_args[1]) : WRONG_VALUE; - // long _arg3l = ArraySize(_args) > 2 ? DataParamEntry::ToInteger(_args[2]) : WRONG_VALUE; + // int64 _arg1l = ArraySize(_args) > 0 ? DataParamEntry::ToInteger(_args[0]) : WRONG_VALUE; + // int64 _arg2l = ArraySize(_args) > 1 ? DataParamEntry::ToInteger(_args[1]) : WRONG_VALUE; + // int64 _arg3l = ArraySize(_args) > 2 ? DataParamEntry::ToInteger(_args[2]) : WRONG_VALUE; switch (_action) { case TERMINAL_ACTION_CRASH: delete THIS_PTR; @@ -1097,5 +1095,3 @@ class Terminal : public Object { // @docs: https://docs.mql4.com/chart_operations/windowexpertname string WindowExpertName(void) { return Terminal::WindowExpertName(); } #endif - -#endif // TERMINAL_MQH diff --git a/Terminal.struct.h b/Platform/Terminal.struct.h similarity index 88% rename from Terminal.struct.h rename to Platform/Terminal.struct.h index 3dd90148c..23dc189ae 100644 --- a/Terminal.struct.h +++ b/Platform/Terminal.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Web.mqh b/Platform/Web/Web.h similarity index 51% rename from Web.mqh rename to Platform/Web/Web.h index 92635b538..14d8af2aa 100644 --- a/Web.mqh +++ b/Platform/Web/Web.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -23,11 +23,13 @@ // Properties. #ifdef __MQL__ #property strict +#else +// Allows the preprocessor to include a header file when it is needed. +#pragma once #endif -// Prevents processing this includes file for the second time. -#ifndef WEB_MQH -#define WEB_MQH +// Includes. +#include "../../Platform/Platform.h" struct WebRequestParams { string method; @@ -37,18 +39,17 @@ struct WebRequestParams { string referer; int timeout; WebRequestParams(string _m, string _u, string _h = NULL, int _t = 500) - : method(_m), url(_u), headers(_h), timeout(_t) {}; + : method(_m), url(_u), headers(_h), timeout(_t){}; WebRequestParams(string _m, string _u, string _c, string _r = NULL, int _t = 500) - : method(_m), url(_u), cookie(_c), referer(_r), timeout(_t) {}; - WebRequestParams(string _u, string _h = NULL, int _t = 500) - : method("GET"), url(_u), headers(_h), timeout(_t) {}; + : method(_m), url(_u), cookie(_c), referer(_r), timeout(_t){}; + WebRequestParams(string _u, string _h = NULL, int _t = 500) : method("GET"), url(_u), headers(_h), timeout(_t){}; }; struct WebRequestResult { - char data[]; - char result[]; + ARRAY(char, data); + ARRAY(char, result); int error; - int http_code; // HTTP server response code or -1 for an error. + int http_code; // HTTP server response code or -1 for an error. string headers; }; @@ -56,39 +57,29 @@ struct WebRequestResult { * Implements Web class. */ class Web { + private: + public: + /** + * Class constructor. + */ + Web() {} - private: - - public: - - /** - * Class constructor. - */ - Web() { - } - - /** - * Web request. - * - * Note: Make sure to add URL to the list of allowed URLs in the Terminal. - */ - WebRequestResult Request(const WebRequestParams &_rp) { - ResetLastError(); - WebRequestResult _res; - if (StringLen(_rp.headers) > 0) { - _res.http_code = WebRequest( - _rp.method, _rp.url, _rp.headers, _rp.timeout, - _res.data, _res.result, _res.headers); - } - else { - int _size = 0; // @fixme: data[] array size in bytes. - _res.http_code = WebRequest( - _rp.method, _rp.url, _rp.cookie, _rp.referer, _rp.timeout, - _res.data, _size, _res.result, _res.headers); - } - _res.error = GetLastError(); - return _res; + /** + * Web request. + * + * Note: Make sure to add URL to the list of allowed URLs in the Terminal. + */ + WebRequestResult Request(const WebRequestParams &_rp) { + ResetLastError(); + WebRequestResult _res; + if (StringLen(_rp.headers) > 0) { + _res.http_code = WebRequest(_rp.method, _rp.url, _rp.headers, _rp.timeout, _res.data, _res.result, _res.headers); + } else { + int _size = 0; // @fixme: data[] array size in bytes. + _res.http_code = WebRequest(_rp.method, _rp.url, _rp.cookie, _rp.referer, _rp.timeout, _res.data, _size, + _res.result, _res.headers); } - + _res.error = GetLastError(); + return _res; + } }; -#endif diff --git a/Platform/Web/tests/Makefile b/Platform/Web/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Platform/Web/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Platform/Web/tests/Web.test.cpp b/Platform/Web/tests/Web.test.cpp new file mode 100644 index 000000000..66e9901f0 --- /dev/null +++ b/Platform/Web/tests/Web.test.cpp @@ -0,0 +1,60 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Web class. + */ + +// Includes. +#include "../../../Storage/String.h" + +// External functions. +extern int WebRequest(const string method, // HTTP method + const string url, // URL + const string cookie, // cookie + const string referer, // referer + int timeout, // timeout + ARRAY_REF(char, data), // the array of the HTTP message body + int data_size, // data[] array size in bytes + ARRAY_REF(char, result), // an array containing server response data + string &result_headers // headers of server response +); + +// External functions. +extern int WebRequest(const string method, // HTTP method + const string url, // URL + const string headers, // headers + int timeout, // timeout + ARRAY_REF(char, data), // the array of the HTTP message body + ARRAY_REF(char, result), // an array containing server response data + string &result_headers // headers of server response +); + +// Includes. +#include "../../Platform/Platform.h" +#include "../Web.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/WebTest.mq4 b/Platform/Web/tests/Web.test.mq4 similarity index 85% rename from tests/WebTest.mq4 rename to Platform/Web/tests/Web.test.mq4 index 470483cde..a3f0fc4eb 100644 --- a/tests/WebTest.mq4 +++ b/Platform/Web/tests/Web.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "WebTest.mq5" +#include "Web.test.mq5" diff --git a/tests/WebTest.mq5 b/Platform/Web/tests/Web.test.mq5 similarity index 88% rename from tests/WebTest.mq5 rename to Platform/Web/tests/Web.test.mq5 index e6ca627ac..9ec1b4b0f 100644 --- a/tests/WebTest.mq5 +++ b/Platform/Web/tests/Web.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,10 +25,10 @@ */ // Includes. -#include "../Convert.mqh" -#include "../Terminal.mqh" -#include "../Test.mqh" -#include "../Web.mqh" +#include "../../../Convert.mqh" +#include "../../Terminal.h" +#include "../../../Test.mqh" +#include "../Web.h" // Properties. #property strict diff --git a/Platform/tests/Makefile b/Platform/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Platform/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Platform/tests/Order.test.cpp b/Platform/tests/Order.test.cpp new file mode 100644 index 000000000..0cc7ffd52 --- /dev/null +++ b/Platform/tests/Order.test.cpp @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Order class. + */ + +// Includes. +#include "../Order.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/OrderTest.mq4 b/Platform/tests/Order.test.mq4 similarity index 85% rename from tests/OrderTest.mq4 rename to Platform/tests/Order.test.mq4 index ff435bfa6..d16189621 100644 --- a/tests/OrderTest.mq4 +++ b/Platform/tests/Order.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "OrderTest.mq5" +#include "Order.test.mq5" diff --git a/tests/OrderTest.mq5 b/Platform/tests/Order.test.mq5 similarity index 94% rename from tests/OrderTest.mq5 rename to Platform/tests/Order.test.mq5 index fe52252a9..71c0df597 100644 --- a/tests/OrderTest.mq5 +++ b/Platform/tests/Order.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,12 +25,12 @@ */ // Includes. -#include "../Chart.mqh" -#include "../Order.mqh" +#include "../../Serializer/SerializerConverter.h" +#include "../../Serializer/SerializerJson.h" +#include "../../Test.mqh" +#include "../Chart/Chart.h" +#include "../Order.h" #include "../Platform.h" -#include "../Serializer/SerializerConverter.h" -#include "../Serializer/SerializerJson.h" -#include "../Test.mqh" // Global defines. #define MAX_ORDERS 10 @@ -86,7 +86,7 @@ void OnTick() { break; } assertFalseOrExit(_order.IsOpen(true), StringFormat("Order %d not closed!", _order.OrderTicket())); - assertTrueOrExit(_order.Get(ORDER_PROP_TIME_CLOSED) > 0, + assertTrueOrExit(_order.Get(ORDER_PROP_TIME_CLOSED) > 0, StringFormat("Order %d close time not correct!", _order.OrderTicket())); } bar_processed++; diff --git a/Platform/tests/OrderQuery.test.cpp b/Platform/tests/OrderQuery.test.cpp new file mode 100644 index 000000000..5b39ef57b --- /dev/null +++ b/Platform/tests/OrderQuery.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of OrderQuery class. + */ + +// Includes. +#include "../OrderQuery.h" + +#include "../Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/OrderQueryTest.mq4 b/Platform/tests/OrderQuery.test.mq4 similarity index 85% rename from tests/OrderQueryTest.mq4 rename to Platform/tests/OrderQuery.test.mq4 index 50f752d0a..0650ec9a0 100644 --- a/tests/OrderQueryTest.mq4 +++ b/Platform/tests/OrderQuery.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "OrderQueryTest.mq5" +#include "OrderQuery.test.mq5" diff --git a/tests/OrderQueryTest.mq5 b/Platform/tests/OrderQuery.test.mq5 similarity index 96% rename from tests/OrderQueryTest.mq5 rename to Platform/tests/OrderQuery.test.mq5 index dc5df5aeb..b25dcd707 100644 --- a/tests/OrderQueryTest.mq5 +++ b/Platform/tests/OrderQuery.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,13 +25,13 @@ */ // Includes. +#include "../../Test.mqh" #include "../OrderQuery.h" -#include "../Test.mqh" bool Test01() { bool _result = true; // Initialize orders. - DictStruct> orders; + DictStruct> orders; // Populate orders. for (int i = -10; i <= 10; i++) { OrderData _odata; diff --git a/Platform/tests/Orders.test.cpp b/Platform/tests/Orders.test.cpp new file mode 100644 index 000000000..daec152fc --- /dev/null +++ b/Platform/tests/Orders.test.cpp @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Orders class. + */ + +// Includes. +#include "../Orders.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/OrdersTest.mq4 b/Platform/tests/Orders.test.mq4 similarity index 85% rename from tests/OrdersTest.mq4 rename to Platform/tests/Orders.test.mq4 index ad295291d..e565a0c0d 100644 --- a/tests/OrdersTest.mq4 +++ b/Platform/tests/Orders.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,4 +26,4 @@ */ // Includes. -#include "OrdersTest.mq5" +#include "Orders.test.mq5" diff --git a/tests/OrdersTest.mq5 b/Platform/tests/Orders.test.mq5 similarity index 86% rename from tests/OrdersTest.mq5 rename to Platform/tests/Orders.test.mq5 index e95bcb2f0..fe49af6f0 100644 --- a/tests/OrdersTest.mq5 +++ b/Platform/tests/Orders.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -27,7 +27,7 @@ */ // Includes. -#include "../Orders.mqh" +#include "../Orders.h" /** * Implements OnInit(). diff --git a/Platform/tests/Platform.test.cpp b/Platform/tests/Platform.test.cpp new file mode 100644 index 000000000..f4a0fce4f --- /dev/null +++ b/Platform/tests/Platform.test.cpp @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Platform class. + */ + +// Includes. +#include "../Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Platform/tests/Platform.test.mq4 b/Platform/tests/Platform.test.mq4 new file mode 100644 index 000000000..0de14c04b --- /dev/null +++ b/Platform/tests/Platform.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Platform class. + */ + +// Includes. +#include "Platform.test.mq5" diff --git a/Platform/tests/Platform.test.mq5 b/Platform/tests/Platform.test.mq5 new file mode 100644 index 000000000..f7df7c7a6 --- /dev/null +++ b/Platform/tests/Platform.test.mq5 @@ -0,0 +1,43 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Platform class. + */ + +// Includes. +#include "../../Test.mqh" +#include "../Platform.h" + +/** + * Implements OnInit(). + */ +int OnInit() { + bool _result = true; + // @todo: Write some tests. + return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED; +} + +/** + * Implements Tick event handler. + */ +void OnTick() {} diff --git a/Platform/tests/Plot.test.cpp b/Platform/tests/Plot.test.cpp new file mode 100644 index 000000000..eb1f2dd5a --- /dev/null +++ b/Platform/tests/Plot.test.cpp @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Plot class. + */ + +// Includes. +#include "../Plot.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/DictTest.mq4 b/Platform/tests/Plot.test.mq4 similarity index 87% rename from tests/DictTest.mq4 rename to Platform/tests/Plot.test.mq4 index 1f46ff282..7a91795da 100644 --- a/tests/DictTest.mq4 +++ b/Platform/tests/Plot.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,20 +9,20 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * @file - * Test functionality of Dict class. + * Test functionality of Plot class. */ // Includes. -#include "DictTest.mq5" +#include "Plot.test.mq5" diff --git a/Platform/tests/Plot.test.mq5 b/Platform/tests/Plot.test.mq5 new file mode 100644 index 000000000..30027b835 --- /dev/null +++ b/Platform/tests/Plot.test.mq5 @@ -0,0 +1,43 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Plot class. + */ + +// Includes. +#include "../../Test.mqh" +#include "../Plot.h" + +/** + * Implements OnInit(). + */ +int OnInit() { + bool _result = true; + // @todo: Write some tests. + return _result && GetLastError() == 0 ? INIT_SUCCEEDED : INIT_FAILED; +} + +/** + * Implements Tick event handler. + */ +void OnTick() {} diff --git a/Platform/tests/Terminal.test.cpp b/Platform/tests/Terminal.test.cpp new file mode 100644 index 000000000..df5b8f272 --- /dev/null +++ b/Platform/tests/Terminal.test.cpp @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Terminal class. + */ + +// Includes. +#include "../Terminal.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/TerminalTest.mq4 b/Platform/tests/Terminal.test.mq4 similarity index 85% rename from tests/TerminalTest.mq4 rename to Platform/tests/Terminal.test.mq4 index d092cd5eb..d41c95f2a 100644 --- a/tests/TerminalTest.mq4 +++ b/Platform/tests/Terminal.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "TerminalTest.mq5" +#include "Terminal.test.mq5" diff --git a/tests/TerminalTest.mq5 b/Platform/tests/Terminal.test.mq5 similarity index 91% rename from tests/TerminalTest.mq5 rename to Platform/tests/Terminal.test.mq5 index 0721111f3..a747334a6 100644 --- a/tests/TerminalTest.mq5 +++ b/Platform/tests/Terminal.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,9 +25,9 @@ */ // Includes. -#include "../Convert.mqh" -#include "../Terminal.mqh" -#include "../Test.mqh" +#include "../../Convert.mqh" +#include "../Terminal.h" +#include "../../Test.mqh" // Variables. Terminal *terminal; @@ -55,7 +55,7 @@ int OnInit() { assertTrueOrFail(StringLen(terminal.GetDataPath()) > 10, "Invalid data path?!"); assertTrueOrFail(StringLen(terminal.GetExpertPath()) > 10, "Invalid Expert path?!"); assertTrueOrFail(StringLen(terminal.GetTerminalPath()) > 10, "Invalid Terminal path?!"); - assertTrueOrFail(Terminal::WindowExpertName() == "TerminalTest", "Invalid EA name!"); + assertTrueOrFail(Terminal::WindowExpertName() == "Terminal.test", "Invalid EA name!"); assertTrueOrFail(terminal.GetScreenDpi() >= 0, "Invalid screen DPI?!"); assertTrueOrFail(terminal.GetBuild() >= 1000, "Invalid Terminal build?!"); assertTrueOrFail(terminal.GetCodePage() >= 0, "Invalid code page?!"); diff --git a/Profiler.mqh b/Profiler.mqh index 6d21201fd..bac2a2ad5 100644 --- a/Profiler.mqh +++ b/Profiler.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,8 +20,13 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "Storage/Collection.mqh" +#include "Storage/Collection.h" #include "Timer.mqh" // Defines macros. @@ -43,7 +48,7 @@ class Profiler { public: // Variables. static Collection *timers; - static unsigned long min_time; + static uint64 min_time; /* Class methods */ @@ -57,4 +62,4 @@ class Profiler { // Initialize static global variables. Collection *Profiler::timers = new Collection(MQLInfoString(MQL_PROGRAM_NAME)); -unsigned long Profiler::min_time = 1; +uint64 Profiler::min_time = 1; diff --git a/README.md b/README.md index b6373c6d1..d8bb0163d 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,18 @@ [![Tag][github-tag-image]][github-tag-link] [![License][license-image]][license-link] [![Status][gha-image-check-master]][gha-link-check-master] -[![Status][gha-image-lint-master]][gha-link-lint-master] -[![Status][gha-image-test-master]][gha-link-test-master] +[![Status][gha-image-compile-cpp-master]][gha-link-compile-cpp-master] +[![Status][gha-image-compile-mql-master]][gha-link-compile-mql-master] [![Channel][tg-channel-image]][tg-channel-link] [![Twitter][twitter-image]][twitter-link] -EA31337 framework is designed for writing trading robots for MetaTrader 4 and 5 platforms. +EA31337 framework is designed for writing software +for popular trading platforms such as MetaTrader (4 & 5). + It can be also used to convert your MQL4 code into MQL5 with minimum code changes. +The code is compatible with MQL4, MQL5 and C++ programming languages. + ## Table of contents @@ -58,6 +62,7 @@ Projects implementing this framework: EA strategies. - [EA31337-indicators-other](https://github.com/EA31337/EA31337-indicators-other): 3rd party indicators +- Check [EA31337 website](https://ea31337.github.io) for more. ## Conversion @@ -71,61 +76,61 @@ Find below the table of conversion (replace code on left with the right one): | MQL4 (original) | MQL4 & MQL5 (replace with) | Required include file | |:---------------------|:---------------------------|:----------------------| -| `WindowRedraw()` | `Chart::WindowRedraw()` | `Chart.mqh` | -| `Day()` | `DateTime::Day()` | `DateTime.mqh` | -| `TimeDayOfWeek()` | `DateTime::DayOfWeek()` | `DateTime.mqh` | -| `DayOfWeek()` | `DateTime::DayOfWeek()` | `DateTime.mqh` | -| `DayOfYear()` | `DateTime::DayOfYear()` | `DateTime.mqh` | -| `Hour()` | `DateTime::Hour()` | `DateTime.mqh` | -| `Month()` | `DateTime::Month()` | `DateTime.mqh` | -| `TimeDay()` | `DateTime::TimeDay()` | `DateTime.mqh` | -| `TimeDayOfYear()` | `DateTime::TimeDayOfYear()` | `DateTime.mqh` | -| `TimeToStr()` | `DateTime::TimeToStr()` | `DateTime.mqh` | -| `Year()` | `DateTime::Year()` | `DateTime.mqh` | +| `WindowRedraw()` | `Chart::WindowRedraw()` | `Platform/Chart/Chart.h` | +| `Day()` | `DateTime::Day()` | `Storage/DateTime.h` | +| `TimeDayOfWeek()` | `DateTime::DayOfWeek()` | `Storage/DateTime.h` | +| `DayOfWeek()` | `DateTime::DayOfWeek()` | `Storage/DateTime.h` | +| `DayOfYear()` | `DateTime::DayOfYear()` | `Storage/DateTime.h` | +| `Hour()` | `DateTime::Hour()` | `Storage/DateTime.h` | +| `Month()` | `DateTime::Month()` | `Storage/DateTime.h` | +| `TimeDay()` | `DateTime::TimeDay()` | `Storage/DateTime.h` | +| `TimeDayOfYear()` | `DateTime::TimeDayOfYear()` | `Storage/DateTime.h` | +| `TimeToStr()` | `DateTime::TimeToStr()` | `Storage/DateTime.h` | +| `Year()` | `DateTime::Year()` | `Storage/DateTime.h` | | `iAC()` | `Indi_AC::iAC()` | `Indicators/Indi_AC.mqh` | | `iAD()` | `Indi_AD::iAD()` | `Indicators/Indi_AD.mqh` | | `iADX()` | `Indi_ADX::iADX()` | `Indicators/Indi_ADX.mqh` | | `iAO()` | `Indi_AO::iAO()` | `Indicators/Indi_AO.mqh` | | `iATR()` | `Indi_ATR::iATR()` | `Indicators/Indi_ATR.mqh` | | `iBWMFI()` | `Indi_BWMFI::iBWMFI()` | `Indicators/Indi_BWMFI.mqh` | -| `iBands()` | `Indi_Bands::iBands()` | `Indicators/Indi_Bands.mqh` | +| `iBands()` | `Indi_Bands::iBands()` | `Indicators/PriceRange/Indi_Bands.h` | | `iBearsPower()` | `Indi_BearsPower::iBearsPower()` | `Indicators/Indi_BearsPower.mqh` | | `iBullsPower()` | `Indi_BullsPower::iBullsPower()` | `Indicators/Indi_BullsPower.mqh` | | `iCCI()` | `Indi_CCI::iCCI()` | `Indicators/Indi_CCI.mqh` | | `iDeMarker()` | `Indi_DeMarker::iDeMarker()` | `Indicators/Indi_DeMarker.mqh` | -| `iEnvelopes()` | `Indi_Envelopes::iEnvelopes()` | `Indicators/Indi_Envelopes.mqh` | +| `iEnvelopes()` | `Indi_Envelopes::iEnvelopes()` | `Indicators/PriceRange/Indi_Envelopes.h` | | `iForce()` | `Indi_Force::iForce()` | `Indicators/Indi_Force.mqh` | | `iFractals()` | `Indi_Fractals::iFractals()` | `Indicators/Indi_Fractals.mqh` | | `iGator()` | `Indi_Gator::iGator()` | `Indicators/Indi_Gator.mqh` | | `iIchimoku()` | `Indi_Ichimoku::iIchimoku()` | `Indicators/Indi_Ichimoku.mqh` | -| `iMA()` | `Indi_MA::iMA()` | `Indicators/Indi_MA.mqh` | -| `iMACD()` | `Indi_MAcD::iMACD()` | `Indicators/Indi_MACD.mqh` | +| `iMA()` | `Indi_MA::iMA()` | `Indicators/Price/Indi_MA.h` | +| `iMACD()` | `Indi_MACD::iMACD()` | `Indicators/Oscillator/Indi_MACD.h` | | `iMFI()` | `Indi_MFI::iMFI()` | `Indicators/Indi_MFI.mqh` | | `iMomentum()` | `Indi_Momentum::iMomentum()` | `Indicators/Indi_Momentum.mqh` | | `iOBV()` | `Indi_OBV::iOBV()` | `Indicators/Indi_OBV.mqh` | | `iOsMA()` | `Indi_OsMA::iOsMA()` | `Indicators/Indi_OsMA.mqh` | -| `iRSI()` | `Indi_RSI::iRSI()` | `Indicators/Indi_RSI.mqh` | +| `iRSI()` | `Indi_RSI::iRSI()` | `Indicators/Oscillator/Indi_RSI.h` | | `iRVI()` | `Indi_RVI::iRVI()` | `Indicators/Indi_RVI.mqh` | -| `iSAR()` | `Indi_SAR::iSAR()` | `Indicators/Indi_SAR.mqh` | +| `iSAR()` | `Indi_SAR::iSAR()` | `Indicators/PriceRange/Indi_SAR.h` | | `iStdDev()` | `Indi_StdDev::iStdDev()` | `Indicators/Indi_StdDev.mqh` | -| `iStochastic()` | `Indi_Stochastic::iStochastic()` | `Indicators/Indi_Stochastic.mqh` | -| `iWPR()` | `Indi_WPR::iWPR()` | `Indicators/Indi_WPR.mqh` | +| `iStochastic()` | `Indi_Stochastic::iStochastic()` | `Indicators/Oscillator/Indi_Stochastic.h` | +| `iWPR()` | `Indi_WPR::iWPR()` | `Indicators/Oscillator/Indi_WPR.h` | | `RefreshRates()` | `Market::RefreshRates()` | `Market.mqh` | -| `delete object` | `Object::Delete(object)` | `Object.mqh` | -| `GetOrderProfit()` | `Order::GetOrderProfit()` | `Order.mqh` | -| `OrderClose()` | `OrderStatic::Close()` | `Order.struct.h` | -| `OrderCloseTime()` | `OrderStatic::CloseTime()` | `Order.struct.h` | -| `OrderCommission()` | `OrderStatic::Commission()` | `Order.struct.h` | -| `OrderLots()` | `OrderStatic::Lots()` | `Order.struct.h` | -| `OrderMagicNumber()` | `OrderStatic::MagicNumber()` | `Order.struct.h` | -| `OrderOpenPrice()` | `OrderStatic::OpenPrice()` | `Order.struct.h` | -| `OrderOpenTime()` | `OrderStatic::OpenTime()` | `Order.struct.h` | -| `OrderPrint()` | `OrderStatic::Print()` | `Order.struct.h` | -| `OrderSelect()` | `OrderStatic::Select()` | `Order.struct.h` | -| `OrderStopLoss()` | `OrderStatic::StopLoss()` | `Order.struct.h` | -| `OrderSymbol()` | `OrderStatic::Symbol()` | `Order.struct.h` | -| `OrderTicket()` | `OrderStatic::Ticket()` | `Order.struct.h` | -| `OrderType()` | `OrderStatic::Type()` | `Order.struct.h` | +| `delete object` | `Object::Delete(object)` | `Storage/Object.h` | +| `GetOrderProfit()` | `Order::GetOrderProfit()` | `Platform/Order.h` | +| `OrderClose()` | `OrderStatic::Close()` | `Platform/Order.struct.h` | +| `OrderCloseTime()` | `OrderStatic::CloseTime()` | `Platform/Order.struct.h` | +| `OrderCommission()` | `OrderStatic::Commission()` | `Platform/Order.struct.h` | +| `OrderLots()` | `OrderStatic::Lots()` | `Platform/Order.struct.h` | +| `OrderMagicNumber()` | `OrderStatic::MagicNumber()` | `Platform/Order.struct.h` | +| `OrderOpenPrice()` | `OrderStatic::OpenPrice()` | `Platform/Order.struct.h` | +| `OrderOpenTime()` | `OrderStatic::OpenTime()` | `Platform/Order.struct.h` | +| `OrderPrint()` | `OrderStatic::Print()` | `Platform/Order.struct.h` | +| `OrderSelect()` | `OrderStatic::Select()` | `Platform/Order.struct.h` | +| `OrderStopLoss()` | `OrderStatic::StopLoss()` | `Platform/Order.struct.h` | +| `OrderSymbol()` | `OrderStatic::Symbol()` | `Platform/Order.struct.h` | +| `OrderTicket()` | `OrderStatic::Ticket()` | `Platform/Order.struct.h` | +| `OrderType()` | `OrderStatic::Type()` | `Platform/Order.struct.h` | | `OrdersTotal()` | `TradeStatic::TotalActive()` | `Trade.mqh` | @@ -137,16 +142,16 @@ Here are the special [predefined variables](https://docs.mql4.com/predefined) co | MQL4 (original) | MQL4 & MQL5 (replace with) | Required include file | |:---------------------|:-----------------------------|:--------------------| | `Ask` | `SymbolInfo::GetAsk()` | `SymbolInfo.struct.static.h` | -| `Bars` | `ChartStatic::iBars()` | `Chart.struct.static.h` | +| `Bars` | `ChartStatic::iBars()` | `Platform/Chart/Chart.struct.static.h` | | `Bid` | `SymbolInfo::GetBid()` | `SymbolInfo.struct.static.h` | -| `Close[]` | `ChartStatic::iClose()` | `Chart.struct.static.h` | +| `Close[]` | `ChartStatic::iClose()` | `Platform/Chart/Chart.struct.static.h` | | `Digits` | `SymbolInfo::GetDigits()` | `SymbolInfo.struct.static.h` | -| `High[]` | `ChartStatic::iHigh()` | `Chart.struct.static.h` | -| `Low[]` | `ChartStatic::iLow()` | `Chart.struct.static.h` | -| `Open[]` | `ChartStatic::iOpen()` | `Chart.struct.static.h` | +| `High[]` | `ChartStatic::iHigh()` | `Platform/Chart/Chart.struct.static.h` | +| `Low[]` | `ChartStatic::iLow()` | `Platform/Chart/Chart.struct.static.h` | +| `Open[]` | `ChartStatic::iOpen()` | `Platform/Chart/Chart.struct.static.h` | | `Point` | `SymbolInfo::GetPointSize()` | `SymbolInfo.struct.static.h` | -| `Time[]` | `ChartStatic::iTime()` | `Chart.struct.static.h` | -| `Volume[]` | `ChartStatic::iVolume()` | `Chart.struct.static.h` | +| `Time[]` | `ChartStatic::iTime()` | `Platform/Chart/Chart.struct.static.h` | +| `Volume[]` | `ChartStatic::iVolume()` | `Platform/Chart/Chart.struct.static.h` | @@ -218,13 +223,9 @@ Example sending e-mail on trade execution: delete mail; } -### `Indicator` class - -The purpose of `Indicator` class is to provide common functionality -across all indicators such as storing and searching for values. +### `Indicator/` -This class is used as a base class to handle technical indicator classes -which can be found in [`Indicators/`](Indicators/) folder. +Collection of indicator base classes used to implement technical indicators. ### `Indicators/` classes @@ -398,11 +399,11 @@ Multiple measurements: [gha-link-check-master]: https://github.com/EA31337/EA31337-classes/actions?query=workflow%3ACheck+branch%3Amaster [gha-image-check-master]: https://github.com/EA31337/EA31337-classes/workflows/Check/badge.svg -[gha-link-lint-master]: https://github.com/EA31337/EA31337-classes/actions?query=workflow%3ALint+branch%3Amaster -[gha-image-lint-master]: https://github.com/EA31337/EA31337-classes/workflows/Lint/badge.svg +[gha-link-compile-cpp-master]: https://github.com/EA31337/EA31337-classes/actions/workflows/compile-cpp.yml?query=branch%3Amaster +[gha-image-compile-cpp-master]: https://github.com/EA31337/EA31337-classes/actions/workflows/compile-cpp.yml/badge.svg -[gha-link-test-master]: https://github.com/EA31337/EA31337-classes/actions?query=workflow%3ATest+branch%3Amaster -[gha-image-test-master]: https://github.com/EA31337/EA31337-classes/workflows/Test/badge.svg +[gha-link-compile-mql-master]: https://github.com/EA31337/EA31337-classes/actions/workflows/compile-mql.yml?query=branch%3Amaster +[gha-image-compile-mql-master]: https://github.com/EA31337/EA31337-classes/actions/workflows/compile-mql.yml/badge.svg [tg-channel-image]: https://img.shields.io/badge/Telegram-join-0088CC.svg?logo=telegram [tg-channel-link]: https://t.me/EA31337 diff --git a/Refs.mqh b/Refs.mqh index 0acc12d8c..839522a60 100644 --- a/Refs.mqh +++ b/Refs.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -21,8 +21,8 @@ */ // Prevents processing this includes file for the second time. -#ifndef REFS_MQH -#define REFS_MQH +#ifndef REFS_H +#define REFS_H // Includes. #include "Refs.rc.h" @@ -142,4 +142,4 @@ class Dynamic { } }; -#endif +#endif // REFS_H diff --git a/Refs.rc.h b/Refs.rc.h index 5d82edddc..9a8ae63ac 100644 --- a/Refs.rc.h +++ b/Refs.rc.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,7 +31,7 @@ #endif // Includes. -#include "String.mqh" +#include "Storage/String.h" // Forward declarations. class Dynamic; diff --git a/Refs.struct.h b/Refs.struct.h index 8748b97ca..e238323c8 100644 --- a/Refs.struct.h +++ b/Refs.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Registry.mqh b/Registry.mqh deleted file mode 100644 index b446a384c..000000000 --- a/Registry.mqh +++ /dev/null @@ -1,272 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * Class to provide storing mechanism. - */ -class Registry { - struct RegistryData - { - string key; - string val; - }; - - int handle; - string filename; - RegistryData array[], copyArray[]; - - public: - - Registry(string path = "") { - - if (path != "") { - - handle = FileOpen(path, FILE_READ|FILE_CSV|FILE_ANSI, "="); - - if (handle != INVALID_HANDLE) - { - int count = 0; - while(FileIsEnding(handle)==false) - { - ArrayResize(array,(count+1),100000); - - array[count].key = FileReadString(handle); - array[count].val = FileReadString(handle); - count++; - } - } - - FileClose(handle); - - filename = path; - } - - } - - bool Save(string path = "") { - - if (path == "") - { - path = filename; - } - - handle = FileOpen(path, FILE_WRITE|FILE_CSV, "="); - - if(handle != INVALID_HANDLE) - { - int size = ArraySize(array); - - if(size > 0) - { - for (int i = 0; i < size; i++) - { - FileWrite(handle, array[i].key, array[i].val); - } - } - - FileClose(handle); - return true; - } else { - FileClose(handle); - return false; - } - } - - string GetKeys (bool withValues = 0) { - - int size = ArraySize(array); - string keys = "Empty"; - - if(size > 0) - { - keys = ""; - for (int i = 0; i < size; i++) - { - keys += array[i].key; - - if (withValues == 1) { - keys += "=" + array[i].val; - } - - keys += ";"; - } - } - - return keys; - } - - bool Delete (string key) { - int size = ArraySize(array); - - if(size > 0) - { - int offset = 0; - for (int i = 0; i < size; i++) - { - if (array[i].key == key) - { - Erase(array, i); - return true; - break; - } - } - } - - return false; - } - - template - void Erase(T& A[], int iPos){ - int iLast = ArraySize(A) - 1; - A[iPos].key = A[iLast].key; - A[iPos].val = A[iLast].val; - ArrayResize(A, iLast); - } - - string GetValueString (string key) { - - int size = ArraySize(array); - - if(size > 0) - { - for (int i = 0; i < size; i++) - { - if (array[i].key == key) - { - return(array[i].val); - break; - } - } - } - - return(NULL); - } - - int GetValueInteger (string key) { - - string value = GetValueString(key); - - if(value != NULL) { -#ifdef MQL4 - return(StrToInteger(value)); -#else - return((int) StringToInteger(value)); -#endif - } else { - return(NULL); - } - } - - double GetValueDouble (string key) { - - string value = GetValueString(key); - - if(value != NULL) { -#ifdef MQL4 - return(StrToDouble(value)); -#else - return(StringToDouble(value)); -#endif - } else { - return(NULL); - } - } - - bool SetValue (string key, string value) { - - int size = ArraySize(array); - int i = 0; - - if(size > 0) - { - for (;i < size; i++) - { - if (array[i].key == key) - { - array[i].val = value; - return true; - break; - } - } - } - - ArrayResize(array, (size+1), 100000); - - array[i].key = key; - array[i].val = value; - - return true; - } - - bool SetValue (string key, double value) { - - int size = ArraySize(array); - int i = 0; - - if(size > 0) - { - for (;i < size; i++) - { - if (array[i].key == key) - { - array[i].val = DoubleToString(value); - return true; - break; - } - } - } - - ArrayResize(array, (size+1), 100000); - - array[i].key = key; - array[i].val = DoubleToString(value); - - return true; - } - - bool SetValue (string key, int value) { - - int size = ArraySize(array); - int i = 0; - - if(size > 0) - { - for (;i < size; i++) - { - if (array[i].key == key) - { - array[i].val = IntegerToString(value); - return true; - break; - } - } - } - - ArrayResize(array, (size+1), 100000); - - array[i].key = key; - array[i].val = IntegerToString(value); - - return true; - } - -}; diff --git a/RegistryBinary.mqh b/RegistryBinary.mqh deleted file mode 100644 index 29b89eb13..000000000 --- a/RegistryBinary.mqh +++ /dev/null @@ -1,274 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -class RegistryBinary { - struct RegistryBinaryData - { - int key; - int val; - }; - - int handle, size; - string filename; - RegistryBinaryData array[], copyArray[]; - - public: - - void RegistryBinary (string path = "", bool binary = 0) { - if (binary == 0) - { - if (path != "") { - - handle = FileOpen(path, FILE_READ|FILE_CSV|FILE_ANSI, "="); - - if (handle != INVALID_HANDLE) - { - int count = 0; - while(FileIsEnding(handle)==false) - { - ArrayResize(array,(count+1),100000); - - array[count].key = FileReadInteger(handle); - array[count].val = FileReadInteger(handle); - count++; - } - } - - FileClose(handle); - - filename = path; - } - } - else - { - // @todo Add support for binary files, numeric instead of string key and val - handle = FileOpen(path, FILE_BIN|FILE_READ); - - if (handle != INVALID_HANDLE) - { - FileReadArray(handle, array, 0, WHOLE_ARRAY); - } - - FileClose(handle); - - filename = path; - } - - } - - bool Save (string path = "", bool binary = 0) { - - if (path == "") - { - path = filename; - } - - if (binary == 0) - { - handle = FileOpen(path, FILE_WRITE|FILE_CSV, "="); - - if(handle != INVALID_HANDLE) - { - size = ArraySize(array); - - if(size > 0) - { - for (int i = 0; i < size; i++) - { - FileWrite(handle, array[i].key, array[i].val); - } - } - - FileClose(handle); - return true; - } else { - FileClose(handle); - return false; - } - } - else - { - // @todo Add support for binary files, numeric instead of string key and val - - handle = FileOpen(path, FILE_BIN|FILE_WRITE); - - if(handle != INVALID_HANDLE) - { - size = ArraySize(array); - - if(size > 0) - { - FileWriteArray(handle,array, 0, WHOLE_ARRAY); - } - - FileClose(handle); - return true; - } else { - FileClose(handle); - return false; - } - } - } - - string GetKeys (bool withValues = 0) { - - size = ArraySize(array); - string keys = "Empty"; - - if(size > 0) - { - keys = ""; - for (int i = 0; i < size; i++) - { - keys += IntegerToString(array[i].key); - - if (withValues == 1) { - keys += "=" + IntegerToString(array[i].val); - } - - keys += ";"; - } - } - - return keys; - } - - bool Delete (int key) { - - size = ArraySize(array); - - if(size > 0) - { - int offset = 0; - for (int i = 0; i < size; i++) - { - if (array[i].key == key) - { - Erase(array, i); - return true; - break; - } - } - } - - return false; - } - - template - void Erase(T& A[], int iPos){ - int iLast = ArraySize(A) - 1; - A[iPos].key = A[iLast].key; - A[iPos].val = A[iLast].val; - ArrayResize(A, iLast); - } - - int GetValueInteger (int key) { - - size = ArraySize(array); - - if(size > 0) - { - for (int i = 0; i < size; i++) - { - if (array[i].key == key) - { - return(array[i].val); - break; - } - } - } - - return(NULL); - } - - /* - double GetValueDouble (int key) { - - string value = GetValueString(key); - - if(value != NULL) { - #ifdef MQL4 - return(StrToDouble(value)); - #else - return(StringToDouble(value)); - #endif - } else { - return(NULL); - } - } - */ - - bool SetValue (int key, int value) { - - size = ArraySize(array); - int i = 0; - - if(size > 0) - { - for (;i < size; i++) - { - if (array[i].key == key) - { - array[i].val = value; - return true; - break; - } - } - } - - ArrayResize(array, (size+1), 100000); - - array[i].key = key; - array[i].val = value; - - return true; - } - - /* - bool SetValue (int key, double value) { - - size = ArraySize(array); - int i = 0; - - if(size > 0) - { - for (;i < size; i++) - { - if (array[i].key == key) - { - array[i].val = DoubleToString(value); - return(1); - break; - } - } - } - - ArrayResize(array, (size+1), 100000); - - array[i].key = key; - array[i].val = DoubleToString(value); - - return(1); - } - */ - -}; diff --git a/Report.mqh b/Report.mqh index a1a61d1a2..fdb756820 100644 --- a/Report.mqh +++ b/Report.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,41 +20,44 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "DateTime.mqh" -#include "String.mqh" +#include "Storage/DateTime.h" +#include "Storage/String.h" /* * Class to provide report handling methods. */ class Report { -public: - - // Used for writing the report file. - string log[]; - - /* - * Add message into the report file. - */ - void ReportAdd(string msg) { - int last = ArraySize(log); - ArrayResize(log, last + 1); - log[last] = DateTimeStatic::TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS) + ": " + msg; - } - - /* - * Write report data into file. - */ - static void WriteReport(string filename, string data, bool verbose = false) { - int handle = FileOpen(filename, FILE_CSV|FILE_WRITE, '\t'); - if (handle < 1) return; - - FileWrite(handle, data); - FileClose(handle); - - if (verbose) { - String::PrintText(data); - } + public: + // Used for writing the report file. + string log[]; + + /* + * Add message into the report file. + */ + void ReportAdd(string msg) { + int last = ArraySize(log); + ArrayResize(log, last + 1); + log[last] = DateTimeStatic::TimeToStr(TimeCurrent(), TIME_DATE | TIME_SECONDS) + ": " + msg; + } + + /* + * Write report data into file. + */ + static void WriteReport(string filename, string data, bool verbose = false) { + int handle = FileOpen(filename, FILE_CSV | FILE_WRITE, '\t'); + if (handle < 1) return; + + FileWrite(handle, data); + FileClose(handle); + + if (verbose) { + String::PrintText(data); } - + } }; diff --git a/Serializer/Serializable.h b/Serializer/Serializable.h index 341e4294b..e76fdb85f 100644 --- a/Serializer/Serializable.h +++ b/Serializer/Serializable.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Serializer/Serializer.define.h b/Serializer/Serializer.define.h index f44b3f694..0e680c44b 100644 --- a/Serializer/Serializer.define.h +++ b/Serializer/Serializer.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Serializer's defines. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + /* Defines */ #ifdef __MQL__ diff --git a/Serializer/Serializer.enum.h b/Serializer/Serializer.enum.h index beab26fc0..e6042c7f2 100644 --- a/Serializer/Serializer.enum.h +++ b/Serializer/Serializer.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Serializer/Serializer.h b/Serializer/Serializer.h index f7d65e66c..c425520c5 100644 --- a/Serializer/Serializer.h +++ b/Serializer/Serializer.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,14 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_MQH -#define SERIALIZER_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. #include "../Convert.basic.h" -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" #include "Serializer.define.h" #include "Serializer.enum.h" #include "SerializerNode.h" @@ -474,5 +475,3 @@ class Serializer { return Struct(key); } }; - -#endif // End: SERIALIZER_MQH diff --git a/Serializer/SerializerBinary.h b/Serializer/SerializerBinary.h index cbcb3c69d..9fd55949c 100644 --- a/Serializer/SerializerBinary.h +++ b/Serializer/SerializerBinary.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,14 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_BINARY_MQH -#define SERIALIZER_BINARY_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../DictBase.mqh" -#include "../Object.mqh" +#include "../Storage/Dict/DictBase.h" +#include "../Storage/Object.h" #include "Serializer.h" #include "SerializerNode.h" @@ -37,7 +38,7 @@ enum ENUM_SERIALIZER_BINARY_FLAGS { SERIALIZER_BINARY_INCLUDE_VERSION }; union SerializerBinaryValue { unsigned char Bytes[8]; double Double; - long Long; + int64 Long; int Integer; short Short; }; @@ -48,9 +49,9 @@ class SerializerBinary { * Serializes node and its children into binary format. */ static string Stringify(SerializerNode* _node, unsigned int stringify_flags = 0, void* stringify_aux_arg = NULL) { - int size = _node.BinarySize(); + int size = _node PTR_DEREF BinarySize(); - unsigned char bytes[]; + ARRAY(unsigned char, bytes); ArrayResize(bytes, size); StringifyNode(_node, stringify_flags, stringify_aux_arg, bytes); @@ -59,10 +60,10 @@ class SerializerBinary { } static void StringifyNode(SerializerNode* _node, unsigned int stringify_flags, void* stringify_aux_arg, - unsigned char& bytes[], int offset = 0) { + ARRAY_REF(unsigned char, bytes), int offset = 0) { SerializerBinaryValue value; int i; - switch (_node.GetType()) { + switch (_node PTR_DEREF GetType()) { case SerializerNodeArray: break; case SerializerNodeObject: @@ -72,27 +73,27 @@ class SerializerBinary { break; case SerializerNodeObjectProperty: case SerializerNodeArrayItem: - switch (_node.GetValueParam().GetType()) { + switch (_node PTR_DEREF GetValueParam() PTR_DEREF GetType()) { case SerializerNodeParamBool: - bytes[offset] = _node.GetValueParam()._integral._bool; + bytes[offset] = _node PTR_DEREF GetValueParam() PTR_DEREF _integral._bool; break; case SerializerNodeParamDouble: - value.Double = _node.GetValueParam()._integral._double; + value.Double = _node PTR_DEREF GetValueParam() PTR_DEREF _integral._double; for (i = 0; i < sizeof(value.Double); ++i) { bytes[offset + i] = value.Bytes[i]; } break; case SerializerNodeParamLong: - value.Long = _node.GetValueParam()._integral._long; + value.Long = _node PTR_DEREF GetValueParam() PTR_DEREF _integral._long; for (i = 0; i < sizeof(value.Long); ++i) { bytes[offset + i] = value.Bytes[i]; } break; case SerializerNodeParamString: - for (i = 0; i < StringLen(_node.GetValueParam()._string); ++i) { - bytes[offset + i] = (unsigned char)_node.GetValueParam()._string[i]; + for (i = 0; i < StringLen(_node PTR_DEREF GetValueParam() PTR_DEREF _string); ++i) { + bytes[offset + i] = (unsigned char)_node PTR_DEREF GetValueParam() PTR_DEREF _string[i]; } - bytes[StringLen(_node.GetValueParam()._string)] = '\0'; + bytes[StringLen(_node PTR_DEREF GetValueParam() PTR_DEREF _string)] = '\0'; break; } break; @@ -115,7 +116,7 @@ class SerializerBinary { Serializer serializer(node, Unserialize); - if (logger != NULL) serializer.Logger().Link(logger); + // if (logger != NULL) serializer.Logger().Link(logger); // We don't use result. We parse data as it is. obj.Serialize(serializer); @@ -129,5 +130,3 @@ class SerializerBinary { return NULL; } }; - -#endif diff --git a/Serializer/SerializerConversions.h b/Serializer/SerializerConversions.h index 5a64e1076..b6b8d1e0d 100644 --- a/Serializer/SerializerConversions.h +++ b/Serializer/SerializerConversions.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,9 +31,8 @@ #endif #include "../Convert.extern.h" -#include "../DateTime.extern.h" -#include "../Object.mqh" -#include "../Refs.struct.h" +#include "../Storage/DateTime.extern.h" +#include "../Storage/Object.h" class SerializerConversions { public: @@ -53,7 +52,7 @@ class SerializerConversions { return string(includeQuotes ? "\"" : "") + IntegerToString(value) + (includeQuotes ? "\"" : ""); } - static string ValueToString(long value, bool includeQuotes = false, bool escape = true, int _fp_precision = 8) { + static string ValueToString(int64 value, bool includeQuotes = false, bool escape = true, int _fp_precision = 8) { return string(includeQuotes ? "\"" : "") + IntegerToString(value) + (includeQuotes ? "\"" : ""); } diff --git a/Serializer/SerializerConverter.h b/Serializer/SerializerConverter.h index f7aaf95ca..31e013779 100644 --- a/Serializer/SerializerConverter.h +++ b/Serializer/SerializerConverter.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,10 +25,6 @@ #pragma once #endif -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_CONVERTER_MQH -#define SERIALIZER_CONVERTER_MQH - // Forward declarations. class SerializerNode; @@ -226,5 +222,3 @@ class SerializerConverter { return SerializerConverter::FromObject(stub, _serializer_flags); } }; - -#endif diff --git a/Serializer/SerializerCsv.h b/Serializer/SerializerCsv.h index 099b50edb..6db82e328 100644 --- a/Serializer/SerializerCsv.h +++ b/Serializer/SerializerCsv.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,17 +20,18 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_CSV_MQH -#define SERIALIZER_CSV_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../Dict.mqh" -#include "../DictObject.mqh" -#include "../DictStruct.mqh" -#include "../Matrix.mqh" -#include "../MiniMatrix.h" -#include "../Object.mqh" +#include "../Math/Matrix.h" +#include "../Math/MatrixMini.h" +#include "../Storage/Dict/Dict.h" +#include "../Storage/Dict/DictObject.h" +#include "../Storage/Dict/DictStruct.h" +#include "../Storage/Object.h" #include "SerializerConverter.h" #include "SerializerNode.h" @@ -50,8 +51,8 @@ enum ENUM_SERIALIZER_CSV_FLAGS { class SerializerCsv { public: static string Stringify(SerializerNode* _root, unsigned int serializer_flags, void* serializer_aux_arg = NULL, - MiniMatrix2d* _matrix_out = NULL, - MiniMatrix2d* _column_types_out = NULL) { + MatrixMini2d* _matrix_out = NULL, + MatrixMini2d* _column_types_out = NULL) { SerializerConverter* _stub = (SerializerConverter*)serializer_aux_arg; if (CheckPointer(_root) == POINTER_INVALID) { @@ -89,9 +90,9 @@ class SerializerCsv { ++_num_columns; } - MiniMatrix2d _cells; - MiniMatrix2d _column_titles; - MiniMatrix2d _column_types; + MatrixMini2d _cells; + MatrixMini2d _column_titles; + MatrixMini2d _column_types; if (_matrix_out == NULL) { _matrix_out = &_cells; @@ -172,8 +173,8 @@ class SerializerCsv { * Extracts column names and types from the stub, so even if there is not data, we'll still have information about * columns. */ - static void ExtractColumns(SerializerNode* _stub, MiniMatrix2d* _titles, - MiniMatrix2d* _column_types, int _flags, int& _column) { + static void ExtractColumns(SerializerNode* _stub, MatrixMini2d* _titles, + MatrixMini2d* _column_types, int _flags, int& _column) { for (unsigned int _stub_entry_idx = 0; _stub_entry_idx < _stub PTR_DEREF NumChildren(); ++_stub_entry_idx) { SerializerNode* _child = _stub PTR_DEREF GetChild(_stub_entry_idx); if (_child PTR_DEREF IsContainer()) { @@ -187,8 +188,8 @@ class SerializerCsv { /** * */ - static bool FlattenNode(SerializerNode* _data, SerializerNode* _stub, MiniMatrix2d& _cells, - MiniMatrix2d* _column_types, int _column, int _row, int _flags) { + static bool FlattenNode(SerializerNode* _data, SerializerNode* _stub, MatrixMini2d& _cells, + MatrixMini2d* _column_types, int _column, int _row, int _flags) { unsigned int _data_entry_idx; bool _include_key = bool(_flags & SERIALIZER_CSV_INCLUDE_KEY); @@ -233,8 +234,8 @@ class SerializerCsv { /** * */ - static bool FillRow(SerializerNode* _data, SerializerNode* _stub, MiniMatrix2d& _cells, - MiniMatrix2d* _column_types, int _column, int _row, int _index, + static bool FillRow(SerializerNode* _data, SerializerNode* _stub, MatrixMini2d& _cells, + MatrixMini2d* _column_types, int _column, int _row, int _index, int _level, int _flags) { unsigned int _data_entry_idx, _entry_size; @@ -292,5 +293,3 @@ class SerializerCsv { return true; } }; - -#endif diff --git a/Serializer/SerializerDict.h b/Serializer/SerializerDict.h index 83fa2ea80..8ad00bef0 100644 --- a/Serializer/SerializerDict.h +++ b/Serializer/SerializerDict.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,10 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_DICT_MQH -#define SERIALIZER_DICT_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. #include "SerializerNode.h" @@ -46,5 +47,3 @@ class SerializerDict { } } }; - -#endif diff --git a/Serializer/SerializerJson.h b/Serializer/SerializerJson.h index 34325c48e..6e841fb31 100644 --- a/Serializer/SerializerJson.h +++ b/Serializer/SerializerJson.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,14 +20,15 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_JSON_MQH -#define SERIALIZER_JSON_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../DictBase.mqh" -#include "../Object.mqh" -#include "../String.extern.h" +#include "../Storage/Dict/DictBase.h" +#include "../Storage/Object.h" +#include "../Storage/String.extern.h" #include "Serializer.enum.h" #include "Serializer.h" #include "SerializerNode.h" @@ -392,5 +393,3 @@ class SerializerJson { return NULL; } }; - -#endif diff --git a/Serializer/SerializerNode.enum.h b/Serializer/SerializerNode.enum.h index a33b4c74b..4dd2e804c 100644 --- a/Serializer/SerializerNode.enum.h +++ b/Serializer/SerializerNode.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Serializer/SerializerNode.h b/Serializer/SerializerNode.h index 516817b71..6f996525c 100644 --- a/Serializer/SerializerNode.h +++ b/Serializer/SerializerNode.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,14 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_NODE_H -#define SERIALIZER_NODE_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../Math.extern.h" -#include "../Terminal.define.h" +#include "../Math/Math.extern.h" +#include "../Platform/Terminal.define.h" #include "SerializerNode.enum.h" #include "SerializerNodeParam.h" @@ -367,5 +368,3 @@ class SerializerNode { return repr; } }; - -#endif // SERIALIZER_NODE_H diff --git a/Serializer/SerializerNodeIterator.h b/Serializer/SerializerNodeIterator.h index f3cfe6a20..25df09683 100644 --- a/Serializer/SerializerNodeIterator.h +++ b/Serializer/SerializerNodeIterator.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,10 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_NODE_ITERATOR_H -#define SERIALIZER_NODE_ITERATOR_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif #include "Serializer.h" #include "SerializerNode.h" @@ -111,5 +112,3 @@ class SerializerIterator : public SerializerNodeIterator { SerializerNodeType ParentNodeType() { return _collection PTR_DEREF GetType(); } }; - -#endif diff --git a/Serializer/SerializerNodeParam.h b/Serializer/SerializerNodeParam.h index 7ba0a834e..c4cd01498 100644 --- a/Serializer/SerializerNodeParam.h +++ b/Serializer/SerializerNodeParam.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -21,11 +21,16 @@ */ // Prevents processing this includes file for the second time. -#include "SerializerConversions.h" - #ifndef SERIALIZER_NODE_PARAM_H #define SERIALIZER_NODE_PARAM_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "SerializerConversions.h" + /** * Enumeration. */ @@ -48,7 +53,7 @@ class SerializerNodeParam { */ union USerializerNodeValue { bool _bool; - long _long; + int64 _long; double _double; } _integral; @@ -71,12 +76,12 @@ class SerializerNodeParam { /** * Returns new SerializerNodeParam object from given source value. */ - static SerializerNodeParam* FromBool(long value); + static SerializerNodeParam* FromBool(int64 value); /** * Returns new SerializerNodeParam object from given source value. */ - static SerializerNodeParam* FromLong(long value); + static SerializerNodeParam* FromLong(int64 value); /** * Returns new SerializerNodeParam object from given source value. @@ -121,7 +126,7 @@ class SerializerNodeParam { /** * Returns new SerializerNodeParam object from given source value. */ - static SerializerNodeParam* FromValue(long value) { return FromLong(value); } + static SerializerNodeParam* FromValue(int64 value) { return FromLong(value); } /** * Returns new SerializerNodeParam object from given source value. @@ -146,7 +151,7 @@ class SerializerNodeParam { /** * Returns new SerializerNodeParam object from given source value. */ - static SerializerNodeParam* FromValue(unsigned long value) { return FromLong(value); } + static SerializerNodeParam* FromValue(uint64 value) { return FromLong(value); } /** * Returns new SerializerNodeParam object from given source value. @@ -182,7 +187,7 @@ class SerializerNodeParam { */ SerializerNodeParamType GetType() { return _type; } - long ToBool() { + int64 ToBool() { switch (_type) { case SerializerNodeParamBool: return _integral._bool; @@ -216,18 +221,18 @@ class SerializerNodeParam { return 0; } - long ToLong() { + int64 ToLong() { switch (_type) { case SerializerNodeParamBool: return _integral._bool ? 1 : 0; case SerializerNodeParamLong: return _integral._long; case SerializerNodeParamDouble: - return (long)_integral._double; + return (int64)_integral._double; case SerializerNodeParamString: return StringToInteger(_string); default: - Alert("Internal Error. Cannot convert source type to long"); + Alert("Internal Error. Cannot convert source type to int64"); } return 0; @@ -286,7 +291,7 @@ class SerializerNodeParam { int ConvertTo(int) { return ToInt(); } - long ConvertTo(long) { return ToInt(); } + int64 ConvertTo(int64) { return ToInt(); } float ConvertTo(float) { return ToFloat(); } @@ -298,7 +303,7 @@ class SerializerNodeParam { /** * Returns new SerializerNodeParam object from given source value. */ -SerializerNodeParam* SerializerNodeParam::FromBool(long value) { +SerializerNodeParam* SerializerNodeParam::FromBool(int64 value) { SerializerNodeParam* param = new SerializerNodeParam(); PTR_ATTRIB(param, _type) = SerializerNodeParamBool; PTR_ATTRIB(param, _integral)._bool = value; @@ -308,7 +313,7 @@ SerializerNodeParam* SerializerNodeParam::FromBool(long value) { /** * Returns new SerializerNodeParam object from given source value. */ -SerializerNodeParam* SerializerNodeParam::FromLong(long value) { +SerializerNodeParam* SerializerNodeParam::FromLong(int64 value) { SerializerNodeParam* param = new SerializerNodeParam(); PTR_ATTRIB(param, _type) = SerializerNodeParamLong; PTR_ATTRIB(param, _integral)._long = value; @@ -335,4 +340,4 @@ SerializerNodeParam* SerializerNodeParam::FromString(string& value) { return param; } -#endif // SERIALIZER_NODE_PARAM_H +#endif // SERIALIZER_NODE_PARAM_H diff --git a/Serializer/SerializerObject.h b/Serializer/SerializerObject.h index 296106211..76fef4f23 100644 --- a/Serializer/SerializerObject.h +++ b/Serializer/SerializerObject.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,13 +20,14 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_OBJECT_MQH -#define SERIALIZER_OBJECT_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../DictBase.mqh" -#include "../Object.mqh" +#include "../Storage/Dict/DictBase.h" +#include "../Storage/Object.h" #include "Serializer.h" #include "SerializerConverter.h" #include "SerializerNode.h" @@ -37,5 +38,3 @@ class SerializerObject { public: static string Stringify(SerializerNode* _root) { return ""; } }; - -#endif diff --git a/Serializer/SerializerSqlite.h b/Serializer/SerializerSqlite.h index 3ad38d373..0204ee589 100644 --- a/Serializer/SerializerSqlite.h +++ b/Serializer/SerializerSqlite.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,12 +20,13 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef SERIALIZER_SQL_MQH -#define SERIALIZER_SQL_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../Database.mqh" +#include "../Storage/Database.h" #include "SerializerConverter.h" #include "SerializerCsv.h" @@ -50,8 +51,8 @@ class SerializerSqlite { static bool ConvertToFile(SerializerConverter& source, string _path, string _table, unsigned int _stringify_flags = 0, void* _stub = NULL) { // We must have titles tree as - MiniMatrix2d _matrix_out; - MiniMatrix2d _column_types; + MatrixMini2d _matrix_out; + MatrixMini2d _column_types; string _csv = SerializerCsv::Stringify(source.root_node, _stringify_flags | SERIALIZER_CSV_INCLUDE_TITLES, _stub, &_matrix_out, &_column_types); @@ -79,17 +80,16 @@ class SerializerSqlite { } if (!_db.TableExists(_table)) { - if (!_db.CreateTable(_table, _db.GetTableSchema(_table))) { + DatabaseTableSchema _schema = _db.GetTableSchema(_table); + if (!_db.CreateTable(_table, _schema)) { return false; } } - if (!_db.ImportData(_table, _matrix_out)) { + if (!_db.Import(_table, _matrix_out)) { return false; } return true; } }; - -#endif diff --git a/Serializer/tests/Makefile b/Serializer/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Serializer/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Serializer/tests/Serializable.test.cpp b/Serializer/tests/Serializable.test.cpp new file mode 100644 index 000000000..ad60d7be0 --- /dev/null +++ b/Serializer/tests/Serializable.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Serializable class. + */ + +// Includes. +#include "../Serializable.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/Serializer.test.cpp b/Serializer/tests/Serializer.test.cpp new file mode 100644 index 000000000..cd6cad5f9 --- /dev/null +++ b/Serializer/tests/Serializer.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Serializer class. + */ + +// Includes. +#include "../Serializer.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/Serializer.test.mq4 b/Serializer/tests/Serializer.test.mq4 index b6c98a8f1..0dd669dc7 100644 --- a/Serializer/tests/Serializer.test.mq4 +++ b/Serializer/tests/Serializer.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Serializer/tests/Serializer.test.mq5 b/Serializer/tests/Serializer.test.mq5 index d218cb208..d6e5e1cb0 100644 --- a/Serializer/tests/Serializer.test.mq5 +++ b/Serializer/tests/Serializer.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -27,13 +27,13 @@ */ // Includes. -#include "../../BufferStruct.mqh" -#include "../../Chart.mqh" +#include "../../Storage/Dict/Buffer/BufferStruct.h" +#include "../../Platform/Chart/Chart.h" #include "../../Config.mqh" -#include "../../Data.define.h" -#include "../../Data.struct.h" -#include "../../Data.struct.serialize.h" -#include "../../DictStruct.mqh" +#include "../../Storage/Data.define.h" +#include "../../Storage/Data.struct.h" +#include "../../Storage/Data.struct.serialize.h" +#include "../../Storage/Dict/DictStruct.h" #include "../../Test.mqh" #include "../Serializer.h" #include "../SerializerBinary.h" diff --git a/Indicators/tests/Indi_CustomMovingAverage.test.mq5 b/Serializer/tests/SerializerBinary.test.cpp similarity index 76% rename from Indicators/tests/Indi_CustomMovingAverage.test.mq5 rename to Serializer/tests/SerializerBinary.test.cpp index 8fc478d8c..1b784bab3 100644 --- a/Indicators/tests/Indi_CustomMovingAverage.test.mq5 +++ b/Serializer/tests/SerializerBinary.test.cpp @@ -1,31 +1,36 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -// Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_CustomMovingAverage.mqh" - -/** - * @file - * Test functionality of Indi_CustomMovingAverage indicator class. - */ -TEST_INDICATOR_DEFAULT_BINDINGS(Indi_CustomMovingAverage); +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerBinary class. + */ + +// Includes. +#include "../SerializerBinary.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerConversions.test.cpp b/Serializer/tests/SerializerConversions.test.cpp new file mode 100644 index 000000000..0b06b3943 --- /dev/null +++ b/Serializer/tests/SerializerConversions.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerConversions class. + */ + +// Includes. +#include "../SerializerConversions.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerConverter.test.cpp b/Serializer/tests/SerializerConverter.test.cpp new file mode 100644 index 000000000..b5156758b --- /dev/null +++ b/Serializer/tests/SerializerConverter.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerConverter class. + */ + +// Includes. +#include "../SerializerConverter.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerCsv.test.cpp b/Serializer/tests/SerializerCsv.test.cpp new file mode 100644 index 000000000..73175c8b9 --- /dev/null +++ b/Serializer/tests/SerializerCsv.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerCsv class. + */ + +// Includes. +#include "../SerializerCsv.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Indicators/tests/Indi_ColorCandlesDaily.test.mq5 b/Serializer/tests/SerializerDict.test.cpp similarity index 77% rename from Indicators/tests/Indi_ColorCandlesDaily.test.mq5 rename to Serializer/tests/SerializerDict.test.cpp index ceb9c7393..68b01a7d4 100644 --- a/Indicators/tests/Indi_ColorCandlesDaily.test.mq5 +++ b/Serializer/tests/SerializerDict.test.cpp @@ -1,31 +1,36 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -// Includes. -#include "../../Platform.h" -#include "../../Test.mqh" -#include "../Indi_ColorCandlesDaily.mqh" - -/** - * @file - * Test functionality of Indi_ColorCandlesDaily indicator class. - */ -TEST_INDICATOR_DEFAULT_BINDINGS(Indi_ColorCandlesDaily); +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerDict class. + */ + +// Includes. +#include "../SerializerDict.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerJson.test.cpp b/Serializer/tests/SerializerJson.test.cpp new file mode 100644 index 000000000..bb3975a0e --- /dev/null +++ b/Serializer/tests/SerializerJson.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerJson class. + */ + +// Includes. +#include "../SerializerJson.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerNode.test.cpp b/Serializer/tests/SerializerNode.test.cpp new file mode 100644 index 000000000..cc4f28237 --- /dev/null +++ b/Serializer/tests/SerializerNode.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerNode class. + */ + +// Includes. +#include "../SerializerNode.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerNodeIterator.test.cpp b/Serializer/tests/SerializerNodeIterator.test.cpp new file mode 100644 index 000000000..f11e9ee51 --- /dev/null +++ b/Serializer/tests/SerializerNodeIterator.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerNodeIterator class. + */ + +// Includes. +#include "../SerializerNodeIterator.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerNodeParam.test.cpp b/Serializer/tests/SerializerNodeParam.test.cpp new file mode 100644 index 000000000..de4601e87 --- /dev/null +++ b/Serializer/tests/SerializerNodeParam.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerNodeParam class. + */ + +// Includes. +#include "../SerializerNodeParam.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerObject.test.cpp b/Serializer/tests/SerializerObject.test.cpp new file mode 100644 index 000000000..66bef2d08 --- /dev/null +++ b/Serializer/tests/SerializerObject.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerObject class. + */ + +// Includes. +#include "../SerializerObject.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Serializer/tests/SerializerSqlite.test.cpp b/Serializer/tests/SerializerSqlite.test.cpp new file mode 100644 index 000000000..13f4002e8 --- /dev/null +++ b/Serializer/tests/SerializerSqlite.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of SerializerSqlite class. + */ + +// Includes. +#include "../SerializerSqlite.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Session.mqh b/Session.mqh deleted file mode 100644 index 971e680d7..000000000 --- a/Session.mqh +++ /dev/null @@ -1,274 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * Class to provide storing mechanism for session variables. - */ -class Session { -public: - - struct SessionData - { - string key; - string val; - }; - - int handle; - string filename; - SessionData array[], copyArray[]; - - public: - - void Registry (string path = "") { - - if (path != "") { - - handle = FileOpen(path, FILE_READ|FILE_CSV|FILE_ANSI, "="); - - if (handle != INVALID_HANDLE) - { - int count = 0; - while(FileIsEnding(handle)==false) - { - ArrayResize(array,(count+1),100000); - - array[count].key = FileReadString(handle); - array[count].val = FileReadString(handle); - count++; - } - } - - FileClose(handle); - - filename = path; - } - - } - - bool Save (string path = "") { - - if (path == "") - { - path = filename; - } - - handle = FileOpen(path, FILE_WRITE|FILE_CSV, "="); - - if(handle != INVALID_HANDLE) - { - int size = ArraySize(array); - - if(size > 0) - { - for (int i = 0; i < size; i++) - { - FileWrite(handle, array[i].key, array[i].val); - } - } - - FileClose(handle); - return true; - } else { - FileClose(handle); - return false; - } - } - - string GetKeys (bool withValues = 0) { - - int size = ArraySize(array); - string keys = "Empty"; - - if(size > 0) - { - keys = ""; - for (int i = 0; i < size; i++) - { - keys += array[i].key; - - if (withValues == 1) { - keys += "=" + array[i].val; - } - - keys += ";"; - } - } - - return keys; - } - - bool Delete (string key) { - int size = ArraySize(array); - - if(size > 0) - { - int offset = 0; - for (int i = 0; i < size; i++) - { - if (array[i].key == key) - { - Erase(array, i); - return true; - break; - } - } - } - - return false; - } - - template - void Erase(T& A[], int iPos){ - int iLast = ArraySize(A) - 1; - A[iPos].key = A[iLast].key; - A[iPos].val = A[iLast].val; - ArrayResize(A, iLast); - } - - string GetValueString (string key) { - - int size = ArraySize(array); - - if(size > 0) - { - for (int i = 0; i < size; i++) - { - if (array[i].key == key) - { - return(array[i].val); - break; - } - } - } - - return(NULL); - } - - int GetValueInteger (string key) { - - string value = GetValueString(key); - - if(value != NULL) { -#ifdef MQL4 - return(StrToInteger(value)); -#else - return((int) StringToInteger(value)); -#endif - } else { - return(NULL); - } - } - - double GetValueDouble (string key) { - - string value = GetValueString(key); - - if(value != NULL) { -#ifdef MQL4 - return(StrToDouble(value)); -#else - return(StringToDouble(value)); -#endif - } else { - return(NULL); - } - } - - bool SetValue (string key, string value) { - - int size = ArraySize(array); - int i = 0; - - if(size > 0) - { - for (;i < size; i++) - { - if (array[i].key == key) - { - array[i].val = value; - return true; - break; - } - } - } - - ArrayResize(array, (size+1), 100000); - - array[i].key = key; - array[i].val = value; - - return true; - } - - bool SetValue (string key, double value) { - - int size = ArraySize(array); - int i = 0; - - if(size > 0) - { - for (;i < size; i++) - { - if (array[i].key == key) - { - array[i].val = DoubleToString(value); - return true; - break; - } - } - } - - ArrayResize(array, (size+1), 100000); - - array[i].key = key; - array[i].val = DoubleToString(value); - - return true; - } - - bool SetValue (string key, int value) { - - int size = ArraySize(array); - int i = 0; - - if(size > 0) - { - for (;i < size; i++) - { - if (array[i].key == key) - { - array[i].val = IntegerToString(value); - return true; - break; - } - } - } - - ArrayResize(array, (size+1), 100000); - - array[i].key = key; - array[i].val = IntegerToString(value); - - return true; - } - -}; diff --git a/SetFile.mqh b/SetFile.mqh index ea70d4086..d291a8c1d 100644 --- a/SetFile.mqh +++ b/SetFile.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,151 +20,140 @@ * */ -class SetFile { - struct SetFileData - { - string key; - string val; - }; - - int handle, count; - SetFileData array[]; - - public: - - bool LoadFromFile(string path) { - handle = FileOpen(path, FILE_READ|FILE_CSV|FILE_ANSI, '='); - - if (handle == INVALID_HANDLE) { - //PrintFormat("Failed to open %s file, Error code = %d", handle,GetLastError()); - FileClose(handle); - return true; - } - - if (FileSize(handle) == 0) { - //PrintFormat("Failed to open %s file, Error code = %d", handle,GetLastError()); - FileClose(handle); - return false; - } - - count = 0; - while(FileIsEnding(handle)==false) - { - ArrayResize(array,(count+1),100000); - - array[count].key = FileReadString(handle); - array[count].val = FileReadString(handle); - count++; - } - - FileClose(handle); - - return true; - } - - string GetValueString (string key) { - - for (int i = 0; i <= ArraySize(array); i++) - { - if (array[i].key == key) - { - return(array[i].val); - break; - } - } - - return(NULL); - } - - int GetValueInteger (string key) { - string value = GetValueString(key); - - if(value != NULL) { - #ifdef MQL4 - return(StrToInteger(value)); - #else - return((int) StringToInteger(value)); - #endif - } else { - return(NULL); - } - } - - double GetValueDouble (string key) { - string value = GetValueString(key); - - if(value != NULL) { - #ifdef MQL4 - return(StrToDouble(value)); - #else - return(StringToDouble(value)); - #endif - } else { - return(NULL); - } - } - - bool SetValue (string key, string value) { - - int i = 0; - for (;i <= ArraySize(array); i++) - { - if (array[i].key == key) - { - array[i].val = value; - return true; - break; - } - } - - ArrayResize(array,(i+2),100000); - - array[(i + 1)].key = key; - array[(i + 1)].val = value; - - return true; - } - - bool SetValue (string key, double value) { - - int i = 0; - for (;i <= ArraySize(array); i++) - { - if (array[i].key == key) - { - array[i].val = DoubleToString(value); - return true; - break; - } - } - - ArrayResize(array,(i+2),100000); - - array[(i + 1)].key = key; - array[(i + 1)].val = DoubleToString(value); - - return true; - } - - bool SetValue (string key, int value) { - - int i = 0; - for (;i <= ArraySize(array); i++) - { - if (array[i].key == key) - { - array[i].val = IntegerToString(value); - return true; - break; - } - } - - ArrayResize(array,(i+2),100000); - - array[(i + 1)].key = key; - array[(i + 1)].val = IntegerToString(value); - - return true; - } +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif +class SetFile { + struct SetFileData { + string key; + string val; + }; + + int handle, count; + SetFileData array[]; + + public: + bool LoadFromFile(string path) { + handle = FileOpen(path, FILE_READ | FILE_CSV | FILE_ANSI, '='); + + if (handle == INVALID_HANDLE) { + // PrintFormat("Failed to open %s file, Error code = %d", handle,GetLastError()); + FileClose(handle); + return true; + } + + if (FileSize(handle) == 0) { + // PrintFormat("Failed to open %s file, Error code = %d", handle,GetLastError()); + FileClose(handle); + return false; + } + + count = 0; + while (FileIsEnding(handle) == false) { + ArrayResize(array, (count + 1), 100000); + + array[count].key = FileReadString(handle); + array[count].val = FileReadString(handle); + count++; + } + + FileClose(handle); + + return true; + } + + string GetValueString(string key) { + for (int i = 0; i <= ArraySize(array); i++) { + if (array[i].key == key) { + return (array[i].val); + break; + } + } + + return (NULL); + } + + int GetValueInteger(string key) { + string value = GetValueString(key); + + if (value != NULL) { +#ifdef MQL4 + return (StrToInteger(value)); +#else + return ((int)StringToInteger(value)); +#endif + } else { + return (NULL); + } + } + + double GetValueDouble(string key) { + string value = GetValueString(key); + + if (value != NULL) { +#ifdef MQL4 + return (StrToDouble(value)); +#else + return (StringToDouble(value)); +#endif + } else { + return (NULL); + } + } + + bool SetValue(string key, string value) { + int i = 0; + for (; i <= ArraySize(array); i++) { + if (array[i].key == key) { + array[i].val = value; + return true; + break; + } + } + + ArrayResize(array, (i + 2), 100000); + + array[(i + 1)].key = key; + array[(i + 1)].val = value; + + return true; + } + + bool SetValue(string key, double value) { + int i = 0; + for (; i <= ArraySize(array); i++) { + if (array[i].key == key) { + array[i].val = DoubleToString(value); + return true; + break; + } + } + + ArrayResize(array, (i + 2), 100000); + + array[(i + 1)].key = key; + array[(i + 1)].val = DoubleToString(value); + + return true; + } + + bool SetValue(string key, int value) { + int i = 0; + for (; i <= ArraySize(array); i++) { + if (array[i].key == key) { + array[i].val = IntegerToString(value); + return true; + break; + } + } + + ArrayResize(array, (i + 2), 100000); + + array[(i + 1)].key = key; + array[(i + 1)].val = IntegerToString(value); + + return true; + } }; diff --git a/Socket.mqh b/Socket.mqh index 5f8140b66..a87c66edb 100644 --- a/Socket.mqh +++ b/Socket.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,15 @@ * Implements class for socket connection. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "File.define.h" +#include "Std.h" + /** * Socket class. */ @@ -163,7 +172,7 @@ class Socket { * Sends string through the socket. */ bool Send(const string text) { - unsigned char _buffer[]; + ARRAY(unsigned char, _buffer); int _buffer_length = StringToCharArray(text, _buffer, 0, WHOLE_ARRAY, CP_UTF8); return Send(_buffer, _buffer_length); } @@ -171,7 +180,7 @@ class Socket { /** * Sends bytes through the socket. */ - bool Send(const unsigned char& _buffer[], unsigned int _buffer_length) { + bool Send(const ARRAY_REF(unsigned char, _buffer), unsigned int _buffer_length) { if (!EnsureConnected()) { return false; } @@ -217,7 +226,7 @@ class Socket { /** * Reads bytes from the socket. Awaits given miliseconds before giving up. */ - bool Read(unsigned char& _buffer[], unsigned int _buffer_max_length, unsigned int _timeout_ms = 1000) { + bool Read(ARRAY_REF(unsigned char, _buffer), unsigned int _buffer_max_length, unsigned int _timeout_ms = 1000) { if (!EnsureConnected()) { return false; } diff --git a/Std.h b/Std.h index 215986aae..3601b01bf 100644 --- a/Std.h +++ b/Std.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -23,11 +23,11 @@ #ifndef __MQL__ // Allows the preprocessor to include a header file when it is needed. #pragma once - #include "Math.define.h" #endif // Includes. -#include "Data.enum.h" +#include "Math/Math.define.h" +#include "Storage/Data.enum.h" // Data types. #ifdef __cplusplus @@ -57,10 +57,13 @@ #define PTR_ATTRIB(O, A) O.A #define PTR_ATTRIB2(O, A, B) O.A.B #define PTR_TO_REF(PTR) PTR + #define REF_TO_PTR(PTR) PTR #define MAKE_REF_FROM_PTR(TYPE, NAME, PTR) TYPE* NAME = PTR + #define nullptr NULL #define REF_DEREF .Ptr(). #define int64 long - #define nullptr NULL + #define uint64 unsigned long + #define VOID_DATA(N) void*& N[] #else #define GET_PTR(obj) (&obj) #define THIS_ATTR this-> @@ -69,81 +72,138 @@ #define PTR_DEREF -> #define PTR_ATTRIB(O, A) O->A #define PTR_ATTRIB2(O, A, B) O->A->B - #define PTR_TO_REF(PTR) (*PTR) + #define PTR_TO_REF(PTR) (*(PTR)) + #define REF_TO_PTR(PTR) (&(PTR)) #define MAKE_REF_FROM_PTR(TYPE, NAME, PTR) TYPE& NAME = PTR #define REF_DEREF .Ptr()-> #define int64 long long + #define uint64 unsigned long long + #define VOID_DATA(N) void* N #endif -// References. -#ifdef __cplusplus - #define REF(X) (&X) +// Reference to simple type like bool, int, double, string. +#ifdef __MQL__ +#define REF(X) X& #else - #define REF(X) X& +#define REF(X) (&X) #endif // Arrays and references to arrays. #define _COMMA , + +// Reference to object. #ifdef __MQL__ - #define ARRAY_DECLARATION_BRACKETS [] +#define REF_TO(T) T* #else - // C++'s _cpp_array is an object, so no brackets are needed. - #define ARRAY_DECLARATION_BRACKETS +#define REF_TO(T) T& #endif +// Const reference to object. +#define CONST_REF_TO(T) const REF_TO(T) + +// Reference to simple type like bool, int, double, string or structure that is not treated as object by MT. +#define REF_TO_SIMPLE(T) T& + +// Const reference to simple type like bool, int, double, string. +#define CONST_REF_TO_SIMPLE(T) const REF_TO_SIMPLE(T) + +// Returning type for methods that returns simple types as int, double, string. #ifdef __MQL__ - /** - * Reference to object. - */ - #define CONST_REF_TO(T) const T +#define RETURN_REF_TO_SIMPLE(T) T +#else +#define RETURN_REF_TO_SIMPLE(T) T& +#endif - /** - * Reference to the array. - * - * @usage - * ARRAY_REF(, ) - */ - #define ARRAY_TYPE(T) T[] - #define ARRAY_REF(T, N) REF(T) N ARRAY_DECLARATION_BRACKETS - #define FIXED_ARRAY_REF(T, N, S) ARRAY_REF(T, N) +// Returning type for methods that returns simple contstant types as int, double, string. +#define RETURN_CONST_REF_TO_SIMPLE(T) const RETURN_REF_TO_SIMPLE(T) - #define CONST_ARRAY_REF(T, N) const N ARRAY_DECLARATION_BRACKETS +// Casts reference to object to given type. +#ifdef __MQL__ +#define REF_CAST(T) (T*) +#else +#define REF_CAST(T) (T&) +#endif - /** - * Array definition. - * - * @usage - * ARRAY(, ) - */ - #define ARRAY(T, N) T N[] +/** + * Type of the array. + * T = Type of the array items. + * Example: ARRAY_TYPE(int) items; ArrayPush(items, 1); + */ +#ifdef __MQL__ +#define ARRAY_TYPE(T) T[] +#else +#define ARRAY_TYPE(T) _cpp_array +#endif +/** + * Declaration of the array of given type and name. + * T = Type of the array items. + * N = Name of the array. + * Example: ARRAY(int, items); ArrayPush(items, 1); + */ +#ifdef __MQL__ +#define ARRAY(T, N) T N[] #else - /** - * Reference to object. - */ - #define CONST_REF_TO(T) const T& +#define ARRAY(T, N) ::_cpp_array N +#endif /** + * Reference to the array of given type and name. + * T = Type of the array items. + * N = Name of the array. + * Example: void Append(ARRAY_REF(int, values)); + */ +#ifdef __MQL__ +#define ARRAY_REF(T, N) REF(T) N[] +#else +#define ARRAY_REF(T, N) ARRAY_TYPE(T) & N +#endif + +/** + * Reference to the constant array of given type and name. + * T = Type of the array items. + * N = Name of the array. + * Example: void Append(CONST_ARRAY_REF(int, values)); + */ +#ifdef __MQL__ +#define CONST_ARRAY_REF(T, N) const T& N[] +#else +#define CONST_ARRAY_REF(T, N) const _cpp_array& N +#endif -* Reference to the array. -* -* @usage -* ARRAY_REF(, ) -*/ - #define ARRAY_TYPE(T) _cpp_array - #define ARRAY_REF(T, N) ARRAY_TYPE(T) & N - #define FIXED_ARRAY_REF(T, N, S) T(&N)[S] +/** + * Declaration of the array of given type, name and fixed size. + * T = Type of the array items. + * N = Name of the array. + * S = Fixed size of the array. + * Example: FIXED_ARRAY(int, values, 1); values[0] = 1; + */ +#define FIXED_ARRAY(T, N, SIZE) T N[SIZE] - #define CONST_ARRAY_REF(T, N) const _cpp_array& N - #define CONST_ARRAY_REF(T, N) const _cpp_array& N +/** + * Reference to the array of given type and name and fixed size. + * T = Type of the array items. + * N = Name of the array. + * S = Fixed size of the array. + * Example: void Append(FIXED_ARRAY_REF(int, values, 5)); + */ +#ifdef __MQL__ +#define FIXED_ARRAY_REF(T, N, S) ARRAY_REF(T, N) +#else +#define FIXED_ARRAY_REF(T, N, S) T(&N)[S] +#endif - /** - * Array definition. - * - * @usage - * ARRAY(, ) - */ - #define ARRAY(T, N) ::_cpp_array N +/** + * Reference to the constant array of given type and name and fixed size. + * T = Type of the array items. + * N = Name of the array. + * S = Fixed size of the array. + * Example: void Append(FIXED_ARRAY_REF(int, values, 5)); + */ +#ifdef __MQL__ +#define CONST_FIXED_ARRAY_REF(T, N, S) const FIXED_ARRAY_REF(T, N, S) +#else +#define CONST_FIXED_ARRAY_REF(T, N, S) const FIXED_ARRAY_REF(T, N, S) #endif // typename(T) @@ -168,7 +228,7 @@ class _cpp_array { _cpp_array() {} template - _cpp_array(const T REF(_arr)[size]) { + _cpp_array(CONST_FIXED_ARRAY_REF(T, _arr, size)) { for (const auto& _item : _arr) m_data.push_back(_item); } @@ -372,7 +432,7 @@ _NULL_VALUE::operator string() const { #endif #ifndef __MQL__ - #include "Chart.enum.h" + #include "Platform/Chart/Chart.enum.h" /** * Returns currently selected period for platform. */ diff --git a/Array.extern.h b/Storage/Array.extern.h similarity index 72% rename from Array.extern.h rename to Storage/Array.extern.h index fcedddc15..1674e2af8 100644 --- a/Array.extern.h +++ b/Storage/Array.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -22,10 +22,11 @@ // Define external global functions. #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once -#include "Common.extern.h" -#include "Std.h" +#include "../Common.extern.h" +#include "../Std.h" #include "String.extern.h" template @@ -34,7 +35,7 @@ int ArraySize(const ARRAY_REF(T, _array)) { } template -constexpr int ArraySize(const T REF(_array)[size]) { +constexpr int ArraySize(CONST_FIXED_ARRAY_REF(T, _array, size)) { return size; } @@ -51,7 +52,7 @@ bool ArraySetAsSeries(ARRAY_REF(T, _array), bool _flag) { } template -bool ArrayGetAsSeries(ARRAY_REF(T, _array)) { +bool ArrayGetAsSeries(CONST_ARRAY_REF(T, _array)) { return _array.getIsSeries(); } @@ -80,15 +81,27 @@ bool ArrayReverse(ARRAY_REF(T, _array)) { } template -extern int ArrayInitialize(ARRAY_REF(T, array), char value) { +int ArrayInitialize(ARRAY_REF(T, array), char value) { + Print("Not yet implemented: ", __FUNCTION__, " returns 0."); + return 0; +} + +template +int ArrayInitialize(FIXED_ARRAY_REF(T, array, size), char value) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } template -extern int ArraySort(ARRAY_REF(T, array)) { +int ArraySort(ARRAY_REF(T, array)) { Print("Not yet implemented: ", __FUNCTION__, " returns 0."); return 0; } +template +void ArrayFill(ARRAY_REF(X, array), int start, int count, X value); + +template +void ArrayFill(FIXED_ARRAY_REF(X, array, size), int start, int count, X value); + #endif diff --git a/Array.mqh b/Storage/Array.h similarity index 92% rename from Array.mqh rename to Storage/Array.h index 80fd81e39..a8d96a6af 100644 --- a/Array.mqh +++ b/Storage/Array.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,11 +26,11 @@ #endif // Includes. +#include "../Common.extern.h" +#include "../Convert.extern.h" +#include "../Math/Math.extern.h" +#include "../Std.h" #include "Array.extern.h" -#include "Common.extern.h" -#include "Convert.extern.h" -#include "Math.extern.h" -#include "Std.h" #include "String.extern.h" // Defines. @@ -102,6 +102,28 @@ class Array { } } + template + static void ArrayFill(ARRAY_REF(X, array), int start, int count, X value) { + start = MathMax(start, 0); + int end = MathMin(ArraySize(array), start + count); + + for (int i = start; i < end; ++i) { + array[i] = value; + } + } + +#ifdef __cplusplus + template + static void ArrayFill(FIXED_ARRAY_REF(X, array, size), int start, int count, X value) { + start = MathMax(start, 0); + int end = MathMin(size, start + count); + + for (int i = start; i < end; ++i) { + array[i] = value; + } + } +#endif + template static int ArrayCopy(ARRAY_REF(T, dst_array), const ARRAY_REF(T, src_array), const int dst_start = 0, const int src_start = 0, const int count = WHOLE_ARRAY) { @@ -533,12 +555,12 @@ static int GetLowestArrDoubleValue(double& arr[][], int key) { * - https://www.mql5.com/en/docs/array/arrayprint */ template - void ArrayPrint(ARRAY_REF(T, _arr), // Printed array. - int _digits = 0, // Number of decimal places. - const string _dlm = NULL, // Separator of the structure field values. - long _start = 0, // First printed element index. - long _count = WHOLE_ARRAY, // Number of printed elements. - long _flags = NULL) { + void ArrayPrint(ARRAY_REF(T, _arr), // Printed array. + int _digits = 0, // Number of decimal places. + const string _dlm = NULL, // Separator of the structure field values. + int64 _start = 0, // First printed element index. + int64 _count = WHOLE_ARRAY, // Number of printed elements. + int64 _flags = NULL) { #ifdef __MQL5__ ::ArrayPrint(_arr, _digits, _dlm, _start, _count, _flags); #else @@ -780,3 +802,17 @@ void ArrayPushObject(ARRAY_REF(X, array), X& value) { ArrayResize(array, Array::ArraySize(array) + 1); array[Array::ArraySize(array) - 1] = value; } + +#ifndef __MQL__ + +template +void ArrayFill(ARRAY_REF(X, array), int start, int count, X value) { + Array::ArrayFill(array, start, count, value); +} + +template +void ArrayFill(FIXED_ARRAY_REF(X, array, size), int start, int count, X value) { + Array::ArrayFill(array, start, count, value); +} + +#endif diff --git a/Indicator/IndicatorData.struct.cache.h b/Storage/Cache/IndiBufferCache.h similarity index 82% rename from Indicator/IndicatorData.struct.cache.h rename to Storage/Cache/IndiBufferCache.h index da27cae48..f0fdaf31c 100644 --- a/Indicator/IndicatorData.struct.cache.h +++ b/Storage/Cache/IndiBufferCache.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,14 +31,14 @@ #endif // Includes. -#include "../Refs.mqh" -#include "../Storage/ValueStorage.h" +#include "../../Refs.mqh" +#include "../ValueStorage.h" /** * Holds buffers used to cache values calculated via OnCalculate methods. */ template -class IndicatorCalculateCache : public Dynamic { +class IndiBufferCache : public Dynamic { public: // Total number of calculated values. int prev_calculated; @@ -68,12 +68,12 @@ class IndicatorCalculateCache : public Dynamic { ARRAY(IValueStorage *, buffers); // Auxiliary caches related to this one. - ARRAY(IndicatorCalculateCache *, subcaches); + ARRAY(IndiBufferCache *, subcaches); /** * Constructor. */ - IndicatorCalculateCache(int _buffers_size = 0) { + IndiBufferCache(int _buffers_size = 0) { prev_calculated = 0; total = 0; initialized = false; @@ -83,7 +83,7 @@ class IndicatorCalculateCache : public Dynamic { /** * Destructor. */ - ~IndicatorCalculateCache() { + ~IndiBufferCache() { int i; for (i = 0; i < ArraySize(buffers); ++i) { @@ -102,7 +102,9 @@ class IndicatorCalculateCache : public Dynamic { /** * Returns size of the current price buffer. */ - int GetTotal() { return price_buffer != NULL ? ArraySize(price_buffer) : ArraySize(price_open_buffer); } + int GetTotal() { + return price_buffer != NULL ? ArraySize(PTR_TO_REF(price_buffer)) : ArraySize(PTR_TO_REF(price_open_buffer)); + } /** * Returns number of already calculated prices (bars). @@ -123,13 +125,13 @@ class IndicatorCalculateCache : public Dynamic { * Returns existing or new cache as a child of current one. Useful when indicator uses other indicators and requires * unique caches for them. */ - IndicatorCalculateCache *GetSubCache(int _idx) { + IndiBufferCache *GetSubCache(int _idx) { if (_idx >= ArraySize(subcaches)) { ArrayResize(subcaches, _idx + 1, 10); } if (subcaches[_idx] == NULL) { - subcaches[_idx] = new IndicatorCalculateCache(); + subcaches[_idx] = new IndiBufferCache(); } return subcaches[_idx]; @@ -154,32 +156,33 @@ class IndicatorCalculateCache : public Dynamic { * Returns given calculation buffer. */ template - ValueStorage *GetBuffer(int _index) { - return (ValueStorage *)buffers[_index]; + REF_TO(ValueStorage) + GetBuffer(int _index) { + return PTR_TO_REF((ValueStorage *)buffers[_index]); } /** * Returns main price buffer. */ - ValueStorage *GetPriceBuffer() { return price_buffer; } + REF_TO(ValueStorage) GetPriceBuffer() { return PTR_TO_REF(price_buffer); } /** * Returns given price buffer. */ - ValueStorage *GetPriceBuffer(ENUM_APPLIED_PRICE _applied_price) { + REF_TO(ValueStorage) GetPriceBuffer(ENUM_APPLIED_PRICE _applied_price) { switch (_applied_price) { case PRICE_OPEN: - return price_open_buffer; + return PTR_TO_REF(price_open_buffer); case PRICE_HIGH: - return price_high_buffer; + return PTR_TO_REF(price_high_buffer); case PRICE_LOW: - return price_low_buffer; + return PTR_TO_REF(price_low_buffer); case PRICE_CLOSE: - return price_close_buffer; + return PTR_TO_REF(price_close_buffer); default: RUNTIME_ERROR("Applied price not supported!"); } - return nullptr; + return PTR_TO_REF((ValueStorage *)nullptr); } /** @@ -242,9 +245,9 @@ class IndicatorCalculateCache : public Dynamic { */ template D GetTailValue(int _buffer_index, int _shift) { - ValueStorage *_buff = GetBuffer(_buffer_index); - int _index = _buff PTR_DEREF IsSeries() ? _shift : (ArraySize(_buff) - _shift - 1); - return _buff[_index].Get(); + ValueStorage *_buff = REF_TO_PTR(GetBuffer(_buffer_index)); + int _index = _buff PTR_DEREF IsSeries() ? _shift : (ArraySize(PTR_TO_REF(_buff)) - _shift - 1); + return PTR_TO_REF(_buff)[_index].Get(); } /** diff --git a/Storage/ObjectsCache.h b/Storage/Cache/ObjectsCache.h similarity index 84% rename from Storage/ObjectsCache.h rename to Storage/Cache/ObjectsCache.h index ee73d69dc..620301f99 100644 --- a/Storage/ObjectsCache.h +++ b/Storage/Cache/ObjectsCache.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,7 +30,7 @@ #endif // Includes. -#include "../DictStruct.mqh" +#include "../../Storage/Dict/DictStruct.h" /** * Makes DictStruct object pointers to be deleted at the end. @@ -64,12 +64,12 @@ class ObjectsCache { * Tries to retrieve pointer to object for a given key. Returns true if object did exist. */ static bool TryGet(string& key, C*& out_ptr) { - int position; - if (!GetObjects().KeyExists(key, position)) { + unsigned int position; + if (!GetObjects() PTR_DEREF KeyExists(key, position)) { out_ptr = NULL; return false; } else { - out_ptr = GetObjects().GetByPos(position); + out_ptr = GetObjects() PTR_DEREF GetByPos(position); return true; } } @@ -78,7 +78,7 @@ class ObjectsCache { * Stores object pointer with a given key. */ static C* Set(string& key, C* ptr) { - GetObjects().Set(key, ptr); + GetObjects() PTR_DEREF Set(key, ptr); return ptr; } }; diff --git a/Storage/Cache/tests/IndiBufferCache.test.cpp b/Storage/Cache/tests/IndiBufferCache.test.cpp new file mode 100644 index 000000000..9934b467c --- /dev/null +++ b/Storage/Cache/tests/IndiBufferCache.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of IndiBufferCache class. + */ + +// Includes. +#include "../IndiBufferCache.h" + +int main(int argc, char **argv) { + // @todo: Add more tests. + // ... + + return 0; +} diff --git a/Storage/Cache/tests/IndiBufferCache.test.mq4 b/Storage/Cache/tests/IndiBufferCache.test.mq4 new file mode 100644 index 000000000..816bd354b --- /dev/null +++ b/Storage/Cache/tests/IndiBufferCache.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of IndiBufferCache class. + */ + +// Includes. +#include "IndiBufferCache.test.mq5" diff --git a/Storage/Cache/tests/IndiBufferCache.test.mq5 b/Storage/Cache/tests/IndiBufferCache.test.mq5 new file mode 100644 index 000000000..39ae3bbe0 --- /dev/null +++ b/Storage/Cache/tests/IndiBufferCache.test.mq5 @@ -0,0 +1,39 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of ObjectsCache class. + */ + +// Includes. +#include "../../../Test.mqh" +#include "../IndiBufferCache.h" + +/** + * Implements OnInit(). + */ +int OnInit() { + // @todo: Add more tests. + // ... + + return (GetLastError() > 0 ? INIT_FAILED : INIT_SUCCEEDED); +} diff --git a/Storage/Cache/tests/Makefile b/Storage/Cache/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Storage/Cache/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Storage/Cache/tests/ObjectsCache.test.cpp b/Storage/Cache/tests/ObjectsCache.test.cpp new file mode 100644 index 000000000..b4b11635d --- /dev/null +++ b/Storage/Cache/tests/ObjectsCache.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of ObjectsCache class. + */ + +// Includes. +#include "../ObjectsCache.h" + +int main(int argc, char **argv) { + // @todo: Add more tests. + // ... + + return 0; +} diff --git a/tests/BufferStructTest.mq4 b/Storage/Cache/tests/ObjectsCache.test.mq4 similarity index 86% rename from tests/BufferStructTest.mq4 rename to Storage/Cache/tests/ObjectsCache.test.mq4 index 3a5dd3d31..a2860056a 100644 --- a/tests/BufferStructTest.mq4 +++ b/Storage/Cache/tests/ObjectsCache.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,20 +9,20 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * @file - * Test functionality of BufferStruct class. + * Test functionality of ObjectsCache class. */ // Includes. -#include "BufferStructTest.mq5" +#include "ObjectsCache.test.mq5" diff --git a/Storage/Cache/tests/ObjectsCache.test.mq5 b/Storage/Cache/tests/ObjectsCache.test.mq5 new file mode 100644 index 000000000..5fcf02d1a --- /dev/null +++ b/Storage/Cache/tests/ObjectsCache.test.mq5 @@ -0,0 +1,39 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of ObjectsCache class. + */ + +// Includes. +#include "../../../Test.mqh" +#include "../ObjectsCache.h" + +/** + * Implements OnInit(). + */ +int OnInit() { + // @todo: Add more tests. + // ... + + return (GetLastError() > 0 ? INIT_FAILED : INIT_SUCCEEDED); +} diff --git a/Storage/Collection.mqh b/Storage/Collection.h similarity index 93% rename from Storage/Collection.mqh rename to Storage/Collection.h index 3d49ab173..cffd107ed 100644 --- a/Storage/Collection.mqh +++ b/Storage/Collection.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,12 +20,13 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef COLLECTION_MQH -#define COLLECTION_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../Object.mqh" +#include "Object.h" /** * Class to deal with collection of objects. @@ -140,7 +141,7 @@ class Collection { /** * Returns object item by object id. */ - X *GetById(long _id) { + X *GetById(int64 _id) { int i; X *_object = GetSize() > 0 ? data[0].Ptr() : NULL; for (i = 0; i < ArraySize(data); i++) { @@ -209,4 +210,3 @@ class Collection { return _out; } }; -#endif // COLLECTION_MQH diff --git a/Data.define.h b/Storage/Data.define.h similarity index 84% rename from Data.define.h rename to Storage/Data.define.h index 9fb26ee47..417f9231b 100644 --- a/Data.define.h +++ b/Storage/Data.define.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Includes Data's defines. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #ifndef __MQL4__ // -- #ifndef DoubleToStr diff --git a/Data.enum.h b/Storage/Data.enum.h similarity index 88% rename from Data.enum.h rename to Storage/Data.enum.h index 985f82244..6c47c9607 100644 --- a/Data.enum.h +++ b/Storage/Data.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -45,12 +45,12 @@ enum ENUM_DATATYPE { TYPE_DOUBLE, // double TYPE_FLOAT, // float TYPE_INT, // int - TYPE_LONG, // long + TYPE_LONG, // int64 TYPE_SHORT, // short TYPE_STRING, // string TYPE_UCHAR, // unsigned char TYPE_UINT, // unsigned int - TYPE_ULONG, // unsigned long + TYPE_ULONG, // uint64 TYPE_USHORT, // unsigned short }; #endif diff --git a/Data.struct.h b/Storage/Data.struct.h similarity index 90% rename from Data.struct.h rename to Storage/Data.struct.h index 38aac559f..eccdcb798 100644 --- a/Data.struct.h +++ b/Storage/Data.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -36,12 +36,12 @@ struct MqlParam; struct MqlRates; // Includes. +#include "../Serializer/Serializer.enum.h" +#include "../Serializer/SerializerNode.enum.h" +#include "../Std.h" #include "Data.enum.h" #include "DateTime.extern.h" -#include "Serializer/Serializer.enum.h" -#include "Serializer/SerializerNode.enum.h" -#include "Std.h" -#include "String.mqh" +#include "String.h" #ifndef __MQL__ /** @@ -54,7 +54,7 @@ struct MqlRates; struct MqlParam { ENUM_DATATYPE type; // Type of the input parameter, value of ENUM_DATATYPE. union { - long integer_value; // Field to store an integer type. + int64 integer_value; // Field to store an integer type. double double_value; // Field to store a double type. string string_value; // Field to store a string type. }; @@ -88,7 +88,7 @@ struct MqlParam { return THIS_REF; } - MqlParam(long _value) { + MqlParam(int64 _value) { type = ENUM_DATATYPE::TYPE_LONG; integer_value = _value; } @@ -122,7 +122,7 @@ struct MqlParam { struct DataParamEntry : public MqlParam { public: DataParamEntry() { type = InvalidEnumValue::value(); } - DataParamEntry(ENUM_DATATYPE _type, long _integer_value, double _double_value, string _string_value) { + DataParamEntry(ENUM_DATATYPE _type, int64 _integer_value, double _double_value, string _string_value) { type = _type; integer_value = _integer_value; double_value = _double_value; @@ -154,13 +154,13 @@ struct DataParamEntry : public MqlParam { type = TYPE_UINT; integer_value = _value; } - DataParamEntry(long _value) { + DataParamEntry(int64 _value) { type = TYPE_LONG; integer_value = _value; } - DataParamEntry(unsigned long _value) { + DataParamEntry(uint64 _value) { type = TYPE_ULONG; - integer_value = (long)_value; + integer_value = (int64)_value; } // Struct operators. @@ -188,13 +188,13 @@ struct DataParamEntry : public MqlParam { type = TYPE_UINT; integer_value = _value; } - void operator=(long _value) { + void operator=(int64 _value) { type = TYPE_LONG; integer_value = _value; } - void operator=(unsigned long _value) { + void operator=(uint64 _value) { type = TYPE_ULONG; - integer_value = (long)_value; + integer_value = (int64)_value; } bool operator==(const DataParamEntry &_s) { @@ -206,7 +206,7 @@ struct DataParamEntry : public MqlParam { /* DataParamEntry() {} - DataParamEntry(ENUM_DATATYPE _type, long _int, double _dbl, string _str) { + DataParamEntry(ENUM_DATATYPE _type, int64 _int, double _dbl, string _str) { type = _type; integer_value = _int; double_value = _dbl; @@ -277,10 +277,10 @@ struct DataParamEntry : public MqlParam { } /** - * Gets DataParamEntry struct based on the value of long type. + * Gets DataParamEntry struct based on the value of int64 type. * */ - static DataParamEntry FromValue(long _value) { + static DataParamEntry FromValue(int64 _value) { DataParamEntry _dpe; _dpe.type = TYPE_LONG; _dpe.integer_value = _value; @@ -332,7 +332,7 @@ struct DataParamEntry : public MqlParam { * Converts MqlParam struct to integer. * */ - static long ToInteger(MqlParam ¶m) { + static int64 ToInteger(MqlParam ¶m) { switch (param.type) { case TYPE_BOOL: return param.integer_value ? 1 : 0; diff --git a/Data.struct.serialize.h b/Storage/Data.struct.serialize.h similarity index 92% rename from Data.struct.serialize.h rename to Storage/Data.struct.serialize.h index d55ad12e1..7ea683617 100644 --- a/Data.struct.serialize.h +++ b/Storage/Data.struct.serialize.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,8 +31,8 @@ #endif // Includes. +#include "../Serializer/Serializer.h" #include "Data.struct.h" -#include "Serializer/Serializer.h" /* Method to serialize DataParamEntry struct. */ SerializerNodeType DataParamEntry::Serialize(Serializer &s) { diff --git a/Storage/Database.enum.h b/Storage/Database.enum.h new file mode 100644 index 000000000..926d67ed9 --- /dev/null +++ b/Storage/Database.enum.h @@ -0,0 +1,47 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Enums. + +enum ENUM_DATABASE_COLUMN_FLAGS { + DATABASE_COLUMN_FLAG_NONE = 0, + DATABASE_COLUMN_FLAG_IS_KEY = 1, + DATABASE_COLUMN_FLAG_IS_NULL = 2, +}; + +#ifndef __MQL5__ + +// @docs: https://www.mql5.com/en/docs/database/databaseopen#enum_database_open_flags +enum ENUM_DATABASE_OPEN_FLAGS { + DATABASE_OPEN_READONLY = 0, // Read only. + DATABASE_OPEN_READWRITE, // Open for reading and writing. + DATABASE_OPEN_CREATE, // Create the file on a disk if necessary. + DATABASE_OPEN_MEMORY, // Create a database in RAM. + DATABASE_OPEN_COMMON, // The file is in the common folder of all terminals. +}; + +#endif diff --git a/Storage/Database.extern.h b/Storage/Database.extern.h new file mode 100644 index 000000000..64a6d25db --- /dev/null +++ b/Storage/Database.extern.h @@ -0,0 +1,66 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +// Includes. + +// Define external global functions. +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once + +// Closes a database. +// @docs: https://www.mql5.com/en/docs/database/databaseclose +void DatabaseClose(int database // database handle received in DatabaseOpen +); +// Executes a request to a specified database. +// @docs: https://www.mql5.com/en/docs/database/databaseexecute +extern bool DatabaseExecute(int database, // database handle received in DatabaseOpen + string sql // SQL request +); + +// Opens or creates a database in a specified file. +// @docs: https://www.mql5.com/en/docs/database/databaseopen +int DatabaseOpen(string filename, // file name + unsigned int flags // combination of flags +); + +// Starts transaction execution. +// @docs: https://www.mql5.com/en/docs/database/databasetransactionbegin +bool DatabaseTransactionBegin(int database // database handle received in DatabaseOpen +); + +// Completes transaction execution. +// @docs: https://www.mql5.com/en/docs/database/databasetransactioncommit +extern bool DatabaseTransactionCommit(int database // database handle received in DatabaseOpen +); + +// Checks the presence of the table in a database. +// @docs: https://www.mql5.com/en/docs/database/databasetableexists +bool DatabaseTableExists(int database, // database handle received in DatabaseOpen + string table // table name +); + +// Rolls back transactions. +// @docs: https://www.mql5.com/en/docs/database/databasetransactionrollback +extern bool DatabaseTransactionRollback(int database // database handle received in DatabaseOpen +); +#endif diff --git a/Storage/Database.h b/Storage/Database.h new file mode 100644 index 000000000..5a59b3426 --- /dev/null +++ b/Storage/Database.h @@ -0,0 +1,259 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* + * Implements Database class. + * + * The methods for working with databases uses SQLite engine. + * + * @docs https://www.mql5.com/en/docs/database + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Includes. +#include "../Math/MatrixMini.h" +#include "../Storage/Dict/DictStruct.h" +#include "Database.enum.h" +#include "Database.extern.h" +#include "Database.struct.h" + +class Database { + private: + int handle; + DictStruct tables; + + public: + /** + * Class constructor. + */ +#ifdef __MQL5__ + Database(string _filename, unsigned int _flags = DATABASE_OPEN_CREATE) +#else + Database(string _filename, unsigned int _flags = 0) +#endif + { +#ifdef __MQL5__ + handle = DatabaseOpen(_filename, _flags); +#else + handle = -1; + SetUserError(ERR_USER_NOT_SUPPORTED); +#endif + } + + /** + * Class deconstructor. + */ + ~Database() { +#ifdef __MQL5__ + DatabaseClose(handle); +#endif + } + + /* Table methods */ + + /** + * Checks if table exists. + */ + bool TableExists(string _name) { +#ifdef __MQL5__ + return DatabaseTableExists(handle, _name); +#else + SetUserError(ERR_USER_NOT_SUPPORTED); + return false; +#endif + } + + /** + * Creates table if not yet exist. + */ + bool CreateTableIfNotExist(string _name, DatabaseTableSchema &_schema) { + if (TableExists(_name)) { + return true; + } + return CreateTable(_name, _schema); + } + + /** + * Creates table. + */ + bool CreateTable(string _name, REF_TO_SIMPLE(DatabaseTableSchema) _schema) { + bool _result = false; +#ifdef __MQL5__ + if (DatabaseTableExists(handle, _name)) { + // Generic error (ERR_DATABASE_ERROR). + SetUserError(5601); + return _result; + } + + string query = "", subquery = ""; + + if (_schema.columns.Size() == 0) { + // SQLite does'nt allow tables without columns; + subquery = "`dummy` INTEGER"; + } else { + for (DictStructIterator iter = _schema.columns.Begin(); iter.IsValid(); ++iter) { + subquery += + StringFormat("`%s` %s %s,", iter.Value().GetName(), iter.Value().GetDatatype(), iter.Value().GetFlags()); + } + subquery = StringSubstr(subquery, 0, StringLen(subquery) - 1); // Removes extra comma. + } + + query = StringFormat("CREATE TABLE `%s`(%s);", _name, subquery); + +#ifdef __debug__ + Print("Database: Executing query:\n", query); +#endif + + if (_result = DatabaseExecute(handle, query)) { + ResetLastError(); + SetTableSchema(_name, _schema); + } else { +#ifdef __debug__ + Print("Database: Query failed with error ", _LastError); + DebugBreak(); +#endif + } +#endif + return _result; + } + + /** + * Drops table. + */ + bool DropTable(string _name) { + tables.Unset(_name); +#ifdef __MQL5__ + return DatabaseExecute(handle, "DROP TABLE IF EXISTS `" + _name + "`"); +#else + return false; +#endif + } + + /* Import methods */ + + /** + * Imports data into table. First row must contain column names. Strings must be enclosed with double quotes. + */ + bool Import(const string _name, MatrixMini2d &data) { + if (data.SizeY() < 2 || data.SizeX() == 0) { + // No data to import or there are no columns in input data (Serialize() serialized no fields). + return true; + } + int x; + bool _result = true; + DatabaseTableSchema _schema = GetTableSchema(_name); + string _query = "", _cols = "", _vals = ""; + for (x = 0; x < data.SizeX(); ++x) { + const string key = data.Get(x, 0); + _cols += "`" + StringSubstr(key, 1, StringLen(key) - 2) + "`,"; + } + _cols = StringSubstr(_cols, 0, StringLen(_cols) - 1); // Removes extra comma. +#ifdef __MQL5__ + if (DatabaseTransactionBegin(handle)) { + _query = StringFormat("INSERT INTO `%s`(%s) VALUES\n", _name, _cols); + for (int y = 1; y < data.SizeY(); ++y) { + _query += "("; + for (x = 0; x < data.SizeX(); ++x) { + _query += data.Get(x, y) + (x < data.SizeX() - 1 ? ", " : ""); + } + _query += ")" + (string)(y < data.SizeY() - 1 ? ",\n" : ""); + } + +#ifdef __debug__ + Print("Database: Executing query:\n", _query); +#endif + + _result &= DatabaseExecute(handle, _query); + } + if (_result) { + DatabaseTransactionCommit(handle); + } else { + Print("Database: Query failed with error ", _LastError); + DebugBreak(); + DatabaseTransactionRollback(handle); + } +#else + return false; +#endif + return _result; + } + +#ifdef DATABASE_INCLUDE_BUFFER_STRUCT + /** + * Imports BufferStruct records into a table. + */ + template + bool Import(const string _name, BufferStruct &_bstruct) { + bool _result = true; + DatabaseTableSchema _schema = GetTableSchema(_name); + string _query = "", _cols = "", _vals = ""; + for (DictStructIterator iter = _schema.columns.Begin(); iter.IsValid(); ++iter) { + _cols += iter.Value().name + ","; + } + _cols = StringSubstr(_cols, 0, StringLen(_cols) - 1); // Removes extra comma. +#ifdef __MQL5__ + if (DatabaseTransactionBegin(handle)) { + for (DictStructIterator iter = _bstruct.Begin(); iter.IsValid(); ++iter) { + _query = StringFormat("INSERT INTO %s(%s) VALUES (%s)", _name, _cols, iter.Value().ToCSV()); + _result &= DatabaseExecute(handle, _query); + } + } + if (_result) { + DatabaseTransactionCommit(handle); + } else { + DatabaseTransactionRollback(handle); + } +#else + return false; +#endif + return _result; + } +#endif + + /* Getters */ + + /** + * Gets database handle. + */ + int GetHandle() { return handle; } + + /** + * Gets table schema. + */ + DatabaseTableSchema GetTableSchema(string _name) { return tables.GetByKey(_name); } + + /** + * Checks if table schema exists. + */ + bool SchemaExists(string _name) { return tables.KeyExists(_name); } + + /* Setters */ + + /** + * Sets table schema. + */ + bool SetTableSchema(string _name, DatabaseTableSchema &_schema) { return tables.Set(_name, _schema); } +}; diff --git a/Storage/Database.struct.h b/Storage/Database.struct.h new file mode 100644 index 000000000..9e380446c --- /dev/null +++ b/Storage/Database.struct.h @@ -0,0 +1,114 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/* + * Defines structures related to Database class. + * + */ + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Structs. +struct DatabaseTableColumnEntry { + string name; + ENUM_DATATYPE type; + unsigned short flags; + unsigned short char_size; + // Getter methods; + string GetDatatype() { + switch (type) { + case TYPE_BOOL: + return "BOOL"; + case TYPE_CHAR: + return StringFormat("CHAR(%d)", char_size); + case TYPE_DOUBLE: + return "REAL"; + case TYPE_INT: + return "INT"; + case TYPE_LONG: + return "LONG"; + case TYPE_STRING: + return "TEXT"; + } + return "UNKNOWN"; + } + string GetFlags() { return GetKey() + " " + GetNull(); } + string GetName() { return name; } + string GetNull() { return !IsNull() ? "NOT NULL" : ""; } + string GetKey() { return IsKey() ? "KEY" : ""; } + // State methods. + bool IsKey() { return bool(flags & DATABASE_COLUMN_FLAG_IS_KEY); } + bool IsNull() { return bool(flags & DATABASE_COLUMN_FLAG_IS_NULL); } + + DatabaseTableColumnEntry() {} + DatabaseTableColumnEntry(const string _name, const ENUM_DATATYPE _type, unsigned short _flags = 0, + unsigned short _char_size = 0) { + name = _name; + type = _type; + flags = _flags; + char_size = _char_size; + } + DatabaseTableColumnEntry(const DatabaseTableColumnEntry &r) { + name = r.name; + type = r.type; + flags = r.flags; + char_size = r.char_size; + } +}; + +struct DatabaseTableSchema { + DictStruct columns; + // Constructor. + DatabaseTableSchema() {} + DatabaseTableSchema(ARRAY_REF(DatabaseTableColumnEntry, _columns)) { + for (int i = 0; i < ArraySize(_columns); i++) { + columns.Push(_columns[i]); + } + } + DatabaseTableSchema(const DatabaseTableSchema &r) { columns = r.columns; } + // Methods. + bool AddColumn(DatabaseTableColumnEntry &column) { return columns.Push(column); } +}; + +// Struct table entry for SymbolInfo. +#ifdef DATABASE_INCLUDE_SYMBOLINFO_STRUCT +struct DbSymbolInfoEntry : public SymbolInfoEntry { + DatabaseTableSchema schema; + // Constructors. + DbSymbolInfoEntry() { DefineSchema(); } + DbSymbolInfoEntry(const DbSymbolInfoEntry &r) { schema = r.schema; } + DbSymbolInfoEntry(const MqlTick &_tick, const string _symbol = NULL) : SymbolInfoEntry(_tick, _symbol) { + DefineSchema(); + } + // Methods. + void DefineSchema() { + schema.columns.Push(DatabaseTableColumnEntry("bid", TYPE_DOUBLE)); + schema.columns.Push(DatabaseTableColumnEntry("ask", TYPE_DOUBLE)); + schema.columns.Push(DatabaseTableColumnEntry("last", TYPE_DOUBLE)); + schema.columns.Push(DatabaseTableColumnEntry("spread", TYPE_DOUBLE)); + schema.columns.Push(DatabaseTableColumnEntry("volume", TYPE_INT)); + } +}; +#endif diff --git a/DateTime.entry.h b/Storage/DateTime.entry.h similarity index 96% rename from DateTime.entry.h rename to Storage/DateTime.entry.h index 539ec5a45..176c43417 100644 --- a/DateTime.entry.h +++ b/Storage/DateTime.entry.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,9 +31,9 @@ #endif // Includes. +#include "../Platform/PlatformTime.h" +#include "../Std.h" #include "DateTime.static.h" -#include "PlatformTime.h" -#include "Std.h" struct DateTimeEntry : MqlDateTime { int week_of_year; diff --git a/DateTime.enum.h b/Storage/DateTime.enum.h similarity index 94% rename from DateTime.enum.h rename to Storage/DateTime.enum.h index 6809eaa8b..495c7dfcf 100644 --- a/DateTime.enum.h +++ b/Storage/DateTime.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/DateTime.extern.h b/Storage/DateTime.extern.h similarity index 94% rename from DateTime.extern.h rename to Storage/DateTime.extern.h index 68c1dc9f6..ebd99b875 100644 --- a/DateTime.extern.h +++ b/Storage/DateTime.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,7 +31,7 @@ #include #include "DateTime.enum.h" -#include "String.mqh" +#include "String.h" // Forward declarations. struct MqlDateTime; diff --git a/DateTime.mqh b/Storage/DateTime.h similarity index 95% rename from DateTime.mqh rename to Storage/DateTime.h index a1cbca946..be8647c64 100644 --- a/DateTime.mqh +++ b/Storage/DateTime.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -29,22 +29,23 @@ * - https://www.mql5.com/en/docs/dateandtime */ -// Prevents processing this includes file for the second time. -#ifndef DATETIME_MQH -#define DATETIME_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Forward declarations. struct DataParamEntry; // Includes class enum and structs. -#include "Array.mqh" +#include "../Platform/PlatformTime.h" +#include "Array.h" #include "Data.struct.h" #include "DateTime.entry.h" #include "DateTime.enum.h" #include "DateTime.extern.h" #include "DateTime.static.h" #include "DateTime.struct.h" -#include "PlatformTime.h" #ifndef __MQL4__ // Defines global functions (for MQL4 backward compatibility). @@ -252,5 +253,3 @@ datetime TimeCurrent(MqlDateTime &dt_struct) { } #endif - -#endif // DATETIME_MQH diff --git a/DateTime.static.h b/Storage/DateTime.static.h similarity index 96% rename from DateTime.static.h rename to Storage/DateTime.static.h index c2ca188d8..cb932ce6c 100644 --- a/DateTime.static.h +++ b/Storage/DateTime.static.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,7 +31,7 @@ #endif // Includes. -#include "PlatformTime.h" +#include "../Platform/PlatformTime.h" /* * Struct to provide static date and time methods. diff --git a/DateTime.struct.h b/Storage/DateTime.struct.h similarity index 91% rename from DateTime.struct.h rename to Storage/DateTime.struct.h index cb44b9325..79862d70d 100644 --- a/DateTime.struct.h +++ b/Storage/DateTime.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -34,8 +34,8 @@ struct DateTimeStatic; // Includes. +#include "../Std.h" #include "DateTime.enum.h" -#include "Std.h" #ifndef __MQLBUILD__ /** diff --git a/Buffer.mqh b/Storage/Dict/Buffer/Buffer.h similarity index 74% rename from Buffer.mqh rename to Storage/Dict/Buffer/Buffer.h index 4a764c69c..00ad9a3a4 100644 --- a/Buffer.mqh +++ b/Storage/Dict/Buffer/Buffer.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,25 +20,26 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef BUFFER_MQH -#define BUFFER_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "Dict.mqh" +#include "../Dict.h" /** * Class to store data values. */ template -class Buffer : public Dict { +class Buffer : public Dict { public: - void Buffer() {} + Buffer() {} /** * Adds new value. */ - void Add(T _value, long _dt = 0) { + void Add(T _value, int64 _dt = 0) { _dt = _dt > 0 ? _dt : TimeCurrent(); Set(_dt, _value); } @@ -49,7 +50,7 @@ class Buffer : public Dict { T GetMin() { T min = NULL; - for (DictIterator iter = Begin(); iter.IsValid(); ++iter) + for (DictIterator iter = Begin(); iter.IsValid(); ++iter) if (min == NULL || min > iter.Value()) min = iter.Value(); return min; @@ -61,7 +62,7 @@ class Buffer : public Dict { T GetMax() { T max = NULL; - for (DictIterator iter = Begin(); iter.IsValid(); ++iter) + for (DictIterator iter = Begin(); iter.IsValid(); ++iter) if (max == NULL || max < iter.Value()) max = iter.Value(); return max; @@ -74,7 +75,7 @@ class Buffer : public Dict { T sum = 0; unsigned int numValues = 0; - for (DictIterator iter = Begin(); iter.IsValid(); ++iter) { + for (DictIterator iter = Begin(); iter.IsValid(); ++iter) { sum += iter.Value(); ++numValues; } @@ -90,7 +91,7 @@ class Buffer : public Dict { ArrayResize(array, Size()); - for (DictIterator iter = Begin(); iter.IsValid(); ++iter) { + for (DictIterator iter = Begin(); iter.IsValid(); ++iter) { array[iter.Index()] = iter.Value(); } @@ -108,4 +109,3 @@ class Buffer : public Dict { return (T)median; } }; -#endif // BUFFER_MQH diff --git a/Buffer/BufferCandle.h b/Storage/Dict/Buffer/BufferCandle.h similarity index 78% rename from Buffer/BufferCandle.h rename to Storage/Dict/Buffer/BufferCandle.h index 856ffb686..1126963b8 100644 --- a/Buffer/BufferCandle.h +++ b/Storage/Dict/Buffer/BufferCandle.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,15 +20,16 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef BUFFER_CANDLE_H -#define BUFFER_CANDLE_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../BufferStruct.mqh" -#include "../Candle.struct.h" -#include "../Serializer/SerializerConverter.h" -#include "../Serializer/SerializerJson.h" +#include "../../../Candle.struct.h" +#include "../../../Serializer/SerializerConverter.h" +#include "../../../Serializer/SerializerJson.h" +#include "BufferStruct.h" /** * Class to store struct data. @@ -62,5 +63,3 @@ class BufferCandle : public BufferStruct> { */ string ToJSON() { return SerializerConverter::FromObject(THIS_REF).ToString(); } }; - -#endif // BUFFER_CANDLE_H diff --git a/BufferFXT.mqh b/Storage/Dict/Buffer/BufferFXT.h similarity index 86% rename from BufferFXT.mqh rename to Storage/Dict/Buffer/BufferFXT.h index 5cd0c72ba..b545d0b17 100644 --- a/BufferFXT.mqh +++ b/Storage/Dict/Buffer/BufferFXT.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -19,15 +19,16 @@ * along with this program. If not, see . */ -// Prevents processing this includes file for the second time. -#ifndef BUFFER_FXT_MQH -#define BUFFER_FXT_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "Account/AccountMt.h" -#include "DictStruct.mqh" -#include "Indicator/IndicatorData.h" -#include "Object.mqh" +#include "../../../Exchange/Account/AccountMt.h" +#include "../../../Indicator/IndicatorData.h" +#include "../../../Storage/Object.h" +#include "../DictStruct.h" // Defines. #define FXT_VERSION 405 @@ -68,7 +69,7 @@ struct BufferFXTEntry { double high; double low; double close; - long volume; + int64 volume; int ctm; // The current time within a bar. int flag; // Flag to launch an expert (0 - bar will be modified, but the expert will not be launched). @@ -99,19 +100,19 @@ struct BufferFXTEntry { // FXT file header. struct BufferFXTHeader { - int version; // Header version: 405 - char copyright[64]; // Copyright/description. - char description[128]; // Account server name. - // 196 - char symbol[12]; // Symbol pair. - int period; // Period of data aggregation in minutes (timeframe). - int model; // Model type: 0 - every tick, 1 - control points, 2 - bar open. - int bars; // Bars - number of modeled bars in history. - int fromdate; // Modelling start date - date of the first tick. - int todate; // Modelling end date - date of the last tick. - int totalTicks; // Total ticks. Add 4 bytes to align to the next double? - double modelquality; // Modeling quality (max. 99.9). - // 240 + int version; // Header version: 405 + FIXED_ARRAY(char, copyright, 64); // Copyright/description. + FIXED_ARRAY(char, description, 128); // Account server name. + // 196 + FIXED_ARRAY(char, symbol, 12); // Symbol pair. + int period; // Period of data aggregation in minutes (timeframe). + int model; // Model type: 0 - every tick, 1 - control points, 2 - bar open. + int bars; // Bars - number of modeled bars in history. + int fromdate; // Modelling start date - date of the first tick. + int todate; // Modelling end date - date of the last tick. + int totalTicks; // Total ticks. Add 4 bytes to align to the next double? + double modelquality; // Modeling quality (max. 99.9). + // 240 // Market symbol properties. char currency[12]; // Base currency (12 bytes). Same as: StringLeft(symbol, 3) int spread; // Spread in points. Same as: MarketInfo(MODE_SPREAD) @@ -209,11 +210,11 @@ struct BufferFXTHeader { swap_long(_source PTR_DEREF GetSymbolProps().GetSwapLong()), swap_short(_source PTR_DEREF GetSymbolProps().GetSwapShort()), swap_rollover3days(3), - leverage((int)_a.GetLeverage()), + leverage((int)_a PTR_DEREF GetLeverage()), free_margin_mode(MARGIN_DONT_USE), margin_mode(MARGIN_CALC_FOREX), margin_stopout(30), // @fixme: _a.GetStopoutLevel() based on ACCOUNT_MARGIN_SO_CALL. - margin_stopout_mode(_a.GetStopoutMode()), + margin_stopout_mode(_a PTR_DEREF GetStopoutMode()), margin_initial(_source PTR_DEREF GetSymbolProps().GetMarginInit()), margin_maintenance(_source PTR_DEREF GetSymbolProps().GetMarginMaintenance()), margin_hedged(0), @@ -244,16 +245,16 @@ struct BufferFXTHeader { struct BufferFXTParams { AccountMt *account; - Ref source; + Ref source; // Struct constructor. - BufferFXTParams(IndicatorBase *_source, AccountMt *_account = NULL) + BufferFXTParams(IndicatorData *_source, AccountMt *_account = NULL) : account(Object::IsValid(_account) ? _account : new AccountMt), source(_source) {} BufferFXTParams(BufferFXTParams &r) { account = r.account; source = r.source; } // Struct deconstructor. - void ~BufferFXTParams() { delete account; } + ~BufferFXTParams() { delete account; } }; string ToJSON(BufferFXTEntry &_value, const bool, const unsigned int) { return _value.ToJSON(); }; @@ -261,7 +262,7 @@ string ToJSON(BufferFXTEntry &_value, const bool, const unsigned int) { return _ /** * Implements class to store tick data. */ -class BufferFXT : public DictStruct { +class BufferFXT : public DictStruct { protected: BufferFXTParams params; @@ -269,7 +270,7 @@ class BufferFXT : public DictStruct { /** * Class constructor. */ - BufferFXT(IndicatorBase *_source) : params(_source) {} + BufferFXT(IndicatorData *_source) : params(_source) {} BufferFXT(BufferFXTParams &_params) : params(_params) {} /** @@ -280,7 +281,7 @@ class BufferFXT : public DictStruct { /** * Adds new entry. */ - void Add(BufferFXTEntry &_value, long _dt = 0) { + void Add(BufferFXTEntry &_value, int64 _dt = 0) { _dt = _dt > 0 ? _dt : TimeCurrent(); Set(_dt, _value); } @@ -302,5 +303,3 @@ class BufferFXT : public DictStruct { // @see: https://docs.mql4.com/files/filewritestruct } }; - -#endif // BUFFER_FXT_MQH diff --git a/BufferStruct.mqh b/Storage/Dict/Buffer/BufferStruct.h similarity index 74% rename from BufferStruct.mqh rename to Storage/Dict/Buffer/BufferStruct.h index 20c60eae2..81cfb9ef0 100644 --- a/BufferStruct.mqh +++ b/Storage/Dict/Buffer/BufferStruct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,14 +20,18 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef BUFFER_STRUCT_MQH -#define BUFFER_STRUCT_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +// Flag for Database.struct.h so BufferStruct structure will be supported by it. +#define DATABASE_INCLUDE_BUFFER_STRUCT // Includes. -#include "DictBase.mqh" -#include "DictStruct.mqh" -#include "Serializer/Serializer.h" +#include "../../../Serializer/Serializer.h" +#include "../DictBase.h" +#include "../DictStruct.h" /** * Implements BufferStruct's Overflow Listener. @@ -53,9 +57,9 @@ bool BufferStructOverflowListener(ENUM_DICT_OVERFLOW_REASON _reason, int _size, * Class to store struct data. */ template -class BufferStruct : public DictStruct { +class BufferStruct : public DictStruct { protected: - long min, max; + int64 min, max; public: /* Constructors */ @@ -72,8 +76,8 @@ class BufferStruct : public DictStruct { /** * Adds new value. */ - void Add(TStruct& _value, long _dt = 0) { - _dt = _dt > 0 ? _dt : (long)TimeCurrent(); + void Add(TStruct& _value, int64 _dt = 0) { + _dt = _dt > 0 ? _dt : (int64)TimeCurrent(); if (THIS_ATTR Set(_dt, _value)) { min = _dt < min ? _dt : min; max = _dt > max ? _dt : max; @@ -83,12 +87,12 @@ class BufferStruct : public DictStruct { /** * Clear entries older than given timestamp. */ - void Clear(long _dt = 0, bool _older = true) { + void Clear(int64 _dt = 0, bool _older = true) { min = INT_MAX; max = INT_MIN; if (_dt > 0) { - for (DictStructIterator iter(THIS_ATTR Begin()); iter.IsValid(); ++iter) { - long _time = iter.Key(); + for (DictStructIterator iter(THIS_ATTR Begin()); iter.IsValid(); ++iter) { + int64 _time = iter.Key(); if (_older && _time < _dt) { Unset(iter.Key()); continue; @@ -100,7 +104,7 @@ class BufferStruct : public DictStruct { max = _time > max ? _time : max; } } else { - DictStruct::Clear(); + DictStruct::Clear(); } } @@ -109,12 +113,10 @@ class BufferStruct : public DictStruct { /** * Gets the newest timestamp. */ - long GetMax() { return max; } + int64 GetMax() { return max; } /** * Gets the oldest timestamp. */ - long GetMin() { return min; } + int64 GetMin() { return min; } }; - -#endif // BUFFER_STRUCT_MQH diff --git a/Buffer/BufferTick.h b/Storage/Dict/Buffer/BufferTick.h similarity index 84% rename from Buffer/BufferTick.h rename to Storage/Dict/Buffer/BufferTick.h index de986565a..d5ea9baf5 100644 --- a/Buffer/BufferTick.h +++ b/Storage/Dict/Buffer/BufferTick.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,15 +20,17 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef BUFFER_TICK_H -#define BUFFER_TICK_H +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "../BufferStruct.mqh" -#include "../Chart.enum.h" -#include "../Storage/IValueStorage.h" -#include "../Tick/Tick.struct.h" +#include "../../../Indicator/IndicatorData.enum.h" +#include "../../../Platform/Chart/Chart.enum.h" +#include "../../../Tick/Tick.struct.h" +#include "../../ValueStorage.h" +#include "BufferStruct.h" // Forward declarations. template @@ -40,15 +42,15 @@ class BufferTickValueStorage : ValueStorage { // Poiner to buffer to take tick from. BufferTick *buffer_tick; - // INDI_VS_TYPE_PRICE_ASK, INDI_VS_TYPE_PRICE_BID, INDI_VS_TYPE_SPREAD, INDI_VS_TYPE_TICK_VOLUME or - // INDI_VS_TYPE_VOLUME. - ENUM_INDI_VS_TYPE vs_type; + // INDI_DATA_VS_TYPE_PRICE_ASK, INDI_DATA_VS_TYPE_PRICE_BID, INDI_DATA_VS_TYPE_SPREAD, INDI_DATA_VS_TYPE_TICK_VOLUME + // or INDI_DATA_VS_TYPE_VOLUME. + ENUM_INDI_DATA_VS_TYPE vs_type; public: /** * Constructor. */ - BufferTickValueStorage(BufferTick *_buffer_tick, ENUM_INDI_VS_TYPE _vs_type) + BufferTickValueStorage(BufferTick *_buffer_tick, ENUM_INDI_DATA_VS_TYPE _vs_type) : buffer_tick(_buffer_tick), vs_type(_vs_type) {} /** @@ -56,15 +58,15 @@ class BufferTickValueStorage : ValueStorage { */ TV Fetch(datetime _dt) override { switch (vs_type) { - case INDI_VS_TYPE_PRICE_ASK: + case INDI_DATA_VS_TYPE_PRICE_ASK: return (TV)buffer_tick PTR_DEREF GetByKey(_dt).ask; - case INDI_VS_TYPE_PRICE_BID: + case INDI_DATA_VS_TYPE_PRICE_BID: return (TV)buffer_tick PTR_DEREF GetByKey(_dt).bid; - case INDI_VS_TYPE_SPREAD: + case INDI_DATA_VS_TYPE_SPREAD: // return (TV)buffer_tick PTR_DEREF GetByKey(_dt).spread; - case INDI_VS_TYPE_TICK_VOLUME: + case INDI_DATA_VS_TYPE_TICK_VOLUME: // return (TV)buffer_tick PTR_DEREF GetByKey(_dt).tick_volume; - case INDI_VS_TYPE_VOLUME: + case INDI_DATA_VS_TYPE_VOLUME: // return (TV)buffer_tick PTR_DEREF GetByKey(_dt).volume; break; } @@ -154,7 +156,7 @@ class BufferTick : public BufferStruct> { */ BufferTickValueStorage *GetAskValueStorage() { if (_vs_ask == NULL) { - _vs_ask = new BufferTickValueStorage(THIS_PTR, INDI_VS_TYPE_PRICE_ASK); + _vs_ask = new BufferTickValueStorage(THIS_PTR, INDI_DATA_VS_TYPE_PRICE_ASK); } return _vs_ask; } @@ -164,7 +166,7 @@ class BufferTick : public BufferStruct> { */ BufferTickValueStorage *GetBidValueStorage() { if (_vs_bid == NULL) { - _vs_bid = new BufferTickValueStorage(THIS_PTR, INDI_VS_TYPE_PRICE_BID); + _vs_bid = new BufferTickValueStorage(THIS_PTR, INDI_DATA_VS_TYPE_PRICE_BID); } return _vs_bid; } @@ -174,7 +176,7 @@ class BufferTick : public BufferStruct> { */ BufferTickValueStorage *GetSpreadValueStorage() { if (_vs_spread == NULL) { - _vs_spread = new BufferTickValueStorage(THIS_PTR, INDI_VS_TYPE_SPREAD); + _vs_spread = new BufferTickValueStorage(THIS_PTR, INDI_DATA_VS_TYPE_SPREAD); } return _vs_spread; } @@ -184,7 +186,7 @@ class BufferTick : public BufferStruct> { */ BufferTickValueStorage *GetVolumeValueStorage() { if (_vs_volume == NULL) { - _vs_volume = new BufferTickValueStorage(THIS_PTR, INDI_VS_TYPE_VOLUME); + _vs_volume = new BufferTickValueStorage(THIS_PTR, INDI_DATA_VS_TYPE_VOLUME); } return _vs_volume; } @@ -194,7 +196,7 @@ class BufferTick : public BufferStruct> { */ BufferTickValueStorage *GetTickVolumeValueStorage() { if (_vs_tick_volume == NULL) { - _vs_tick_volume = new BufferTickValueStorage(THIS_PTR, INDI_VS_TYPE_TICK_VOLUME); + _vs_tick_volume = new BufferTickValueStorage(THIS_PTR, INDI_DATA_VS_TYPE_TICK_VOLUME); } return _vs_tick_volume; } @@ -215,5 +217,3 @@ class BufferTick : public BufferStruct> { return NULL; } }; - -#endif // BUFFER_TICK_H diff --git a/Storage/Dict/Buffer/tests/Buffer.test.cpp b/Storage/Dict/Buffer/tests/Buffer.test.cpp new file mode 100644 index 000000000..6ef3b0d38 --- /dev/null +++ b/Storage/Dict/Buffer/tests/Buffer.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Buffer class. + */ + +// Includes. +#include "../Buffer.h" + +#include "../../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Storage/Dict/Buffer/tests/Buffer.test.mq4 b/Storage/Dict/Buffer/tests/Buffer.test.mq4 new file mode 100644 index 000000000..6db857659 --- /dev/null +++ b/Storage/Dict/Buffer/tests/Buffer.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Buffer class. + */ + +// Includes. +#include "Buffer.test.mq5" diff --git a/tests/BufferTest.mq5 b/Storage/Dict/Buffer/tests/Buffer.test.mq5 similarity index 91% rename from tests/BufferTest.mq5 rename to Storage/Dict/Buffer/tests/Buffer.test.mq5 index f4b2d74a7..55e8e4cca 100644 --- a/tests/BufferTest.mq5 +++ b/Storage/Dict/Buffer/tests/Buffer.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,8 +25,8 @@ */ // Includes -#include "../Buffer.mqh" -#include "../Test.mqh" +#include "../../../../Test.mqh" +#include "../Buffer.h" /** * Implements OnInit(). diff --git a/Storage/Dict/Buffer/tests/BufferCandle.test.cpp b/Storage/Dict/Buffer/tests/BufferCandle.test.cpp new file mode 100644 index 000000000..c876d4f5c --- /dev/null +++ b/Storage/Dict/Buffer/tests/BufferCandle.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of BufferCandle class. + */ + +// Includes. +#include "../BufferCandle.h" + +#include "../../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Buffer/tests/BufferCandle.test.mq4 b/Storage/Dict/Buffer/tests/BufferCandle.test.mq4 similarity index 87% rename from Buffer/tests/BufferCandle.test.mq4 rename to Storage/Dict/Buffer/tests/BufferCandle.test.mq4 index f7795e845..be2da3509 100644 --- a/Buffer/tests/BufferCandle.test.mq4 +++ b/Storage/Dict/Buffer/tests/BufferCandle.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Buffer/tests/BufferCandle.test.mq5 b/Storage/Dict/Buffer/tests/BufferCandle.test.mq5 similarity index 88% rename from Buffer/tests/BufferCandle.test.mq5 rename to Storage/Dict/Buffer/tests/BufferCandle.test.mq5 index 19bc812ca..aea48ba79 100644 --- a/Buffer/tests/BufferCandle.test.mq5 +++ b/Storage/Dict/Buffer/tests/BufferCandle.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,14 +25,14 @@ */ // Includes -#include "../../Test.mqh" +#include "../../../../Test.mqh" #include "../BufferCandle.h" /** * Implements OnInit(). */ int OnInit() { - BufferCandle buffer1; // 128 + BufferCandle buffer1; // 128 CandleOHLC _ohlc_d; // 32 CandleOHLC _ohlc_f; // 16 CandleTOHLC _tohlc_d; // 32 diff --git a/Storage/Dict/Buffer/tests/BufferCompileAll.test.cpp b/Storage/Dict/Buffer/tests/BufferCompileAll.test.cpp new file mode 100644 index 000000000..406cbcb6b --- /dev/null +++ b/Storage/Dict/Buffer/tests/BufferCompileAll.test.cpp @@ -0,0 +1,38 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of all Buffer related classes + */ + +// Includes. +#include "../../../../Platform/Platform.h" +#include "../BufferCandle.h" +#include "../BufferFXT.h" +#include "../BufferStruct.h" +#include "../BufferTick.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/BufferFXTTest.mq4 b/Storage/Dict/Buffer/tests/BufferCompileAll.test.mq4 similarity index 89% rename from tests/BufferFXTTest.mq4 rename to Storage/Dict/Buffer/tests/BufferCompileAll.test.mq4 index 1a30333a2..10cdd614e 100644 --- a/tests/BufferFXTTest.mq4 +++ b/Storage/Dict/Buffer/tests/BufferCompileAll.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,12 +9,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -25,4 +25,4 @@ */ // Includes. -#include "BufferFXTTest.mq5" +#include "BufferCompileAll.test.mq5" diff --git a/tests/CompileIndicatorsTest.mq5 b/Storage/Dict/Buffer/tests/BufferCompileAll.test.mq5 similarity index 66% rename from tests/CompileIndicatorsTest.mq5 rename to Storage/Dict/Buffer/tests/BufferCompileAll.test.mq5 index 72a003731..994f95d9e 100644 --- a/tests/CompileIndicatorsTest.mq5 +++ b/Storage/Dict/Buffer/tests/BufferCompileAll.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -21,18 +21,18 @@ /** * @file - * Test compilation of Indicators/ files. + * Test compilation of all Buffer class files. */ // Includes. -#include "../Indicators/indicators.h" -#include "../Indicators/Account/Indi_AccountStats.mqh" -#include "../Indicators/Bitwise/indicators.h" -#include "../Indicators/OHLC/indicators.h" -#include "../Indicators/Price/indicators.h" -#include "../Indicators/Special/indicators.h" +#include "../../../../Test.mqh" +#include "../Buffer.h" +#include "../BufferCandle.h" +#include "../BufferFXT.h" +#include "../BufferStruct.h" +#include "../BufferTick.h" /** * Implements Init event handler. */ -int OnInit() { return 0; } +int OnInit() { return (_LastError == ERR_NO_ERROR ? INIT_SUCCEEDED : INIT_FAILED); } diff --git a/Storage/Dict/Buffer/tests/BufferFXT.test.cpp b/Storage/Dict/Buffer/tests/BufferFXT.test.cpp new file mode 100644 index 000000000..121059ac5 --- /dev/null +++ b/Storage/Dict/Buffer/tests/BufferFXT.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Dict class. + */ + +// Includes. +#include "../BufferFXT.h" + +#include "../../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Storage/Dict/Buffer/tests/BufferFXT.test.mq4 b/Storage/Dict/Buffer/tests/BufferFXT.test.mq4 new file mode 100644 index 000000000..e10021035 --- /dev/null +++ b/Storage/Dict/Buffer/tests/BufferFXT.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of BufferFXT class. + */ + +// Includes. +#include "BufferFXT.test.mq5" diff --git a/tests/BufferFXTTest.mq5 b/Storage/Dict/Buffer/tests/BufferFXT.test.mq5 similarity index 84% rename from tests/BufferFXTTest.mq5 rename to Storage/Dict/Buffer/tests/BufferFXT.test.mq5 index 25168a969..c260919c5 100644 --- a/tests/BufferFXTTest.mq5 +++ b/Storage/Dict/Buffer/tests/BufferFXT.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,12 +9,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -25,9 +25,9 @@ */ // Includes -#include "../BufferFXT.mqh" -#include "../Platform.h" -#include "../Test.mqh" +#include "../../../../Platform/Platform.h" +#include "../../../../Test.mqh" +#include "../BufferFXT.h" BufferFXT *ticks; diff --git a/Storage/Dict/Buffer/tests/BufferStruct.test.cpp b/Storage/Dict/Buffer/tests/BufferStruct.test.cpp new file mode 100644 index 000000000..1df21adc3 --- /dev/null +++ b/Storage/Dict/Buffer/tests/BufferStruct.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Dict class. + */ + +// Includes. +#include "../BufferStruct.h" + +#include "../../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Storage/Dict/Buffer/tests/BufferStruct.test.mq4 b/Storage/Dict/Buffer/tests/BufferStruct.test.mq4 new file mode 100644 index 000000000..f115ab76f --- /dev/null +++ b/Storage/Dict/Buffer/tests/BufferStruct.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of BufferStruct class. + */ + +// Includes. +#include "BufferStruct.test.mq5" diff --git a/tests/BufferStructTest.mq5 b/Storage/Dict/Buffer/tests/BufferStruct.test.mq5 similarity index 84% rename from tests/BufferStructTest.mq5 rename to Storage/Dict/Buffer/tests/BufferStruct.test.mq5 index c68d6b4bc..98c2005de 100644 --- a/tests/BufferStructTest.mq5 +++ b/Storage/Dict/Buffer/tests/BufferStruct.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,14 +25,14 @@ */ // Includes -#include "../BufferStruct.mqh" -#include "../Data.define.h" -#include "../Data.struct.h" -#include "../Data.struct.serialize.h" -#include "../Serializer/SerializerConverter.h" -#include "../Serializer/SerializerJSON.h" -#include "../Std.h" -#include "../Test.mqh" +#include "../../../../Serializer/SerializerConverter.h" +#include "../../../../Serializer/SerializerJSON.h" +#include "../../../../Std.h" +#include "../../../../Test.mqh" +#include "../../../Data.define.h" +#include "../../../Data.struct.h" +#include "../../../Data.struct.serialize.h" +#include "../BufferStruct.h" /** * Implements OnInit(). diff --git a/Storage/Dict/Buffer/tests/BufferTick.test.cpp b/Storage/Dict/Buffer/tests/BufferTick.test.cpp new file mode 100644 index 000000000..5c47f6d58 --- /dev/null +++ b/Storage/Dict/Buffer/tests/BufferTick.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Dict class. + */ + +// Includes. +#include "../BufferTick.h" + +#include "../../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Buffer/tests/BufferTick.test.mq4 b/Storage/Dict/Buffer/tests/BufferTick.test.mq4 similarity index 87% rename from Buffer/tests/BufferTick.test.mq4 rename to Storage/Dict/Buffer/tests/BufferTick.test.mq4 index 71958f521..d86b5d67a 100644 --- a/Buffer/tests/BufferTick.test.mq4 +++ b/Storage/Dict/Buffer/tests/BufferTick.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Buffer/tests/BufferTick.test.mq5 b/Storage/Dict/Buffer/tests/BufferTick.test.mq5 similarity index 90% rename from Buffer/tests/BufferTick.test.mq5 rename to Storage/Dict/Buffer/tests/BufferTick.test.mq5 index c284a5f00..409952d16 100644 --- a/Buffer/tests/BufferTick.test.mq5 +++ b/Storage/Dict/Buffer/tests/BufferTick.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes -#include "../../Test.mqh" +#include "../../../../Test.mqh" #include "../BufferTick.h" /** diff --git a/Storage/Dict/Buffer/tests/Makefile b/Storage/Dict/Buffer/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Storage/Dict/Buffer/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Dict.enum.h b/Storage/Dict/Dict.enum.h similarity index 93% rename from Dict.enum.h rename to Storage/Dict/Dict.enum.h index c746f87e3..1ff6a2bb7 100644 --- a/Dict.enum.h +++ b/Storage/Dict/Dict.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Dict.mqh b/Storage/Dict/Dict.h similarity index 96% rename from Dict.mqh rename to Storage/Dict/Dict.h index cd16c0c05..c7979ec29 100644 --- a/Dict.mqh +++ b/Storage/Dict/Dict.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,16 +20,17 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef DICT_MQH -#define DICT_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif -#include "Convert.basic.h" -#include "DictBase.mqh" -#include "DictIteratorBase.mqh" -#include "Matrix.mqh" -#include "Serializer/Serializer.h" -#include "Serializer/SerializerNodeIterator.h" +#include "../../Convert.basic.h" +#include "../../Math/Matrix.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/SerializerNodeIterator.h" +#include "DictBase.h" +#include "DictIteratorBase.h" template class DictIterator : public DictIteratorBase { @@ -225,7 +226,7 @@ class Dict : public DictBase { // If we have a slot then we can overwrite it. if (_slot != NULL) { - WriteSlot(_slot, key, value, DICT_SLOT_HAS_KEY | DICT_SLOT_IS_USED | DICT_SLOT_WAS_USED); + WriteSlot(PTR_TO_REF(_slot), key, value, DICT_SLOT_HAS_KEY | DICT_SLOT_IS_USED | DICT_SLOT_WAS_USED); // We're done, we don't have to increment number of slots used. return true; } @@ -467,5 +468,3 @@ class Dict : public DictBase { return result; } }; - -#endif diff --git a/DictBase.mqh b/Storage/Dict/DictBase.h similarity index 96% rename from DictBase.mqh rename to Storage/Dict/DictBase.h index c9d1f140b..60340ee65 100644 --- a/DictBase.mqh +++ b/Storage/Dict/DictBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,15 +20,16 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef DICT_BASE_MQH -#define DICT_BASE_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "Convert.mqh" +#include "../../Convert.mqh" #include "Dict.enum.h" -#include "DictIteratorBase.mqh" -#include "DictSlot.mqh" +#include "DictIteratorBase.h" +#include "DictSlot.h" /** * Dictionary overflow listener. arguments are: @@ -274,7 +275,7 @@ class DictBase { /** * Returns number of used DictSlots. */ - const unsigned int Size() { return _DictSlots_ref PTR_DEREF _num_used; } + const unsigned int Size() const { return _DictSlots_ref PTR_DEREF _num_used; } /** * Returns number of all (reserved) DictSlots. @@ -425,5 +426,3 @@ class DictBase { */ unsigned int Hash(unsigned long value) { return Hash((unsigned long)value); } }; - -#endif diff --git a/DictIteratorBase.mqh b/Storage/Dict/DictIteratorBase.h similarity index 89% rename from DictIteratorBase.mqh rename to Storage/Dict/DictIteratorBase.h index 80f0340b0..eddf34e56 100644 --- a/DictIteratorBase.mqh +++ b/Storage/Dict/DictIteratorBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -29,9 +29,10 @@ template class DictBase; -#include "DictBase.mqh" +#include "../../Convert.basic.h" +#include "../../Serializer/SerializerConversions.h" +#include "DictBase.h" #include "DictSlotsRef.h" -#include "Serializer/SerializerConversions.h" template class DictIteratorBase { @@ -93,7 +94,14 @@ class DictIteratorBase { K Key() { CheckValidity(); - return PTR_ATTRIB(_dict, GetMode()) == DictModeList ? (K)_slotIdx : _dict PTR_DEREF GetSlot(_slotIdx) PTR_DEREF key; + + if (PTR_ATTRIB(_dict, GetMode()) == DictModeList) { + K _key; + ConvertBasic::Convert(_slotIdx, _key); + return _key; + } + + return _dict PTR_DEREF GetSlot(_slotIdx) PTR_DEREF key; } string KeyAsString(bool includeQuotes = false) { diff --git a/DictObject.mqh b/Storage/Dict/DictObject.h similarity index 98% rename from DictObject.mqh rename to Storage/Dict/DictObject.h index 24d31e41c..a44d27748 100644 --- a/DictObject.mqh +++ b/Storage/Dict/DictObject.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,10 +25,10 @@ #pragma once #endif -#include "Convert.basic.h" -#include "DictBase.mqh" -#include "Serializer/Serializer.h" -#include "Serializer/SerializerNodeIterator.h" +#include "../../Convert.basic.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/SerializerNodeIterator.h" +#include "DictBase.h" template class DictObjectIterator : public DictIteratorBase { diff --git a/DictSlot.mqh b/Storage/Dict/DictSlot.h similarity index 87% rename from DictSlot.mqh rename to Storage/Dict/DictSlot.h index 06d31650d..6f7b292d0 100644 --- a/DictSlot.mqh +++ b/Storage/Dict/DictSlot.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,10 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef DICT_SLOT_MQH -#define DICT_SLOT_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif enum DICT_SLOT_FLAGS { DICT_SLOT_INVALID = 1, DICT_SLOT_HAS_KEY = 2, DICT_SLOT_IS_USED = 4, DICT_SLOT_WAS_USED = 8 }; @@ -60,5 +61,3 @@ class DictSlot { void RemoveFlags(unsigned char flags) { _flags &= (unsigned char)~flags; } }; - -#endif // DICT_SLOT_MQH diff --git a/DictSlotsRef.h b/Storage/Dict/DictSlotsRef.h similarity index 89% rename from DictSlotsRef.h rename to Storage/Dict/DictSlotsRef.h index 32da49a6e..87997b697 100644 --- a/DictSlotsRef.h +++ b/Storage/Dict/DictSlotsRef.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,11 +31,11 @@ #endif // Includes. -#include "Array.mqh" +#include "../../Std.h" +#include "../../Storage/Array.h" +#include "../../Util.h" #include "Dict.enum.h" -#include "DictSlot.mqh" -#include "Std.h" -#include "Util.h" +#include "DictSlot.h" // Forward class declaration. template diff --git a/DictStruct.mqh b/Storage/Dict/DictStruct.h similarity index 96% rename from DictStruct.mqh rename to Storage/Dict/DictStruct.h index 7d29195f7..e406278aa 100644 --- a/DictStruct.mqh +++ b/Storage/Dict/DictStruct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,11 +26,11 @@ #endif // Includes. -#include "Convert.basic.h" -#include "DictBase.mqh" -#include "DictIteratorBase.mqh" -#include "Serializer/Serializer.h" -#include "Serializer/SerializerNodeIterator.h" +#include "../../Convert.basic.h" +#include "../../Serializer/Serializer.h" +#include "../../Serializer/SerializerNodeIterator.h" +#include "DictBase.h" +#include "DictIteratorBase.h" // DictIterator could be used as DictStruct iterator. #define DictStructIterator DictIteratorBase @@ -71,7 +71,7 @@ class DictStruct : public DictBase { Clear(); Resize(right.GetSlotCount()); for (unsigned int i = 0; i < (unsigned int)ArraySize(right._DictSlots_ref PTR_DEREF DictSlots); ++i) { - this PTR_DEREF _DictSlots_ref PTR_DEREF DictSlots[i] = right._DictSlots_ref PTR_DEREF DictSlots[i]; + THIS_ATTR _DictSlots_ref PTR_DEREF DictSlots[i] = right._DictSlots_ref PTR_DEREF DictSlots[i]; } THIS_ATTR _DictSlots_ref PTR_DEREF _num_used = right._DictSlots_ref PTR_DEREF _num_used; THIS_ATTR _current_id = right._current_id; @@ -468,7 +468,7 @@ class DictStruct : public DictBase { SerializerNodeType Serialize(Serializer& s) { if (s.IsWriting()) { for (DictIteratorBase i(Begin()); i.IsValid(); ++i) - s.PassObject(this, THIS_ATTR GetMode() == DictModeDict ? i.KeyAsString() : "", i.Value()); + s.PassObject(THIS_REF, THIS_ATTR GetMode() == DictModeDict ? i.KeyAsString() : "", i.Value()); return (THIS_ATTR GetMode() == DictModeDict) ? SerializerNodeObject : SerializerNodeArray; } else { diff --git a/Storage/Dict/README.md b/Storage/Dict/README.md new file mode 100644 index 000000000..247f7218b --- /dev/null +++ b/Storage/Dict/README.md @@ -0,0 +1,20 @@ +# Dict + +## Classes + +### `Dict` class + +Use this class to store the values in form of a collective attribute–value pairs, +in similar way as [associative arrays](https://en.wikipedia.org/wiki/Associative_array) +with a [hash table](https://en.wikipedia.org/wiki/Hash_table) work. + +#### Example 1 - Storing string-int data structures + +Example of storing key-value data with string as a key: + + Dict data1; + data1.Set("a", 1); + data1.Set("b", 2); + data1.Set("c", 3); + data1.Unset("c"); + Print(data1.GetByKey("a")); diff --git a/Storage/Dict/tests/Dict.test.cpp b/Storage/Dict/tests/Dict.test.cpp new file mode 100644 index 000000000..165e312d1 --- /dev/null +++ b/Storage/Dict/tests/Dict.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Dict class. + */ + +// Includes. +#include "../Dict.h" + +#include "../../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Storage/Dict/tests/Dict.test.mq4 b/Storage/Dict/tests/Dict.test.mq4 new file mode 100644 index 000000000..ecdeeb199 --- /dev/null +++ b/Storage/Dict/tests/Dict.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Dict class. + */ + +// Includes. +#include "Dict.test.mq5" diff --git a/tests/DictTest.mq5 b/Storage/Dict/tests/Dict.test.mq5 similarity index 96% rename from tests/DictTest.mq5 rename to Storage/Dict/tests/Dict.test.mq5 index be4c19a2d..3b51d1e38 100644 --- a/tests/DictTest.mq5 +++ b/Storage/Dict/tests/Dict.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,14 +25,14 @@ */ // Includes. -#include "../Dict.mqh" -#include "../DictObject.mqh" -#include "../DictStruct.mqh" -#include "../Object.mqh" -#include "../Serializer/Serializer.h" -#include "../Serializer/SerializerConverter.h" -#include "../Serializer/SerializerJson.h" -#include "../Test.mqh" +#include "../../../Serializer/Serializer.h" +#include "../../../Serializer/SerializerConverter.h" +#include "../../../Serializer/SerializerJson.h" +#include "../../../Storage/Object.h" +#include "../../../Test.mqh" +#include "../Dict.h" +#include "../DictObject.h" +#include "../DictStruct.h" class DictTestClass { public: diff --git a/Storage/Dict/tests/Makefile b/Storage/Dict/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Storage/Dict/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Flags.h b/Storage/Flags.struct.h similarity index 95% rename from Flags.h rename to Storage/Flags.struct.h index 8807629b4..9876cdff1 100644 --- a/Flags.h +++ b/Storage/Flags.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Storage/IValueStorage.h b/Storage/IValueStorage.h index 001c1e660..a553e36d9 100644 --- a/Storage/IValueStorage.h +++ b/Storage/IValueStorage.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Storage/ItemsHistory.h b/Storage/ItemsHistory.h index 1420a5076..08cc1f37a 100644 --- a/Storage/ItemsHistory.h +++ b/Storage/ItemsHistory.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -16,7 +16,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * aint64 with this program. If not, see . * */ @@ -29,8 +29,8 @@ #pragma once #endif -#include "../DictStruct.mqh" #include "../Refs.mqh" +#include "../Storage/Dict/DictStruct.h" /** * Direction used by ItemsHistoryItemProvider's methods. @@ -59,7 +59,7 @@ class ItemsHistoryItemProvider : public Dynamic { * want previous or next items from selected starting point. Should return false if retrieving items by this method * is not available. */ - bool GetItems(ItemsHistory>* _history, long _from_time_ms, + bool GetItems(ItemsHistory>* _history, int64 _from_time_ms, ENUM_ITEMS_HISTORY_DIRECTION _dir, int _num_items, ARRAY_REF(IV, _out_arr)) { return false; } @@ -76,16 +76,16 @@ class ItemsHistoryItemProvider : public Dynamic { /** * Time of the first possible item/candle/tick. */ - virtual long GetInitialTimeMs() { + virtual int64 GetInitialTimeMs() { // Item's provider does not implement GetInitialTimeMs(), but it should. We'll use current time for the time of the // first item. - return (long)TimeCurrent() * 1000; + return (int64)TimeCurrent() * 1000; } /** * Returns information about item provider. */ - string const ToString() override { return "Abstract items history item provider."; } + virtual string const ToString() override { return "Abstract items history item provider."; } }; /** @@ -164,7 +164,7 @@ class ItemsHistory { * Gets time in milliseconds of the last(oldest) item's time in current history time or 0. */ /* - long GetLastValidTimeInCache() { + int64 GetLastValidTimeInCache() { return history.GetByKey(last_valid_index).GetTime(); } */ @@ -238,7 +238,7 @@ class ItemsHistory { /* int _item_count = _to_index - _from_index + 1; - long _from_time_ms; + int64 _from_time_ms; IV _item; // Calculating time to be passed to GetItems(). @@ -261,9 +261,9 @@ class ItemsHistory { _from_time_ms = _item.GetTimeMs() + _item.GetLengthMs() + 1; } - long _current_time_ms = TimeCurrent() * 1000; + int64 _current_time_ms = TimeCurrent() * 1000; - if (_from_time_ms > (long)TimeCurrent() * 1000) { + if (_from_time_ms > (int64)TimeCurrent() * 1000) { // There won't be items in the future. return; } @@ -412,11 +412,11 @@ class ItemsHistory { */ bool EnsureShiftExists(int _shift) { if (history.Size() == 0) { - // return false; + return false; } #ifdef __debug_items_history__ - // Print("EnsureShiftExists(", _shift, ")"); + Print("EnsureShiftExists(", _shift, ")"); #endif int _index = GetShiftIndex(_shift); @@ -501,7 +501,7 @@ class ItemsHistory { /** * Returns item time in milliseconds for the given shift. */ - long GetItemTimeByShiftMsc(int _shift) { + int64 GetItemTimeByShiftMsc(int _shift) { if (!EnsureShiftExists(_shift)) { // There won't be item at given shift. return (datetime)0; diff --git a/Storage/MemoryFileSystem.h b/Storage/MemoryFileSystem.h index bd84d7a68..dd8272fd7 100644 --- a/Storage/MemoryFileSystem.h +++ b/Storage/MemoryFileSystem.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,9 +31,9 @@ // Includes. #include -#include "../DictStruct.mqh" #include "../File.define.h" -#include "../String.mqh" +#include "../Storage/Dict/DictStruct.h" +#include "../Storage/String.h" class MemoryFileSystemFile : public Dynamic { public: diff --git a/Object.enum.h b/Storage/Object.enum.h similarity index 82% rename from Object.enum.h rename to Storage/Object.enum.h index d56973d4b..33b9ec74d 100644 --- a/Object.enum.h +++ b/Storage/Object.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ -//| EA31337 - multi-strategy advanced trading robot. | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,7 +26,7 @@ */ #ifndef __MQLBUILD__ - +// Allows the preprocessor to include a header file when it is needed. #pragma once // Used for checking the type of the object pointer. diff --git a/Object.extern.h b/Storage/Object.extern.h similarity index 94% rename from Object.extern.h rename to Storage/Object.extern.h index 69d25ece1..8e8c6cb1f 100644 --- a/Object.extern.h +++ b/Storage/Object.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,6 +26,7 @@ */ #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once // Includes. diff --git a/Object.mqh b/Storage/Object.h similarity index 85% rename from Object.mqh rename to Storage/Object.h index cc27a1ad8..f2a629652 100644 --- a/Object.mqh +++ b/Storage/Object.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ -//| EA31337 - multi-strategy advanced trading robot. | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,16 +20,17 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef OBJECT_MQH -#define OBJECT_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. +#include "../Refs.mqh" +#include "../Refs.struct.h" #include "Object.enum.h" #include "Object.extern.h" -#include "Refs.mqh" -#include "Refs.struct.h" -#include "String.mqh" +#include "String.h" /** * Class to deal with objects. @@ -37,14 +38,14 @@ class Object : public Dynamic { protected: void *obj; - long id; + int64 id; public: /** * Class constructor. */ Object() : obj(THIS_PTR), id(rand()) {} - Object(void *_obj, long _id = __LINE__) { + Object(void *_obj, int64 _id = __LINE__) { obj = _obj; id = _id; } @@ -54,14 +55,14 @@ class Object : public Dynamic { /** * Get ID of the object. */ - virtual long GetId() { return id; } + virtual int64 GetId() { return id; } /* Setters */ /** * Set ID of the object. */ - void SetId(long _id) { id = _id; } + void SetId(int64 _id) { id = _id; } /** * Get the object handler. @@ -135,4 +136,3 @@ class Object : public Dynamic { // Initialize static global variables. // Object *Object::list = { 0 }; -#endif // OBJECT_MQH diff --git a/Storage/Objects.h b/Storage/Objects.h index 1f4174ca2..836ac1f3d 100644 --- a/Storage/Objects.h +++ b/Storage/Objects.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,8 +30,8 @@ #endif // Includes. -#include "../DictStruct.mqh" #include "../Refs.mqh" +#include "../Storage/Dict/DictStruct.h" /** * Stores objects to be reused using a string-based key. @@ -48,7 +48,7 @@ class Objects { /** * Tries to retrieve pointer to object for a given key. Returns true if object did exist. */ - static bool TryGet(CONST_REF_TO(string) key, C*& out_ptr) { + static bool TryGet(CONST_REF_TO_SIMPLE(string) key, C*& out_ptr) { unsigned int position; if (!GetObjects() PTR_DEREF KeyExists(key, position)) { out_ptr = NULL; @@ -62,7 +62,7 @@ class Objects { /** * Stores object pointer with a given key. */ - static C* Set(CONST_REF_TO(string) key, C* ptr) { + static C* Set(CONST_REF_TO_SIMPLE(string) key, C* ptr) { Ref _ref(ptr); GetObjects() PTR_DEREF Set(key, _ref); return ptr; diff --git a/Storage/README.md b/Storage/README.md index c6e55ecfa..5d2cbb9e8 100644 --- a/Storage/README.md +++ b/Storage/README.md @@ -1,6 +1,8 @@ -# Storage classes +# Storage -## `Collection` class +## Classes + +### `Collection` class This class is for storing various type of objects. Here is the example usage: diff --git a/Redis.mqh b/Storage/Redis.h similarity index 89% rename from Redis.mqh rename to Storage/Redis.h index 6857daf37..5eae1b415 100644 --- a/Redis.mqh +++ b/Storage/Redis.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,13 +24,19 @@ * @file * Implements class for storing/retrieving Redis database data. */ -#include "Dict.mqh" -#include "Object.mqh" + +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + +#include "../Serializer/Serializer.h" +#include "../Serializer/SerializerConversions.h" +#include "../Serializer/SerializerJson.h" +#include "../Socket.mqh" +#include "Dict/Dict.h" +#include "Object.h" #include "Redis.struct.h" -#include "Serializer/Serializer.h" -#include "Serializer/SerializerConversions.h" -#include "Serializer/SerializerJson.h" -#include "Socket.mqh" enum ENUM_REDIS_VALUE_SET { REDIS_VALUE_SET_ALWAYS, REDIS_VALUE_SET_IF_NOT_EXIST, REDIS_VALUE_SET_IF_ALREADY_EXIST }; @@ -42,7 +48,7 @@ typedef void (*RedisCallback)(string); class RedisQueue { protected: // Messages queue for simulation purposes. - string _queue[]; + ARRAY(string, _queue); // Current message index to be processed. Set to 0 if all messages have been popped out. int _queue_index; @@ -155,7 +161,7 @@ class Redis : public Object { string command_args = StringSubstr(command, StringLen(command_name) + 1); if (command_name == "SUBSCRIBE") { - string subscriptions[]; + ARRAY(string, subscriptions); StringSplit(command_args, ' ', subscriptions); for (int i = 0; i < ArraySize(subscriptions); ++i) { _subscriptions.Set(subscriptions[i], true); @@ -213,7 +219,7 @@ class Redis : public Object { string GetString(const string _key, string _default = NULL) { string result = Command("GET " + SerializerConversions::ValueToString(_key, true)); - if (result == NULL) return _default; + if (result == NULL_STRING) return _default; return result; } @@ -224,10 +230,10 @@ class Redis : public Object { bool Increment(const string _key, const int _value = 1) { if (_value > 0) { return Command("INCRBY " + SerializerConversions::ValueToString(_key, true) + " " + IntegerToString(_value)) != - NULL; + NULL_STRING; } else if (_value < 0) { return Command("DECRBY " + SerializerConversions::ValueToString(_key, true) + " " + IntegerToString(-_value)) != - NULL; + NULL_STRING; } // _value was 0. Nothing to do. @@ -240,10 +246,10 @@ class Redis : public Object { bool Increment(const string _key, const float _value = 1.0f) { if (_value > 0.0f) { return Command("INCRBYFLOAT " + SerializerConversions::ValueToString(_key, true) + " " + - DoubleToString(_value)) != NULL; + DoubleToString(_value)) != NULL_STRING; } else if (_value < 0.0f) { return Command("DECRBYFLOAT " + SerializerConversions::ValueToString(_key, true) + " " + - DoubleToString(_value)) != NULL; + DoubleToString(_value)) != NULL_STRING; } // _value was 0. Nothing to do. @@ -263,25 +269,27 @@ class Redis : public Object { /** * Deletes variable by given key. */ - bool Delete(const string _key) { return Command("DEL " + SerializerConversions::ValueToString(_key, true)) != NULL; } + bool Delete(const string _key) { + return Command("DEL " + SerializerConversions::ValueToString(_key, true)) != NULL_STRING; + } /** * Subscribes to string-based values on the given channels (separated by space). * * After subscribe, please use TryReadString() in the loop to retrieve values. */ - bool Subscribe(const string _channel_list) { return Command("SUBSCRIBE " + _channel_list) != NULL; } + bool Subscribe(const string _channel_list) { return Command("SUBSCRIBE " + _channel_list) != NULL_STRING; } /** * Unsubscribes from the given channels (separated by space). */ - bool Unsubscribe(const string _channel_list) { return Command("UNSUBSCRIBE " + _channel_list) != NULL; } + bool Unsubscribe(const string _channel_list) { return Command("UNSUBSCRIBE " + _channel_list) != NULL_STRING; } /** * Publishes string-based value on the given channel (channel must be previously subscribed). */ bool Publish(const string _channel, const string _value) { - return Command("PUBLISH " + _channel + " " + SerializerConversions::ValueToString(_value, true)) != NULL; + return Command("PUBLISH " + _channel + " " + SerializerConversions::ValueToString(_value, true)) != NULL_STRING; } /** diff --git a/Redis.struct.h b/Storage/Redis.struct.h similarity index 95% rename from Redis.struct.h rename to Storage/Redis.struct.h index dade26291..feb563e25 100644 --- a/Redis.struct.h +++ b/Storage/Redis.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,7 +31,7 @@ #endif // Includes. -#include "Serializer/SerializerConversions.h" +#include "../Serializer/SerializerConversions.h" // Forward declaration. class Serializer; @@ -58,7 +58,7 @@ struct RedisMessage { string Message; // Items of array returned from Redis. - string Items[]; + ARRAY(string, Items); /** * Adds string value into Redis message array. diff --git a/Storage/Singleton.h b/Storage/Singleton.h index 0a75e7f48..7886fd82c 100644 --- a/Storage/Singleton.h +++ b/Storage/Singleton.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -45,6 +45,10 @@ class Singleton { }; template +#ifdef __MQL__ C Singleton::_ref; +#else +C Singleton::_ref; +#endif #endif // SINGLETON_H diff --git a/String.extern.h b/Storage/String.extern.h similarity index 83% rename from String.extern.h rename to Storage/String.extern.h index 16e44b2b2..bd8f3079e 100644 --- a/String.extern.h +++ b/Storage/String.extern.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,8 +20,8 @@ * */ -// Prevents processing this includes file for the second time. #ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. #pragma once // Includes. @@ -33,13 +33,24 @@ #include #include -#include "Math.extern.h" -#include "Std.h" -#include "Terminal.define.h" +#include "../Math/Math.extern.h" +#include "../Platform/Terminal.define.h" +#include "../Std.h" // Define external global functions. double StringToDouble(string value) { return std::stod(value); } +string StringTrimLeft(string text) { + text.erase(text.begin(), std::find_if(text.begin(), text.end(), [](unsigned char ch) { return !std::isspace(ch); })); + return text; +} + +string StringTrimRight(string text) { + text.erase(std::find_if(text.rbegin(), text.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), + text.end()); + return text; +} + auto StringFind(const string string_value, string match_substring, int start_pos = 0) -> int { return string_value.find(match_substring); } @@ -54,7 +65,7 @@ int StringSplit(const string& string_value, const unsigned short separator, ARRA } return result.size(); } -long StringToInteger(string value) { return std::stol(value); } +int64 StringToInteger(string value) { return std::stol(value); } string IntegerToString(int64 number, int str_len = 0, unsigned short fill_symbol = ' ') { return std::to_string(number); } @@ -102,6 +113,26 @@ unsigned short StringGetCharacter(string string_value, int pos) { return string_value[pos]; } +bool StringInit(string& string_var, int new_len = 0, unsigned short character = 0) { + string_var = string(new_len, (char)character); + return true; +} + +string CharArrayToString(ARRAY_REF(unsigned char, arr), int start = 0, int count = -1, unsigned int codepage = CP_ACP) { + if (count == -1) count = (arr.size() - start); + + int _end = MathMin(count - start, arr.size()); + + string result; + StringInit(result, count); + + for (int i = 0; i < count; ++i) { + result[i] = arr[i]; + } + + return result; +} + int StringToCharArray(string text_string, ARRAY_REF(unsigned char, array), int start = 0, int count = -1, unsigned int codepage = CP_ACP) { if (count == -1) count = text_string.size(); @@ -112,11 +143,6 @@ int StringToCharArray(string text_string, ARRAY_REF(unsigned char, array), int s return array.size(); } -bool StringInit(string& string_var, int new_len = 0, unsigned short character = 0) { - string_var = string(new_len, (char)character); - return true; -} - /** * It replaces all the found substrings of a string by a set sequence of symbols. * diff --git a/String.mqh b/Storage/String.h similarity index 90% rename from String.mqh rename to Storage/String.h index 1c64ef5f7..c6f58dc97 100644 --- a/String.mqh +++ b/Storage/String.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,14 +20,15 @@ * */ -// Prevents processing this includes file for the second time. -#ifndef STRING_MQH -#define STRING_MQH +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. +#include "../Common.extern.h" +#include "../Std.h" #include "Array.extern.h" -#include "Common.extern.h" -#include "Std.h" #include "String.extern.h" // Defines. @@ -119,4 +120,3 @@ class String { #endif } }; -#endif // STRING_MQH diff --git a/Storage/ValueStorage.accessor.h b/Storage/ValueStorage.accessor.h index fab97fac3..a7c176cd3 100644 --- a/Storage/ValueStorage.accessor.h +++ b/Storage/ValueStorage.accessor.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Storage/ValueStorage.all.h b/Storage/ValueStorage.all.h index 20cb16163..741f94d3a 100644 --- a/Storage/ValueStorage.all.h +++ b/Storage/ValueStorage.all.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Storage/ValueStorage.applied_price.h b/Storage/ValueStorage.applied_price.h index b7de7fd42..7db4e9ce1 100644 --- a/Storage/ValueStorage.applied_price.h +++ b/Storage/ValueStorage.applied_price.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,9 +24,14 @@ * Price getter version of ValueStorage. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../Chart.struct.h" -#include "ObjectsCache.h" +#include "../Platform/Chart/Chart.struct.h" +#include "Cache/ObjectsCache.h" #include "ValueStorage.history.h" // Forward declarations. diff --git a/Storage/ValueStorage.h b/Storage/ValueStorage.h index 7d37e11b4..3c507f716 100644 --- a/Storage/ValueStorage.h +++ b/Storage/ValueStorage.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -47,31 +47,33 @@ enum ENUM_IPEAK { IPEAK_LOWEST, IPEAK_HIGHEST }; #define INDICATOR_CALCULATE_PARAMS_LONG \ ValueStorage &_time, ValueStorage &_open, ValueStorage &_high, ValueStorage &_low, \ - ValueStorage &_close, ValueStorage &_tick_volume, ValueStorage &_volume, \ - ValueStorage &_spread + ValueStorage &_close, ValueStorage &_tick_volume, ValueStorage &_volume, \ + ValueStorage &_spread #define INDICATOR_CALCULATE_PARAMS_SHORT ValueStorage &_price #define INDICATOR_CALCULATE_METHOD_PARAMS_LONG \ const int rates_total, const int prev_calculated, ValueStorage &time, ValueStorage &open, \ ValueStorage &high, ValueStorage &low, ValueStorage &close, \ - ValueStorage &tick_volume, ValueStorage &volume, ValueStorage &spread + ValueStorage &tick_volume, ValueStorage &volume, ValueStorage &spread #define INDICATOR_CALCULATE_METHOD_PARAMS_SHORT \ const int rates_total, const int prev_calculated, const int begin, ValueStorage &price -#define INDICATOR_CALCULATE_GET_PARAMS_LONG \ - _cache.GetTotal(), _cache.GetPrevCalculated(), _time, _cache.GetPriceBuffer(PRICE_OPEN), \ - _cache.GetPriceBuffer(PRICE_HIGH), _cache.GetPriceBuffer(PRICE_LOW), _cache.GetPriceBuffer(PRICE_CLOSE), \ - _tick_volume, _volume, _spread +#define INDICATOR_CALCULATE_GET_PARAMS_LONG \ + _cache PTR_DEREF GetTotal(), _cache PTR_DEREF GetPrevCalculated(), _time, \ + _cache PTR_DEREF GetPriceBuffer(PRICE_OPEN), _cache PTR_DEREF GetPriceBuffer(PRICE_HIGH), \ + _cache PTR_DEREF GetPriceBuffer(PRICE_LOW), _cache PTR_DEREF GetPriceBuffer(PRICE_CLOSE), _tick_volume, _volume, \ + _spread -#define INDICATOR_CALCULATE_GET_PARAMS_SHORT _cache.GetTotal(), _cache.GetPrevCalculated(), 0, _cache.GetPriceBuffer() +#define INDICATOR_CALCULATE_GET_PARAMS_SHORT \ + _cache PTR_DEREF GetTotal(), _cache PTR_DEREF GetPrevCalculated(), 0, _cache PTR_DEREF GetPriceBuffer() -#define INDICATOR_CALCULATE_POPULATE_CACHE(INDI, KEY) \ - IndicatorCalculateCache *_cache; \ - string _key = Util::MakeKey(INDI PTR_DEREF GetId(), KEY); \ - if (!Objects>::TryGet(_key, _cache)) { \ - _cache = Objects>::Set(_key, new IndicatorCalculateCache()); \ +#define INDICATOR_CALCULATE_POPULATE_CACHE(INDI, KEY) \ + IndiBufferCache *_cache; \ + string _key = Util::MakeKey(INDI PTR_DEREF GetId(), KEY); \ + if (!Objects>::TryGet(_key, _cache)) { \ + _cache = Objects>::Set(_key, new IndiBufferCache()); \ } /** @@ -81,9 +83,9 @@ enum ENUM_IPEAK { IPEAK_LOWEST, IPEAK_HIGHEST }; * (the one that doesn't exist in the hierarchy). */ #define INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_SHORT(INDI, APPLIED_PRICE, KEY) \ - ValueStorage *_price; \ + ValueStorage *_price_ptr = nullptr; \ if (INDI PTR_DEREF GetSuitableDataSource() PTR_DEREF HasSpecificAppliedPriceValueStorage(APPLIED_PRICE, INDI)) { \ - _price = \ + _price_ptr = \ INDI PTR_DEREF GetSuitableDataSource() PTR_DEREF GetSpecificAppliedPriceValueStorage(APPLIED_PRICE, INDI); \ } else { \ Print("Source indicator ", INDI PTR_DEREF GetFullName(), \ @@ -93,26 +95,35 @@ enum ENUM_IPEAK { IPEAK_LOWEST, IPEAK_HIGHEST }; ", AP overriden: ", EnumToString(INDI PTR_DEREF GetDataSourceAppliedType())); \ DebugBreak(); \ } \ + REF_TO(ValueStorage) _price = PTR_TO_REF(_price_ptr); \ INDICATOR_CALCULATE_POPULATE_CACHE(INDI, KEY) -#define INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(INDI, KEY) \ - IndicatorData *_suitable_ds = INDI PTR_DEREF GetSuitableDataSource(); \ - ValueStorage *_time = \ - (ValueStorage *)_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_VS_TYPE_TIME); \ - ValueStorage *_tick_volume = \ - (ValueStorage *)_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_VS_TYPE_TICK_VOLUME); \ - ValueStorage *_volume = \ - (ValueStorage *)_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_VS_TYPE_VOLUME); \ - ValueStorage *_spread = \ - (ValueStorage *)_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_VS_TYPE_SPREAD); \ - ValueStorage *_price_open = \ - (ValueStorage *)_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_VS_TYPE_PRICE_OPEN); \ - ValueStorage *_price_high = \ - (ValueStorage *)_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_VS_TYPE_PRICE_HIGH); \ - ValueStorage *_price_low = \ - (ValueStorage *)_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_VS_TYPE_PRICE_LOW); \ - ValueStorage *_price_close = \ - (ValueStorage *)_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_VS_TYPE_PRICE_CLOSE); \ +#define INDICATOR_CALCULATE_POPULATE_PARAMS_AND_CACHE_LONG(INDI, KEY) \ + IndicatorData *_suitable_ds = INDI PTR_DEREF GetSuitableDataSource(); \ + REF_TO(ValueStorage) \ + _time = REF_CAST(ValueStorage) \ + PTR_TO_REF(_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_DATA_VS_TYPE_TIME)); \ + REF_TO(ValueStorage) \ + _tick_volume = REF_CAST(ValueStorage) \ + PTR_TO_REF(_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_DATA_VS_TYPE_TICK_VOLUME)); \ + REF_TO(ValueStorage) \ + _volume = REF_CAST(ValueStorage) \ + PTR_TO_REF(_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_DATA_VS_TYPE_VOLUME)); \ + REF_TO(ValueStorage) \ + _spread = REF_CAST(ValueStorage) \ + PTR_TO_REF(_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_DATA_VS_TYPE_SPREAD)); \ + REF_TO(ValueStorage) \ + _price_open = REF_CAST(ValueStorage) \ + PTR_TO_REF(_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_OPEN)); \ + REF_TO(ValueStorage) \ + _price_high = REF_CAST(ValueStorage) \ + PTR_TO_REF(_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_HIGH)); \ + REF_TO(ValueStorage) \ + _price_low = REF_CAST(ValueStorage) \ + PTR_TO_REF(_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_LOW)); \ + REF_TO(ValueStorage) \ + _price_close = REF_CAST(ValueStorage) \ + PTR_TO_REF(_suitable_ds PTR_DEREF GetSpecificValueStorage(INDI_DATA_VS_TYPE_PRICE_CLOSE)); \ INDICATOR_CALCULATE_POPULATE_CACHE(INDI, KEY) #define INDICATOR_CALCULATE_POPULATED_PARAMS_LONG \ @@ -121,8 +132,8 @@ enum ENUM_IPEAK { IPEAK_LOWEST, IPEAK_HIGHEST }; #define INDICATOR_CALCULATE_POPULATED_PARAMS_SHORT _price // Includes. -#include "../Array.mqh" #include "../Util.h" +#include "Array.h" #include "IValueStorage.h" #include "ValueStorage.accessor.h" @@ -262,6 +273,52 @@ int ArrayCopy(ARRAY_REF(D, _target), ValueStorage &_source, int _dst_start = return _num_copied; } +/** + * Array-Array wrapper for ArrayCopy. + * @note It's a copy-past of the above ArrayCopy. + */ +template +int ArrayCopy(ARRAY_REF(C, _target), CONST_ARRAY_REF(C, _source), int _dst_start = 0, int _src_start = 0, + int count = WHOLE_ARRAY) { + if (count == WHOLE_ARRAY) { + count = ArraySize(_source); + } + + if (ArrayGetAsSeries(_target)) { + if ((ArraySize(_target) == 0 && _dst_start != 0) || + (ArraySize(_target) != 0 && ArraySize(_target) < _dst_start + count)) { + // The receiving array is declared as AS_SERIES, and it is of insufficient size. + SetUserError(ERR_SMALL_ASSERIES_ARRAY); + ArrayResize(_target, 0); + return 0; + } + } + + count = MathMin(count, ArraySize(_source) - _src_start); + + int _dst_required_size = _dst_start + count; + + if (ArraySize(_target) < _dst_required_size) { + ArrayResize(_target, _dst_required_size, 32); + } + + int _num_copied, t, s; + + for (_num_copied = 0, t = _dst_start, s = _src_start; _num_copied < count; ++_num_copied, ++t, ++s) { + if (s >= ArraySize(_source)) { + // No more data to copy. + break; + } + + bool _reverse = ArrayGetAsSeries(_target) != ArrayGetAsSeries(_source); + + int _source_idx = _reverse ? (ArraySize(_source) - s - 1 + _src_start) : s; + + _target[t] = _source[_source_idx]; + } + + return _num_copied; +} /** * iLowest() version working on ValueStorage. diff --git a/Storage/ValueStorage.history.h b/Storage/ValueStorage.history.h index f4924139f..6997ea032 100644 --- a/Storage/ValueStorage.history.h +++ b/Storage/ValueStorage.history.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -34,12 +34,12 @@ #include "ValueStorage.h" // Forward declarations. -class IndicatorData; +class IndicatorBase; template class ValueStorage; #ifndef __MQL__ -extern int GetBarsFromStart(IndicatorData* _indi); +extern int GetBarsFromStart(IndicatorBase* _indi); #endif /** @@ -49,7 +49,7 @@ template class HistoryValueStorage : public ValueStorage { protected: // Indicator used as an OHLC source, e.g. IndicatorCandle. - WeakRef indi_candle; + WeakRef indi_candle; // Whether storage operates in as-series mode. bool is_series; @@ -58,7 +58,7 @@ class HistoryValueStorage : public ValueStorage { /** * Constructor. */ - HistoryValueStorage(IndicatorData* _indi_candle, bool _is_series = false) + HistoryValueStorage(IndicatorBase* _indi_candle, bool _is_series = false) : indi_candle(_indi_candle), is_series(_is_series) { if (_indi_candle == nullptr) { Print("You have to pass IndicatorCandle-compatible indicator as parameter to HistoryValueStorage!"); diff --git a/Storage/ValueStorage.indicator.h b/Storage/ValueStorage.indicator.h index bdd2ee376..4b36b561f 100644 --- a/Storage/ValueStorage.indicator.h +++ b/Storage/ValueStorage.indicator.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -49,7 +49,7 @@ class IndicatorBufferValueStorage : public HistoryValueStorage { /** * Constructor. */ - IndicatorBufferValueStorage(IndicatorData* _indi_candle, int _mode = 0, bool _is_series = false) + IndicatorBufferValueStorage(IndicatorBase* _indi_candle, int _mode = 0, bool _is_series = false) : HistoryValueStorage(_indi_candle), mode(_mode) {} /** @@ -57,7 +57,7 @@ class IndicatorBufferValueStorage : public HistoryValueStorage { */ #ifdef __MQL__ C Fetch(int _rel_shift) override { - IndicatorData* _indi = THIS_ATTR indi_candle.Ptr(); + IndicatorBase* _indi = THIS_ATTR indi_candle.Ptr(); return _indi PTR_DEREF GetValue(mode, THIS_ATTR RealShift(_rel_shift)); } #else @@ -72,7 +72,7 @@ class IndicatorBufferValueStorage : public HistoryValueStorage { #ifndef __MQL__ template C IndicatorBufferValueStorage::Fetch(int _rel_shift) { - IndicatorData* _indi = THIS_ATTR indi_candle.Ptr(); + IndicatorBase* _indi = THIS_ATTR indi_candle.Ptr(); return _indi PTR_DEREF GetValue(mode, THIS_ATTR RealShift(_rel_shift)); } #endif diff --git a/Storage/ValueStorage.native.h b/Storage/ValueStorage.native.h index 81281c45f..84686630d 100644 --- a/Storage/ValueStorage.native.h +++ b/Storage/ValueStorage.native.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,6 +24,11 @@ * Native array version of ValueStorage. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "ValueStorage.h" @@ -33,7 +38,7 @@ template class NativeValueStorage : public ValueStorage { // Dynamic native array. - C _values[]; + ARRAY(C, _values); int _values_size; public: @@ -50,7 +55,7 @@ class NativeValueStorage : public ValueStorage { /** * Initializes array with given one. */ - void SetData(ARRAY_REF(C, _arr)) { + void SetData(CONST_ARRAY_REF(C, _arr)) { bool _was_series = ArrayGetAsSeries(_arr); ArraySetAsSeries(_arr, false); ArraySetAsSeries(_values, false); diff --git a/Storage/ValueStorage.price_median.h b/Storage/ValueStorage.price_median.h index 890ffee3e..e58953c08 100644 --- a/Storage/ValueStorage.price_median.h +++ b/Storage/ValueStorage.price_median.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,11 +24,14 @@ * Median price version of ValueStorage. */ -// Forward declarations. -class IndicatorBase; +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif // Includes. -#include "ObjectsCache.h" +#include "../Indicator/IndicatorBase.h" +#include "Cache/ObjectsCache.h" #include "ValueStorage.history.h" /** @@ -39,7 +42,7 @@ class PriceMedianValueStorage : public HistoryValueStorage { /** * Constructor. */ - PriceMedianValueStorage(IndicatorData *_indi_candle) : HistoryValueStorage(_indi_candle) {} + PriceMedianValueStorage(IndicatorBase *_indi_candle) : HistoryValueStorage(_indi_candle) {} /** * Copy constructor. diff --git a/Storage/ValueStorage.price_typical.h b/Storage/ValueStorage.price_typical.h index fe99eb869..d063e0112 100644 --- a/Storage/ValueStorage.price_typical.h +++ b/Storage/ValueStorage.price_typical.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,8 +24,13 @@ * Typical price version of ValueStorage. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "ObjectsCache.h" +#include "Cache/ObjectsCache.h" #include "ValueStorage.history.h" /** @@ -36,7 +41,7 @@ class PriceTypicalValueStorage : public HistoryValueStorage { /** * Constructor. */ - PriceTypicalValueStorage(IndicatorData *_indi_candle) : HistoryValueStorage(_indi_candle) {} + PriceTypicalValueStorage(IndicatorBase *_indi_candle) : HistoryValueStorage(_indi_candle) {} /** * Copy constructor. diff --git a/Storage/ValueStorage.price_weighted.h b/Storage/ValueStorage.price_weighted.h index 91029acc4..04581f325 100644 --- a/Storage/ValueStorage.price_weighted.h +++ b/Storage/ValueStorage.price_weighted.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,8 +24,13 @@ * Weighted price version of ValueStorage. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "ObjectsCache.h" +#include "Cache/ObjectsCache.h" #include "ValueStorage.history.h" /** @@ -36,7 +41,7 @@ class PriceWeightedValueStorage : public HistoryValueStorage { /** * Constructor. */ - PriceWeightedValueStorage(IndicatorData *_indi_candle) : HistoryValueStorage(_indi_candle) {} + PriceWeightedValueStorage(IndicatorBase *_indi_candle) : HistoryValueStorage(_indi_candle) {} /** * Copy constructor. diff --git a/Storage/ValueStorage.spread.h b/Storage/ValueStorage.spread.h index e19e3b01c..484314d98 100644 --- a/Storage/ValueStorage.spread.h +++ b/Storage/ValueStorage.spread.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,27 +24,32 @@ * Spread getter version of ValueStorage. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "ObjectsCache.h" +#include "Cache/ObjectsCache.h" #include "ValueStorage.history.h" /** * Storage to retrieve spread. */ -class SpreadValueStorage : public HistoryValueStorage { +class SpreadValueStorage : public HistoryValueStorage { public: /** * Constructor. */ - SpreadValueStorage(IndicatorData *_indi_candle) : HistoryValueStorage(_indi_candle) {} + SpreadValueStorage(IndicatorBase *_indi_candle) : HistoryValueStorage(_indi_candle) {} /** * Copy constructor. */ - SpreadValueStorage(SpreadValueStorage &_r) : HistoryValueStorage(_r.indi_candle.Ptr()) {} + SpreadValueStorage(SpreadValueStorage &_r) : HistoryValueStorage(_r.indi_candle.Ptr()) {} /** * Fetches value from a given shift. Takes into consideration as-series flag. */ - long Fetch(int _rel_shift) override { return indi_candle REF_DEREF GetSpread(RealShift(_rel_shift)); } + int64 Fetch(int _rel_shift) override { return indi_candle REF_DEREF GetSpread(RealShift(_rel_shift)); } }; diff --git a/Storage/ValueStorage.tick_volume.h b/Storage/ValueStorage.tick_volume.h index 6a901bc8a..3ba66e34c 100644 --- a/Storage/ValueStorage.tick_volume.h +++ b/Storage/ValueStorage.tick_volume.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,27 +24,32 @@ * Tick volume getter version of ValueStorage. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "ObjectsCache.h" +#include "Cache/ObjectsCache.h" #include "ValueStorage.history.h" /** * Storage to retrieve tick volume. */ -class TickVolumeValueStorage : public HistoryValueStorage { +class TickVolumeValueStorage : public HistoryValueStorage { public: /** * Constructor. */ - TickVolumeValueStorage(IndicatorData *_indi_candle) : HistoryValueStorage(_indi_candle) {} + TickVolumeValueStorage(IndicatorBase *_indi_candle) : HistoryValueStorage(_indi_candle) {} /** * Copy constructor. */ - TickVolumeValueStorage(TickVolumeValueStorage &_r) : HistoryValueStorage(_r.indi_candle.Ptr()) {} + TickVolumeValueStorage(TickVolumeValueStorage &_r) : HistoryValueStorage(_r.indi_candle.Ptr()) {} /** * Fetches value from a given shift. Takes into consideration as-series flag. */ - long Fetch(int _rel_shift) override { return indi_candle REF_DEREF GetVolume(RealShift(_rel_shift)); } + int64 Fetch(int _rel_shift) override { return indi_candle REF_DEREF GetVolume(RealShift(_rel_shift)); } }; diff --git a/Storage/ValueStorage.time.h b/Storage/ValueStorage.time.h index ee4edc93c..af83b8ecf 100644 --- a/Storage/ValueStorage.time.h +++ b/Storage/ValueStorage.time.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,9 +24,14 @@ * Time getter version of ValueStorage. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "../Util.h" -#include "ObjectsCache.h" +#include "Cache/ObjectsCache.h" #include "ValueStorage.history.h" /** @@ -37,7 +42,7 @@ class TimeValueStorage : public HistoryValueStorage { /** * Constructor. */ - TimeValueStorage(IndicatorData *_indi_candle) : HistoryValueStorage(_indi_candle) {} + TimeValueStorage(IndicatorBase *_indi_candle) : HistoryValueStorage(_indi_candle) {} /** * Copy constructor. diff --git a/Storage/ValueStorage.volume.h b/Storage/ValueStorage.volume.h index 33d8c01f6..db7442655 100644 --- a/Storage/ValueStorage.volume.h +++ b/Storage/ValueStorage.volume.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,31 +24,36 @@ * Volume getter version of ValueStorage. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "ObjectsCache.h" +#include "Cache/ObjectsCache.h" #include "ValueStorage.history.h" /** * Storage to retrieve volume. */ -class VolumeValueStorage : public HistoryValueStorage { +class VolumeValueStorage : public HistoryValueStorage { public: /** * Constructor. */ - VolumeValueStorage(IndicatorData *_indi_candle) : HistoryValueStorage(_indi_candle) {} + VolumeValueStorage(IndicatorBase *_indi_candle) : HistoryValueStorage(_indi_candle) {} /** * Copy constructor. */ - VolumeValueStorage(VolumeValueStorage &_r) : HistoryValueStorage(_r.indi_candle.Ptr()) {} + VolumeValueStorage(VolumeValueStorage &_r) : HistoryValueStorage(_r.indi_candle.Ptr()) {} /** * Fetches value from a given shift. Takes into consideration as-series flag. */ - long Fetch(int _rel_shift) override { + int64 Fetch(int _rel_shift) override { ResetLastError(); - long _volume = indi_candle REF_DEREF GetVolume(RealShift(_rel_shift)); + int64 _volume = indi_candle REF_DEREF GetVolume(RealShift(_rel_shift)); if (_LastError != ERR_NO_ERROR) { Print("Cannot fetch iVolume! Error: ", _LastError); DebugBreak(); diff --git a/Storage/tests/Collection.test.cpp b/Storage/tests/Collection.test.cpp new file mode 100644 index 000000000..5a4b7b859 --- /dev/null +++ b/Storage/tests/Collection.test.cpp @@ -0,0 +1,73 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Collection class. + */ + +// Includes. +#include "../Collection.h" + +// Define classes. +class Stack : public Object { + public: + virtual string GetName() = 0; +}; +class Foo : public Stack { + public: + string GetName() { return "Foo"; }; + double GetWeight() { return 0; }; +}; +class Bar : public Stack { + public: + string GetName() { return "Bar"; }; + double GetWeight() { return 1; }; +}; +class Baz : public Stack { + public: + string GetName() { return "Baz"; }; + double GetWeight() { return 2; }; +}; + +int main(int argc, char **argv) { + // Define and add items. + Collection *stack = new Collection(); + /* @fixme + stack.Add(new Foo); + stack.Add(new Bar); + stack.Add(new Baz); + + // Print the lowest and the highest items. + Print("Lowest: ", ((Stack *)stack.GetLowest()).GetName()); + Print("Highest: ", ((Stack *)stack.GetHighest()).GetName()); + // Print all items. + int i; + for (i = 0; i < stack.GetSize(); i++) { + Print(i, ": ", ((Stack *)stack.GetByIndex(i)).GetName()); + } + */ + + // Clean up. + Object::Delete(stack); + + return 0; +} diff --git a/Storage/tests/Collection.test.mq4 b/Storage/tests/Collection.test.mq4 index 98c475183..bb2819fd3 100644 --- a/Storage/tests/Collection.test.mq4 +++ b/Storage/tests/Collection.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Storage/tests/Collection.test.mq5 b/Storage/tests/Collection.test.mq5 index 3289f8f2b..e78fdb99b 100644 --- a/Storage/tests/Collection.test.mq5 +++ b/Storage/tests/Collection.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,13 +25,13 @@ */ // Includes. -#include "../Collection.mqh" #include "../../Test.mqh" +#include "../Collection.h" // Define classes. class Stack : public Object { public: - virtual string GetName() = NULL; + virtual string GetName() = 0; }; class Foo : public Stack { public: diff --git a/Storage/tests/Database.test.cpp b/Storage/tests/Database.test.cpp new file mode 100644 index 000000000..6074ef4a3 --- /dev/null +++ b/Storage/tests/Database.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Database class. + */ + +// Includes. +#include "../Database.h" + +#include "../../Test.mqh" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Storage/tests/Database.test.mq4 b/Storage/tests/Database.test.mq4 new file mode 100644 index 000000000..3601ee123 --- /dev/null +++ b/Storage/tests/Database.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Database class. + */ + +// Includes. +#include "Database.test.mq5" diff --git a/tests/DatabaseTest.mq5 b/Storage/tests/Database.test.mq5 similarity index 87% rename from tests/DatabaseTest.mq5 rename to Storage/tests/Database.test.mq5 index 5bf18c8dd..89838cb4b 100644 --- a/tests/DatabaseTest.mq5 +++ b/Storage/tests/Database.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,13 +24,16 @@ * Test functionality of Database class. */ -// Need to be include before Database.mqh. -#include "../SymbolInfo.mqh" // FOOBAR pragma: keep +// Need to be include before Database.h. +#include "../../Exchange/SymbolInfo/SymbolInfo.h" // FOOBAR pragma: keep // Includes. -#include "../BufferStruct.mqh" -#include "../Database.mqh" -#include "../Test.mqh" +#include "../../Test.mqh" +// clang-format off +// Following include order is important. +#include "../Dict/Buffer/BufferStruct.h" +#include "../Database.h" +// clang-format on // Global variables. Database *db; diff --git a/tests/DateTimeTest.mq4 b/Storage/tests/DateTime.test.mq4 similarity index 85% rename from tests/DateTimeTest.mq4 rename to Storage/tests/DateTime.test.mq4 index a509a6233..299f4084a 100644 --- a/tests/DateTimeTest.mq4 +++ b/Storage/tests/DateTime.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "DateTimeTest.mq5" +#include "DateTime.test.mq5" diff --git a/tests/DateTimeTest.mq5 b/Storage/tests/DateTime.test.mq5 similarity index 94% rename from tests/DateTimeTest.mq5 rename to Storage/tests/DateTime.test.mq5 index 838b9aab0..0fb163c2a 100644 --- a/tests/DateTimeTest.mq5 +++ b/Storage/tests/DateTime.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,8 +25,8 @@ */ // Includes. -#include "../DateTime.mqh" -#include "../Test.mqh" +#include "../../Test.mqh" +#include "../DateTime.h" /** * Implements OnInit(). diff --git a/Storage/tests/ItemsHistory.test.cpp b/Storage/tests/ItemsHistory.test.cpp new file mode 100644 index 000000000..6465dbc36 --- /dev/null +++ b/Storage/tests/ItemsHistory.test.cpp @@ -0,0 +1,34 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of ItemsHistory class. + */ + +// Includes. +#include "../ItemsHistory.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/Storage/tests/ItemsHistory.test.mq4 b/Storage/tests/ItemsHistory.test.mq4 new file mode 100644 index 000000000..e65c781e4 --- /dev/null +++ b/Storage/tests/ItemsHistory.test.mq4 @@ -0,0 +1,28 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of ItemsHistory class. + */ + +// Includes. +#include "ItemsHistory.test.mq5" diff --git a/Storage/tests/ItemsHistory.mq5 b/Storage/tests/ItemsHistory.test.mq5 similarity index 93% rename from Storage/tests/ItemsHistory.mq5 rename to Storage/tests/ItemsHistory.test.mq5 index 43ac6abf3..d9f928b63 100644 --- a/Storage/tests/ItemsHistory.mq5 +++ b/Storage/tests/ItemsHistory.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2020, 31337 Investments Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,12 +9,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -28,7 +28,7 @@ #define INDI_CANDLE_HISTORY_SIZE 4 // Includes -#include "../../Platform.h" +#include "../../Platform/Platform.h" #include "../../Test.mqh" #include "../ItemsHistory.h" diff --git a/Storage/tests/Makefile b/Storage/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Storage/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Storage/tests/Object.test.cpp b/Storage/tests/Object.test.cpp new file mode 100644 index 000000000..dc6b4889f --- /dev/null +++ b/Storage/tests/Object.test.cpp @@ -0,0 +1,41 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Object class. + */ + +// Includes. +#include "../Object.h" + +int main(int argc, char **argv) { + // Create a new object. + Object *obj = new Object(); + + // @todo: Add more tests. + // ... + + // Clean up. + Object::Delete(obj); + + return 0; +} diff --git a/tests/BufferTest.mq4 b/Storage/tests/Object.test.mq4 similarity index 87% rename from tests/BufferTest.mq4 rename to Storage/tests/Object.test.mq4 index 00dae2a4e..75fa8274e 100644 --- a/tests/BufferTest.mq4 +++ b/Storage/tests/Object.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | //| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -9,20 +9,20 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * @file - * Test functionality of Buffer class. + * Test functionality of Object class. */ // Includes. -#include "BufferTest.mq5" +#include "Object.test.mq5" diff --git a/Storage/tests/Object.test.mq5 b/Storage/tests/Object.test.mq5 new file mode 100644 index 000000000..f9dbfbc6e --- /dev/null +++ b/Storage/tests/Object.test.mq5 @@ -0,0 +1,45 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Object class. + */ + +// Includes. +#include "../../Test.mqh" +#include "../Object.h" + +/** + * Implements OnInit(). + */ +int OnInit() { + // Create a new object. + Object *obj = new Object(); + + // @todo: Add more tests. + // ... + + // Clean up. + Object::Delete(obj); + + return (GetLastError() > 0 ? INIT_FAILED : INIT_SUCCEEDED); +} diff --git a/Storage/tests/Redis.test.cpp b/Storage/tests/Redis.test.cpp new file mode 100644 index 000000000..dc9eab2b1 --- /dev/null +++ b/Storage/tests/Redis.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of RedisTest class. + */ + +// Includes. +#include "../Redis.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/RedisTest.mq4 b/Storage/tests/Redis.test.mq4 similarity index 87% rename from tests/RedisTest.mq4 rename to Storage/tests/Redis.test.mq4 index 3f9b2c3e1..9ad09b704 100644 --- a/tests/RedisTest.mq4 +++ b/Storage/tests/Redis.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,7 +26,7 @@ // Includes. #ifdef __MQL5__ -#include "RedisTest.mq5" +#include "Redis.test.mq5" #else // Sockets are not supported on MQL4, so Redis wouldn't work for now. int OnInit() { return (INIT_SUCCEEDED); } diff --git a/tests/RedisTest.mq5 b/Storage/tests/Redis.test.mq5 similarity index 90% rename from tests/RedisTest.mq5 rename to Storage/tests/Redis.test.mq5 index 85627167b..3931590ec 100644 --- a/tests/RedisTest.mq5 +++ b/Storage/tests/Redis.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,9 +25,9 @@ */ // Includes. -#include "../Redis.mqh" -#include "../Socket.mqh" -#include "../Test.mqh" +#include "../../Socket.mqh" +#include "../../Test.mqh" +#include "../Redis.h" // Properties. #property strict diff --git a/Storage/tests/ValueStorage.test.cpp b/Storage/tests/ValueStorage.test.cpp new file mode 100644 index 000000000..15061eda1 --- /dev/null +++ b/Storage/tests/ValueStorage.test.cpp @@ -0,0 +1,36 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of ValueStorage class. + */ + +// Includes. +#include "../ValueStorage.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/ValueStorageTest.mq4 b/Storage/tests/ValueStorage.test.mq4 similarity index 84% rename from tests/ValueStorageTest.mq4 rename to Storage/tests/ValueStorage.test.mq4 index ebbec6704..a364b2e8f 100644 --- a/tests/ValueStorageTest.mq4 +++ b/Storage/tests/ValueStorage.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -24,4 +24,4 @@ * Test functionality of ValueStorage class. */ -#include "ValueStorageTest.mq5" +#include "ValueStorage.test.mq5" diff --git a/tests/ValueStorageTest.mq5 b/Storage/tests/ValueStorage.test.mq5 similarity index 92% rename from tests/ValueStorageTest.mq5 rename to Storage/tests/ValueStorage.test.mq5 index 6ae29378d..56517bb53 100644 --- a/tests/ValueStorageTest.mq5 +++ b/Storage/tests/ValueStorage.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,12 +28,12 @@ #define __debug__ // Enables debug. // Includes. -#include "../Indicators/Indi_MA.mqh" -#include "../Indicators/Price/Indi_Price.mqh" -#include "../Serializer/SerializerConverter.h" -#include "../Serializer/SerializerJson.h" -#include "../Storage/ValueStorage.h" -#include "../Test.mqh" +#include "../../Indicators/Price/Indi_MA.h" +#include "../../Indicators/Price/Indi_Price.h" +#include "../../Serializer/SerializerConverter.h" +#include "../../Serializer/SerializerJson.h" +#include "../../Test.mqh" +#include "../ValueStorage.h" // Global variables. double _test_values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; diff --git a/Strategy.enum.h b/Strategy.enum.h index f00b54e55..564910851 100644 --- a/Strategy.enum.h +++ b/Strategy.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Strategy.mqh b/Strategy.mqh index 79ab81eba..0c1255b9d 100644 --- a/Strategy.mqh +++ b/Strategy.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,14 +28,15 @@ class Trade; // Includes. -#include "Data.struct.h" -#include "Dict.mqh" #include "Indicator/Indicator.h" #include "Market.mqh" -#include "Object.mqh" +#include "Math/Math.h" +#include "Storage/Data.struct.h" +#include "Storage/Dict/Dict.h" +#include "Storage/Object.h" +#include "Storage/String.h" #include "Strategy.enum.h" #include "Strategy.struct.h" -#include "String.mqh" #include "Task/TaskManager.h" #include "Task/Taskable.h" #include "Trade.mqh" @@ -113,9 +114,9 @@ class Strategy : public Taskable { // Base variables. string name; // Other variables. - int filter_method[]; // Filter method to consider the trade REF_DEREF - int open_condition[]; // Open conditions. - int close_condition[]; // Close conditions. + ARRAY(int, filter_method); // Filter method to consider the trade REF_DEREF + ARRAY(int, open_condition); // Open conditions. + ARRAY(int, close_condition); // Close conditions. public: /* Special methods */ @@ -123,11 +124,12 @@ class Strategy : public Taskable { /** * Class constructor. */ - Strategy(StgParams &_sparams, TradeParams &_tparams, IndicatorBase *_indi_source, string _name = "") + Strategy(StgParams &_sparams, TradeParams &_tparams, IndicatorData *_indi_source, string _name = "") : sparams(_sparams), trade(new Trade(_tparams, _indi_source)), indi_source(_indi_source) { // Initialize variables. name = _name; - MqlTick _tick = {0}; + MqlTick _tick; + _tick.time = (datetime)0; last_tick = _tick; // Link log instances. @@ -208,7 +210,7 @@ class Strategy : public Taskable { /** * Returns handler to the strategy's indicator class. */ - IndicatorBase *GetIndicator(int _id = 0) { + IndicatorData *GetIndicator(int _id = 0) { if (indicators.KeyExists(_id)) { return indicators[_id].Ptr(); } @@ -260,8 +262,8 @@ class Strategy : public Taskable { */ StgEntry GetEntry() { StgEntry _entry = {}; - for (ENUM_STRATEGY_STATS_PERIOD _p = EA_STATS_DAILY; _p < FINAL_ENUM_STRATEGY_STATS_PERIOD; _p++) { - _entry.SetStats(stats_period[(int)_p], _p); + for (int _p = EA_STATS_DAILY; _p < FINAL_ENUM_STRATEGY_STATS_PERIOD; _p++) { + _entry.SetStats(stats_period[_p], (ENUM_STRATEGY_STATS_PERIOD)_p); } return _entry; } @@ -285,7 +287,7 @@ class Strategy : public Taskable { * Executes OnTick() on every attached indicator. */ void Tick(int _global_tick_index) { - for (DictIterator> it = indicators.Begin(); it.IsValid(); ++it) { + for (DictStructIterator> it = indicators.Begin(); it.IsValid(); ++it) { it.Value() REF_DEREF Tick(_global_tick_index); } } @@ -298,7 +300,7 @@ class Strategy : public Taskable { /** * Get strategy's ID. */ - virtual long GetId() { return sparams.id; } + virtual int64 GetId() { return sparams.id; } /** * Get strategy's signal open method. @@ -454,9 +456,9 @@ class Strategy : public Taskable { /** * Sets strategy's ID. */ - void SetId(long _id) { + void SetId(int64 _id) { sparams.id = _id; - ((Object *)THIS_PTR).SetId(_id); + ((Object *)THIS_PTR) PTR_DEREF SetId(_id); } /** @@ -480,9 +482,9 @@ class Strategy : public Taskable { /** * Sets custom data. */ - void SetData(Dict *_ddata) { ddata = _ddata; } - void SetData(Dict *_fdata) { fdata = _fdata; } - void SetData(Dict *_idata) { idata = _idata; } + void SetData(Dict *_ddata) { ddata = PTR_TO_REF(_ddata); } + void SetData(Dict *_fdata) { fdata = PTR_TO_REF(_fdata); } + void SetData(Dict *_idata) { idata = PTR_TO_REF(_idata); } /** * Sets reference to indicator. @@ -738,8 +740,8 @@ class Strategy : public Taskable { ENUM_TIMEFRAMES _stf = GetSource() PTR_DEREF GetTf(); unsigned int _stf_secs = ChartTf::TfToSeconds(_stf); if (sparams.order_close_time != 0) { - long _close_time_arg = sparams.order_close_time > 0 ? sparams.order_close_time * 60 - : (int)round(-sparams.order_close_time * _stf_secs); + int64 _close_time_arg = sparams.order_close_time > 0 ? sparams.order_close_time * 60 + : MathRound(-sparams.order_close_time * _stf_secs); _oparams.Set(ORDER_PARAM_COND_CLOSE, ORDER_COND_LIFETIME_GT_ARG, _index); _oparams.Set(ORDER_PARAM_COND_CLOSE_ARG_VALUE, _close_time_arg, _index); _index++; @@ -785,7 +787,7 @@ class Strategy : public Taskable { if ((_periods & DATETIME_DAY) != 0) { // New day started. #ifndef __optimize__ - GetLogger().Flush(); + GetLogger() PTR_DEREF Flush(); #endif } if ((_periods & DATETIME_WEEK) != 0) { @@ -818,7 +820,7 @@ class Strategy : public Taskable { bool _res = _method >= 0; bool _val; - int _method_abs = fabs(_method); + int _method_abs = MathAbs(_method); if (_method_abs != 0) { if (METHOD(_method_abs, 0)) { // 1 // Process on every minute. @@ -1102,7 +1104,7 @@ class Strategy : public Taskable { return (float)_result; } float _trade_dist = trade REF_DEREF GetTradeDistanceInValue(); - int _count = (int)fmax(fabs(_level), fabs(_method)); + int _count = (int)fmax(MathAbs(_level), MathAbs(_method)); int _direction = Order::OrderDirection(_cmd, _mode); IndicatorData *_data_source = trade REF_DEREF GetSource(); IndicatorData *_indi = GetIndicators().Begin().Value().Ptr(); @@ -1110,7 +1112,7 @@ class Strategy : public Taskable { _psm.SetCandleSource(_data_source); if (Object::IsValid(_indi)) { int _ishift = 12; // @todo: Make it dynamic or as variable. - double _value = _indi.GetValuePrice(_ishift, 0, _direction > 0 ? PRICE_HIGH : PRICE_LOW); + double _value = _indi PTR_DEREF GetValuePrice(_ishift, 0, _direction > 0 ? PRICE_HIGH : PRICE_LOW); _value = _value + (float)Math::ChangeByPct(fabs(_value - SymbolInfoStatic::GetCloseOffer(_Symbol, _cmd)), _level) * _direction; @@ -1124,7 +1126,8 @@ class Strategy : public Taskable { */ _result = _psm.GetValue(_ishift, _direction, _trade_dist); } else { - int _pshift = _direction > 0 ? _data_source.GetHighest(_count) : _data_source.GetLowest(_count); + int _pshift = + _direction > 0 ? _data_source PTR_DEREF GetHighest(_count) : _data_source PTR_DEREF GetLowest(_count); _result = _psm.GetValue(_pshift, _direction, _trade_dist); } return (float)_result; @@ -1144,14 +1147,14 @@ class Strategy : public Taskable { float _result = 0; IndicatorData *_data_source = trade REF_DEREF GetSource(); - BarOHLC _bar1 = _data_source.GetOHLC(_shift); + BarOHLC _bar1 = _data_source PTR_DEREF GetOHLC(_shift); if (!_bar1.IsValid()) { return 0; } float _range = (float)_bar1.GetRange(); if (_range > 0) { - float _open = (float)_data_source.GetOpen(_tf); + float _open = (float)_data_source PTR_DEREF GetOpen(_tf); float _pp = (float)_bar1.GetPivot(); _result = 1 / _range * (_open - _pp); _result = fmin(1, fmax(-1, _result)); @@ -1203,7 +1206,7 @@ class Strategy : public Taskable { return SignalOpen(_entry.GetArg(0).ToValue(), _entry.GetArg(1).ToValue(), _entry.GetArg(2).ToValue()); default: - GetLogger().Error(StringFormat("Invalid EA condition: %d!", _entry.GetId(), __FUNCTION_LINE__)); + GetLogger() PTR_DEREF Error(StringFormat("Invalid EA condition: %d at %s!", _entry.GetId(), __FUNCTION_LINE__)); SetUserError(ERR_INVALID_PARAMETER); break; } @@ -1245,7 +1248,8 @@ class Strategy : public Taskable { sparams.Suspended(false); return true; default: - GetLogger().Error(StringFormat("Invalid Strategy action: %d!", _entry.GetId(), __FUNCTION_LINE__)); + GetLogger() + PTR_DEREF Error(StringFormat("Invalid Strategy action: %d at %s!", _entry.GetId(), __FUNCTION_LINE__)); SetUserError(ERR_INVALID_PARAMETER); break; } diff --git a/Strategy.struct.h b/Strategy.struct.h index 3e25ac4a0..5df14b88f 100644 --- a/Strategy.struct.h +++ b/Strategy.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -47,7 +47,7 @@ struct StgParams { bool is_suspended; // State of the strategy (whether suspended or not) bool is_boosted; // State of the boost feature (to increase lot size). float weight; // Weight of the strategy. - long order_close_time; // Order close time in mins (>0) or bars (<0). + int64 order_close_time; // Order close time in mins (>0) or bars (<0). float order_close_loss; // Order close loss (in pips). float order_close_profit; // Order close profit (in pips). int signal_open_method; // Signal open method. @@ -72,7 +72,7 @@ struct StgParams { int tp_max; // Hard limit on maximum take profit (in pips). int sl_max; // Hard limit on maximum stop loss (in pips). int type; // Strategy type (@see: ENUM_STRATEGY). - long id; // Unique identifier of the strategy. + int64 id; // Unique identifier of the strategy. datetime refresh_time; // Order refresh frequency (in sec). short shift; // Shift (relative to the current bar, 0 - default) ChartTf tf; // Main timeframe where strategy operates on. @@ -145,7 +145,7 @@ struct StgParams { sl_max(0), type(0), refresh_time(0) {} - StgParams(StgParams &_stg_params) { this = _stg_params; } + StgParams(const StgParams &_stg_params) { THIS_REF = _stg_params; } // Deconstructor. ~StgParams() {} @@ -217,7 +217,7 @@ struct StgParams { void Set(ENUM_STRATEGY_PARAM _param, T _value) { switch (_param) { case STRAT_PARAM_ID: // ID (magic number). - id = (long)_value; + id = (int64)_value; return; case STRAT_PARAM_LOG_LEVEL: // Log level. log_level = (ENUM_LOG_LEVEL)_value; @@ -256,7 +256,7 @@ struct StgParams { order_close_profit = (float)_value; return; case STRAT_PARAM_OCT: // Order close time - order_close_time = (long)_value; + order_close_time = (int64)_value; return; case STRAT_PARAM_SOM: // Signal open method signal_open_method = (int)_value; @@ -305,7 +305,7 @@ struct StgParams { Set(_enum_param, _mql_param.integer_value); } } - void SetId(long _id) { id = _id; } + void SetId(int64 _id) { id = _id; } void SetStops(Strategy *_sl = NULL, Strategy *_tp = NULL) { // @todo: To remove. } diff --git a/Strategy.struct.pricestop.h b/Strategy.struct.pricestop.h index de4e55118..772a3862f 100644 --- a/Strategy.struct.pricestop.h +++ b/Strategy.struct.pricestop.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -35,7 +35,7 @@ struct ChartParams; struct IndicatorParams; // Includes. -#include "Chart.struct.h" +#include "Platform/Chart/Chart.struct.h" /* Structure for strategy price stops. */ struct StrategyPriceStop { @@ -55,12 +55,12 @@ struct StrategyPriceStop { float ivalue; // Indicator price value. unsigned int method; // Store price stop methods (@see: ENUM_STRATEGY_PRICE_STOP). // unsigned int mode[2]; // Indicator modes to use. - Ref indi_candle; + Ref indi_candle; // IndicatorDataEntry idata[]; // IndicatorParams iparams; /* Constructors */ - void StrategyPriceStop(int _method = 0, float _ivalue = 0) : method(_method), ivalue(_ivalue) {} + StrategyPriceStop(int _method = 0, float _ivalue = 0) : method(_method), ivalue(_ivalue) {} // Main methods. // Calculate price stop value. float GetValue(int _shift = 0, int _direction = -1, float _min_trade_dist = 0.0f) { @@ -83,7 +83,7 @@ struct StrategyPriceStop { } if (CheckMethod(STRATEGY_PRICE_STOP_PRICE_PP)) { double _pp, _r1, _r2, _r3, _r4, _s1, _s2, _s3, _s4; - double _prices[4]; + FIXED_ARRAY(double, _prices, 4); _prices[0] = _ohlc0.GetClose(); _prices[1] = _direction > 0 ? _ohlc0.GetHigh() : _ohlc0.GetLow(); _prices[2] = _direction > 0 ? _ohlc1.GetHigh() : _ohlc1.GetLow(); @@ -102,7 +102,7 @@ struct StrategyPriceStop { return (float)_result; } /* Setters */ - void SetCandleSource(IndicatorBase* _indi_candle) { indi_candle = _indi_candle; } + void SetCandleSource(IndicatorData* _indi_candle) { indi_candle = _indi_candle; } void SetIndicatorPriceValue(float _ivalue) { ivalue = _ivalue; } /* void SetIndicatorDataEntry(IndicatorDataEntry &_data[]) { @@ -142,7 +142,8 @@ struct StrategyPriceStop { int _size = sizeof(int) * 8; for (int i = 0; i < _size; i++) { int _value = CheckMethod(1 << i) ? 1 : 0; - _s.Pass(this, (string)(i + 1), _value, SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE); + _s.Pass(THIS_REF, IntegerToString(i + 1), _value, + (int)(SERIALIZER_FIELD_FLAG_DYNAMIC | SERIALIZER_FIELD_FLAG_FEATURE)); } return SerializerNodeObject; } diff --git a/SummaryReport.mqh b/SummaryReport.mqh index 2e88769b5..405ab6482 100644 --- a/SummaryReport.mqh +++ b/SummaryReport.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,11 +20,16 @@ * */ -#include "Account/AccountMt.h" +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + #include "Convert.mqh" +#include "Exchange/Account/AccountMt.h" #include "Indicator/IndicatorData.h" -#include "Order.struct.h" -#include "Terminal.mqh" +#include "Platform/Order.struct.h" +#include "Platform/Terminal.h" #include "Trade.mqh" /** diff --git a/Task/Task.enum.h b/Task/Task.enum.h index 6c3e1b6dc..5ffe9febf 100644 --- a/Task/Task.enum.h +++ b/Task/Task.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/Task.h b/Task/Task.h index 104c44fc4..f6e2b483e 100644 --- a/Task/Task.h +++ b/Task/Task.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,9 +31,11 @@ #endif // Includes. -#include "../DictStruct.mqh" +#include "../Storage/Dict/DictStruct.h" #include "../Refs.mqh" -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" +#include "../Storage/Dict/DictStruct.h" +#include "../Platform/Terminal.define.h" #include "Task.enum.h" #include "Task.struct.h" #include "TaskAction.h" diff --git a/Task/Task.struct.h b/Task/Task.struct.h index ebf9bada0..7adfcde5e 100644 --- a/Task/Task.struct.h +++ b/Task/Task.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,7 +31,8 @@ #endif // Includes. -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" +#include "../Serializer/Serializer.h" #include "Task.enum.h" #include "TaskAction.struct.h" #include "TaskCondition.struct.h" diff --git a/Task/TaskAction.enum.h b/Task/TaskAction.enum.h index 76843f15a..c88fde7bc 100644 --- a/Task/TaskAction.enum.h +++ b/Task/TaskAction.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskAction.h b/Task/TaskAction.h index 83792f8af..21bc63826 100644 --- a/Task/TaskAction.h +++ b/Task/TaskAction.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -35,9 +35,9 @@ #define TASK_ACTION_H // Includes. -#include "../DateTime.mqh" +#include "../Storage/DateTime.h" #include "../Std.h" -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" #include "TaskAction.enum.h" #include "TaskAction.struct.h" #include "TaskActionBase.h" diff --git a/Task/TaskAction.struct.h b/Task/TaskAction.struct.h index 5b4d87baf..367967349 100644 --- a/Task/TaskAction.struct.h +++ b/Task/TaskAction.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,10 +30,10 @@ #endif // Includes. -#include "../Data.struct.h" +#include "../Storage/Data.struct.h" #include "../Serializer/Serializer.define.h" #include "../Std.h" -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" #include "Task.enum.h" // Forward declarations. diff --git a/Task/TaskAction.struct.serialize.h b/Task/TaskAction.struct.serialize.h index 54d0fc39e..f0091ee45 100644 --- a/Task/TaskAction.struct.serialize.h +++ b/Task/TaskAction.struct.serialize.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskActionBase.h b/Task/TaskActionBase.h index b02b07a62..89857c2b2 100644 --- a/Task/TaskActionBase.h +++ b/Task/TaskActionBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskCondition.enum.h b/Task/TaskCondition.enum.h index 30e74d1d7..a32081927 100644 --- a/Task/TaskCondition.enum.h +++ b/Task/TaskCondition.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskCondition.h b/Task/TaskCondition.h index f604fa60c..423cb4c05 100644 --- a/Task/TaskCondition.h +++ b/Task/TaskCondition.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -35,9 +35,9 @@ #define TASK_CONDITION_H // Includes. -#include "../DateTime.mqh" +#include "../Storage/DateTime.h" #include "../Std.h" -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" #include "TaskCondition.enum.h" #include "TaskCondition.struct.h" #include "TaskConditionBase.h" diff --git a/Task/TaskCondition.struct.h b/Task/TaskCondition.struct.h index c2af7fc3a..27c0b3e90 100644 --- a/Task/TaskCondition.struct.h +++ b/Task/TaskCondition.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,11 +30,11 @@ #endif // Includes. -#include "../Data.struct.h" +#include "../Storage/Data.struct.h" #include "../Serializer/Serializer.define.h" #include "../Serializer/Serializer.enum.h" #include "../Std.h" -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" #include "Task.enum.h" // Forward declarations. diff --git a/Task/TaskCondition.struct.serialize.h b/Task/TaskCondition.struct.serialize.h index 36385b572..72f9d6dad 100644 --- a/Task/TaskCondition.struct.serialize.h +++ b/Task/TaskCondition.struct.serialize.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskConditionBase.h b/Task/TaskConditionBase.h index b2414e10e..949705744 100644 --- a/Task/TaskConditionBase.h +++ b/Task/TaskConditionBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskGetter.h b/Task/TaskGetter.h index 9ece2c0ba..3dff59362 100644 --- a/Task/TaskGetter.h +++ b/Task/TaskGetter.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -36,8 +36,8 @@ // Includes. //#include "TaskGetter.enum.h" -#include "../DateTime.mqh" -#include "../Terminal.define.h" +#include "../Storage/DateTime.h" +#include "../Platform/Terminal.define.h" #include "TaskGetter.struct.h" #include "TaskGetterBase.h" diff --git a/Task/TaskGetter.struct.h b/Task/TaskGetter.struct.h index f17f16d45..140a246ad 100644 --- a/Task/TaskGetter.struct.h +++ b/Task/TaskGetter.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,10 +30,10 @@ #endif // Includes. -#include "../Data.struct.h" +#include "../Storage/Data.struct.h" #include "../Serializer/Serializer.define.h" #include "../Std.h" -#include "../Terminal.define.h" +#include "../Platform/Terminal.define.h" #include "Task.enum.h" /* Entry for TaskGetter class. */ diff --git a/Task/TaskGetter.struct.serialize.h b/Task/TaskGetter.struct.serialize.h index 6afcaa1ac..982f724a6 100644 --- a/Task/TaskGetter.struct.serialize.h +++ b/Task/TaskGetter.struct.serialize.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2021, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskGetterBase.h b/Task/TaskGetterBase.h index c12c3975d..6edffc47e 100644 --- a/Task/TaskGetterBase.h +++ b/Task/TaskGetterBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskManager.h b/Task/TaskManager.h index f9937324e..704c4af59 100644 --- a/Task/TaskManager.h +++ b/Task/TaskManager.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -35,7 +35,7 @@ #define TASK_MANAGER_H // Includes. -#include "../DictObject.mqh" +#include "../Storage/Dict/DictObject.h" #include "../Serializer/SerializerConverter.h" #include "../Serializer/SerializerJson.h" #include "Task.struct.h" diff --git a/Task/TaskObject.h b/Task/TaskObject.h index 279a12935..9f93a0265 100644 --- a/Task/TaskObject.h +++ b/Task/TaskObject.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskSetter.h b/Task/TaskSetter.h index ee2a28884..9909541b5 100644 --- a/Task/TaskSetter.h +++ b/Task/TaskSetter.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/TaskSetter.struct.h b/Task/TaskSetter.struct.h index 8c8cf3bb4..e249caf1f 100644 --- a/Task/TaskSetter.struct.h +++ b/Task/TaskSetter.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,7 +30,7 @@ #endif // Includes. -#include "../Data.struct.h" +#include "../Storage/Data.struct.h" #include "../Serializer/Serializer.h" #include "../Std.h" #include "Task.enum.h" diff --git a/Task/TaskSetterBase.h b/Task/TaskSetterBase.h index 3c36919a8..9087f9d27 100644 --- a/Task/TaskSetterBase.h +++ b/Task/TaskSetterBase.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/Taskable.h b/Task/Taskable.h index ec8ce47c6..4ce0b9603 100644 --- a/Task/Taskable.h +++ b/Task/Taskable.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -35,7 +35,7 @@ #define TASKABLE_H // Includes. -#include "../Object.mqh" +#include "../Storage/Object.h" #include "TaskAction.h" #include "TaskCondition.h" #include "TaskGetter.h" diff --git a/Task/tests/Makefile b/Task/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Task/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Task/tests/Task.test.cpp b/Task/tests/Task.test.cpp index 6696a00a6..a0dd6d06a 100644 --- a/Task/tests/Task.test.cpp +++ b/Task/tests/Task.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/Task.test.mq4 b/Task/tests/Task.test.mq4 index 7ef9313ea..0f8c2f778 100644 --- a/Task/tests/Task.test.mq4 +++ b/Task/tests/Task.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/Task.test.mq5 b/Task/tests/Task.test.mq5 index b7ab9ec83..8afc6e39c 100644 --- a/Task/tests/Task.test.mq5 +++ b/Task/tests/Task.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/TaskAction.test.cpp b/Task/tests/TaskAction.test.cpp index 46595e496..009211461 100644 --- a/Task/tests/TaskAction.test.cpp +++ b/Task/tests/TaskAction.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/TaskAction.test.mq4 b/Task/tests/TaskAction.test.mq4 index 09ea8bb11..7ef500872 100644 --- a/Task/tests/TaskAction.test.mq4 +++ b/Task/tests/TaskAction.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/TaskAction.test.mq5 b/Task/tests/TaskAction.test.mq5 index b1e2a26cf..b7cc8cfca 100644 --- a/Task/tests/TaskAction.test.mq5 +++ b/Task/tests/TaskAction.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -36,11 +36,11 @@ enum ENUM_TASK_ACTION_TEST { class TaskActionTest01 : public TaskActionBase { protected: - long sum; + int64 sum; public: TaskActionTest01() : sum(0){}; - long GetSum() { return sum; } + int64 GetSum() { return sum; } bool Run(const TaskActionEntry &_entry) { sum += _entry.GetId(); PrintFormat("%s; sum=%d", __FUNCSIG__, sum); @@ -50,11 +50,11 @@ class TaskActionTest01 : public TaskActionBase { class TaskActionTest02 : public TaskActionBase { protected: - long sum; + int64 sum; public: TaskActionTest02() : sum(0){}; - long GetSum() { return sum; } + int64 GetSum() { return sum; } bool Run(const TaskActionEntry &_entry) { sum += _entry.GetId(); PrintFormat("%s; sum=%d", __FUNCSIG__, sum); diff --git a/Task/tests/TaskActionBase.test.cpp b/Task/tests/TaskActionBase.test.cpp index 2833dcad5..2a3f62539 100644 --- a/Task/tests/TaskActionBase.test.cpp +++ b/Task/tests/TaskActionBase.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/TaskCondition.test.cpp b/Task/tests/TaskCondition.test.cpp index 2271640cb..0b54af8dc 100644 --- a/Task/tests/TaskCondition.test.cpp +++ b/Task/tests/TaskCondition.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/TaskCondition.test.mq4 b/Task/tests/TaskCondition.test.mq4 index 792991e6e..1bfe39712 100644 --- a/Task/tests/TaskCondition.test.mq4 +++ b/Task/tests/TaskCondition.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/TaskCondition.test.mq5 b/Task/tests/TaskCondition.test.mq5 index 9f84a33a0..4ad0c698d 100644 --- a/Task/tests/TaskCondition.test.mq5 +++ b/Task/tests/TaskCondition.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -36,11 +36,11 @@ enum ENUM_TASK_CONDITION_TEST { class TaskConditionTest01 : public TaskConditionBase { protected: - long sum; + int64 sum; public: TaskConditionTest01() : sum(0){}; - long GetSum() { return sum; } + int64 GetSum() { return sum; } bool Check(const TaskConditionEntry &_entry) { sum += _entry.GetId(); PrintFormat("%s; sum=%d", __FUNCSIG__, sum); @@ -50,11 +50,11 @@ class TaskConditionTest01 : public TaskConditionBase { class TaskConditionTest02 : public TaskConditionBase { protected: - long sum; + int64 sum; public: TaskConditionTest02() : sum(0){}; - long GetSum() { return sum; } + int64 GetSum() { return sum; } bool Check(const TaskConditionEntry &_entry) { sum += _entry.GetId(); PrintFormat("%s; sum=%d", __FUNCSIG__, sum); diff --git a/Task/tests/TaskConditionBase.test.cpp b/Task/tests/TaskConditionBase.test.cpp index 98536265a..7ba53474d 100644 --- a/Task/tests/TaskConditionBase.test.cpp +++ b/Task/tests/TaskConditionBase.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/TaskGetter.test.cpp b/Task/tests/TaskGetter.test.cpp index 6bc453109..08ef51a26 100644 --- a/Task/tests/TaskGetter.test.cpp +++ b/Task/tests/TaskGetter.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) { return 0; } diff --git a/Task/tests/TaskGetter.test.mq4 b/Task/tests/TaskGetter.test.mq4 index d2bd22562..b1e96f2da 100644 --- a/Task/tests/TaskGetter.test.mq4 +++ b/Task/tests/TaskGetter.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/TaskGetter.test.mq5 b/Task/tests/TaskGetter.test.mq5 index 03be663d0..a21385fbb 100644 --- a/Task/tests/TaskGetter.test.mq5 +++ b/Task/tests/TaskGetter.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -47,7 +47,7 @@ class TaskGetterTest01 : public TaskGetter { public: TaskGetterTest01(){}; - // long GetSum() { return sum; } + // int64 GetSum() { return sum; } TaskGetterTest01Data Get() { return TaskGetter::Get(); } TaskGetterTest01Data Get(const TaskGetterEntry &_entry) { data.SetValue(_entry.GetId()); diff --git a/Task/tests/TaskGetterBase.test.cpp b/Task/tests/TaskGetterBase.test.cpp index 709722087..1d75280ff 100644 --- a/Task/tests/TaskGetterBase.test.cpp +++ b/Task/tests/TaskGetterBase.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/TaskManager.test.cpp b/Task/tests/TaskManager.test.cpp index a26370b87..673eeb18e 100644 --- a/Task/tests/TaskManager.test.cpp +++ b/Task/tests/TaskManager.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/TaskManager.test.mq4 b/Task/tests/TaskManager.test.mq4 index 10e20035e..879320a19 100644 --- a/Task/tests/TaskManager.test.mq4 +++ b/Task/tests/TaskManager.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/TaskManager.test.mq5 b/Task/tests/TaskManager.test.mq5 index a8e4ad9c7..4fadba2ce 100644 --- a/Task/tests/TaskManager.test.mq5 +++ b/Task/tests/TaskManager.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,7 +28,7 @@ struct DataParamEntry; // Includes. -#include "../../Data.struct.serialize.h" +#include "../../Storage/Data.struct.serialize.h" #include "../../Test.mqh" #include "../TaskAction.struct.serialize.h" #include "../TaskCondition.struct.serialize.h" diff --git a/Task/tests/TaskObject.test.cpp b/Task/tests/TaskObject.test.cpp index 236a7be82..027cf055b 100644 --- a/Task/tests/TaskObject.test.cpp +++ b/Task/tests/TaskObject.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/TaskObject.test.mq4 b/Task/tests/TaskObject.test.mq4 index 08705d1bf..792c23783 100644 --- a/Task/tests/TaskObject.test.mq4 +++ b/Task/tests/TaskObject.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/TaskObject.test.mq5 b/Task/tests/TaskObject.test.mq5 index 4db435d23..ea2ea4fb3 100644 --- a/Task/tests/TaskObject.test.mq5 +++ b/Task/tests/TaskObject.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/TaskSetter.test.cpp b/Task/tests/TaskSetter.test.cpp index b114e8460..77aafc5eb 100644 --- a/Task/tests/TaskSetter.test.cpp +++ b/Task/tests/TaskSetter.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,11 +25,10 @@ */ // Includes. -#include "../TaskSetter.h" - #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../TaskSetter.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/TaskSetter.test.mq4 b/Task/tests/TaskSetter.test.mq4 index 2aa87950d..e688922fe 100644 --- a/Task/tests/TaskSetter.test.mq4 +++ b/Task/tests/TaskSetter.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/TaskSetter.test.mq5 b/Task/tests/TaskSetter.test.mq5 index 6831c460f..d06f48149 100644 --- a/Task/tests/TaskSetter.test.mq5 +++ b/Task/tests/TaskSetter.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/Taskable.car.test.mq4 b/Task/tests/Taskable.car.test.mq4 index 0beae428a..20cb7866f 100644 --- a/Task/tests/Taskable.car.test.mq4 +++ b/Task/tests/Taskable.car.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/Taskable.car.test.mq5 b/Task/tests/Taskable.car.test.mq5 index 75b701973..c2b42c4e0 100644 --- a/Task/tests/Taskable.car.test.mq5 +++ b/Task/tests/Taskable.car.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,7 +28,7 @@ struct DataParamEntry; // Includes. -#include "../../Data.struct.h" +#include "../../Storage/Data.struct.h" #include "../../Test.mqh" #include "../Task.h" diff --git a/Task/tests/Taskable.test.cpp b/Task/tests/Taskable.test.cpp index d86116b03..a774023db 100644 --- a/Task/tests/Taskable.test.cpp +++ b/Task/tests/Taskable.test.cpp @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,6 +30,6 @@ #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" -#include "../../String.extern.h" +#include "../../Storage/String.extern.h" int main(int argc, char **argv) {} diff --git a/Task/tests/Taskable.test.mq4 b/Task/tests/Taskable.test.mq4 index 2d57ffefb..474415b93 100644 --- a/Task/tests/Taskable.test.mq4 +++ b/Task/tests/Taskable.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Task/tests/Taskable.test.mq5 b/Task/tests/Taskable.test.mq5 index e6d4b022c..4fce362c2 100644 --- a/Task/tests/Taskable.test.mq5 +++ b/Task/tests/Taskable.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Test.mqh b/Test.mqh index 83bb03664..f69b557f8 100644 --- a/Test.mqh +++ b/Test.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Provides base functionality for testing purposes. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Define an assert macros. #define assertTrueOrFail(cond, msg) \ if (!(cond)) { \ diff --git a/Tester.mqh b/Tester.mqh index cea7241a4..e60c6c76b 100644 --- a/Tester.mqh +++ b/Tester.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "SymbolInfo.mqh" -#include "Terminal.mqh" +#include "Exchange/SymbolInfo/SymbolInfo.h" +#include "Platform/Terminal.h" /** * Class to provide functions to work with the strategy tester. diff --git a/Tests.mqh b/Tests.mqh index 212333e9e..416578c4a 100644 --- a/Tests.mqh +++ b/Tests.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,6 +20,11 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "Indicator/Indicator.h" #include "Market.mqh" diff --git a/Tick/Tick.struct.h b/Tick/Tick.struct.h index 83e7ebf51..f01bd662a 100644 --- a/Tick/Tick.struct.h +++ b/Tick/Tick.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,8 +30,8 @@ #endif // Includes. -#include "../DateTime.extern.h" #include "../Std.h" +#include "../Storage/DateTime.extern.h" #ifndef __MQL__ /** @@ -40,14 +40,14 @@ * https://www.mql5.com/en/docs/constants/structures/mqltick */ struct MqlTick { - datetime time; // Time of the last prices update. - double ask; // Current Ask price. - double bid; // Current Bid price. - double last; // Price of the last deal (last). - double volume_real; // Volume for the current last price with greater accuracy. - int64 time_msc; // Time of a price last update in milliseconds. - unsigned int flags; // Tick flags. - unsigned int64 volume; // Volume for the current last price. + datetime time; // Time of the last prices update. + double ask; // Current Ask price. + double bid; // Current Bid price. + double last; // Price of the last deal (last). + double volume_real; // Volume for the current last price with greater accuracy. + int64 time_msc; // Time of a price last update in milliseconds. + unsigned int flags; // Tick flags. + uint64 volume; // Volume for the current last price. // Default constructor. MqlTick() {} diff --git a/Tick/TickManager.h b/Tick/TickManager.h index 2445c026a..c41b8df5b 100644 --- a/Tick/TickManager.h +++ b/Tick/TickManager.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,8 +25,13 @@ * Implements TickManager class. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../BufferStruct.mqh" +#include "../Storage/Dict/Buffer/BufferStruct.h" #include "Tick.struct.h" #include "TickManager.h" //#include "TickManager.struct.h" diff --git a/Tick/tests/Makefile b/Tick/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Tick/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Tick/tests/TickManager.test.cpp b/Tick/tests/TickManager.test.cpp new file mode 100644 index 000000000..650a84fbc --- /dev/null +++ b/Tick/tests/TickManager.test.cpp @@ -0,0 +1,32 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of TickManager class. + */ + +// Includes. +#include "../TickManager.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) {} diff --git a/Tick/tests/TickManager.test.mq4 b/Tick/tests/TickManager.test.mq4 index 5ed2a0b2a..e003e4846 100644 --- a/Tick/tests/TickManager.test.mq4 +++ b/Tick/tests/TickManager.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Tick/tests/TickManager.test.mq5 b/Tick/tests/TickManager.test.mq5 index e507b43d9..925c13a87 100644 --- a/Tick/tests/TickManager.test.mq5 +++ b/Tick/tests/TickManager.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Timer.mqh b/Timer.mqh index de6890f0d..d7ac2e14c 100644 --- a/Timer.mqh +++ b/Timer.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,9 +20,14 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "Math.h" -#include "Object.mqh" +#include "Math/Math.h" +#include "Storage/Object.h" /** * Class to provide functions to deal with the timer. @@ -34,7 +39,7 @@ class Timer : public Object { int index; unsigned int data[]; unsigned int start, end; - unsigned long max; + uint64 max; public: /** @@ -73,7 +78,7 @@ class Timer : public Object { /** * Print the current timer times when maximum value is reached. */ - Timer *PrintOnMax(unsigned long _min = 1) { + Timer *PrintOnMax(uint64 _min = 1) { return data[index] > _min && data[this PTR_DEREF index] >= this PTR_DEREF max ? PrintSummary() : GetPointer(this); } @@ -93,9 +98,9 @@ class Timer : public Object { /** * Get the sum of all values. */ - unsigned long GetSum() { + uint64 GetSum() { unsigned int _size = ArraySize(this PTR_DEREF data); - unsigned long _sum = 0; + uint64 _sum = 0; for (unsigned int _i = 0; _i < _size; _i++) { _sum += data[_i]; } diff --git a/Trade.enum.h b/Trade.enum.h index 74c5ed02b..560e4831c 100644 --- a/Trade.enum.h +++ b/Trade.enum.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Trade.mqh b/Trade.mqh index 4ec0a0ec5..0446da64b 100644 --- a/Trade.mqh +++ b/Trade.mqh @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2022, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -30,14 +30,14 @@ class Trade; #define TRADE_MQH // Includes. -#include "Account/AccountMt.h" #include "Convert.mqh" -#include "DictStruct.mqh" +#include "Exchange/Account/AccountMt.h" #include "Indicator/IndicatorData.h" -#include "Math.h" -#include "Object.mqh" -#include "Order.mqh" -#include "OrderQuery.h" +#include "Math/Math.h" +#include "Platform/Order.h" +#include "Platform/OrderQuery.h" +#include "Storage/Dict/DictStruct.h" +#include "Storage/Object.h" #include "Task/TaskManager.h" #include "Task/Taskable.h" #include "Trade.enum.h" @@ -47,9 +47,9 @@ class Trade : public Taskable { public: AccountMt account; Ref indi_candle; - DictStruct> orders_active; - DictStruct> orders_history; - DictStruct> orders_pending; + DictStruct> orders_active; + DictStruct> orders_history; + DictStruct> orders_pending; Log logger; // Trade logger. TaskManager tasks; // Tasks. TradeParams tparams; // Trade parameters. @@ -183,7 +183,7 @@ class Trade : public Taskable { * @return * Returns DictStruct's of active orders. */ - DictStruct> *GetOrdersActive() { return &orders_active; } + DictStruct> *GetOrdersActive() { return &orders_active; } /** * Gets list of history orders. @@ -191,7 +191,7 @@ class Trade : public Taskable { * @return * Returns DictStruct's of orders from history. */ - DictStruct> *GetOrdersHistory() { return &orders_history; } + DictStruct> *GetOrdersHistory() { return &orders_history; } /** * Gets list of pending orders. @@ -199,7 +199,7 @@ class Trade : public Taskable { * @return * Returns DictStruct's of pending orders. */ - DictStruct> *GetOrdersPending() { return &orders_pending; } + DictStruct> *GetOrdersPending() { return &orders_pending; } /** * Get a trade request. @@ -207,13 +207,14 @@ class Trade : public Taskable { * @return * Returns true on successful request. */ - MqlTradeRequest GetTradeOpenRequest(ENUM_ORDER_TYPE _type, float _volume = 0, long _magic = 0, string _comment = "") { + MqlTradeRequest GetTradeOpenRequest(ENUM_ORDER_TYPE _type, float _volume = 0, int64 _magic = 0, + string _comment = "") { // Create a request. MqlTradeRequest _request = {(ENUM_TRADE_REQUEST_ACTIONS)0}; _request.action = TRADE_ACTION_DEAL; _request.comment = _comment; _request.deviation = tparams.Get(TRADE_PARAM_SLIPPAGE); // The maximal price deviation, specified in points. - _request.magic = _magic > 0 ? _magic : tparams.Get(TRADE_PARAM_MAGIC_NO); + _request.magic = _magic > 0 ? _magic : tparams.Get(TRADE_PARAM_MAGIC_NO); _request.symbol = GetSource() PTR_DEREF GetSymbol(); _request.price = GetSource() PTR_DEREF GetOpenOffer(_type); _request.type = _type; @@ -350,15 +351,15 @@ class Trade : public Taskable { Ref _order = order_last; if (_order.IsSet() && _order REF_DEREF Get(ORDER_TYPE) == _cmd && - _order REF_DEREF Get(ORDER_TIME_SETUP) > GetSource() PTR_DEREF GetBarTime()) { + _order REF_DEREF Get(ORDER_TIME_SETUP) > GetSource() PTR_DEREF GetBarTime()) { _result |= true; } if (!_result) { - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { _order = iter.Value(); if (_order REF_DEREF Get(ORDER_TYPE) == _cmd) { - long _time_opened = _order REF_DEREF Get(ORDER_TIME_SETUP); + int64 _time_opened = _order REF_DEREF Get(ORDER_TIME_SETUP); _result |= _shift > 0 && _time_opened < GetSource() PTR_DEREF GetBarTime(_shift - 1); _result |= _time_opened >= GetSource() PTR_DEREF GetBarTime(_shift); if (_result) { @@ -396,7 +397,7 @@ class Trade : public Taskable { } if (!_result) { - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid() && !_result; ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid() && !_result; ++iter) { _order = iter.Value(); if (_order.IsSet() && _order REF_DEREF IsOpen()) { if (_odata.Get(ORDER_TYPE) == _cmd) { @@ -434,7 +435,7 @@ class Trade : public Taskable { } if (!_result) { - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid() && !_result; ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid() && !_result; ++iter) { _order = iter.Value(); if (_order.IsSet()) { _result = _odata.Get(ORDER_TYPE) != _cmd; @@ -691,7 +692,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. tstats.Add(TRADE_STAT_ORDERS_ERRORS); // Pass-through. case ERR_NO_ERROR: // 0 - orders_active.Set(_order PTR_DEREF Get(ORDER_PROP_TICKET), _ref_order); + orders_active.Set(_order PTR_DEREF Get(ORDER_PROP_TICKET), _ref_order); order_last = _order; tstates.AddState(TRADE_STATE_ORDERS_ACTIVE); tstats.Add(TRADE_STAT_ORDERS_OPENED); @@ -724,9 +725,9 @@ HistorySelect(0, TimeCurrent()); // Select history for access. */ bool OrderMoveToHistory(Order *_order) { _order PTR_DEREF Refresh(true); - orders_active.Unset(_order PTR_DEREF Get(ORDER_PROP_TICKET)); + orders_active.Unset(_order PTR_DEREF Get(ORDER_PROP_TICKET)); Ref _ref_order = _order; - bool result = orders_history.Set(_order PTR_DEREF Get(ORDER_PROP_TICKET), _ref_order); + bool result = orders_history.Set(_order PTR_DEREF Get(ORDER_PROP_TICKET), _ref_order); /* @todo if (strategy != NULL) { strategy.OnOrderClose(_order); @@ -740,7 +741,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. tstates.RemoveState(TRADE_STATE_ORDERS_MAX_SOFT); return result; } - bool OrderMoveToHistory(unsigned long _ticket) { + bool OrderMoveToHistory(uint64 _ticket) { Ref _order = orders_active.GetByKey(_ticket); return OrderMoveToHistory(_order.Ptr()); } @@ -750,7 +751,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. */ bool RefreshActiveOrders(bool _force = false, bool _first_close = false) { bool _result = true; - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { Ref _order = iter.Value(); if (_order.IsSet() && _order REF_DEREF IsOpen(true)) { _order REF_DEREF Refresh(_force); @@ -770,7 +771,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. template bool RefreshActiveOrdersByProp(E _prop, bool _force = false) { bool _result = true; - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { Ref _order = iter.Value(); if (_order.IsSet() && _order REF_DEREF IsOpen(true)) { if (_force || _order REF_DEREF ShouldRefresh()) { @@ -828,11 +829,11 @@ HistorySelect(0, TimeCurrent()); // Select history for access. Ref _order_ref = _order; if (_order PTR_DEREF IsOpen()) { // @todo: _order.IsPending()? - _result &= orders_active.Set(_order PTR_DEREF Get(ORDER_PROP_TICKET), _order_ref); + _result &= orders_active.Set(_order PTR_DEREF Get(ORDER_PROP_TICKET), _order_ref); logger.Link(_order.GetLogger()); _order PTR_DEREF GetLogger().SetLevel((ENUM_LOG_LEVEL)tparams.Get(TRADE_PARAM_LOG_LEVEL)); } else { - _result &= orders_history.Set(_order PTR_DEREF Get(ORDER_PROP_TICKET), _order_ref); + _result &= orders_history.Set(_order PTR_DEREF Get(ORDER_PROP_TICKET), _order_ref); } return _result && GetLastError() == ERR_NO_ERROR; } @@ -840,13 +841,13 @@ HistorySelect(0, TimeCurrent()); // Select history for access. /** * Loads active orders by magic number. */ - bool OrdersLoadByMagic(unsigned long _magic_no) { + bool OrdersLoadByMagic(uint64 _magic_no) { ResetLastError(); int _total_active = TradeStatic::TotalActive(); for (int pos = 0; pos < _total_active; pos++) { if (OrderStatic::SelectByPosition(pos)) { if (OrderStatic::MagicNumber() == _magic_no) { - unsigned long _ticket = OrderStatic::Ticket(); + uint64 _ticket = OrderStatic::Ticket(); Ref _order = new Order(_ticket); orders_active.Set(_ticket, _order); OrderLoad(_order.Ptr()); @@ -886,7 +887,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. int _closed = 0; Ref _order; _comment = _comment != "" ? _comment : "TOCA:"; - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { _order = iter.Value(); if (_order REF_DEREF IsOpen(true)) { if (_order REF_DEREF OrderClose(_reason, _comment)) { @@ -921,7 +922,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. int _oid = 0, _closed = 0; Ref _order; _comment = _comment != "" ? _comment : "TOCVC:"; - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { _order = iter.Value(); if (_order REF_DEREF IsOpen(true)) { _order REF_DEREF Refresh(); @@ -964,7 +965,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. int _closed = 0; Ref _order; _comment = _comment != "" ? _comment : __FUNCTION__; - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { _order = iter.Value(); if (_order REF_DEREF IsOpen(true)) { _order REF_DEREF Refresh((E)_prop); @@ -974,7 +975,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. OrderMoveToHistory(_order.Ptr()); order_last = _order; } else { - logger.AddLastError(__FUNCTION_LINE__, _order REF_DEREF Get(ORDER_PROP_LAST_ERROR)); + logger.AddLastError(__FUNCTION_LINE__, _order REF_DEREF Get(ORDER_PROP_LAST_ERROR)); return -1; } } @@ -1000,7 +1001,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. int _closed = 0; Ref _order; _comment = _comment != "" ? _comment : __FUNCTION__; - for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { + for (DictStructIterator> iter = orders_active.Begin(); iter.IsValid(); ++iter) { _order = iter.Value(); if (_order REF_DEREF IsOpen(true)) { _order REF_DEREF Refresh(); @@ -1042,15 +1043,15 @@ HistorySelect(0, TimeCurrent()); // Select history for access. /** * Calculate number of allowed orders to open. */ - unsigned long CalcMaxOrders(float volume_size, float _risk_ratio = 1.0, long prev_max_orders = 0, long hard_limit = 0, - bool smooth = true) { + uint64 CalcMaxOrders(float volume_size, float _risk_ratio = 1.0, int64 prev_max_orders = 0, int64 hard_limit = 0, + bool smooth = true) { float _avail_margin = fmin(account.GetMarginFree(), account.GetBalance() + account.GetCredit()); if (_avail_margin == 0 || volume_size == 0) { return 0; } float _margin_required = GetMarginRequired(); float _avail_orders = _avail_margin / _margin_required / volume_size; - long new_max_orders = (long)(_avail_orders * _risk_ratio); + int64 new_max_orders = (int64)(_avail_orders * _risk_ratio); if (hard_limit > 0) new_max_orders = fmin(hard_limit, new_max_orders); if (smooth && new_max_orders > prev_max_orders) { // Increase the limit smoothly. @@ -1198,10 +1199,10 @@ HistorySelect(0, TimeCurrent()); // Select history for access. * * @see: https://book.mql4.com/appendix/limits */ - static long GetTradeDistanceInPts(string _symbol) { + static int64 GetTradeDistanceInPts(string _symbol) { return fmax(SymbolInfoStatic::GetTradeStopsLevel(_symbol), SymbolInfoStatic::GetFreezeLevel(_symbol)); } - long GetTradeDistanceInPts() { return GetTradeDistanceInPts(GetSource() PTR_DEREF GetSymbol()); } + int64 GetTradeDistanceInPts() { return GetTradeDistanceInPts(GetSource() PTR_DEREF GetSymbol()); } /** * Get a market distance in pips. @@ -1772,7 +1773,7 @@ HistorySelect(0, TimeCurrent()); // Select history for access. */ virtual void OnOrderOpen(const Order &_order) { if (logger.GetLevel() >= V_INFO) { - // logger.Info(_order.ToString(), (string)_order.Get(ORDER_TICKET)); // @fixme + // logger.Info(_order.ToString(), (string)_order.Get(ORDER_TICKET)); // @fixme ResetLastError(); // @fixme: Error 69539 } } diff --git a/Trade.struct.h b/Trade.struct.h index 19fb2c171..8f8ac43fd 100644 --- a/Trade.struct.h +++ b/Trade.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -34,7 +34,7 @@ struct TradeStats; // Includes. -#include "DateTime.mqh" +#include "Storage/DateTime.h" #include "Trade.enum.h" /* Structure for trade statistics. */ @@ -149,7 +149,7 @@ struct TradeParams { slippage(_slippage) { SetLimits(0); } - TradeParams(unsigned long _magic_no, ENUM_LOG_LEVEL _ll = V_INFO) + TradeParams(uint64 _magic_no, ENUM_LOG_LEVEL _ll = V_INFO) : bars_min(100), lot_size(0), order_comment(""), @@ -226,22 +226,24 @@ struct TradeParams { void Set(ENUM_TRADE_PARAM _param, T _value) { switch (_param) { case TRADE_PARAM_BARS_MIN: - bars_min = (unsigned short)_value; + ConvertBasic::Convert(_value, bars_min); return; case TRADE_PARAM_LOT_SIZE: - lot_size = (float)_value; + ConvertBasic::Convert(_value, lot_size); return; case TRADE_PARAM_MAGIC_NO: - magic_no = (unsigned long)_value; + ConvertBasic::Convert(_value, magic_no); return; - case TRADE_PARAM_ORDER_COMMENT: - order_comment = SerializerConversions::ValueToString(_value); + case TRADE_PARAM_ORDER_COMMENT: { + string _value_string = SerializerConversions::ValueToString(_value); + ConvertBasic::Convert(_value_string, order_comment); return; + } case TRADE_PARAM_RISK_MARGIN: - risk_margin = (float)_value; + ConvertBasic::Convert(_value, risk_margin); return; case TRADE_PARAM_SLIPPAGE: - slippage = (unsigned int)_value; + ConvertBasic::Convert(_value, slippage); return; default: break; @@ -289,7 +291,7 @@ struct TradeParams { } } void SetLotSize(float _lot_size) { lot_size = _lot_size; } - void SetMagicNo(unsigned long _mn) { magic_no = _mn; } + void SetMagicNo(uint64 _mn) { magic_no = _mn; } void SetRiskMargin(float _value) { risk_margin = _value; } // Serializers. void SerializeStub(int _n1 = 1, int _n2 = 1, int _n3 = 1, int _n4 = 1, int _n5 = 1) {} diff --git a/Trade/TradeSignal.h b/Trade/TradeSignal.h index b9861db88..1d130ddd1 100644 --- a/Trade/TradeSignal.h +++ b/Trade/TradeSignal.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -20,6 +20,11 @@ * */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. #include "TradeSignal.struct.h" diff --git a/Trade/TradeSignal.struct.h b/Trade/TradeSignal.struct.h index 41d864b34..7369fb138 100644 --- a/Trade/TradeSignal.struct.h +++ b/Trade/TradeSignal.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,8 +25,13 @@ * Includes TradeSignal's structs. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../Chart.enum.h" +#include "../Platform/Chart/Chart.enum.h" #include "../Serializer/SerializerConverter.h" #include "../Serializer/SerializerJson.h" @@ -60,11 +65,11 @@ // Structure for a trade signal. struct TradeSignalEntry { protected: - long magic_id; // Magic identifier. + int64 magic_id; // Magic identifier. unsigned int signals; // Store signals (@see: ENUM_TRADE_SIGNAL_FLAG). float strength; // Signal strength. ENUM_TIMEFRAMES tf; // Timeframe. - long timestamp; // Creation timestamp + int64 timestamp; // Creation timestamp float weight; // Signal weight. public: @@ -119,8 +124,8 @@ struct TradeSignalEntry { }; /* Constructor */ - TradeSignalEntry(unsigned int _signals = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, long _magic_id = 0, - float _strength = 0.0f, float _weight = 0.0f, long _time = 0) + TradeSignalEntry(unsigned int _signals = 0, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int64 _magic_id = 0, + float _strength = 0.0f, float _weight = 0.0f, int64 _time = 0) : magic_id(_magic_id), signals(_signals), strength(_strength), tf(_tf), timestamp(_time), weight(_weight) {} TradeSignalEntry(const TradeSignalEntry &_entry) { THIS_REF = _entry; } /* Getters */ @@ -149,7 +154,7 @@ struct TradeSignalEntry { void Set(STRUCT_ENUM(TradeSignalEntry, ENUM_TRADE_SIGNAL_PROP) _prop, T _value) { switch (_prop) { case TRADE_SIGNAL_PROP_MAGIC_ID: - magic_id = (long)_value; + magic_id = (int64)_value; return; case TRADE_SIGNAL_PROP_SIGNALS: signals = (unsigned int)_value; @@ -158,10 +163,10 @@ struct TradeSignalEntry { strength = (float)_value; return; case TRADE_SIGNAL_PROP_TF: - tf = (ENUM_TIMEFRAMES)_value; + tf = (ENUM_TIMEFRAMES)(int)_value; return; case TRADE_SIGNAL_PROP_TIME: - timestamp = (long)_value; + timestamp = (int64)_value; return; case TRADE_SIGNAL_PROP_WEIGHT: weight = (float)_value; diff --git a/Trade/TradeSignalManager.h b/Trade/TradeSignalManager.h index c159d64af..20cc09be6 100644 --- a/Trade/TradeSignalManager.h +++ b/Trade/TradeSignalManager.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,8 +25,13 @@ * Implements TradeSignalManager class. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Includes. -#include "../DictObject.mqh" +#include "../Storage/Dict/DictObject.h" #include "TradeSignal.h" #include "TradeSignalManager.struct.h" @@ -175,7 +180,7 @@ class TradeSignalManager : Dynamic { continue; } } - Set(TSM_PROP_LAST_CHECK, ::TimeGMT()); + Set(TSM_PROP_LAST_CHECK, ::TimeGMT()); } /* State methods */ @@ -187,9 +192,9 @@ class TradeSignalManager : Dynamic { * _update Update last check timestamp when true. */ bool IsReady(bool _update = true) { - bool _res = Get(TSM_PROP_LAST_CHECK) <= ::TimeGMT() - Get(TSM_PROP_FREQ); + bool _res = Get(TSM_PROP_LAST_CHECK) <= ::TimeGMT() - Get(TSM_PROP_FREQ); if (_res) { - Set(TSM_PROP_LAST_CHECK, ::TimeGMT()); + Set(TSM_PROP_LAST_CHECK, ::TimeGMT()); } return _res; } diff --git a/Trade/TradeSignalManager.struct.h b/Trade/TradeSignalManager.struct.h index 81415ce02..79d568382 100644 --- a/Trade/TradeSignalManager.struct.h +++ b/Trade/TradeSignalManager.struct.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,6 +25,11 @@ * Implements TradeSignalManager's structures. */ +#ifndef __MQL__ +// Allows the preprocessor to include a header file when it is needed. +#pragma once +#endif + // Defines. #define TSM_PROP_FREQ STRUCT_ENUM(TradeSignalManagerParams, TSM_PARAMS_PROP_FREQ) #define TSM_PROP_LAST_CHECK STRUCT_ENUM(TradeSignalManagerParams, TSM_PARAMS_PROP_LAST_CHECK) @@ -34,8 +39,8 @@ */ struct TradeSignalManagerParams { protected: - short freq; // Signal process refresh frequency (in sec). - long last_check; // Last check. + short freq; // Signal process refresh frequency (in sec). + int64 last_check; // Last check. public: /* Struct's enumerations */ @@ -79,7 +84,7 @@ struct TradeSignalManagerParams { freq = (short)_value; return; case TSM_PARAMS_PROP_LAST_CHECK: - last_check = (long)_value; + last_check = (int64)_value; return; } SetUserError(ERR_INVALID_PARAMETER); diff --git a/Trade/tests/Makefile b/Trade/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/Trade/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/Trade/tests/TradeSignal.test.cpp.fixme b/Trade/tests/TradeSignal.test.cpp.fixme index ac2fe8fba..2b0f87911 100644 --- a/Trade/tests/TradeSignal.test.cpp.fixme +++ b/Trade/tests/TradeSignal.test.cpp.fixme @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,5 +31,12 @@ #include "../../Common.extern.h" #include "../../Std.h" #include "../../String.extern.h" +#include "../TradeSignal.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo -int main(int argc, char **argv) {} + return 0; +} diff --git a/Storage/tests/ItemsHistory.mq4 b/Trade/tests/TradeSignal.test.mq4 similarity index 81% rename from Storage/tests/ItemsHistory.mq4 rename to Trade/tests/TradeSignal.test.mq4 index eaed0b07c..be9a138d8 100644 --- a/Storage/tests/ItemsHistory.mq4 +++ b/Trade/tests/TradeSignal.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2020, 31337 Investments Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -21,8 +21,8 @@ /** * @file - * Test functionality of ItemsHistory class. + * Test functionality of TradeSignal class. */ // Includes. -#include "ItemsHistory.mq5" +#include "TradeSignal.test.mq5" diff --git a/Trade/tests/TradeSignalTest.mq5 b/Trade/tests/TradeSignal.test.mq5 similarity index 99% rename from Trade/tests/TradeSignalTest.mq5 rename to Trade/tests/TradeSignal.test.mq5 index 8bad23661..f3deaa5ff 100644 --- a/Trade/tests/TradeSignalTest.mq5 +++ b/Trade/tests/TradeSignal.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Trade/tests/TradeSignalManager.test.cpp.fixme b/Trade/tests/TradeSignalManager.test.cpp.fixme index 31fdfefe6..cc8149f0e 100644 --- a/Trade/tests/TradeSignalManager.test.cpp.fixme +++ b/Trade/tests/TradeSignalManager.test.cpp.fixme @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,11 +25,16 @@ */ // Includes. -#include "../TradeSignalManager.h" - #include "../../Common.define.h" #include "../../Common.extern.h" #include "../../Std.h" #include "../../String.extern.h" +#include "../TradeSignalManager.h" + +#include "../../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo -int main(int argc, char **argv) {} + return 0; +} diff --git a/Trade/tests/TradeSignalManagerTest.mq4 b/Trade/tests/TradeSignalManager.test.mq4 similarity index 84% rename from Trade/tests/TradeSignalManagerTest.mq4 rename to Trade/tests/TradeSignalManager.test.mq4 index 4daf84f36..9455df7e6 100644 --- a/Trade/tests/TradeSignalManagerTest.mq4 +++ b/Trade/tests/TradeSignalManager.test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,4 +25,4 @@ */ // Includes. -#include "TradeSignalManagerTest.mq5" +#include "TradeSignalManager.test.mq5" diff --git a/Trade/tests/TradeSignalManagerTest.mq5 b/Trade/tests/TradeSignalManager.test.mq5 similarity index 95% rename from Trade/tests/TradeSignalManagerTest.mq5 rename to Trade/tests/TradeSignalManager.test.mq5 index 8cab44e6a..7e1f32651 100644 --- a/Trade/tests/TradeSignalManagerTest.mq5 +++ b/Trade/tests/TradeSignalManager.test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/Util.h b/Util.h index 8e1f88f76..ecd4a81bc 100644 --- a/Util.h +++ b/Util.h @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/CompileIndicatorsTest.mq4 b/tests/CompileIndicatorsTest.mq4 deleted file mode 100644 index 4be5ffc3d..000000000 --- a/tests/CompileIndicatorsTest.mq4 +++ /dev/null @@ -1,28 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test compilation of Indicators/ files. - */ - -// Includes. -#include "CompileIndicatorsTest.mq5" diff --git a/tests/CompileTest.mq4 b/tests/CompileTest.mq4 index b3e891e7a..e733efa72 100644 --- a/tests/CompileTest.mq4 +++ b/tests/CompileTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/CompileTest.mq5 b/tests/CompileTest.mq5 index 0f5153d1c..047b1301b 100644 --- a/tests/CompileTest.mq5 +++ b/tests/CompileTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,76 +26,68 @@ // 3D includes (MQL5 only). #ifdef __MQL5__ -#include "../3D/Chart3D.h" -#include "../3D/Cube.h" -#include "../3D/Devices/MTDX/MTDXDevice.h" -#include "../3D/Devices/MTDX/MTDXIndexBuffer.h" -#include "../3D/Devices/MTDX/MTDXShader.h" -#include "../3D/Devices/MTDX/MTDXVertexBuffer.h" -#include "../3D/Frontends/MT5Frontend.h" +#include "../Platform/Chart3D/Chart3D.h" +#include "../Platform/Chart3D/Cube.h" +#include "../Platform/Chart3D/Devices/MTDX/MTDXDevice.h" +#include "../Platform/Chart3D/Devices/MTDX/MTDXIndexBuffer.h" +#include "../Platform/Chart3D/Devices/MTDX/MTDXShader.h" +#include "../Platform/Chart3D/Devices/MTDX/MTDXVertexBuffer.h" +#include "../Platform/Chart3D/Frontends/MT5Frontend.h" #endif // Forward declaration. struct IndicatorParams; // Includes. -#include "../Account/AccountMt.h" -#include "../Array.mqh" +#include "../Exchange/Account/AccountMt.h" +#include "../Storage/Array.h" #include "../Task/TaskAction.h" -//#include "../BasicTrade.mqh" // @removeme -#include "../Buffer.mqh" -#include "../BufferFXT.mqh" -#include "../BufferStruct.mqh" -#include "../Chart.mqh" +#include "../Storage/Dict/Buffer/Buffer.h" +#include "../Storage/Dict/Buffer/BufferFXT.h" +#include "../Storage/Dict/Buffer/BufferStruct.h" +#include "../Platform/Chart/Chart.h" +#include "../Storage/Collection.h" #include "../Config.mqh" #include "../Convert.mqh" -#include "../Database.mqh" -#include "../DateTime.mqh" -#include "../Dict.mqh" -#include "../DictBase.mqh" -#include "../DictIteratorBase.mqh" -#include "../DictObject.mqh" -#include "../DictSlot.mqh" -#include "../DictStruct.mqh" -#include "../Draw.mqh" -#include "../DrawIndicator.mqh" +#include "../Storage/Database.h" +#include "../Storage/DateTime.h" +#include "../Storage/Dict/Dict.h" +#include "../Storage/Dict/DictBase.h" +#include "../Storage/Dict/DictIteratorBase.h" +#include "../Storage/Dict/DictObject.h" +#include "../Storage/Dict/DictSlot.h" +#include "../Storage/Dict/DictStruct.h" +#include "../Platform/Plot.h" +#include "../Indicators/DrawIndicator.mqh" #include "../EA.mqh" #include "../File.mqh" -// #include "../Inet.mqh" #include "../Log.mqh" #include "../MD5.mqh" #include "../Storage/IValueStorage.h" #include "../Task/TaskCondition.h" -//#include "../MQL4.mqh" // @removeme -//#include "../MQL5.mqh" // @removeme #include "../Mail.mqh" #include "../Market.mqh" -#include "../Math.h" -#include "../Matrix.mqh" -#include "../MiniMatrix.h" -#include "../Msg.mqh" -#include "../Object.mqh" -#include "../Order.mqh" -#include "../Orders.mqh" +#include "../Math/Math.h" +#include "../Math/Matrix.h" +#include "../Math/MatrixMini.h" +#include "../Storage/Object.h" +#include "../Platform/Order.h" +#include "../Platform/Orders.h" #include "../Pattern.mqh" // #include "../Profiler.mqh" -#include "../Redis.mqh" +#include "../Storage/Redis.h" #include "../Refs.mqh" -#include "../Registry.mqh" -#include "../RegistryBinary.mqh" #include "../Report.mqh" #include "../Storage/Objects.h" -#include "../Storage/ObjectsCache.h" -// #include "../SVG.mqh" // @removeme -#include "../Session.mqh" +#include "../Storage/Cache/ObjectsCache.h" #include "../SetFile.mqh" #include "../Socket.mqh" #include "../Std.h" #include "../Storage/Singleton.h" #include "../Strategy.mqh" -#include "../String.mqh" +#include "../Storage/String.h" #include "../SummaryReport.mqh" -#include "../SymbolInfo.mqh" +#include "../Exchange/SymbolInfo/SymbolInfo.h" #include "../Task/Task.h" #include "../Task/TaskAction.h" #include "../Task/TaskCondition.h" @@ -104,7 +96,7 @@ struct IndicatorParams; #include "../Task/TaskObject.h" #include "../Task/TaskSetter.h" #include "../Task/Taskable.h" -#include "../Terminal.mqh" +#include "../Platform/Terminal.h" // #include "../Tester.mqh" // @removeme #include "../Storage/Collection.mqh" #include "../Storage/ValueStorage.h" @@ -112,7 +104,6 @@ struct IndicatorParams; #include "../Timer.mqh" #include "../Trade.mqh" #include "../Util.h" -#include "../Web.mqh" // Includes Indicator files. #include "../Indicator/Indicator.define.h" @@ -124,7 +115,7 @@ struct IndicatorParams; #include "../Indicator/IndicatorTf.h" #include "../Indicator/IndicatorTick.h" #include "../Indicator/IndicatorTickSource.h" -#include "../Indicators/indicators.h" +#include "../Indicators/includes.h" // Includes Serializer files. #include "../Serializer/Serializable.h" diff --git a/tests/ConfigTest.mq4 b/tests/ConfigTest.mq4 index 4d043b446..2dc2b2e66 100644 --- a/tests/ConfigTest.mq4 +++ b/tests/ConfigTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/ConfigTest.mq5 b/tests/ConfigTest.mq5 index 7c62bb7f4..a69dab72b 100644 --- a/tests/ConfigTest.mq5 +++ b/tests/ConfigTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -26,9 +26,9 @@ // Includes. #include "../Config.mqh" -#include "../Data.define.h" -#include "../Dict.mqh" -#include "../DictObject.mqh" +#include "../Storage/Data.define.h" +#include "../Storage/Dict/Dict.h" +#include "../Storage/Dict/DictObject.h" #include "../Serializer/SerializerConverter.h" #include "../Serializer/SerializerCsv.h" #include "../Serializer/SerializerJson.h" diff --git a/tests/ConvertTest.mq4 b/tests/ConvertTest.mq4 index 711279063..31035d881 100644 --- a/tests/ConvertTest.mq4 +++ b/tests/ConvertTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/ConvertTest.mq5 b/tests/ConvertTest.mq5 index 901abcc56..539ab23e6 100644 --- a/tests/ConvertTest.mq5 +++ b/tests/ConvertTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/DrawIndicatorTest.mq4 b/tests/DrawIndicatorTest.mq4 deleted file mode 100644 index c4fae6484..000000000 --- a/tests/DrawIndicatorTest.mq4 +++ /dev/null @@ -1,27 +0,0 @@ -//+------------------------------------------------------------------+ -//| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | -//+------------------------------------------------------------------+ - -/* - * This file is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * @file - * Test functionality of DrawIndicator class. - */ - -#include "DrawIndicatorTest.mq5" diff --git a/tests/EA.test.cpp b/tests/EA.test.cpp new file mode 100644 index 000000000..5a93ec93c --- /dev/null +++ b/tests/EA.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of EA class. + */ + +// Includes. +#include "../EA.mqh" +#include "../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/EATest.mq4 b/tests/EATest.mq4 index ff71bd166..e0f92580f 100644 --- a/tests/EATest.mq4 +++ b/tests/EATest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/EATest.mq5 b/tests/EATest.mq5 index e8c9dcbce..23b0b731f 100644 --- a/tests/EATest.mq5 +++ b/tests/EATest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,8 +28,8 @@ struct DataParamEntry; // Includes. -#include "../Account/Account.struct.h" #include "../EA.mqh" +#include "../Exchange/Account/Account.struct.h" #include "../Test.mqh" // Defines EA classes. diff --git a/tests/IndicatorsTest.mq4 b/tests/IndicatorsTest.mq4 index e6abdbc06..1c1032b97 100644 --- a/tests/IndicatorsTest.mq4 +++ b/tests/IndicatorsTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/IndicatorsTest.mq5 b/tests/IndicatorsTest.mq5 index b5c32f4df..d7587de9a 100644 --- a/tests/IndicatorsTest.mq5 +++ b/tests/IndicatorsTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -34,15 +34,15 @@ struct DataParamEntry; // Includes. //#include "../ChartMt.h" -#include "../Dict.mqh" -#include "../DictObject.mqh" +#include "../Storage/Dict/Dict.h" +#include "../Storage/Dict/DictObject.h" #include "../Indicator/Indicator.h" #include "../Indicator/tests/classes/IndicatorTfDummy.h" #include "../Indicator/tests/classes/Indicators.h" -#include "../Indicators/Bitwise/indicators.h" -#include "../Indicators/Tick/Indi_TickMt.mqh" -#include "../Indicators/indicators.h" -#include "../Platform.h" +#include "../Indicators/Bitwise/includes.h" +#include "../Indicators/Tick/includes.h" +#include "../Indicators/includes.h" +#include "../Platform/Platform.h" #include "../Serializer/SerializerConverter.h" #include "../Serializer/SerializerJson.h" #include "../Std.h" @@ -126,7 +126,7 @@ void OnTick() { // if (_indi.GetType() != INDI_AMA) // continue; - if (_indi PTR_DEREF Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) { + if (_indi PTR_DEREF Get(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_IS_READY))) { if (_entry.IsValid()) { PrintFormat("%s: bar %d: %s", _indi PTR_DEREF GetFullName(), _candles PTR_DEREF GetBars(), _indi PTR_DEREF ToString()); @@ -152,7 +152,7 @@ void OnDeinit(const int reason) { } PrintFormat("%s: Indicators not tested: %d", __FUNCTION__, num_not_tested); - assertTrueOrExit(num_not_tested == 0, "Not all indicators has been tested!"); + assertTrueOrExit(num_not_tested == 0, "Not all includes.has been tested!"); } /** @@ -162,7 +162,7 @@ bool InitIndicators() { /* Price/OHLC indicators */ // Price indicator. - Ref indi_price = new Indi_Price(PriceIndiParams()); + Ref indi_price = new Indi_Price(IndiPriceParams()); // indis.Add(indi_price); // @fixme: Make it work with the test? /* Standard indicators */ @@ -289,7 +289,7 @@ bool InitIndicators() { IndiBandsParams indi_bands_over_rsi_params(20, 2, 0, PRICE_OPEN); Ref indi_bands_over_rsi = new Indi_Bands(indi_bands_over_rsi_params); // Using RSI's mode 0 as applied price. - indi_bands_over_rsi REF_DEREF SetDataSourceAppliedPrice(INDI_VS_TYPE_INDEX_0); + indi_bands_over_rsi REF_DEREF SetDataSourceAppliedPrice(INDI_DATA_VS_TYPE_INDEX_0); indi_bands_over_rsi REF_DEREF SetDataSource(indi_rsi.Ptr()); indis.Add(indi_bands_over_rsi); @@ -313,9 +313,9 @@ bool InitIndicators() { indis.Add(new Indi_SAR(sar_params)); // Standard Deviation (StdDev). - Ref indi_price_for_stdev = new Indi_Price(PriceIndiParams()); + Ref indi_price_for_stdev = new Indi_Price(IndiPriceParams()); IndiStdDevParams stddev_on_price_params(); - // stddev_on_price_params.SetDraw(clrBlue, 1); // @fixme + // stddev_on_price_params.SetPlot(clrBlue, 1); // @fixme Ref indi_stddev_on_price = new Indi_StdDev(stddev_on_price_params, IDATA_BUILTIN, indi_price_for_stdev.Ptr()); indis.Add(indi_stddev_on_price.Ptr()); @@ -338,10 +338,10 @@ bool InitIndicators() { indis.Add(new Indi_Demo()); // Bollinger Bands over Price indicator. - PriceIndiParams price_params_4_bands(); + IndiPriceParams price_params_4_bands(); Ref indi_price_4_bands = new Indi_Price(price_params_4_bands); IndiBandsParams bands_on_price_params(); - // bands_on_price_params.SetDraw(clrCadetBlue); // @fixme + // bands_on_price_params.SetPlot(clrCadetBlue); // @fixme Ref indi_bands_on_price = new Indi_Bands(bands_on_price_params, IDATA_BUILTIN, indi_price_4_bands.Ptr()); indis.Add(indi_bands_on_price.Ptr()); @@ -352,52 +352,52 @@ bool InitIndicators() { Ref indi_ma_sma_for_stddev = new Indi_MA(ma_sma_params_for_stddev); IndiStdDevParams stddev_params_on_ma_sma(13, 10); - // stddev_params_on_ma_sma.SetDraw(true, 1); // @fixme + // stddev_params_on_ma_sma.SetPlot(true, 1); // @fixme Ref indi_stddev_on_ma_sma = new Indi_StdDev(stddev_params_on_ma_sma, IDATA_BUILTIN, indi_ma_sma_for_stddev.Ptr()); indis.Add(indi_stddev_on_ma_sma.Ptr()); // Standard Deviation (StdDev) in SMA mode over Price. - PriceIndiParams price_params_for_stddev_sma(); + IndiPriceParams price_params_for_stddev_sma(); Ref indi_price_for_stddev_sma = new Indi_Price(price_params_for_stddev_sma); IndiStdDevParams stddev_sma_on_price_params(); - // stddev_sma_on_price_params.SetDraw(true, 1); // @fixme + // stddev_sma_on_price_params.SetPlot(true, 1); // @fixme Ref indi_stddev_on_sma = new Indi_StdDev(stddev_sma_on_price_params, IDATA_BUILTIN, indi_price_for_stddev_sma.Ptr()); indis.Add(indi_stddev_on_sma.Ptr()); // Moving Average (MA) over Price indicator. - PriceIndiParams price_params_4_ma(); + IndiPriceParams price_params_4_ma(); Ref indi_price_4_ma = new Indi_Price(price_params_4_ma); IndiMAParams ma_on_price_params(13, 0, MODE_SMA, PRICE_OPEN, 0); - // ma_on_price_params.SetDraw(clrYellowGreen); // @fixme + // ma_on_price_params.SetPlot(clrYellowGreen); // @fixme ma_on_price_params.SetIndicatorType(INDI_MA_ON_PRICE); Ref indi_ma_on_price = new Indi_MA(ma_on_price_params, IDATA_BUILTIN, indi_price_4_ma.Ptr()); indis.Add(indi_ma_on_price.Ptr()); // Commodity Channel Index (CCI) over Price indicator. - PriceIndiParams price_params_4_cci(); + IndiPriceParams price_params_4_cci(); Ref indi_price_4_cci = new Indi_Price(price_params_4_cci); IndiCCIParams cci_on_price_params(); - // cci_on_price_params.SetDraw(clrYellowGreen, 1); // @fixme + // cci_on_price_params.SetPlot(clrYellowGreen, 1); // @fixme Ref indi_cci_on_price = new Indi_CCI(cci_on_price_params, IDATA_BUILTIN, indi_price_4_cci.Ptr()); indis.Add(indi_cci_on_price.Ptr()); // Envelopes over Price indicator. - PriceIndiParams price_params_4_envelopes(); + IndiPriceParams price_params_4_envelopes(); Ref indi_price_4_envelopes = new Indi_Price(price_params_4_envelopes); IndiEnvelopesParams env_on_price_params(); - // env_on_price_params.SetDraw(clrBrown); // @fixme + // env_on_price_params.SetPlot(clrBrown); // @fixme Ref indi_envelopes_on_price = new Indi_Envelopes(env_on_price_params, IDATA_BUILTIN, indi_price_4_envelopes.Ptr()); indis.Add(indi_envelopes_on_price.Ptr()); // DEMA over Price indicator. - PriceIndiParams price_params_4_dema(); + IndiPriceParams price_params_4_dema(); Ref indi_price_4_dema = new Indi_Price(price_params_4_dema); IndiDEMAParams dema_on_price_params(13, 2, PRICE_OPEN); - // dema_on_price_params.SetDraw(clrRed); // @fixme + // dema_on_price_params.SetPlot(clrRed); // @fixme Ref indi_dema_on_price = new Indi_DEMA(dema_on_price_params, INDI_DEMA_DEFAULT_IDSTYPE, indi_price_4_dema.Ptr()); // indis.Add(indi_dema_on_price.Ptr()); // @fixme @@ -405,28 +405,28 @@ bool InitIndicators() { // Momentum over Price indicator. Ref indi_price_4_momentum = new Indi_Price(); IndiMomentumParams mom_on_price_params(); - // mom_on_price_params.SetDraw(clrDarkCyan); // @fixme + // mom_on_price_params.SetPlot(clrDarkCyan); // @fixme Ref indi_momentum_on_price = new Indi_Momentum(mom_on_price_params, IDATA_BUILTIN, indi_price_4_momentum.Ptr()); indis.Add(indi_momentum_on_price.Ptr()); // Relative Strength Index (RSI) over Price indicator. - PriceIndiParams price_params_4_rsi(); + IndiPriceParams price_params_4_rsi(); Ref indi_price_4_rsi = new Indi_Price(price_params_4_rsi); IndiRSIParams rsi_on_price_params(); - // rsi_on_price_params.SetDraw(clrBisque, 1); // @fixme + // rsi_on_price_params.SetPlot(clrBisque, 1); // @fixme Ref indi_rsi_on_price = new Indi_RSI(rsi_on_price_params, IDATA_BUILTIN, indi_price_4_rsi.Ptr()); indis.Add(indi_rsi_on_price.Ptr()); // Drawer (socket-based) indicator over RSI over Price. IndiDrawerParams drawer_params(14, PRICE_OPEN); - // drawer_params.SetDraw(clrBisque, 0); // @fixme + // drawer_params.SetPlot(clrBisque, 0); // @fixme Ref indi_drawer_on_rsi = new Indi_Drawer(drawer_params, IDATA_BUILTIN, indi_rsi_on_price.Ptr()); indis.Add(indi_drawer_on_rsi.Ptr()); // Applied Price over OHCL indicator. IndiAppliedPriceParams applied_price_params(); - // applied_price_params.SetDraw(clrAquamarine, 0); // @fixme + // applied_price_params.SetPlot(clrAquamarine, 0); // @fixme IndiOHLCParams applied_price_ohlc_params(PRICE_TYPICAL); Ref indi_applied_price_on_price = new Indi_AppliedPrice(applied_price_params, IDATA_INDICATOR, new Indi_OHLC(applied_price_ohlc_params)); @@ -457,18 +457,6 @@ bool InitIndicators() { IndiCHVParams chv_params(); indis.Add(new Indi_CHV(chv_params)); - // Color Bars. - IndiColorBarsParams color_bars_params(); - indis.Add(new Indi_ColorBars(color_bars_params)); - - // Color Candles Daily. - IndiColorCandlesDailyParams color_candles_daily_params(); - indis.Add(new Indi_ColorCandlesDaily(color_candles_daily_params)); - - // Color Line. - IndiColorLineParams color_line_params(); - indis.Add(new Indi_ColorLine(color_line_params)); - // Detrended Price Oscillator. IndiDetrendedPriceParams detrended_params(); indis.Add(new Indi_DetrendedPrice(detrended_params)); @@ -529,20 +517,16 @@ bool InitIndicators() { IndiZigZagColorParams zigzag_color_params(); indis.Add(new Indi_ZigZagColor(zigzag_color_params)); - // Custom Moving Average. - IndiCustomMovingAverageParams cma_params(); - indis.Add(new Indi_CustomMovingAverage(cma_params)); - // Math (specialized indicator). IndiMathParams math_params(MATH_OP_SUB, BAND_UPPER, BAND_LOWER, 0, 0); - // math_params.SetDraw(clrBlue); // @fixme + // math_params.SetPlot(clrBlue); // @fixme math_params.SetName("Bands(UP - LO)"); Ref indi_math_1 = new Indi_Math(math_params, IDATA_INDICATOR, indi_bands.Ptr()); indis.Add(indi_math_1.Ptr()); // Math (specialized indicator) via custom math method. IndiMathParams math_custom_params(MathCustomOp, BAND_UPPER, BAND_LOWER, 0, 0); - // math_custom_params.SetDraw(clrBeige); // @fixme + // math_custom_params.SetPlot(clrBeige); // @fixme math_custom_params.SetName("Bands(Custom math fn)"); Ref indi_math_2 = new Indi_Math(math_custom_params, IDATA_INDICATOR, indi_bands.Ptr()); indis.Add(indi_math_2.Ptr()); @@ -563,7 +547,7 @@ bool InitIndicators() { CandleParams candle_params(); indis.Add(new Indi_Candle(candle_params)); - // Push white-listed indicators here. + // Push white-listed includes.here. // whitelisted_indis.Add(_indi_test); return GetLastError() == ERR_NO_ERROR; @@ -595,7 +579,7 @@ bool PrintIndicators(string _prefix = "") { ResetLastError(); continue; } - if (_indi.Get(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) { + if (_indi.Get(STRUCT_ENUM(IndicatorDataState, INDICATOR_DATA_STATE_PROP_IS_READY))) { PrintFormat("%s: %s: %s", _prefix, _indi.GetName(), _indi.ToString()); } } diff --git a/tests/Log.test.cpp b/tests/Log.test.cpp new file mode 100644 index 000000000..23112c803 --- /dev/null +++ b/tests/Log.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Log class. + */ + +// Includes. +#include "../Log.mqh" +#include "../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/LogTest.mq4 b/tests/LogTest.mq4 index 47bbd4e80..49855237b 100644 --- a/tests/LogTest.mq4 +++ b/tests/LogTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/LogTest.mq5 b/tests/LogTest.mq5 index 0b7d3cb1e..41e0e7d53 100644 --- a/tests/LogTest.mq5 +++ b/tests/LogTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes. -#include "../DictStruct.mqh" +#include "../Storage/Dict/DictStruct.h" #include "../Log.mqh" #include "../Refs.struct.h" #include "../Test.mqh" diff --git a/tests/MD5Test.mq4 b/tests/MD5Test.mq4 index 3311317e7..85c2a91d2 100644 --- a/tests/MD5Test.mq4 +++ b/tests/MD5Test.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/MD5Test.mq5 b/tests/MD5Test.mq5 index 8f9183a7f..03b355730 100644 --- a/tests/MD5Test.mq5 +++ b/tests/MD5Test.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/MailTest.mq4 b/tests/MailTest.mq4 index 16e4fc12f..5d3d758aa 100644 --- a/tests/MailTest.mq4 +++ b/tests/MailTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/MailTest.mq5 b/tests/MailTest.mq5 index 261273304..c0c10881d 100644 --- a/tests/MailTest.mq5 +++ b/tests/MailTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 000000000..e792364f0 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,12 @@ +CC := g++ # C++ compiler +CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags +SRCS := $(wildcard *.cpp) # Get all .cpp files in the current directory +OBJS := $(SRCS:.cpp=.o) # Object files corresponding to the source files + +all: $(OBJS) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -v $(OBJS) diff --git a/tests/MarketTest.mq4 b/tests/MarketTest.mq4 index 628815528..92112c7c7 100644 --- a/tests/MarketTest.mq4 +++ b/tests/MarketTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/MarketTest.mq5 b/tests/MarketTest.mq5 index f3a71ed8a..18f92b43e 100644 --- a/tests/MarketTest.mq5 +++ b/tests/MarketTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,7 +25,7 @@ */ // Includes. -#include "../Chart.define.h" +#include "../Platform/Chart/Chart.define.h" #include "../Market.mqh" #include "../Test.mqh" diff --git a/tests/ProfilerTest.mq4 b/tests/ProfilerTest.mq4 index 8c5b765d1..31c7be413 100644 --- a/tests/ProfilerTest.mq4 +++ b/tests/ProfilerTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/ProfilerTest.mq5 b/tests/ProfilerTest.mq5 index f2f585114..157ff4ed4 100644 --- a/tests/ProfilerTest.mq5 +++ b/tests/ProfilerTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/Refs.test.cpp b/tests/Refs.test.cpp new file mode 100644 index 000000000..2f78a63b1 --- /dev/null +++ b/tests/Refs.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Refs class. + */ + +// Includes. +#include "../Refs.mqh" +#include "../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/RefsTest.mq4 b/tests/RefsTest.mq4 index 69abbbf5f..31fabbf83 100644 --- a/tests/RefsTest.mq4 +++ b/tests/RefsTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/RefsTest.mq5 b/tests/RefsTest.mq5 index 0cbb8cc72..2f48e0ba6 100644 --- a/tests/RefsTest.mq5 +++ b/tests/RefsTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -25,8 +25,8 @@ */ // Includes. -#include "../DictObject.mqh" -#include "../DictStruct.mqh" +#include "../Storage/Dict/DictObject.h" +#include "../Storage/Dict/DictStruct.h" #include "../Refs.mqh" #include "../Test.mqh" diff --git a/tests/Strategy.test.cpp b/tests/Strategy.test.cpp new file mode 100644 index 000000000..30f554008 --- /dev/null +++ b/tests/Strategy.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Strategy class. + */ + +// Includes. +#include "../Strategy.mqh" +#include "../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/StrategyTest-RSI.mq4 b/tests/StrategyTest-RSI.mq4 index eb6f64ea1..2517e2405 100644 --- a/tests/StrategyTest-RSI.mq4 +++ b/tests/StrategyTest-RSI.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/StrategyTest-RSI.mq5 b/tests/StrategyTest-RSI.mq5 index 532c63442..0ce6b299b 100644 --- a/tests/StrategyTest-RSI.mq5 +++ b/tests/StrategyTest-RSI.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -28,10 +28,10 @@ //#define __debug_verbose__ // Includes. -#include "../ChartMt.h" #include "../Indicator/tests/classes/IndicatorTfDummy.h" -#include "../Indicators/Indi_RSI.mqh" -#include "../Indicators/Tick/Indi_TickMt.mqh" +#include "../Indicators/Oscillator/Indi_RSI.h" +#include "../Indicators/Tick/Indi_TickMt.h" +#include "../Platform/Chart/ChartMt.h" #include "../Strategy.mqh" #include "../Test.mqh" @@ -95,7 +95,7 @@ int OnInit() { // Initialize strategy instance. stg_rsi = Stg_RSI::Init(_candles = Platform::FetchDefaultCandleIndicator(_Symbol, PERIOD_M5)); stg_rsi REF_DEREF SetName("Stg_RSI"); - stg_rsi REF_DEREF Set(STRAT_PARAM_ID, 1234); + stg_rsi REF_DEREF Set(STRAT_PARAM_ID, 1234); // Initialize trade instance. TradeParams _tparams; @@ -113,7 +113,7 @@ int OnInit() { Print(stg_rsi REF_DEREF ToString()); // Check for errors. - long _last_error = GetLastError(); + int64 _last_error = GetLastError(); if (_last_error > 0) { assertTrueOrFail(_last_error == ERR_NO_ERROR, StringFormat("Error occured! Code: %d", _last_error)); } @@ -129,23 +129,23 @@ void OnTick() { if (Platform::IsNewMinute()) { if (stg_rsi REF_DEREF SignalOpen(ORDER_TYPE_BUY)) { MqlTradeRequest _request = trade REF_DEREF GetTradeOpenRequest( - ORDER_TYPE_BUY, 0, stg_rsi REF_DEREF Get(STRAT_PARAM_ID), stg_rsi REF_DEREF GetName()); + ORDER_TYPE_BUY, 0, stg_rsi REF_DEREF Get(STRAT_PARAM_ID), stg_rsi REF_DEREF GetName()); trade REF_DEREF RequestSend(_request); } else if (stg_rsi REF_DEREF SignalOpen(ORDER_TYPE_SELL)) { MqlTradeRequest _request = trade REF_DEREF GetTradeOpenRequest( - ORDER_TYPE_SELL, 0, stg_rsi REF_DEREF Get(STRAT_PARAM_ID), stg_rsi REF_DEREF GetName()); + ORDER_TYPE_SELL, 0, stg_rsi REF_DEREF Get(STRAT_PARAM_ID), stg_rsi REF_DEREF GetName()); trade REF_DEREF RequestSend(_request); } if (trade REF_DEREF Get(TRADE_STATE_ORDERS_ACTIVE)) { if (stg_rsi REF_DEREF SignalClose(ORDER_TYPE_BUY)) { // Close signal for buy order. - trade REF_DEREF OrdersCloseViaProp2( - ORDER_MAGIC, stg_rsi REF_DEREF Get(STRAT_PARAM_ID), ORDER_TYPE, ORDER_TYPE_BUY, MATH_COND_EQ, + trade REF_DEREF OrdersCloseViaProp2( + ORDER_MAGIC, stg_rsi REF_DEREF Get(STRAT_PARAM_ID), ORDER_TYPE, ORDER_TYPE_BUY, MATH_COND_EQ, ORDER_REASON_CLOSED_BY_SIGNAL, stg_rsi REF_DEREF GetOrderCloseComment()); } if (stg_rsi REF_DEREF SignalClose(ORDER_TYPE_SELL)) { - trade REF_DEREF OrdersCloseViaProp2( - ORDER_MAGIC, stg_rsi REF_DEREF Get(STRAT_PARAM_ID), ORDER_TYPE, ORDER_TYPE_SELL, MATH_COND_EQ, + trade REF_DEREF OrdersCloseViaProp2( + ORDER_MAGIC, stg_rsi REF_DEREF Get(STRAT_PARAM_ID), ORDER_TYPE, ORDER_TYPE_SELL, MATH_COND_EQ, ORDER_REASON_CLOSED_BY_SIGNAL, stg_rsi REF_DEREF GetOrderCloseComment()); } } @@ -155,7 +155,7 @@ void OnTick() { // Print strategy values every hour. Print(stg_rsi REF_DEREF ToString()); } - long _last_error = GetLastError(); + int64 _last_error = GetLastError(); if (_last_error > 0) { assertTrueOrExit(_last_error == ERR_NO_ERROR, StringFormat("Error occured! Code: %d", _last_error)); } diff --git a/tests/StrategyTest.mq4 b/tests/StrategyTest.mq4 index 10ffc14dc..981f90c9e 100644 --- a/tests/StrategyTest.mq4 +++ b/tests/StrategyTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/StrategyTest.mq5 b/tests/StrategyTest.mq5 index 06de56370..6ebf91b9e 100644 --- a/tests/StrategyTest.mq5 +++ b/tests/StrategyTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/SummaryReportTest.mq4 b/tests/SummaryReportTest.mq4 index 89b28b84a..1ce2f799d 100644 --- a/tests/SummaryReportTest.mq4 +++ b/tests/SummaryReportTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/SummaryReportTest.mq5 b/tests/SummaryReportTest.mq5 index 3cd9e607b..ba5b7439f 100644 --- a/tests/SummaryReportTest.mq5 +++ b/tests/SummaryReportTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/TickerTest.mq5 b/tests/TickerTest.mq5 new file mode 100644 index 000000000..b0dd567d5 --- /dev/null +++ b/tests/TickerTest.mq5 @@ -0,0 +1,142 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test functionality of Ticker class. + */ + +// Includes. +#include "../Indicators/Tick/Indi_TickMt.h" +#include "../Test.mqh" +#include "../Ticker.mqh" + +// Global variables. +Ref indi_tick; +uint64 total_ticks; +Ticker *ticker_csv; +Ticker *ticker01; +Ticker *ticker02; +Ticker *ticker03; +Ticker *ticker04; +Ticker *ticker05; +Ticker *ticker06; +Ticker *ticker07; +Ticker *ticker08; + +/** + * Implements initialization function. + */ +int OnInit() { + /* + // Initialize instances. + // SymbolInfo symbol = new SymbolInfo(); + indi_tick = new Indi_TickMt(_Symbol); + + // Print market details. + Print("SYMBOL: ", symbol.ToString()); + Print("CHART: ", chart.ToString()); + + // Initialize Ticker instances. + ticker_csv = new Ticker(symbol); + ticker01 = new Ticker(symbol); + ticker02 = new Ticker(symbol); + ticker03 = new Ticker(symbol); + ticker04 = new Ticker(symbol); + ticker05 = new Ticker(symbol); + ticker06 = new Ticker(symbol); + ticker07 = new Ticker(symbol); + ticker08 = new Ticker(symbol); + + // Test adding ticks using local scope class. + Ticker *ticker_test = new Ticker(); + assertTrueOrFail(ticker_test.GetTotalAdded() == 0, "Incorrect number of ticks added"); + assertTrueOrFail(ticker_test.GetTotalIgnored() == 0, "Incorrect number of ticks ignored"); + assertTrueOrFail(ticker_test.GetTotalProcessed() == 0, "Incorrect number of ticks processed"); + assertTrueOrFail(ticker_test.GetTotalSaved() == 0, "Incorrect number of ticks saved"); + ticker_test.Add(); + assertTrueOrFail(ticker_test.GetTotalAdded() == 1, "Incorrect number of ticks added"); + ticker_test.Add(); + assertTrueOrFail(ticker_test.GetTotalAdded() == 2, "Incorrect number of ticks added"); + ticker_test.Reset(); + assertTrueOrFail(ticker_test.GetTotalAdded() == 0, "Incorrect number of ticks after reset"); + ticker_test.Add(); + assertTrueOrFail(ticker_test.GetTotalAdded() == 1, "Incorrect number of ticks added"); + delete ticker_test; + */ + return (INIT_SUCCEEDED); +} + +/** + * Implements OnTick(). + */ +void OnTick() { + /* + total_ticks++; + + // Process the ticks using different methods. + ticker01.Process(chart, 1); + ticker02.Process(chart, 2); + ticker03.Process(chart, 3); + ticker04.Process(chart, 4); + ticker05.Process(chart, 5); + ticker06.Process(chart, 6); + ticker07.Process(chart, 7); + ticker08.Process(chart, 8); + ticker_csv.Add(); + */ +} + +/** + * Implements deinitialization function. + */ +void OnDeinit(const int reason) { + /* + // Save ticks into CSV. + ticker_csv.SaveToCSV(StringFormat("ticks_%s.csv", _Symbol)); + // @fixme + // assertTrueOrExit(ticker_csv.GetTotalSaved() == ticker_csv.GetTotalAdded(), "Incorrect number of ticks added"); + + // Print final details. + Print("TICKER01: ", ticker01.ToString()); + Print("TICKER02: ", ticker02.ToString()); + Print("TICKER03: ", ticker03.ToString()); + Print("TICKER04: ", ticker04.ToString()); + Print("TICKER05: ", ticker05.ToString()); + Print("TICKER06: ", ticker06.ToString()); + Print("TICKER07: ", ticker07.ToString()); + Print("TICKER08: ", ticker08.ToString()); + Print("TICKER CSV: ", ticker_csv.ToString()); + + // Deinitialize objects. + delete chart; + delete symbol; + delete ticker_csv; + delete ticker01; + delete ticker02; + delete ticker03; + delete ticker04; + delete ticker05; + delete ticker06; + delete ticker07; + delete ticker08; + */ +} diff --git a/tests/TimerTest.mq4 b/tests/TimerTest.mq4 index 485587ffb..c19c173d7 100644 --- a/tests/TimerTest.mq4 +++ b/tests/TimerTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/TimerTest.mq5 b/tests/TimerTest.mq5 index d3f7a66d2..e6c55898a 100644 --- a/tests/TimerTest.mq5 +++ b/tests/TimerTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/Trade.test.cpp b/tests/Trade.test.cpp new file mode 100644 index 000000000..60970ff19 --- /dev/null +++ b/tests/Trade.test.cpp @@ -0,0 +1,35 @@ +//+------------------------------------------------------------------+ +//| EA31337 framework | +//| Copyright 2016-2023, EA31337 Ltd | +//| https://ea31337.github.io | +//+------------------------------------------------------------------+ + +/* + * This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * @file + * Test C++ compilation of Trade class. + */ + +// Includes. +#include "../Trade.mqh" +#include "../Platform/Platform.h" + +int main(int argc, char **argv) { + // @todo + + return 0; +} diff --git a/tests/TradeTest.mq4 b/tests/TradeTest.mq4 index 2c338fcbf..71265cb35 100644 --- a/tests/TradeTest.mq4 +++ b/tests/TradeTest.mq4 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* diff --git a/tests/TradeTest.mq5 b/tests/TradeTest.mq5 index 09f476f95..eb6c0aed8 100644 --- a/tests/TradeTest.mq5 +++ b/tests/TradeTest.mq5 @@ -1,7 +1,7 @@ //+------------------------------------------------------------------+ //| EA31337 framework | -//| Copyright 2016-2023, EA31337 Ltd | -//| https://github.com/EA31337 | +//| Copyright 2016-2024, EA31337 Ltd | +//| https://ea31337.github.io | //+------------------------------------------------------------------+ /* @@ -31,9 +31,9 @@ struct DataParamEntry; // Includes. -#include "../ChartMt.h" -#include "../Indicators/Tick/Indi_TickMt.mqh" -#include "../Platform.h" +#include "../Platform/Chart/ChartMt.h" +#include "../Indicators/Tick/Indi_TickMt.h" +#include "../Platform/Platform.h" #include "../Test.mqh" #include "../Trade.mqh"