// Downloaded From https://www.WiseStockTrader.com
/*
This is not my code, I found it in the internet. I hope that you will benefit from it. 
Good Luck
*/

//=========PARAMETERS====================

myVol=Param("Min Volume (Million)", 0,0,10,0.5);           // Filter out stocks below certain Volume (average over sampled periods). Default 0 (not filtered)
myVol = myVol * 1000000;                                   // Volume * million multiplier
myMaxPrice = Param("Price Max",200,0.0001,200,1);          // Filter for stocks below certain price. Default 0 (not filtered)
myMinPrice = Param("Price Min",0,0.0001,199,1);            // Filter for stocks above certain price. Default 0 (not filtered)
myPercentMin = Param("Min ADPV %",0,0,30,0.5);             // Filter  for minimum Average Dollar Price Volatility %. Default 0 (not filtered)
myMinPriceSteps = Param("Min Price Steps",0,0,500,1);      // Filter for minimum ticks in ADPV (eg H=0.005, L=0.002, price steps=3)
                                                           // Default 0 (not filtered)
myPeriods = Param("No. Of Days To Sample",20,2,90,1);
myPeriods = IIf(myPeriods>BarCount,BarCount,myPeriods);    // Just in case there are less data bars than the number of periods wanted

                                                           // ****** Uncomment next 2 lines for use in Australian ASX market *********
//myTickerMax = ParamList("Stocks only?","Yes|No");        // Filter to exclude options/warrants. Default "Yes" (stocks only)
//myTickerMax = IIf(myTickerMax == "Yes", 3,10);           // Ticker max length. 3 for stocks only.

//==========================================



trig1 = IIf(C<=O,True,False);
trig2 = IIf(Ref(C,-1)<=Ref(O,-1),True,False);
trig3 = IIf(Ref(C,-2)<=Ref(O,-2),True,False);
trig4 = IIf(C<Ref(C,-1) AND Ref(C,-1)<Ref(C,-2), True, False);

ADPV  = H - L;                                  // Average Dollar Price Volatility of current quotation (ie today's H to L range)
MedianPrice = ADPV/2 + L;                       // Median price of current quotation
ADPVpercent = (ADPV  / MedianPrice ) * 100;     // ADPV as percent of median price

// Calculate the same for the last x days, keep a running total for averaging
for( i = 1; i < myPeriods; i++ ) 
{
    x = i * -1; // negate counter to enable count back
    MedianPrice =MedianPrice + Ref(H-L,x)/2 + Ref(L,x);
    ADPV  = ADPV  + Ref(H-L,x);
    ADPVpercent = ADPVpercent + ((ADPV  / MedianPrice ) * 100);
}



MedianPrice = MedianPrice / myPeriods;       // Average median price over x days
ADPV  = ADPV  / myPeriods;                   // Average ADPV over x days
ADPVpercent = ADPVpercent / myPeriods;       // ADPV percentage over x days


Buy = trig1 AND trig2 AND trig3 AND trig4 AND MA(V,20)>500000;
Filter=Buy;
// ==============OUTPUT==================

// Tidy up output
txtADPVpercent=NumToStr(ADPVpercent,10.2 );
txtADPVpercent=txtADPVpercent + " %";
txtADPV = NumToStr(ADPV,3.3);
txtADPV = "$" + txtADPV ;
txtClose=NumToStr(Close,4.3 );
txtClose = "$" + txtClose;

AddTextColumn( txtClose , "Close");
AddColumn( MA(V,myPeriods), "Avg Daily Vol",20.0 );
AddTextColumn( txtADPV  , "$Avg Range",10.3 );
AddTextColumn( txtADPVpercent, "Av % Range",10.2 );
// AddColumn( PriceSteps , "Price Steps",8.0 );     // Remove comment tags to display price steps

// ====================================  END CODE ====================================================