Multi time frame filter not giving expected results


#1

I am trying to filter symbols by using information from 2 different times frames, please see the details here:

  1. 75 mins time frame: here it I am checking 50 moving average- it should ne down. (current value less than previous 6th value and current value less than the immediate previous value.
     This is not working. System is even filtering records where MA50 is up.
    I have plotted Down arrow when MA50 is moving down. Those are appearing correctly. I am running the filter on daily time frame which in turn checks the info in 75 min time frame. Only those rows where last value meets the criteria should be appearing as I am running for the last value.
  2. Daily time frame: here I am checking if the last candle is down candle (red) with candle’s body height more that 0.5 of the total length of the candle and previous candles body height is less than the total length of the candle.
_SECTION_BEGIN("EBuyMin Close");

tf15= 5*in15Minute;
TimeFrameSet( tf15 ); // switch to 15 minute time frame
dr15=MA(Close,50);
col50=IIf(dr15>Ref(dr15,-1),colorGreen,colorRed);
tr15 = MA(Close,50)-Ref(MA(Close,50),-1);
tr151= MA(Close,50)-Ref(MA(Close,50),-6);
TimeFrameRestore(); // restore time frame to original

ma20=MA(Close,50);
col20=IIf(ma20>Ref(ma20,-1),colorBlue,colorRed);
Plot(C, "price", colorblue, stylecandle, width=1);
Plot(ma20, "ma20", col20, styleline, width=1);
cc=timeframeexpand(dr15,tf15);
colcc=IIf(cc>Ref(cc,-1),colorBlue,colorRed);

Plot(cc, "15tf", colcc, styleline, width=1);

itfm506=timeframeexpand(tr151,tf15);
itfm501=timeframeexpand(tr151,tf15);

long=H-L;
body=abs(O-C);
typ=IIf(body>0.5*long,1,2);

scon=typ==1 AND C<O AND Ref(typ,-1)==2;


sell=itfm506<0 AND itfm501<0 ;//AND scon;

Plotshapes(IIf(Sell,shapedownTriangle, Null),colorLightBlue, layer=0, yposition=ma20, offset=-10,XShift=0);

Filter = Sell; 
AlertIf(Sell, "SOUND C:\\Windows\\Media\\Alarm10.wav", "Audio alert", 1);
if (SelectedValue(Sell)==1) Say("short call ");
 
AddTextColumn( Interval(2), "Set Interval", 1 );
AddColumn(MA(Close,50), "MA15"); 
AddColumn(Ref(MA(Close,50),-6), "Ref,MA15,-6"); 
AddColumn(tr15, "diffMA 15 -3"); 
AddColumn(tr151, "diffMA 15 -6"); 
SetSortColumns(-2);
_SECTION_END();

MTF%20issue