Adding script to watchlist

#1
Hello All,
Could you please let me know what is wrong in the below sample code? I want to add only the scripts which satisfies condition when new bar arrives and remove the old scripts. But it adds all the scripts to the watchlist.
Code:
_SECTION_BEGIN("Export Analysis");
    prevDTLast = Nz( StaticVarGet ( "prevDTLast"+Name() ) );
    DT=DateTime();
    DTLast = DT[BarCount-1];
    if ( DTLast  != prevDTLast )   
    {
        Buy = C > MA(C,21);
        Sell = C < MA(C,21);
        Filter = Ref(Buy,-1) OR Ref(Sell,-1);

        if ( LastValue(  Filter)  ){
            CategoryAddSymbol( Name(), categoryWatchlist, 0 );
        }
        else
        {
            CategoryRemoveSymbol(  Name() , categoryWatchlist, 0 ); 
        }
        StaticVarSet( "prevDTLast"+Name(), DTLast );
    }
   
_SECTION_END();
thanks much for the help in advance
Bala
 
Last edited:
#2
Hello All,
Could you please let me know what is wrong in the below sample code? I want to add only the scripts which satisfies condition when new bar arrives and remove the old scripts. But it adds all the scripts to the watchlist.
Code:
_SECTION_BEGIN("Export Analysis");
    prevDTLast = Nz( StaticVarGet ( "prevDTLast"+Name() ) );
    DT=DateTime();
    DTLast = DT[BarCount-1];
    if ( DTLast  != prevDTLast )  
    {
        Buy = C > MA(C,21);
        Sell = C < MA(C,21);
        Filter = Ref(Buy,-1) OR Ref(Sell,-1);

        if ( LastValue(  Filter)  ){
            CategoryAddSymbol( Name(), categoryWatchlist, 0 );
        }
        else
        {
            CategoryRemoveSymbol(  Name() , categoryWatchlist, 0 );
        }
        StaticVarSet( "prevDTLast"+Name(), DTLast );
    }
  
_SECTION_END();
thanks much for the help in advance
Bala
Anyone could you please help on this? Thank you
 

Similar threads