Problem While Scan and signal are not trigger in Real Time

Please help me.

  1. When I scan this code nothing is happening. I Check a every single line its working but its not trigger when I use this code in Real Time.
  2. Is it possible to write a more than one buy or sell signal in same afl. If not please suggest another way to do it.

Thanks in advance.

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Beta_1");
Range = Param("Range", 15, 5, 260,1);
ParamPer = Param("PDH_%", 20, 1, 100,1);
ParamPer_H = Param("Buy_%", 50, 1, 100, 1);
ParamPer_L = Param("Sell_%", 50, 1, 100, 1);
BarNum = Param( "BarNumbers", 3 ,1,100,1);


//-- today Day---
DayChange = Day() != Ref(Day(), -1);
DayChange[0] = True;
HSDayChange = HighestSince(DayChange, H); 
TDH =Ref(HighestSince(DayChange,H),-1);

LSDayChange = LowestSince(DayChange, L);
TDL = Ref(LowestSince(DayChange ,L),-1);


DH= HSDayChange >TDH ;
DL= LSDayChange < TDL ;


//Previous day high and low
HSDayChangePrev = TimeFrameGetPrice("H", inDaily, -1);
LSDayChangePrev= TimeFrameGetPrice("L", inDaily, -1);

//Bars which is Highest/Lowest than prevday and today high/low.
High_1 = C >= HSDayChangePrev AND C >= Ref(HighestSince(DayChange,H),-1);//True
Low_1 =C <= LSDayChangePrev AND C <= Ref(LowestSince(DayChange ,L),-1);//True

//--------Range--------
 Range15 = MA((H-L),Range);

//--------high----------
Hi_range = ValueWhen(High_1==1,(H-L));
Hi_range_perc = ((Hi_range/100)*ParamPer );
New_prevDay_h = (HSDayChangePrev + Hi_range_perc);
New_TodayDay_h = (TDH + Hi_range_perc);

//-------Low----------

Low_range =ValueWhen(Low_1 ==1,(H-L));
Low_range_perc = ((Low_range/100)*ParamPer );
New_prevDay_l = (LSDayChangePrev - Low_range_perc);
New_TodayDay_l = (TDL  - Low_range_perc);

//-------case_3-----

HighLow_range =ValueWhen(Low_1 ==1 OR  High_1 ==1,(H-L));

C_LH =  ValueWhen(Low_1==1 OR High_1 ==1,(C));
O_LH=  ValueWhen(Low_1==1 OR High_1 ==1,(O));
H_LH =  ValueWhen(Low_1==1 OR High_1 ==1,(H));
L_LH =  ValueWhen(Low_1==1 OR High_1 ==1,(L));

C_val_H = ValueWhen(High_1 ==1,(C));
C_val_L = ValueWhen(Low_1==1,(C));

RangePer_HL = (((H_LH - C_LH)/HighLow_range)*100);

//-------- Intraday Buy and sell ---------

per10 = Param( "Trade Entry From(HHMM)", 0915, 900, 2300, 1 );
per11 = Param( "Trade Upto(HHMM)", 1515, 900, 2300, 1 );
per12 = Param( "Trade Exit(HHMM)", 1520, 900, 2300, 100 );

intraex =TimeNum() > per12 * 100;
intraen =( TimeNum() < per11 * 100 AND TimeNum() > per10 * 100 );

High_sig_Range =((High_1 ==1 AND Hi_range > Range15));//True 1st condtion i.e Range
Low_sig_Range = ((Low_1 ==1 AND Low_range > Range15));//True

High_sig_PDHTDH = ((High_1 ==1 AND C_val_H > New_prevDay_h  AND C_val_H > New_TodayDay_h));//true
Low_sig_PDLTDL = ((Low_1 ==1 AND C_val_L < New_prevDay_l  AND C_val_L < New_TodayDay_l)) ;//true

LastBar = BarIndex() == LastValue(BarIndex());//ignore the current bar

Buy2 = High_sig_PDHTDH AND High_sig_Range AND RangePer_HL < ParamPer_H AND NOT LastBar;//true

Sell2 =Low_sig_PDLTDL AND Low_sig_Range AND RangePer_HL > ParamPer_L AND NOT LastBar;//true


Short_=0;
Cover_ =0;
Buy1 = Buy2;
Sell1 = Sell2;
Short1 = Short_;
Cover1 = Cover_;
bflag = sflag = 0;

for ( i = 1; i < BarCount; i++ )
{
    

    if ( ( Buy1 [i] AND intraen[i] AND bflag==0 ))
    {
        Buy2[i] = 1;
        bflag =1 ;
    }
    else
        Buy2[i] = 0;

	   if ( ( Cover1[i] OR intraex[i] AND bflag ))
    {
			
        Cover_[i] = 1;
        bflag = 0;
    }
    else
        Cover_[i] = 0;
	

    if ( ( Sell1 [i] AND intraen[i] AND sflag==0 ))
    {
        Sell2[i] = 1;
        sflag =1 ;

    }
    else
        Sell2[i] = 0;
	   if ( ( Short1[i] OR intraex[i] AND sflag ))
    {
			
        Short_[i] = 1;
        sflag = 0;
    }
    else
        Short_[i] = 0;

}

PlotShapes( IIf( Buy2, shapeUpArrow, shapeNone) ,colorBlue,0,L);
PlotShapes( IIf( Sell2, shapeDownArrow, shapeNone) ,colorRed,0,H);
//==========================================================

Buyval = ValueWhen(Buy2==1,H);
Sellval= ValueWhen(Sell2==1,L);

BSFBar = BarsSince(DayChange);
BSBuy2 = BarsSince(Buy2);
BSSell2 = BarsSince(Sell2);

fbv = ValueWhen(DayChange,C)==C;

BCase= H > Buyval  ;
SCase = L < Sellval;

Buy= BCase AND fbv==False AND (BSFbar >=BSBuy2);
Sell = SCase AND fbv==False AND (BSFBar >= BSSell2 );

Buy = ExRem(Buy,Buy2);
Sell = ExRem(Sell, Sell2);



PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-30);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25);

PlotShapes(IIf(Sell , shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell , shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);                      
PlotShapes(IIf(Sell , shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);


Buy_1= Buy;
Sell_1=Sell;

BuyVal_2= ValueWhen(Buy_1,L);
SellVal_2 = ValueWhen( Sell_1==1, H);


Buy = (C > SellVal_2 AND C > Ref(HighestSince(Sell_1==1,H),-1)AND NOT LastBar) OR intraex   ;
Sell = (C < BuyVal_2  AND C < Ref( LowestSince(Buy_1==1,L),-1) AND NOT LastBar) OR intraex ;


Buy = ExRem(Buy,Sell_1);
Sell = ExRem(Sell, Buy_1);

                   
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorViolet, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-30);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-25);

PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorBlue, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);                      
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);

_SECTION_END();


@Deepak I had not the time to look at your code in detail, but here are my general considerations.

  1. Instead of relying on PlotShapes, for such complex formula, I suggest creating an exploration to check ALL the variables (arrays) used in your logic.1
    If running your code never triggers any signal it simply means that at a certain point the logic conditions are very likely producing a Buy array entirely filled with False (or Null) values.

    Moreover, when you are dealing with so many condition/rules in your code (the actual cause of the problem could be something not immediately evident 2, 3) in order to properly debug your formula I recommend you to NEVER reuse the same variables in the code but to use a distinct variable for each step (buy1, buy2, buy3, signalbuy1, signalbuy2, etc.) so you can actually examine all the intermediate calculations both in the exploration and/or in the debugger (and/or using the _TRACE/TRACEF function).

  2. You can create multiple intermediate arrays with all your conditions and signals, but in the end, the relevant ones should be combined to a single Buy and a single Sell arrays (Sell can be a zero filled array in case you decide to exit using only the ApplyStop function to close any opened positions).
    Same for Short/Cover if your Analysis is set for "Long and Short".

1) If adding all the variables to your exploration is too much work, at least, start with the arrays directly used to create your Buy/Sell arrays. If any of these arrays are entirely False/Nulls then add additional lines to inspect any other array that was used to generate them, and so on.

2) Another area that needs particular care when dealing with an intraday system is to double check the "timenum" related logic. Sometimes you may be working on bars that have different timestamps of what you expect.

3) It may be that in your selected restricted time ranges the conditions you are expecting will appear so rarely that you have to examine many past days ever to see an actual signal (for instance if you are looking for % moves that will almost never happen in very short timeframes).

1 Like

Thank you so much for suggestion, its really help me.