ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to place multiple symbols on the same index in finance chart.
Posted by London on Oct-25-2024 07:11
Attachments:
I'm in php.


Sell Signal at Index 134: 1.87
Sell Signal at Index 134: 1.72

Buy Signal at Index 134: 1.35
Buy Signal at Index 134: 1.24
Buy Signal at Index 134: 1.1
Buy Signal at Index 134: 1.1
Buy Signal at Index 134: 1.1

as you can see they are all using the same index but I'm having trouble placing more than 1 symbol for each execution

I can get 1 sell symbol and 1 buy symbol and they are the last ones in the array.

        // Plot execution markers
        $buySignal = array_fill(0, count($finalTimeStamps), NoValue);
        $sellSignal = array_fill(0, count($finalTimeStamps), NoValue);


        foreach ($entryTime as $index => $entry) {
            $closestIndex = array_search($entry, $finalTimeStamps);
            \Log::info("Entry: $entry | Closest Index: $closestIndex");

            if ($closestIndex !== false) {
                $sellSignal[$closestIndex] = $entryPrices[$index]; // Add sell marker (short)
                \Log::info("Sell Signal at Index $closestIndex: " . $entryPrices[$index]);
            } else {
                \Log::info("Sell marker not found for entry: $entry");
            }
        }

        foreach ($exitTime as $index => $exit) {
            $closestIndex = array_search($exit, $finalTimeStamps);
            \Log::info("Exit: $exit | Closest Index: $closestIndex");

            if ($closestIndex !== false) {
                $buySignal[$closestIndex] = $exitPrices[$index]; // Add buy marker (cover)
                \Log::info("Buy Signal at Index $closestIndex: " . $exitPrices[$index]);
            } else {
                \Log::info("Buy marker not found for exit: $exit");
            }
        }

        // \Log::info("Final Time Stamps: " . json_encode($finalTimeStamps));

        // Log the final signals for verification
        \Log::info("Final Buy Signals: " . json_encode($buySignal));
        \Log::info("Final Sell Signals: " . json_encode($sellSignal));

        // Add scatter layers for sells and buys
        $sellLayer = $mainChart->addScatterLayer(null, $sellSignal, "sells", 6, 10, 0xffadad);
        $sellLayer->moveFront();

        $buyLayer = $mainChart->addScatterLayer(null, $buySignal, "buys", 3, 10, 0xccffcc);
        $buyLayer->moveFront();

Would I need to use something like a scatter layer data set so that when 2 executions are on the same index they both show up?

my desired outcome is the pic.
Snag_4ab545b3.png

  Re: How to place multiple symbols on the same index in finance chart.
Posted by Peter Kwan on Oct-25-2024 14:46
Hi London,

The following is an example:

https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1426148425#N1426270666

In brief, you can add a scatter layer with both x and y coordinates. However, like all other data series in FinanceChart, the first 30 points (assume extraPoints = 30) are not plotted, so the first 30 positions in the array are unused. Also, the x coordinate need to be the array index subtracted by the extraPoints.

Best Regards
Peter Kwan