Transfer signals from Lower TF to Daily (or any higher TF)

Hello dear sirs,
I'll try to apply in AFL an idea for the intraday trending. The idea is that it takes some Long or Short positions and closes in a Target, while there is a stop level too. Other times it is successful (profit) and others not (losses). So I thought I'd pass these signals on a daily chart to look at, what could be causes the losses to be avoided. So I did (for example) the following effort, but I did not.
Is there a possibility for some help? Thanks for any help.

Buy=Cross(MACD(),0);  	
Sell=Cross( 0, MACD()); 	
BuyPrice = ValueWhen(buy , Close);
SellPrice =  ValueWhen(sell , Close);

loss= SellPrice< BuyPrice ; 
bir = Status( "barinrange" );
dn = DateNum();
bi = BarIndex(); 
dt = DateTime();

Plot( ml = MACD(),"MACD", colorRed,1 );
PlotGrid(0, colorBlue);
PlotShapes(IIf(Sell, shapeHollowCircle,shapeNone),IIf(loss,colorRed,colorGreen),0,ml,0); 
PlotShapes(IIf(Buy, shapeSmallCircle,shapeNone),5,0,ml,0); 
 

//my first step is In Intraday - lower time frame to run an exploration and store a custom array in statickvar with dateNum()
if( Status( "Action" ) == actionExplore )
{
    Filter = Sell;
    SetOption( "NoDefaultColumns", True );
    AddColumn( DateTime(), "Date", formatDateTime );
    AddColumn( sell, "SellSignal", 1 );
    AddColumn( IIf( Sell, loss, Null ) , "loss", 1, colorDefault, IIf( loss, colorRed, colorDefault ) );

    for( i = 0; i < BarCount; i++ )
    {
        if( bir[i] )
        {
			// store a custom array in staticvar with dateNum()
           IIf( Sell[i]  ,  StaticVarSet( "SYS_dateSell_" + i, dn[i] ,1)  , Null );
        }
    }
}


// my second step is to see if debbuger is right? and looks ok 
// Then i try to PlotShapes on the chart on dayly (or higher Time Frame)
// but no luck....what i am doing wrong here? 

if(ParamTrigger(" for debuger", "press to run Once") ) 
{
    for( i = 0; i < BarCount; i++ )
    {
		if(Sell[i] and loss[i] )   // if we have a loss potition  
		{
		//SV= StaticVarget( "SYS_dateSell_" + i);
		specificDay= DateTimeConvert(2, StaticVarget( "SYS_dateSell_" + i));  
		
		x= Lookup( loss[i], specificDay  );  // <<< this line looks ok on the debbuger
		PlotShapes(IIf(x[i], shapeDigit0,shapeNone),IIf(loss,colorRed,colorGreen),0,0,-50);  // but PlotShapes NOT plot 
		
		_TRACE("#, dt"+ dn[i]+",   look up= " + x);
		_TRACE("#, dn= "+ dn[i]+",   look up= " + x +  ", specificDay "+DateTimeConvert(2, StaticVarget( "SYS_dateSell_" + i)));  
		//_TRACE("#, i= " + i  + " ,SYS_dateSell_ = "+ StaticVarget( "SYS_dateSell_" + i) + ", specificDay "+DateTimeConvert(2, StaticVarget( "SYS_dateSell_" + i))  ) ;
		}
    }
}

Hello Christo

Actually I really like your question "how to retrieve the event/signals that came from lower time frame to appear in higher time frame bars".

I found a very nice conversation in this thread here

And I like @beppe “loop logic: instead of looping over the bars to see if there is a corresponding date” So you may like this type of coding to store more information in matrix.

But @chrismet as I don't know how much familiar you are with matrix, I use @fxshrat thinking for your question.

Also the code it is easier to understand as you only need the date and time of the bars of the lower time frame signals.

Thank you guys, this forum has become a good database

A full working code as a treat to Enjoy your Pancake Day :wink:

/// @link  https://forum.amibroker.com/t/transfer-signals-from-lower-tf-to-daily-or-any-higher-tf/11636
// by Panos 05-03-2019   (pancake day)

prefix = "MySysMacd";
bi = BarIndex(); 
dn = DateNum();
tn = TimeNum();
Buy=Cross(MACD(),0);  	
Sell=Cross( 0, MACD()); 	
BuyPrice = ValueWhen(buy , Close);
SellPrice =  ValueWhen(sell , Close);
loss= SellPrice< BuyPrice ; 


if( Status( "Action" ) == actionExplore )
{
	counter = 0; 
	bir = Status( "barinrange" );
	StaticVarRemove(prefix+"*");   // remove all old signals before exploration

    Filter = Sell;
    AddColumn( sell, "SellSignal", 1 );
    AddColumn( IIf( Sell, loss, Null ) , "loss", 1, colorDefault, IIf( loss, colorRed, colorDefault ) );

    for( i = 0; i < BarCount; i++ )
    {
        if( bir[i] )
        {
           If( Sell[i]) {   // if sell store the date and time of the evend in staticVar
            StaticVarSet( prefix+"DateSell_" + (counter++), dn[i] );
            StaticVarSet( prefix+"TimeSell_" + counter, tn[i] );
            StaticVarSet( prefix+"SVcounter", counter ); 
	    
			_TRACE("#,counter " +counter +", StatDAYtime = " + StaticVarget( prefix+"DateSell_"+ counter)  + ",    dn[i]" + dn[i]);
			}
        }
    }
}




if( Status( "Action" ) == actionIndicator )
{

DayArr = intraArr = 0;
SVcounter= Nz(staticVarGet(  prefix+"SVcounter"),0);    printf( "\nSVcounter \t " + SVcounter ); 

	for( i = 0; i <= SVcounter ; i++ )
	{
		
		if( Interval()== inDaily )		// retrieve signals for daily chart
		{ 			
		specificDay = StaticVarget( prefix+"DateSell_" + i ) ;     printf( "\nspecificDay("+i+")\t " + StaticVarget(  prefix+"DateSell_" + i )  ); 
		DAYidx = Lookup( bi, DateTimeConvert( 2, specificDay )  , -1 );
		if( NOT IsNull( DAYidx ) )	DayArr[DAYidx] = 1;
		}

		else				// retrieve signals for intraday chart
		{
		specificDay = StaticVarget( prefix+"DateSell_" + i ) ;								
		specificTime = StaticVarget(  prefix+"TimeSell_" + i );
		intraidx = Lookup( bi, DateTimeConvert( 2, specificDay, specificTime ), -2 );
		if( NOT IsNull( intraidx ) )	intraArr[intraidx] = 1;
		}
	}


if( Interval() == inDaily )
    PlotShapes( IIf( DayArr, shapeDownArrow, shapeNone ), colorRed, 0, H , -50 );
else
    PlotShapes( IIf( intraArr, shapeDownArrow, shapeNone ), colorRed, 0, H , -50 );

Plot( C, "", colorDefault, styleCandle );

_N(Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.2f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ) );
if (SVcounter<1) title = EncodeColor(4)+ "\n You must run exploration in lower time frame first to see the aroows ";

}

6 Likes

Dear @PanoS, I want to thank you very much for your time to spend for me and for your kindness to try to help me. Indeed, through this code I have the solution I just wanted.