1 (edited by begoodall 2025-01-16 18:46:15)

Topic: Powershell Automation --input not working

Hi All

I've recently got into EG and I'm trying to automate as much as possible. I started with DOS cmd, but I am now moving all my programs onto Powershell, so I can then move to Linux, so I can then get a Cloud VPS to run things 24/7. The Powershell on Linux part is to avoid expensive Windows cloud licences, but still remain compatible with my local machine.

Attached is a validate and generate powershell script. It runs, but it can't find any existing collection to load - and I know they exist. It ouputs the collection at the end of the run perfectly well. It can't then read it back in.

Any ideas? Maybe I've gone bug-blind and can't see something obvious in my code :-/

Many thanks.

[I can't seem to attach the ps1 file, but hopefully the code is readable / will run if someone were to put it in a ps1 file]

# Define the parameters for each run
$runs = @(
    @{ Symbol = "AUDJPY"; Period = "M15"; DataStart = "2014-01-01"; DataEnd = "2023-04-01"; RunTimeMinutes = "1" },
    @{ Symbol = "AUDJPY"; Period = "M15"; DataStart = "2014-10-01"; DataEnd = "2023-10-01"; RunTimeMinutes = "1" }
)

# Run each process in parallel
$runs | ForEach-Object -Parallel {
    # Define the function for Node.js process execution
    function Run-NodeProcess {
        param (
            [string]$Symbol,
            [string]$Period,
            [string]$DataStart,
            [string]$DataEnd,
            [string]$RunTimeMinutes,
            [string]$BaseDirectory = "D:/EG",
            [string]$SettingsFilePath = "$BaseDirectory/genmaster.ini",
            [string]$ScriptFilePath = "$BaseDirectory/bin/gen.js"
        )

        # Generate input and output filenames using string interpolation
        $inputFileName = "$BaseDirectory/collections/$Period/Coll-IS-$Symbol-$Period-$DataStart"
        $outputFileName = "$BaseDirectory/collections/$Period/Coll-IS-$Symbol-$Period-$DataStart"

        # Ensure the output directory exists
        $outputDir = Split-Path -Path $outputFileName -Parent
        if (-not (Test-Path -Path $outputDir)) {
            New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
        }

        # Debugging: Log paths
        Write-Output "Input File:  $inputFileName"
        Write-Output "Output File: $outputFileName"

        # Start the Node.js process with the provided variables
        Start-Process -FilePath "node" -ArgumentList @(
            "`"$ScriptFilePath`"",
            "--settings", "`"$SettingsFilePath`"",
            "--symbol", $Symbol,
            "--period", $Period,
            "--use_data_start", "true",
            "--data_start", $DataStart,
            "--use_data_end", "true",
            "--data_end", $DataEnd,
            "--max_working_minutes", $RunTimeMinutes,
            "--validate_then_generate", "true",
            "--opposite_entry_signal", "IgnoreOrReverse",
            "--stop_loss_usage", "AlwaysUse",
            "--stop_loss_type", "Fixed",
            "--stop_loss_range_min", "20",
            "--stop_loss_range_max", "200",
            "--take_profit_usage", "AlwaysUse",
            "--take_profit_range_min", "20",
            "--take_profit_range_max", "200",
            "--take_profit_gte_stop_loss", "true",
            "--min_count_of_trades", "100",
            "--min_profit", "10",
            "--min_profit_factor", "1.2",
            "--enable_monte_carlo", "false",
            "--input", "`"$inputFileName`"",
            "--output", "`"$outputFileName`""
        ) -WindowStyle Normal -Wait
    }

    # Call the function
    Run-NodeProcess -Symbol $_.Symbol -Period $_.Period -DataStart $_.DataStart -DataEnd $_.DataEnd -RunTimeMinutes $_.RunTimeMinutes
} -ThrottleLimit 4

Re: Powershell Automation --input not working

Try to print the `$inputFileName` and check if the file actually exists.

The quotes seem to me unbalanced here:

 "--input", "`"$inputFileName`"",

Edit: The backticks are correct!

Re: Powershell Automation --input not working

Popov wrote:

Try to print the `$inputFileName` and check if the file actually exists.

The quotes seem to me unbalanced here:

 "--input", "`"$inputFileName`"",

Thanks for the quick response.

I did question the strange imbalanced looking quotes, but apprently it is correct and has to do with handling of the variables/strings and so on within PS. And the --output was working with the same imbalanced looking quotes anyway.

But, your suggestion for checking file existence got me to the answer: Because I'm using absolute paths when calling generate.js, I need to also specify the file extension .json on the end. Not needed on the output side as I guess your js handles this. For completness I have added it on the output side anyway.

Thanks