TOP GAINER N LOOSER LIST FOR INTRADAY N EXPORT LIST TO SPECIFIC WATCHLIST

type or _SECTION_BEGIN("Top 10 Gainers and Losers with Watchlist Export");

SetChartOptions(0, chartShowArrows|chartShowDates);

// Setting the time frame to 1 minute for intraday analysis
TimeFrameSet(in1Minute);

// Calculation of percentage change in the compressed time frame
percentChange = (C - Ref(C, -1)) / Ref(C, -1) * 100;

// Restoring the original time frame
TimeFrameRestore();

// Expanding the percentChange array to the original time frame
percentChangeExpanded = TimeFrameExpand(percentChange, in1Minute, expandFirst);

// Filter to run the script only at 9:20 AM in the expanded time frame
Filter = TimeNum() == 92000;

// Adding columns to the exploration output
AddColumn(C, "Current Price", 1.2);
AddColumn(Ref(C, -1), "Previous Close", 1.2);
AddColumn(percentChangeExpanded, "Percent Change", 1.2);

// Watchlist Number
listnum = 10;

// Clearing the watchlist for the first symbol
if (Status("stocknum") == 0) {
    oldlist = CategoryGetSymbols(categoryWatchlist, listnum);
    for (i = 0; (sym = StrExtract(oldlist, i)) != ""; i++) {
        CategoryRemoveSymbol(sym, categoryWatchlist, listnum);
    }
}

// Adding symbols to watchlist based on filter criteria
if (LastValue(Filter)) {
    for (i = 0; i < BarCount; i++) {
        if (TimeNum()[i] == 92000 && (percentChangeExpanded[i] > 0 || percentChangeExpanded[i] < 0)) {
            CategoryAddSymbol(Name(), categoryWatchlist, listnum);
        }
    }
}

 //Adding symbols to watchlist based on filter criteria
if (LastValue(Filter)) {
    for (i = 0; i < BarCount; i++) {
        if (TimeNum()[i] == 92000 && (percentChangeExpanded[i] > 0 || percentChangeExpanded[i] < 0)) {
            CategoryAddSymbol(Name(), categoryWatchlist, listnum);
        }
    }
}

_SECTION_END();

i dnt no why this code giving errors

can anyone help me into this

What errors are you getting?. Please follow this advice: How to ask a good question

what is the Periodicty set in the Analysis settings? because you seem to set to 1min i'm curious.
Top Gainer/loser generally is % change from previous day (Daily)

That's two times wrong coding in your boy loops.
You have to store timenum() function to variable outside of loop and then use that variable inside loop

// Outside of loop
tn = TimeNum();

//.... 

//Inside of loop
if( tn[i] == ....

Also in first line remove "type or".

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.