Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

KNP analysis 1 for Amibroker (AFL)

Rating:
3 / 5 (Votes 2)
Tags:
trading system, amibroker, exploration, pivots

Its a 1st time try to modify few of the indicators and tried hard to get the best buy and sell values.

Screenshots

Similar Indicators / Formulas

Khichadi_R50_R3212.afl
Submitted by kartmer555 over 8 years ago
PRA TTS v1.1
Submitted by jaipal7786 about 6 years ago
PRA TTS
Submitted by jaipal7786 about 6 years ago
HOLY GRAIL
Submitted by prasadbrao almost 7 years ago
PIVOT POINT WITH VPA1 FOR AMIBROKER
Submitted by METHUN over 8 years ago

Indicator / Formula

Copy & Paste Friendly
/* KNP analysis */
  
_SECTION_BEGIN("Setup"); 
//required settings: 
//      Tools --> Preferences | go to Intraday tab and select "START time of interval" 
//      View --> Intraday --> "Show 24 Hours Trading" 
//      View --> Intraday --> "Filter Weekends" 
  
// Rounding the Study line values 
StopLst = ParamList("Select Stop", ".25|.33|.50|.66|.75|1.0|1.5", 6); 
TargetLst = ParamList("Adjust Target", "0.50|0.66|0.75|1.00|1.10|1.20|1.25|1.30|1.35", 0); 
Instrument = ParamList("Instrument", "Stocks|Forex|Futures"); 
length  = ParamList("Digits to R of Decimal","0|2|4",1);        // Number or numbers to the right of the decimal 
rounding  = ParamList("Rounding (for pts.)", "Truncate|NearestQuarter");    // don't round, round to nearest 1, round to nearest .25 
ExpFilter = ParamList("Exploration", "ORB|STATS|OHLC", 1); 
FltrHolidays = ParamToggle("Filter Holidays", "YES|NO", 0); 
UseDaySave = ParamToggle("Daylight Savings", "YES|NO", 0); 
UserSpringFoward = ParamDate("SpringForward", "3/8/2009"); 
UserFallBehind = ParamDate("FallBehind", "11/2/2008"); 
UserOpen = ParamTime("Market Open", "09:30"); 
UserClose = ParamTime("Market Close", "16:00"); 
_SECTION_END(); 
_SECTION_BEGIN("Plot lines"); 
//Set parameter default to YES for displaying the final 
//results of the break out calculations. 
PlotBreak =  ParamToggle("Plot Breakout", "YES|NO", 0); 
//set parameter default to YES for displaying PP, S1 and R1 
PPSR1 = ParamToggle("PP,S1/R1", "YES|NO", 0); 
//set paramter default to NO for displaying S2 and R2 
S2R2 = ParamToggle("S2,R2", "YES|NO", 1); 
//set parameter default to NO for dsiplaying S3 and R3 
S3R3 = ParamToggle("S3,R3", "YES|NO", 1); 
//set paramter default to NO for diplaying S4 and R4 
S4R4 = ParamToggle("S4,R4", "YES|NO", 1); 
_SECTION_END(); 
  
_SECTION_BEGIN("Price"); 
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );  
SetChartBkColor(ParamColor("Panel color ",colorLightBlue)); 
_SECTION_END(); 
  
_SECTION_BEGIN("Speed Lines"); 
P20 = 20; 
Plot( EMA( C, P20 ), "Spd20" ,colorBlack, styleLine | styleThick );  
  
P18 = 18; 
Plot( EMA( C, P18 ), "Spd18" ,colorCustom9, styleLine | styleThick );  
  
P50 = 50; 
Plot( MA( C, P50 ), "Spd 50" , colorBlue,styleDashed | styleThick);  
  
P200 = 200; 
Plot( MA( C, P200 ), "Spd 200" , colorRed, ParamStyle("Style") );  
  
Prd3HLC = Param("HLC 3 Prds", 3, 3, 10, 1); 
Plot(MA((H + L + C)/3, Prd3HLC), "HLC 3MA", colorBlue, styleLine | styleThick); 
  
Prd5HLC = Param("HLC 5 Prds", 5, 3, 10, 1); 
Plot(MA((H + L + C)/3, Prd5HLC), "HLC 5MA", colorCustom12, styleLine | styleThick); 
_SECTION_END(); 
  
_SECTION_BEGIN("Open Range Break Out"); 
  
CurBarTime = TimeNum(); 
  
//Need to use VBscript here to take the user selected date 
//and covert it to the DateNum() format for use by AFL 
EnableScript("vbscript"); 
<% 
dim VarPart 
    varPartSpring = Split(AFL("UserSpringFoward"), "/", 3) 
  
AFL("Spring") = varPartSpring(0)  
    VarPartFall = Split(AFL("UserFallBehind"), "/", 3) 
AFL("Fall") = VarPartFall(0) 
  
%> 
//convert VBscript output to number format and assign to  
//AFL variables 
SpringForward = StrToNum(Spring); 
FallBehind = StrToNum(Fall); 
  
//based on user selection in parameters dialog for daylight savings and 
// market open and close times, adjust the Open/Close for the market accordingly 
if(UseDaySave == 0) 
{ 
//if user selects daylight savings then test to see if each bar is within the daylight 
//savings time window. For each bar that lies within the window, shift the time one hour 
//forward.  
TimeOpen = IIf(DateTimeConvert( 0, DateTime() ) >= FallBehind AND DateTimeConvert( 0, DateTime() ) <= SpringForward, 
             UserOpen + 10000, UserOpen ) ; 
CalcClose = IIf(DateTimeConvert( 0, DateTime() ) >= FallBehind AND DateTimeConvert( 0, DateTime() ) <= SpringForward,  
                UserClose + 10000, UserClose ) ; 
} 
if(UseDaySave == 1) 
{ 
//if user selects no for daylight savings then use the values as the are 
TimeOpen = UserOpen ; 
CalcClose = UserClose; 
} 
 
//=IF(MID(A17,3,2)="00",6000-(B17*100)+(A17-10000),A17-(100*B17)) 
TimeClose = IIf(StrMid(NumToStr(CalcClose ,1,False),2,2)=="00", 
            6000-((Interval()/60)*100)+(CalcClose-10000), 
            CalcClose-(100*(Interval()/60))); 
  
//Determine the value of the market open. Initial setting is for 

MrktOpen = ValueWhen(CurBarTime  == TimeOpen , Open); 
DlyOpen =ValueWhen(CurBarTime == TimeClose, MrktOpen); 
//Determine the highest high for each day's trading. 
//Adjust time as needed for your market. 
DlyHigh = HighestSince(CurBarTime  == TimeOpen , High); 
//Take a snapshot value of the day's high at the time of market    
//Adjust as needed for your market. 
DlyHighest = ValueWhen(CurBarTime  == TimeClose , DlyHigh); 
//Do the same for the lowest value of the trading day. 
//Adjust time as needed for your market. 
DlyLow = LowestSince(CurBarTime  == TimeOpen , Low); 
DlyLowest = ValueWhen(CurBarTime  == TimeClose , DlyLow); 
//determine the market closing price 
DlyClose = ValueWhen(CurBarTime  == TimeClose , C); 
//Now calculate the min range value using Open, Low and High 
//variables calculated above 
RngMin = Min(DlyHighest - MrktOpen, MrktOpen - DlyLowest); 
//Compres this to a daily time frame in order to capture 
//the final value of the Range Min for each trading day 
DlyRngMin = TimeFrameCompress(RngMin, inDaily, compressLast); 
//Use the compressed variable to calculate a 10 day average\ 
RngMinAvg = MA(DlyRngMin , 10); 
  
//uncompress the daily variable so that it can be used in  
//calcuating the long and short break out levels for each day 
RngMinAvg = TimeFrameExpand(RngMinAvg, inDaily); 
  
//caclculate the max range value using the opn, low and high 
//variables 
RngMax = Max(DlyHighest - MrktOpen, MrktOpen - DlyLowest); 
//compress this to a daily time frame in order to capture 
//the final value of the range max for each trading day 
DlyRngMax = TimeFrameCompress(RngMax, inDaily, compressLast); 
//use the compressed variable to calculate a 10 day average 
RngMaxAvg = MA(DlyRngMax, 10); 
//uncompress the daily variable so that it can be used in 
//calculating the profit target for opening range breakouts 
RngMaxAvg = TimeFrameExpand(RngMaxAvg, inDaily); 
//Use the values calculated above to determine the opening 
//range break outs. Notice the Range Min has been shifted so 
//that is reads the previous day's value and this is used against 
//the current day's open to determine the break out levels 
BreakOutLong = MrktOpen + Ref(RngMinAvg, -1); 
BreakOutShort = MrktOpen - Ref(RngMinAvg, -1); 
  
//round the breakout levels based on user selection in parameters 
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
if(Length == "0") 
    { 
        breakOutLong = int(breakOutLong ); 
        breakOutShort = int(breakOutShort ); 
    } 
else if(Length == "2") 
    { 
    if(rounding == "NearestQuarter" AND Instrument == "Futures") 
        { 
        breakOutLong = 0.25 * ceil( 0.5 + BreakOutLong * 4 ); 
        breakOutShort = 0.25 * floor( 0.5 + BreakOutShort * 4 ); 
        } 
    else
        { 
        breakOutLong = 0.01 * round(0.5 + BreakOutLong * 100); 
        breakOutShort = 0.01 * round(0.5 + BreakOutShort * 100); 
        } 
test = 0; 
    } 
else if(Length == "4") 
{ 
        breakOutLong = Prec(breakOutLong , 4); 
        breakOutShort = Prec(breakOutShort , 4); 
} 
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
//now use the average max range to calculate a profit target 
//for each day's opening range break out 
UserTarget = StrToNum(TargetLst); 
  
//allow user to modify the profit target from selection made in  
//the parameters. 
ProfitLong = MrktOpen + (Ref(RngMaxAvg, -1))*UserTarget ; 
ProfitShort = MrktOpen - (Ref(RngMaxAvg, -1))*UserTarget ; 
  
UserStop = StrToNum(StopLst); 
  
  
//Allow user to modify the stop loss values from selection made 
//in the parameters. 
StopAmtLong = Prec((breakOutLong - MrktOpen)*UserStop ,2); 
StopAmtShort = Prec((MrktOpen - breakOutShort)*UserStop ,2); 
  
//round the stop and profit target levels based on user selection in parameter 
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
if(Length == "0") 
    { 
        StopAmtShort = int(StopAmtShort); 
        StopAmtLong = int(StopAmtLong); 
        ProfitShort = int(ProfitShort) ; 
        ProfitLong = int(ProfitLong);  
    } 
else if(Length == "2") 
    { 
    if(rounding == "NearestQuarter" AND Instrument == "Futures") 
        { 
        StopAmtShort = 0.25 * ceil( 0.5 + StopAmtShort * 4 )+0.25; 
        StopAmtLong = 0.25 * floor( 0.5 + StopAmtLong * 4 ); 
        ProfitShort = 0.25 * ceil( 0.5 + ProfitShort * 4 ) ; 
        ProfitLong = 0.25 * floor( 0.5 + ProfitLong * 4 ) - 0.25; 
        } 
    else
        { 
        StopAmtShort = 0.01 * floor(0.5 + StopAmtShort * 100); 
        StopAmtLong = 0.01 * round(0.5 + StopAmtLong * 100)+0.01; 
        ProfitShort = Prec(ProfitShort , 2) ; 
        ProfitLong = Prec(ProfitLong , 2); 
        } 
  
    } 
else if(Length == "4") 
{ 
        StopAmtShort = Prec(StopAmtShort , 4); 
        StopAmtLong = Prec(StopAmtLong , 4); 
        ProfitShort = Prec(ProfitShort , 4) ; 
        ProfitLong = Prec(ProfitLong , 4);  
} 
  
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
  
//create the title layout for the various levels 
TitleBreakOuts = EncodeColor(colorCustom11) +"Today's Breakout Levels:" +"\n"
                    +"Long Target: " +ProfitLong + "\n"
                    +"Breakout Long: " +breakOutLong +"\n"
                    +"Long Stop: " +(BreakOutLong - StopAmtLong) +"\n"
                    +"Today's Open: " +MrktOpen +"\n"
                    +"Breakout Short: " +breakOutShort +"\n"
                    +"Short Target: " +ProfitShort +"\n"
                    +"Short Stop: " + (BreakOutShort + StopAmtShort)+"\n"; 
  
_SECTION_END(); 
  
_SECTION_BEGIN("Toby Crabel Patterns"); 
TitleHeader = EncodeColor(colorYellow) +"Yesterday's Price Patterns" +"\n"; 
TitleSwing = EncodeColor(colorLavender) +"1 Day Swing Trend" + "\n"; 
  
//compress daily high and low for use in calculations 
DlyC = TimeFrameCompress(DlyClose , inDaily, compressLast); 
DlyH = TimeFrameCompress(DlyHighest, inDaily, compressLast); 
DlyL = TimeFrameCompress(DlyLowest, inDaily, compressLast); 
DlyO = TimeFrameCompress(MrktOpen, inDaily, compressLast); 
DlyRng = DlyH-DlyL; 
//use compressed daily high and low to expand day's 2-5 
PrevO = TimeFrameExpand(DlyO, inDaily);//day 2 open 
//PrevO2 = TimeFrameExpand(Ref(DlyO, -1), inDaily);//day 3 open 
CurH = TimeFrameExpand(DlyH, inDaily);//day 2 high 
PrevH = TimeFrameExpand(Ref(DlyH,-1), inDaily);//day 3 high 
PrevH2 = TimeFrameExpand(Ref(DlyH,-2), inDaily);//day 4 high 
//PrevH3 = TimeFrameExpand(Ref(DlyH,-3), inDaily);//day 5 high 
CurL = TimeFrameExpand(DlyL, inDaily);//day 2 low 
PrevL = TimeFrameExpand(Ref(DlyL,-1), inDaily);//day 3 low 
PrevL2 = TimeFrameExpand(Ref(DlyL,-2), inDaily);//day 4 low 
//PrevL3 = TimeFrameExpand(Ref(DlyL,-3), inDaily);//day 5 low 
PrevC = TimeFrameExpand(DlyC, inDaily);//day 2 close 
PrevC2 = TimeFrameExpand(Ref(DlyC,-1), inDaily);//day 3 close 
PrevC3 = TimeFrameExpand(Ref(DlyC,-2), inDaily);//day 4 close 
  
//code and plot the Doji  
//abs(O-C)/(H-L) < .11 AND (O+C)/2 < H-((H-L)*.33) AND (O+C)/2 > L+((H-L)*.33) 
DlyDoji = (abs(DlyO-DlyC)/(DlyRng)) < 0.11 AND  
            ((DlyO+DlyC)/2) < (DlyH-((DlyRng)*0.33)) AND 
            ((DlyO+DlyC)/2) > (DlyL+((DlyRng)*0.33)); 
doji = TimeFrameExpand(DlyDoji, inDaily); 
  
Cntr = 0; 
Holiday = 0; 
for(i=1;i<BarCount;i++) 
    { 
    if(CurBarTime[i] >= TimeOpen[i] AND CurBarTime[i] <= TimeClose[i]) 
        Cntr = 1;    
        if(Cntr[i] >= 1 AND CurBarTime[i] == TimeClose[i]) 
        { 
            Cntr = 2; 
        } 
            if(Cntr[i] < 2 AND CurBarTime[i] > TimeClose[i]) 
            { 
                Holiday[i] = 1; 
            } 
    } 
  
Holiday = TimeFrameCompress(Holiday,inDaily); 
  
//apply holiday filter if the user selects it in the parameters 
if(FltrHolidays == 0) 
{ 
  
//code and plot the NR4 
DlyNR4 = IIf(Holiday OR (BarsSince(Holiday) >= 1 AND BarsSince(Holiday) <= 4), 
            (LLV(DlyRng,5) == (DlyRng)), 
            (LLV(DlyRng,4) == (DlyRng))); 
//code and plot the WS4 
DlyWS4 = IIf(Holiday OR (BarsSince(Holiday) >= 1 AND BarsSince(Holiday) <= 4), 
            (HHV(DlyRng,5) == (DlyRng)), 
            HHV(DlyRng,4) == (DlyRng)); 
//code and plot the NR7 
DlyNR7 = IIf(Holiday OR (BarsSince(Holiday) >= 1 AND BarsSince(Holiday) <= 7), 
            (LLV(DlyRng,8) == (DlyRng)), 
            (LLV(DlyRng,7) == (DlyRng))); 
//code and plot the WS7 
DlyWS7 = IIf(Holiday OR (BarsSince(Holiday) >= 1 AND BarsSince(Holiday) <= 7), 
            (HHV(DlyRng,8) == (DlyRng)), 
            (HHV(DlyRng,7) == (DlyRng))); 
//calculate the 2 day range 
DlyTwoDayRng = IIf(Holiday OR (BarsSince(Holiday) == 1 ), 
                    HHV(DlyH ,3) - LLV(DlyL ,3), 
                    HHV(DlyH ,2) - LLV(DlyL ,2)); 
//calculate the 3 day range 
DlyThreeDayRng = IIf(Holiday OR (BarsSince(Holiday) >= 1 AND BarsSince(Holiday) <= 2), 
                    HHV(DlyH ,4) - LLV(DlyL ,4), 
                    HHV(DlyH ,3) - LLV(DlyL ,3)); 
  
TitleDoji = WriteIf(Holiday OR (BarsSince(Holiday) >= 1 AND BarsSince(Holiday) <= 2), 
                        EncodeColor(colorGold) +WriteIf(Ref(doji,-2), " Doji Day" +"\n", ""), 
                        EncodeColor(colorGold) +WriteIf(Ref(doji,-1), " Doji Day" +"\n", "")); 
} 
  
  
//calculate the price patterns based on standard method if the user 
//has selected NO in the filter holidays parameter. 
if(FltrHolidays == 1) 
{ 
//code and plot the NR4 
DlyNR4 = (LLV(DlyRng,4) == (DlyRng)); 
//code and plot the WS4 
DlyWS4 = (HHV(DlyRng,4) == (DlyRng)); 
//code and plot the NR7 
DlyNR7 = (LLV(DlyRng,7) == (DlyRng)); 
//code and plot the WS7 
DlyWS7 = (HHV(DlyRng,7) == (DlyRng)); 
//calculate the 2 day range 
DlyTwoDayRng = HHV(DlyH ,2) - LLV(DlyL ,2); 
//calculate the 3 day range 
DlyThreeDayRng = HHV(DlyH ,3) - LLV(DlyL ,3); 
  
TitleDoji = EncodeColor(colorGold) +WriteIf(Ref(doji,-1), " Doji Day" +"\n", ""); 
} 
  
//code the NR 
NR = (CurH - CurL) < (PrevH - PrevL); 
  
NR4 = TimeFrameExpand(DlyNR4, inDaily); 
TitleNR4 = EncodeColor(colorWhite) + WriteIf(Ref(NR4,0), " NR4 Day"+"\n", ""); 
  
WS4 = TimeFrameExpand(DlyWS4, inDaily); 
TitleWS4 = EncodeColor(colorRed) +WriteIf(Ref(WS4,0), " WS4 Day"+"\n", ""); 
  
NR7 = TimeFrameExpand(DlyNR7, inDaily); 
TitleNR7 = EncodeColor(colorWhite) + WriteIf(Ref(NR7,0), " NR7 Day"+"\n", ""); 
  
WS7 = TimeFrameExpand(DlyWS7, inDaily); 
TitleWS7 = EncodeColor(colorRed) +WriteIf(Ref(WS7,0), " WS7 Day" +"\n", ""); 
  
TwoDayRng = TimeFrameExpand(DlyTwoDayRng, inDaily); 
  
//determine lowest 2 day range in previous 20 days 
DlyTwoBarNR = LLV(DlyTwoDayRng , 20) == DlyTwoDayRng ; 
TwoBarNR = TimeFrameExpand(DlyTwoBarNR, inDaily); 
TitleTwoBarNR = WriteIf(Ref(TwoBarNR, -1), " 2DayNR" +"\n", ""); 
  
ThreeDayRng = TimeFrameExpand(DlyThreeDayRng, inDaily); 
  
//determine lowest 3 day range in previous 20 days 
DlyThreeBarNR = LLV(DlyThreeDayRng , 20) == DlyThreeDayRng ; 
ThreeBarNR = TimeFrameExpand(DlyThreeBarNR, inDaily); 
TitleThreeBarNR = WriteIf(Ref(ThreeBarNR, -1), " 3DayNR" +"\n", ""); 
  
//code and plot the pivot top 
PivotTop = CurL < PrevL  AND CurH < PrevH  AND PrevH > PrevH2; 
  
//code and plot the pivot bottom 
PivotBottom = CurH > PrevH   AND CurL > PrevL   AND PrevL < PrevL2; 
  
SwingUP = PrevC > ValueWhen(PivotTop, PrevH,1); 
SwingDWN = PrevC < ValueWhen(PivotBottom, PrevL,1); 
  
TitleSwingTrend = WriteIf(SwingUP, " Swing UP" +"\n", 
                        WriteIf(SwingDWN, " Swing DWN" +"\n", " Swing Flat" +"\n")); 
ExpSwingTrend = IIf(SwingUP, 9, 
                        IIf(SwingDWN, 0, 1)); 
  
//determine if previous day closed up or down 
CloseUP = PrevO > PrevH; 
//printf("Closed: " +WriteIf( Ref(DlyO,-1) < DlyC, "UP" +"\n", "DWN" +"\n")); 
TitleUPDWN = WriteIf(PrevO > PrevH, " UP Day" +"\n", " DWN Day" +"\n"); 
GapDayUP = PrevO > PrevH2 ; 
GapDayDWN = PrevO < PrevL2; 
TitleGapDay = WriteIf(GapDayUP, 
                WriteIf(CloseUP, " Gap UP and closed UP" +"\n", " Gap UP and closed DWN" +"\n"), 
                WriteIf(GapDayDWN,  
                WriteIf(CloseUP, " Gap DWN and closed UP" +"\n", " Gap DWN and closed DWN" +"\n"),"")); 
_SECTION_END(); 
  
_SECTION_BEGIN("Exploration"); 
//the exploration is divided into two sections. each section is tied to the  
//the value of the parameter toggle which is used to select from two choices 
  
//Choice 1 is ORB which is a simple scan showing the brekout, profit and stop  
//levels for each ticker. Run this scan within first minutes of market open to 
//record the levels for each of the securities you are tracking. Set the range 
//of the analsys window to 'n last days' where n=1. 
  
//Choice 2 is STATS wich is a more thorough scan that is intended to be used on 
//a single security at a time. Results can then be exported into a spread sheet for 
//further analysis. While it is not perfect the intended goal is to output a set  
//of data which can be used to measure the profitabilty of the system on a given 
//security as well as determine the best way to filter out undesirable trades. Set 
//the range in the analysis window to include whatever range of days you want to  
//output. 
  
/* 
$$$$$$$$ The two lines below display the output of the STATS exploration $$$$$$$$$$ 
$$$$$$$$ The top line contains the column headings and the bottom line   $$$$$$$$$$ 
$$$$$$$$ contains the data for each time stamp. Trend is measured as a 1 $$$$$$$$$$ 
$$$$$$$$ day swing pivot. U means the previous day closed above a recent $$$$$$$$$$ 
$$$$$$$$ pivot top. D mena the previous day closed below a recent        $$$$$$$$$$ 
$$$$$$$$ pivot bottom. F means the previous day closed between a         $$$$$$$$$$ 
$$$$$$$$ both the recent pivot top and pivot bottom. D3 and D2 are  plus $$$$$$$$$$ 
$$$$$$$$ and minus symbols to show the close of each day relative to the $$$$$$$$$$ 
$$$$$$$$ previous. D1 is the current day's open relative to previous     $$$$$$$$$$ 
$$$$$$$$ day's close. D1 is trade day, D2 is the day before trade day    $$$$$$$$$$ 
$$$$$$$$ and D3 is the day before that. After this is a series of 5      $$$$$$$$$$ 
$$$$$$$$ price patterns taken from Toby Crabel's book. 1's and 0's show  $$$$$$$$$$ 
$$$$$$$$ for each time stamp what the PREVIOUS day's price pattern       $$$$$$$$$$ 
$$$$$$$$ looked like. After the price patterns you find the 6 dollar     $$$$$$$$$$ 
$$$$$$$$ values for the breakout, stop and profit targets. The final 6   $$$$$$$$$$ 
$$$$$$$$ columns show what occured during each step and using 1's and    $$$$$$$$$$ 
$$$$$$$$ 0's diplays when you enter long/short, stop out long/short or   $$$$$$$$$$ 
$$$$$$$$ hit the long/short target.                                      $$$$$$$$$$ 
  
Ticker              Date/Time           Trend   D3  D2  D1  WS4 WS7 Doji    NR4 NR7     BOL     LngTarg LngStp  BOS     ShrtTarg    ShrtStp LngEnt  StpOut  Targ    ShrtEnt StpOut  Targ 
ESU9-GLOBEX-FUT 5/1/2009 9:37       U       +   -   +   1   1    0      0   0       873     886.75      871.5   867.25  853.25      868.5       0       0       0       1           0       0 
  
So the line above tells us these things: 
(Trend) Yesterday closed above a recent pivot top. (D1)Today's open was above yesterday's close, (D2) yesterday 
closed below the previous day's close and (D3) that day closed above it's prior day. Yesterday was 
also WS4 and WS7 day which means expansion. At 9:37 am pries broke below the short breakout level 
and a short entry was indicated. 
It is best to run the STATS exploration in a 1 minute time frame to prevent false stops occurring when 
a single 5 or 15 minute bar stretches across both the stop loss and breakout levels 
*/
  
intraHigh = HighestSince(CurBarTime  == TimeOpen, H); 
intraLow = LowestSince(CurBarTime  == TimeOpen, L); 
FirstBOL = Cross(H, breakOutLong) AND Ref(intraHigh,-1)  < breakOutLong OR
                H == breakOutLong AND Ref(intrahigh,-1) < breakOutlong OR 
            Cross(H, breakOutLong) AND CurBarTime  == TimeOpen OR
                H == breakOutLong AND CurBarTime  == TimeOpen; 
  
LongStop = L <= (breakOutLong - StopAmtLong) AND intraHigh >= breakOutLong AND intraHigh < ProfitLong; 
FirstLongStop = LongStop AND Ref(LowestSince(Ref(FirstBOL,-1),L),-1) > (BreakOutLong - StopAmtLong) OR
                    LongStop AND Ref(FirstBOL,-1); 
  
StgProfitLong = Cross(H, ProfitLong) AND Ref(intraHigh,-1) <= ProfitLong; 
FirstProfitLong = IIf(HighestSince(CurBarTime  == TimeOpen, LongStop) < 1, StgProfitLong, 0); 
  
FirstBOS = Cross(BreakOutShort, L) AND Ref(intraLow,-1) > breakOutShort OR
                L == breakOutShort AND Ref(intraLow,-1) > breakOutShort OR
            Cross(breakOutShort, L) AND CurBarTime  == TimeOpen OR
                L == breakOutShort AND CurBarTime  == TimeOpen; 
  
ShortStop = H >= (BreakOutShort + StopAmtShort) AND intraLow <= breakoutShort AND intraLow > ProfitShort; 
FirstShortStop  = ShortStop AND Ref(HighestSince(Ref(FirstBOS,-1),H),-1) < (BreakOutShort + StopAmtShort) OR
                        ShortStop AND Ref(FirstBOS,-1); 
  
StgProfitShort = Cross(ProfitShort, L) AND Ref(intraLow,-1) >= ProfitShort; 
FirstProfitShort = IIf(HighestSince(CurBarTime  == TimeOpen, ShortStop) < 1, StgProfitShort , 0); 
MrktHours = CurBarTime  >= TimeOpen AND CurBarTime  <= TimeClose; 
if(expFilter == "ORB") 
{ 
Filter = TimeNum() == TimeOpen; 
AddColumn(breakOutLong, "BOL", 1.2); 
AddColumn(ProfitLong, "LngTarg", 1.2); 
AddColumn(breakOutLong - StopAmtLong, "LngStp", 1.2); 
AddColumn(breakOutShort, "BOS", 1.2); 
AddColumn(ProfitShort, "ShrtTarg", 1.2); 
AddColumn(breakOutShort + StopAmtShort, "ShrtStp", 1.2); 
  
} 
if(expFilter == "STATS") 
{ 
  
Filter = MrktHours  AND 
            ( FirstBOS  OR FirstShortStop OR FirstProfitShort OR FirstBOL OR FirstLongStop OR FirstProfitLong  ); 
AddColumn(IIf( ExpSwingTrend == 9, 85,  
            IIf( ExpSwingTrend == 0, 68, 70 )), "Trend", formatChar ); 
AddColumn(IIf(PrevC2 > PrevC3, 43, 45), "D3", formatChar); 
AddColumn(IIf(PrevC > PrevC2, 43, 45), "D2", formatChar); 
AddColumn(IIf(MrktOpen > PrevC, 43, 45), "D1", formatChar); 
AddColumn(WS4, "WS4", 1); 
AddColumn(WS7, "WS7", 1); 
AddColumn(doji, "Doji", 1); 
AddColumn(NR4, "NR4", 1); 
AddColumn(NR7, "NR7", 1); 
  
AddColumn(breakOutLong, "BOL", 1.2); 
AddColumn(ProfitLong, "LngTarg", 1.2); 
AddColumn(breakOutLong - StopAmtLong, "LngStp", 1.2); 
AddColumn(breakOutShort, "BOS", 1.2); 
AddColumn(ProfitShort, "ShrtTarg", 1.2); 
AddColumn(breakOutShort + StopAmtShort, "ShrtStp", 1.2); 
  
AddColumn(FirstBOL, "LngEnt", 1); 
AddColumn(FirstLongStop, "StpOut", 1); 
AddColumn(FirstProfitLong, "Targ", 1); 
  
AddColumn(FirstBOS, "ShrtEnt", 1); 
AddColumn(FirstShortStop, "StpOut", 1); 
AddColumn(FirstProfitShort, "Targ", 1); 
} 
  
if(expFilter == "OHLC") 
{ 
//When exploration filter is set to OHLC in parameters, 
//this will output the O,H,L,C for each day/ticker selected in 
//the analysis window. 
Filter = CurBarTime == TimeClose ; 
AddColumn(DlyOpen, "O", 1.2); 
AddColumn(DlyHighest, "H", 1.2); 
AddColumn(DlyLowest, "L", 1.2); 
AddColumn(DlyClose, "C", 1.2); 
  
} 
_SECTION_END(); 
  
_SECTION_BEGIN("Daily Pivots"); 
//Determine the value of the market close. Initial setting is for 
//4:00 PM to match US Market Open. Adjust as need for your market 
MrktClose = ValueWhen(CurBarTime  == TimeClose , Close); 
Range = DlyHighest - DlyLowest; 
PP = (DlyHighest + DlyLowest + MrktClose)/3; 
PP = round(PP * 4) / 4; 
R1 = (2 * PP) - DlyLowest; 
S1 = (2 * PP) - DlyHighest; 
R2 = PP + Range; 
S2 = PP - Range; 
R3 = R2 + Range; 
S3 = S2 - Range; 
R4 = R3 + Range; 
S4 = S3 - Range; 
  
TitlePivots = EncodeColor(colorBlack) +"Today's Daily Pivots" +"\n"
                +"R1: " +R1 +"\n" +"PP: " +PP +"\n" +"S1: " +S1 +"\n"; 
if(PPSR1 == 0) 
{ 
Plot(R1, "Dly R1", colorBlue, styleLine | styleThick | styleNoRescale); 
Plot(PP, "Dly Pivot", colorCustom12, styleLine | styleThick | styleNoRescale); 
Plot(S1, "Dly S1", colorBlue, styleLine | styleThick | styleNoRescale); 
} 
if(S2R2 == 0) 
{ 
Plot(R2, "Dly R2", colorBlue, styleLine  | styleNoRescale); 
Plot(S2, "Dly S2", colorBlue, styleLine  | styleNoRescale); 
} 
if(S3R3 == 0) 
{ 
Plot(R3, "Dly R3", colorBlue, styleDashed | styleThick | styleNoRescale); 
Plot(S3, "Dly S3", colorBlue, styleDashed | styleThick | styleNoRescale); 
} 
if(S4R4 == 0) 
{ 
Plot(R4, "Dly R4", colorBlue, styleDashed  | styleNoRescale); 
Plot(S4, "Dly S4", colorBlue, styleDashed  | styleNoRescale); 
} 
  
_SECTION_END(); 
if(PlotBreak == 0) 
{ 
Plot(MrktOpen, "Daily Open", colorBlack, styleLine | styleNoRescale); 
Plot(BreakOutLong , "Break Out Long", colorGreen, styleLine | styleNoRescale); 
Plot(BreakOutShort , "Break Out Short", colorRed, styleLine | styleNoRescale); 
Plot(ProfitLong, "Long Target", colorGold, styleDots | styleThick | styleNoRescale); 
Plot(ProfitShort, "Short Target", colorGold, styleDots | styleThick | styleNoRescale); 
PlotOHLC(MrktOpen, breakOutLong, MrktOpen, MrktOpen, "", colorPaleGreen, styleCloud | styleNoRescale | styleNoLabel); 
PlotOHLC(MrktOpen, MrktOpen, BreakOutShort , MrktOpen, "", colorRose, styleCloud | styleNoRescale | styleNoLabel); 
} 
RibbonColor = IIf(MrktHours  , colorGreen, colorRed); 
  
Plot( 2, "ribbon",RibbonColor,styleOwnScale|styleArea|styleNoLabel, -1, 100 ); 
  
_SECTION_BEGIN("Title"); 
SetChartOptions(0,chartShowArrows|chartShowDates); 
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) ", O, H, L, C,  
SelectedValue( ROC( C, 1 ) ) )+"\n" +TitleBreakOuts  +TitlePivots +TitleSwing +TitleSwingTrend +TitleHeader  
+TitleNR4  +TitleNR7 +TitleTwoBarNR +TitleThreeBarNR +TitleWS4  
+TitleWS7 +TitleDoji  
+EncodeColor(colorWhite) +WriteIf(TitleGapDay == "", TitleUPDWN, "") +TitleGapDay   ); 
_SECTION_END();
// *********************************************************
// *
// * Prediction with model AR by Least Square / Autocorrelation
// * - Native AFL and VBS (for Gaussian Elimination if selected)
// * - biased or not biased estimator depending volatility
// * - averaging by T3 zerolag
// * - detrend by derivation
// *
// * - tomy_frenchy, v0.1
// * - fred for VBS Gaussian Elimination. Thanks a lot.
// * 
// *********************************************************

// *********************************************************
// *
// *     Price field = Data to predict 
// *     Periods = Periods for T3 filtering
// *     Slope = Slope for T3 filtering (0.7 to 0.83 for usual value)
// *     Methode = 0: Durbin-Levinson, 1: Gaussian Elimination
// *     Order  = Order of AR model
// *     ExtraF = Number of Bars to Extrapolate Forward
// *
// *********************************************************

// *********************************************************
// *
// *     Plotting :
// *     The bar position on the graphics separe in/out samples
// *     Green: computed from current data (centered T3 moving average)
// *     Blue: predicted, in-sample (AR, for the bar delayed because of T3 MA)
// *     Red: predicted, out-sample (AR, pure prediction)
// *
// *********************************************************


// For a resolution with Gaussian Elimination (more stable than Levinson-Durbin but slower)
EnableScript("VBScript");
<%
function Gaussian_Elimination (OrderAR, Autocorr)
    Dim b(200, 200)
    Dim w(200)
    Dim Coeff(200)

    for i = 1 To 200
        Coeff(i) = 0
    next

    n = OrderAR

    for i = 1 to n
        for j = 1 to  n
                b(i, j) = cDbl(Autocorr(abs(j - i)))
        next      
        w(i) = cDbl(Autocorr(i))
    next

    n1 = n - 1
    for i = 1 to n1
        big = cDbl(abs(b(i, i)))
        q = i
        i1 = i + 1

        for j = i1 to n
            ab = cDbl(abs(b(j, i)))
            if (ab >= big) then
                big = ab
                q = j
            end if
        next

        if (big <> 0.0) then
            if (q <> i) then
                for j = 1 to n
                    Temp = cDbl(b(q, j))
                    b(q, j) = b(i, j)
                    b(i, j) = Temp
                next
                Temp = w(i)
                w(i) = w(q)
                w(q) = Temp
            end if
        end if

        for j = i1 to n
            t = cDbl(b(j, i) / b(i, i))
            for k = i1 to n
                b(j, k) = b(j, k) - t * b(i, k)
            next         
            w(j) = w(j) - t * w(i)
        next      
    next

    if (b(n, n) <> 0.0) then

        Coeff(n) = w(n) / b(n, n)
        i = n - 1

        while i > 0
            SumY = cDbl(0)
            i1 = i + 1
            for j = i1 to n
                SumY = SumY + b(i, j) * Coeff(j)
            next
            Coeff(i) = (w(i) - SumY) / b(i, i)
            i = i - 1
        wend   

        Gaussian_Elimination = Coeff

    end if
end function
%>

function T3(price,periods,s) {
	e1=EMA(price,periods);
	e2=EMA(e1,Periods);
	e3=EMA(e2,Periods);
	e4=EMA(e3,Periods);
	e5=EMA(e4,Periods);
	e6=EMA(e5,Periods);
	c1=-s*s*s;
	c2=3*s*s+3*s*s*s;
	c3=-6*s*s-3*s-3*s*s*s;
	c4=1+3*s+s*s*s+3*s*s;
	Ti3=c1*e6+c2*e5+c3*e4+c4*e3;
	return ti3;
}

function f_centeredT3(data) {
	global slide;
	periods = Param("Periods", 5, 1, 200, 1);
	slope = Param("Slope", 0.7, 0, 3, 0.01);
	slide = floor(periods/2);
	centeredT3 = data;
	centeredT3 = Ref(T3(data,periods,slope),slide);
	centeredT3 = IIf( IsNan(centeredT3) OR !IsFinite(centeredT3) OR IsNull(centeredT3), data, centeredT3);
	return centeredT3;
}

function f_detrend(data) {
	detrended[0]=0;
	for (i = 1; i < BarCount; i++) detrended[i] = data[i] - data[i-1];
	return detrended;
}

function f_retrend(data, first_value, first_index, last_index) {
	for (i = 0; i < first_index; i++) retrended[i] = -1e10;
	retrended[first_index]=first_value;
	for (i = first_index + 1; i < last_index + 1; i++) retrended[i] = data[i] + retrended[i-1];
	for (i = last_index + 1; i < BarCount; i++) retrended[i] = -1e10;
	return retrended;
}

function AR(Data, BegBar, EndBar, OrderAR, ExtraF, Methode) {
BI = BarIndex();
Data_all = Data;
Data = IIf(BI < BegBar, 0, IIf(BI > EndBar, 0, Data));

LongBar = EndBar - BegBar + 1;


// Calcul for autocorrelation function
temp = MA(Data,LongBar);
moy_data = temp[EndBar];
data_centred = Data - moy_data;

for (i = 0; i < OrderAR + 1; i++) {
	temp = 0;
	for (j = BegBar; j < EndBar + 1 - i; j++) {
		temp = temp + data_centred[j]*data_centred[j+i];
	}
	//Autocorr[i]=(1/(LongBar))*temp; //biased estimator, small variance
	Autocorr[i]=(1/(LongBar-i))*temp; //not biased estimator, strong variance
}
Autocorr=Autocorr/Autocorr[0];


Gaussian_Elimination = Methode; // 0: Durbin-Levison, 1: Gaussian Elimination

if ( Gaussian_Elimination == 1 ) {
// Calcul AR parameters with Gaussian Elimination (vbs, more stable and precise, but slower)
VBS    = GetScriptObject();
AR_Coeff  = VBS.Gaussian_Elimination(OrderAR, Autocorr);
}

else {
// Calcul AR parameters with Durbin-Levison algorythm for Toeplitz matrix

// initialisation :
AR_Coeff = 0;
alpha[1] = Autocorr[0];
beta[1] = Autocorr[1];
k[1] = Autocorr[1] / Autocorr[0];
AR_Coeff[1] = k[1];

// itertive calcul :
for (n = 1; n < OrderAR; n++) {

// Last coefficient calcul
	// Step 1 : invert Coeff array
	for (i = 1; i < n + 1; i++) AR_Coeff_inv[n+1-i] =  AR_Coeff[i];

	// Step 2
	temp = 0;
	for (i = 1; i < n + 1; i++) temp = temp + Autocorr[i] * AR_Coeff_inv[i];
	beta[n+1] = Autocorr[n+1] - temp;

	// Step 3
	alpha[n+1] = alpha[n] * (1 - k[n]*k[n]);

	// Step 4
	k[n+1] = beta[n+1] / alpha[n+1];
	AR_Coeff[n+1] = k[n+1];

// Other older coefficients calcul
	// Step 5
	for (i = 1; i < n + 1; i++) New_AR_Coeff[i] = AR_Coeff[i] - k[n+1] * AR_Coeff_inv[i];

	// Step 6
	New_AR_Coeff[n+1] =  AR_Coeff[n+1];

// Update
	AR_Coeff = New_AR_Coeff;
}
}



// Prediction to +1 :
//Data = Data * Data_max;
AR_data = 0;
for (i = 1; i < OrderAR + 1; i++) {
	AR_data = AR_data + AR_Coeff[i] * Ref(Data,-i);
	printf("Coeff AR " + NumToStr(i, 1.0) + " = " + NumToStr(AR_Coeff[i], 1.9) + "\n");
}
AR_data = IIf(BI < BegBar, -1e10, IIf(BI > EndBar, -1e10, AR_data));


// Pr├ędiction to +Forward
AR_data_pred = IIf(BI > EndBar, -1e10, Data); // to be sure not to compute future value
for (i = EndBar + 1; i < EndBar + 1 + ExtraF; i++) {
	temp = 0;
	for (j = 1; j < OrderAR + 1; j++) {
		temp = temp + AR_Coeff[j] * AR_data_pred[i-j];
	}
	AR_data_pred[i] = temp;
}
for (i = EndBar + 1; i < EndBar + 1 + ExtraF; i++) {
	AR_data[i] = AR_data_pred[i];
}


// End
return AR_data;
}


// *********************************************************
// *
// * Demo AFL to use AR Prediction
// *
// *********************************************************

SetBarsRequired(20000,20000);

BI = BarIndex();
current_pos = SelectedValue( BI ) - BI[ 0 ];
printf( "Position: " + WriteVal(current_pos) + "\n" );


// Denoising and detrending for stationnarity
data_source = ParamField("Price field",-1);
centeredT3 = f_centeredT3(data_source);
data = f_detrend(centeredT3);


// Choice of parameters
Methode = Param("Methode 0:DL, 1:GE",  0, 0, 1, 1);
longueur = Param("Longueur",  200, 1, 5000, 1);
OrderAR  = Param("nth Order AR", 2, 1, 50, 1);
ExtraF = Param("Extrapolate Forwards",  0, 0, 50, 1);


BegBar = current_pos - longueur - slide;
EndBar = current_pos - slide;


// Prediction calcul
AR_pred = AR(data, BegBar, EndBar, OrderAR, ExtraF, Methode);
AR_pred = f_retrend(AR_pred, centeredT3[EndBar], EndBar, EndBar + slide + ExtraF);


// Reconstruct data + prediction
Data_reconstruct = -1e10;
Data_reconstruct = IIf( BI <= EndBar AND BI >= BegBar, centeredT3, AR_pred);


// Plot result
Plot(Data_reconstruct, "AR Prediction - " + NumToStr(OrderAR, 1.0), IIf(BI > EndBar + slide, colorRed, IIf(BI > EndBar AND BI <= EndBar + slide, colorBlue, colorBrightGreen)), styleThick, Null, Null, 0);

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	THIS SECTION DRAWS TD TREND LINES */

percent  = 0.01 * 1; /* Adjust this percent as necessary, I use .01 because FOREX is a 0.0000 number */
firstpointL = 2;
firstpointH = 2;

y0=LastValue(Trough(L,percent,firstpointL)); 
y1=LastValue(Trough(Ref(L,-1),percent,1));

for( i = 1; i < BarCount AND y0 >= y1; i++ )
{
		
		firstpointL++;	
		y0=LastValue(Trough(L,percent,firstpointL));		 
}

x0=BarCount - 1 - LastValue(TroughBars(L,percent,firstpointL)); 
x1=BarCount - 1 - LastValue(TroughBars(Ref(L,-1),percent,1)); 
LineL = LineArray( x0, y0, x1, y1, 1 ); 
/*
Plot(C, "C", colorBlack, styleCandle); 
*/
Plot( LineL, " Support Trend line", colorWhite,4 +8 ); 


yt0=LastValue(Peak(H,percent,firstpointH)); 
yt1=LastValue(Peak(Ref(H,-1),percent,1));

for(i = 1; i < BarCount AND yt0 <= yt1; i++ )
{
		
		firstpointH++;		
		yt0=LastValue(Peak(H,percent,firstpointH)); 
}
xt0=BarCount - 1 - LastValue(PeakBars(H,percent,firstpointH)); 
xt1=BarCount - 1 - LastValue(PeakBars(Ref(H,-1),percent,1)); 
LineH = LineArray( xt0, yt0, xt1, yt1, 1 ); 

Plot( LineH, "Resistance Trend line", colorBrown,4 + 8 ); 

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

_SECTION_BEGIN("Time Left"); 
function GetSecondNum() 
{ 
Time = Now( 4 ); 
Seconds = int( Time % 100 ); 
Minutes = int( Time / 100 % 100 ); 
Hours = int( Time / 10000 % 100 ); 
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds ); 
return SecondNum; 
} 
RequestTimedRefresh( 1 ); 
TimeFrame = Interval(); 
SecNumber = GetSecondNum(); 
Newperiod = SecNumber % TimeFrame == 0; 
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame; 
SecsToGo = TimeFrame - SecsLeft; 
  
x=Param("xposn",300,0,1000,1); 
y=Param("yposn",50,0,1000,1); 
  
GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) ); 
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 ); 
if ( NewPeriod ) 
{ 
GfxSelectSolidBrush( colorYellow ); 
GfxSelectPen( colorYellow, 2 ); 
Say( "New period" ); 
} 
GfxRoundRect( x+45, y+17, x-3, y-2, 0, 0 ); 
GfxSetBkMode(1); 
GfxSelectFont( "Arial", 12, 700, False ); 
GfxSetTextColor( colorBlack ); 
GfxTextOut( ""+SecsToGo+" / "+NumToStr( TimeFrame, 1.0 ), x, y ); 
_SECTION_END();

_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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );  
_SECTION_END(); 
  
_SECTION_BEGIN("Time and Money"); 
// plot candlestick price chart 
Plot( Close, "Price", colorBlack, styleCandle ); 
GraphXSpace = 1; 
// define TAM chart period 
period = 25; 
// users of AB version 4.30 can use Param 
// period = Param( "TAM period", 25, 2, 100, 1 ); 
halfperiod = floor( period /2 ); 
// minor term average 
Arm = MA( Close, period ); 
Plot( Arm, "Minor term avg", colorRed ); 
// calculate volatility 
yom = 100 * ( C - Ref( Arm, halfperiod ))/Ref( Arm, halfperiod ); 
avyom = MA( yom, 2 * period ); 
varyom = MA( yom * yom, 2 * period ) - avyom * avyom; 
som = Ref( sqrt( varyom ), -halfperiod ); 
sigom = MA( som, period ); 
// plot reference price grid 
Plot( Arm * ( 1 + 0.01 * sigom ), "Ch+1", colorLightGrey ); 
Plot( Arm * ( 1 - 0.01 * sigom ), "Ch-1", colorLightGrey ); 
Plot( Arm * ( 1 + 0.02 * sigom ), "Ch+2", colorLightGrey ); 
Plot( Arm * ( 1 - 0.02 * sigom ), "Ch-2", colorLightGrey ); 
Plot( Arm * ( 1 + 0.03 * sigom ), "Ch+3", colorLightGrey ); 
Plot( Arm * ( 1 - 0.03 * sigom ), "Ch-3", colorLightGrey ); 
_SECTION_END();

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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );  
  
//TIME FRAME CALCULATION 
H1 = TimeFrameGetPrice("H", inDaily, -1);       // yesterdays high 
L1 = TimeFrameGetPrice("L", inDaily, -1);       //              low 
C1= TimeFrameGetPrice("C", inDaily, -1);        //              close 
DayO = TimeFrameGetPrice("O", inDaily);         // current day open 
  
  
// PIVOT Calculation 
P = ( H1+ L1 + C1 )/3; 
S1 = (2*P)-H1; 
R1 = (2*P)-L1; 
S2 = P -(H1 - L1); 
S3 = S1 - (H1-L1);  
R2 = P +(H1 - L1); 
R3 = R1 +(H1-L1); 
  
// PIVOT mid points 
MIDR1 = (P+R1)/2; 
MIDR2 = (R1+R2)/2; 
MIDR3 = (R2+R3)/2; 
MIDS1 = (P+S1)/2; 
MIDS2 = (S1+S2)/2; 
MIDS3 = (S2+S3)/2; 
  
//PLOTS 
Plot(R1, "",colorRed,styleLine+styleNoRescale); 
Plot(R2, "",colorRed,styleLine+styleNoRescale); 
Plot(R3, "",colorRed,styleLine+styleNoRescale); 
  
Plot(P, "",colorGold,styleDots+styleNoRescale); 
  
Plot(S1, "",colorDarkBlue,styleLine+styleNoRescale); 
Plot(S2, "",colorDarkBlue,styleLine+styleNoRescale); 
Plot(S3, "",colorDarkBlue,styleLine+styleNoRescale); 
  
Plot(MIDR1, "",colorRed,styleDashed+styleNoRescale); 
Plot(MIDR2, "",colorRed,styleDashed+styleNoRescale); 
Plot(MIDR3, "",colorRed,styleDashed+styleNoRescale); 
  
Plot(MIDS1, "",colorBlue,styleDashed+styleNoRescale); 
Plot(MIDS2, "",colorBlue,styleDashed+styleNoRescale); 
Plot(MIDS3, "",colorBlue,styleDashed+styleNoRescale); 
  
Plot(H1, "",colorRed,styleDots+styleNoRescale); 
Plot(L1, "",colorBlue,styleDots); 
Plot(C1, "",colorBlack,styleDots+styleNoRescale); 
  
// text section 
  
"HIGH /LOW /CLOSE = " +H +" / "+ L+" / "+ C +"\n"; 
"H1 /L1 /C1 = " +H1 +" / "+ L1+" / "+ C1 +"\n"; 
  
"R3 = " +R3; 
"midr3 = " +MIDR3; 
"R2 = " +R2; 
"midr2 = " +MIDR2; 
"R1 = " +R1; 
"midr1 = " +MIDR1; 
"*************"; 
"p = " +p; 
"*************"; 
"mids1 = " +MIDS1; 
"S1 = " +S1; 
"mids2 = " +MIDS2; 
"S2 = " +S2; 
"mids3 = " +MIDS3; 
"S3 = " +S3; 
  
_SECTION_END();

/***************************************************************************** 
Name        :   Three Day Balance Points 
Coded   By  :   Lal 
Note        :   This is a simple idea - using the range of  
the last three days, find the mid-point.  Price above 
this mid-point is bullish and price below, bearish. 
  
You can optionally mark bars to show whether they 
are above or below the balance point.  Also included is 
an explorer to highlight stocks with a new close  
above/below the balance point. 
 *****************************************************************************/
  
  
  
Bal_Days = Param("Days for Balance Point", 3, 2, 10, 1); 
Mark_Bars = ParamToggle("Mark Bars?", "No|Yes", 0); 
Plottype = ParamList("Price Plotstyle ", "Stylebar|StyleCandle"); 
  
SetChartBkGradientFill(ParamColor("Top", colorTeal), ParamColor("Bottom", colorLightGrey), ParamColor("Title", colorTeal)); 
SetChartBkColor(ParamColor("Chart Background", colorWhite)); 
  
// Find the High and Low of said period 
Period_High = HHV(H, Bal_Days); 
Period_Low = LLV(L, Bal_Days); 
  
Balance_Point = Period_High - (Period_High - Period_Low) / Bal_Days; 
Current_BP = Ref(Balance_Point,  - 1); // For the current day, we need the BP as worked out at Close yesterday ! 
  
Price_Style = IIf(Plottype == "Stylebar", styleBar, styleCandle); 
Plot(C, "Close", ParamColor("Bar Color", colorBlack), Price_Style | styleThick); 
Plot(Current_BP, "Current BP", ParamColor("BP Color", colorRed), styleStaircase); 
Plot(Balance_Point, "Next Day's BP", colorBrown, styleNoDraw); 
  
// Optional Visual Marking of bars above/below the Balance Point 
if (Mark_Bars) 
{ 
  PlotShapes(shapeSmallCircle *(C < Current_BP), colorRed, 0, H, 12); 
  PlotShapes(shapeSmallCircle *(C > Current_BP), colorBlue, 0, L,  - 12); 
} 
  
//Explorer section 
Close_Up = C > Current_BP; 
New_Close_UP = Close_Up AND NOT Ref(Close_Up,  - 1); 
  
Close_Dn = C < Current_BP; 
New_Close_DN = Close_Dn AND NOT Ref(Close_DN,  - 1); 
  
AddColumn(New_Close_Up, "New_Close_Up", 1, colorWhite, IIf(New_Close_Up, colorGreen, colorWhite)); 
AddColumn(New_Close_Dn, "New_Close_Dn", 1, colorWhite, IIf(New_Close_Dn, colorRed, colorWhite)); 
Filter = New_Close_Up OR New_Close_Dn;

// techtrader v2 amibroker version 
// here we define buy conditions and name each one as a variable 
PositionSize = -10; // always invest only 10% of the current Equity 
cond1=Cross(H,Ref(HHV(H,10),-1)); // when todays high crosses last highest high over the last 10 periods 
cond2=H > EMA(C,24); // todays high is greater than the 40 day Exp MA of closes 
cond3=HHVBars(H,52) == 0; // todays high is the highest for 70 periods 
cond4=EMA(V*C,18) > 100000; // ensure at least $100k of money flow 
 
  
// the following line is the trigger if all conditions satisfied 
Buy=cond1 AND cond2 AND cond3 AND cond4 ; 
  
// here we define variables used once in the trade 
ApplyStop( stopTypeLoss, stopModePercent, amount=10 ); 
Sell= Cross(Ref(EMA(L,90),-1),C); // close crosses below yesterdays average of the low 
// here we define what gets displayed on the chart 
shape = Buy * shapeUpArrow + Sell * shapeDownArrow; 
PlotShapes( shape, IIf( Buy , colorYellow, colorRed ), 0, IIf( Buy , Low, High)); 
  
Filter = Buy; // lists exploration results conforming to our buy criteria 
AddColumn(Buy, "buy", 1.0); // 
Filter = Sell; // lists exploration results conforming to our buy criteria 
AddColumn(Sell, "sell", 1.0); // 
  
// This section creates the data that you can plot to see how often TT2 trades 
// NOTE:- Using VOLUME array so get correct number when switching to WEEKLY or MONTHLY display 
AddToComposite(Buy,"~TTBuys","V"); 
AddToComposite(Sell,"~TTSells","V"); 
  
Buy = ExRem(Buy,Sell) ; 
Sell = ExRem(Sell, Buy); 
Binary = Flip(Buy , Sell);

Title= " Td seq I";
/*TD seq long et short side full version*/

/********Optimize***********/
Opt1=Param("Opt1",5,5,21,1);
Opt2=Param("Opt2",12,1,21,1);

/*********Setup Buy*********/
TD1=IIf(Close<Ref(Close,-4),1,0); 
TD2=IIf(BarsSince(BarsSince(TD1))==Opt1, 1,0); //Sum(TD1,9)==9;
TD3= Ref(H,-1)>=Ref(LLV(L,Opt1-4),-3);
TD4= Ref(C,-Opt1)>=Ref(C,-Opt2);
SetupBuy= TD3 AND TD2 AND TD4;

/***********SetupSell************/
TD1=IIf(Close>Ref(Close,-4),1,0); 
TD2=IIf(BarsSince(BarsSince(TD1))==Opt1, 1,0); 
TD3= Ref(L,-1)<=Ref(HHV(H,Opt1-4),-3);
TD4= Ref(C,-Opt1)<=Ref(C,-Opt2);
SetupSell= TD3 AND TD2 AND TD4 ;

/*********Count Buy ********/
CountBuy= Sum(IIf(C<Ref(C,-2),1,0),BarsSince(SetupBuy));
//or C<Ref(H,-2)

/*********Count Sell ********/
CountSell= Sum(IIf(C>Ref(C,-2),1,0),BarsSince(SetupSell));
//or C>Ref(L,-2)

/***********A***********/
B1= CountBuy >=Opt2; 
B1= Hold(B1==0,2) AND B1;
Timing=(BarsSince(SetUpbuy)< BarsSince(SetUpsell));
Ccount=IIf(CountBuy >=Opt2,ValueWhen(B1,HHV(C,BarsSince(SetupBuy))),Null);
Hsetup=IIf(CountBuy >=Opt2,ValueWhen(SetupBuy,HHV(H,Opt1)),Null);
BuyA=B1 AND Timing AND Hsetup > Ccount;

/******B**********/
B2= CountBuy >Opt2 AND Close > Ref(Close,-4);
B2=Hold(B2==0,2) AND B2;
B2=ExRem(B2,B1);
BuyB=B2  AND Timing  AND Hsetup > Ccount;

/*************C***********/
B3= CountBuy >Opt2 AND Close > Ref(High,-2);
B3= Hold(B3==0,2) AND B3;
B3=ExRem(B3,B1);
BuyC= B3  AND Timing  AND Hsetup > Ccount;

/************Buy Signal********/
Buy=BuyB OR BuyC  ;

////////////////////////////////
//SHORT
/////////////////////////////////

/***********A***********/
S1= CountSell >=Opt2; 
S1= Hold(S1==0,2) AND S1;
Timing=(BarsSince(SetUpSell)< BarsSince(SetUpbuy));
Ccount=IIf(CountSell >=Opt2,ValueWhen(S1,LLV(C,BarsSince(SetupSell))),Null);
Lsetup=IIf(CountSell >=Opt2,ValueWhen(SetupSell,LLV(L,Opt1)),Null);
SellA=S1 AND Timing AND Lsetup < Ccount;

/******B**********/
S2= CountSell >Opt2 AND Close < Ref(Close,-4);
S2=Hold(S2==0,2) AND S2;
S2=ExRem(S2,S1);
SellB=S2  AND Timing  AND Lsetup < Ccount;

/*************C***********/
S3= CountSell >Opt2 AND Close < Ref(Low,-2);
S3= Hold(S3==0,2) AND S3;
S3=ExRem(S3,S1);
SellC= S3  AND Timing  AND Lsetup < Ccount;

/***********Short Signal********/
Short= SellB OR SellC  ;

Plot(C,"",IIf(Short,colorYellow,IIf(Buy,colorGreen,1)),64);

PlotShapes(IIf(Short,
shapeDownArrow,shapeNone),colorYellow,0,H,-10); 
PlotShapes(IIf(Buy,
shapeUpArrow,shapeNone),colorGreen,0,L,-10);

PlotShapes(IIf(SetupSell,
shapeDigit9,shapeNone),colorRed,0,H,20);  
PlotShapes(IIf(SetupBuy,
shapeDigit9,shapeNone),colorBlue,0,L,-20); 

/* T3 trading system */
a = 0.7;
n = 2;

alpha = 2/(n + 1);
e1 =  EMA(Close, n);
e2 = EMA (e1, n);
e3 = EMA (e2, n);
e4 = EMA (e3,  n);
e5 = EMA (e4, n);
e6 = EMA (e5, n);

x = -a^3 * e6 + (3 * a^2 +3 * a^3) * e5 + (-6 * a^2 - 3 *
 a - 3 * a^3) * e4 + (1 + 3 * a + a^3 + 3 * a^2) * e3;

Graph0 = Close;
Graph1 = x;

Sell = Cross ( Close, x );
Buy = Cross (x, Close );
Short = Cross ( Close, x);
Cover = Cross (x, Close );

///// Chaloke.com Peak-Trough System 1.0 ///// 

Sens=Param("Sens",1,0.25,5,0.25); 
PK=Peak(Close,Sens,1); 
TGH=Trough(Close,Sens,1); 
Color=IIf(BarsSince(Cross(C,Ref(PK,-1)))<BarsSince(Cross(Ref(TGH,-1),C)),colorBrightGreen,colorRed); 
Plot(Zig(C,Sens),"",colorWhite);
Plot(C,"Chaloke.com Peak-Trough System",Color,styleCandle); 
PlotShapes( Cross(C,Ref(PK,-1)) *shapeUpArrow,colorYellow,0,L,Offset=-20); 
PlotShapes( Cross(Ref(TGH,-1),C) *shapeDownArrow,11,0,H,Offset=-20); 

 Title=EncodeColor(colorBrightGreen)+Date()+"    " +Name() +"  Chaloke.com Peak-Trough System 1.0 " + EncodeColor(10)+"   O="+O+"   H="+H+"   L="+L+EncodeColor(colorPink)+"   C="+C+"  ("+NumToStr((C-Ref(C,-1))/Ref(C,-1)*100,1.2)+" %)    "
;

//==================================================================================== 
_SECTION_BEGIN("Volume Price Analysis - V.1.0"); 
SetChartOptions(0,chartShowArrows|chartShowDates); 
//======================================================================================= 
DTL=Param("Linear regression period",60,10,100,10);  
wbf=Param("WRB factor",1.5,1.3,2.5,.1); 
nbf=Param("NRB factor",0.7,0.3,0.9,0.1); 
TL=LinRegSlope(MA(C, DTL),2);  
 Vlp=Param("Volume lookback period",30,20,300,10); 
Vrg=MA(V,Vlp); 
St = StDev(Vrg,Vlp);  
Vp3 = Vrg + 3*st;  
Vp2 = Vrg + 2*st;; 
Vp1 = Vrg + 1*st;; 
Vn1 = Vrg -1*st;  
Vn2 = Vrg -2*st;  
rg=(H-L); 
arg=Wilders(rg,30); 
wrb=rg>(wbf*arg); 
nrb=rg<(nbf*arg);  
Vl=V<Ref(V,-1) AND V<Ref(V,-2); 
upbar=C>Ref(C,-1); 
dnbar=C<Ref(C,-1);  
Vh=V>Ref(V,-1) AND Ref(V,-1)>Ref(V,-2); 
Cloc=C-L; 
x=rg/Cloc; 
x1=IIf(Cloc=0,arg,x); 
Vb=V>Vrg OR V>Ref(V,-1); 
ucls=x1<2; 
dcls=x1>2; 
mcls=x1<2.2 AND x1>1.8 ; 
Vlcls=x1>4; 
Vhcls=x1<1.35; 
j=MA(C,5); 
TLL=LinRegSlope(j,40) ; 
Tlm=LinRegSlope(j,15) ; 
tls=LinRegSlope(j,5); 
mp=(H+L)/2; 
_SECTION_END(); 
//========================================================================================== 
_SECTION_BEGIN("VSA"); 
utbar=wrb AND dcls AND tls>0 ; 
utcond1=Ref(utbar,-1) AND dnbar ; 
utcond2=Ref(utbar,-1) AND dnbar AND V>Ref(V,-1); 
utcond3=utbar AND V> 2*Vrg; 
trbar=Ref(V,-1)>Vrg  AND Ref(upbar,-1) AND Ref(wrb,-1) AND dnbar AND dcls AND wrb AND tll>0 AND H==HHV(H,10); 
Hutbar=Ref(upbar,-1) AND Ref(V,-1)>1.5*Vrg AND dnbar AND dcls AND NOT wrb AND NOT utbar; 
Hutcond=Ref(Hutbar,-1) AND dnbar AND dcls AND NOT utbar; 
tcbar=Ref(upbar,-1) AND H==HHV(H,5)AND dnbar AND (dcls OR mcls) AND V>vrg AND NOT wrb AND NOT Hutbar ; 
Scond1=(utcond1 OR utcond2 OR utcond3) ; 
Scond2=Ref(scond1,-1)==0; 
scond=scond1 AND scond2; 
stdn0= tll<0 AND V>Ref(V,-1) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls) AND tls<0 AND tlm<0; 
stdn= V>Ref(V,-1) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls) AND tls<0 AND tlm<0; 
stdn1= tll<0 AND V>(vrg*1.5) AND Ref(dnbar,-1) AND upbar AND (ucls OR mcls)AND tls<0 AND tlm<0; 
stdn2=tls<0 AND Ref(V,-1)<Vrg  AND upbar AND vhcls AND V>Vrg; 
bycond1= stdn OR stdn1; 
bycond= upbar  AND Ref(bycond1,-1); 
stvol= L==LLV(L,5)  AND (ucls OR mcls) AND V>1.5*Vrg AND tll<0; 
ndbar=upbar AND nrb AND Vl  AND dcls ; 
nsbar=dnbar AND nrb AND Vl  AND dcls ; 
nbbar= C>Ref(C,-1) AND Vl AND nrb AND x1<2; 
nbbar= IIf(C>Ref(C,-1) AND V<Ref(V,-1) AND V<Ref(V,-2) AND x1<1.1,1,0); 
lvtbar= vl AND L<Ref(L,-1) AND ucls; 
lvtbar1= V<Vrg AND L<Ref(L,-1) AND ucls AND tll>0 AND tlm>0 AND wrb; 
lvtbar2= Ref(Lvtbar,-1) AND upbar AND ucls; 
dbar= V>2*Vrg AND dcls AND upbar AND tls>0 AND tlm>0 AND NOT Scond1 AND NOT utbar; 
eftup=H>Ref(H,-1) AND L>Ref(L,-1) AND C>Ref(C,-1) AND C>=((H-L)*0.7+L) AND rg>arg AND V>Ref(V,-1); 
eftupfl=Ref(eftup,-1) AND (utbar OR utcond1 OR utcond2 OR utcond3); 
eftdn=H<Ref(H,-1) AND L<Ref(L,-1) AND C<Ref(C,-1) AND  C<=((H-L)*0.25+L) AND rg>arg AND V>Ref(V,-1); 
_SECTION_END(); 
//======================================================================================================================= 
_SECTION_BEGIN("Chart"); 
Vcolor=IIf(tls>0 AND tlm>0 AND tll>0,colorLime,IIf(tls>0 AND tlm>0 AND tll<0,colorGreen, 
IIf(tls>0 AND tlm<0 AND tll<0,colorPaleGreen,IIf(tls<0 AND tlm<0 AND tll<0,colorRed,IIf(tls<0 AND tlm>0 AND tll>0,colorPaleGreen, 
IIf(tls<0 AND tlm<0 AND tll>0,colorOrange,colorBlue)))))); 
GraphXSpace = 5; 
PlotOHLC( Open,  High,  Low,  Close, "", vcolor, styleBar | styleThick  ); 
_SECTION_END(); 
//============================================================================================================================ 
// commentary 
  
_SECTION_BEGIN("Commentary"); 
Vpc= utbar OR utcond1 OR utcond2 OR utcond3 OR stdn0 OR stdn1 OR stdn2 OR stdn OR lvtbar1 OR Lvtbar OR Lvtbar2 OR Hutbar OR Hutcond OR ndbar OR stvol OR tcbar; 
  
if( Status("action") == actionCommentary )  
( 
printf ( "=========================" +"\n")); 
printf ( "VOLUME PRICE ANALYSIS" +"\n"); 
printf ( "www.vpanalysis.blogspot.com" +"\n"); 
printf ( "=========================" +"\n"); 
printf ( Name() + " - " +Interval(2) +  "  - " + Date() +" - " +"\n"+"High-"+H+"\n"+"Low-"+L+"\n"+"Open-"+O+"\n"+ 
"Close-"+C+"\n"+ "Volume= "+ WriteVal(V)+"\n"); 
WriteIf(Vpc,"=======================",""); 
WriteIf(Vpc,"VOLUME ANALYSIS COMMENTARY:\n",""); 
  
WriteIf(utbar , "Up-thrusts are designed to catch stops and to mislead as many traders as possible.   
They are normally seen after there has been weakness in the background. The market makers know that the 
market is weak, so the price is marked up to catch stops, encourage traders to go long in a weak market, 
AND panic traders that are already Short into covering their very good position.","")+ 
WriteIf(utcond3,"This upthrust bar is at high volume.This is a sure sign of weakness. One may even seriously  
consider ending the Longs AND be ready to reverse","")+WriteIf(utbar OR utcond3," Also note that A wide spread  
down-bar that appears immediately after any up-thrust, tends to confirm the weakness (the market makers are  
locking in traders into poor positions). 
With the appearance of an upthrust you should  
certainly be paying attention to your trade AND your stops. On many upthrusts you will find that the market will  
'test' almost immediately.","")+WriteIf(utcond1 , "A wide spread down bar following a Upthrust Bar. 
This confirms weakness. The Smart Money is locking in Traders into poor positions",""); 
WriteIf(utcond2 , "Also here the volume is high( Above Average).This is a sure sign of weakness. The Smart Money is  
locking in Traders into poor positions","")+WriteIf(stdn, "Strength Bar. The stock has been in a down Trend. An upbar  
with higher Volume closing near the High is a sign of strength returning. The downtrend is likely to reverse soon. ","")+ 
WriteIf(stdn1,"Here the volume is very much above average. This makes this indication more stronger. ","")+  
WriteIf(bycond,"The previous bar saw strength coming back. This upbar confirms strength. ","")+ 
WriteIf(Hutbar," A pseudo Upthrust. This normally appears after an Up Bar with above average volume. This looks like an upthrust bar 
closing down near the Low. But the Volume is normally Lower than average. this is a sign of weakness.If the Volume is High then weakness  
increases. Smart Money is trying to trap the retailers into bad position. ","")+ 
WriteIf(Hutcond, "A downbar after a pseudo Upthrust Confirms weakness. If the volume is above average the weakness is increased. ","")+ 
WriteIf(Lvtbar2,"The previous bar was a successful Test of supply. The current bar is a upbar with higher volume. This confirms strength","")+ 
WriteIf(dbar,"A wide range, high volume bar in a up trend closing down is an indication the Distribution is in progress. The smart money 
is Selling the stock to the late Comers rushing to Buy the stock NOT to be Left Out Of a Bullish move. ","")+ 
WriteIf(Lvtbar2,"The previous bar was a successful Test of supply. The current bar is a upbar with higher volume. This confirms strength","")+ 
WriteIf(tcbar,"The stock has been moving up on high volume. The current bar is a Downbar with high volume. Indicates weakness and probably end of the up move","")+ 
WriteIf(eftup,"Effort to Rise bar. This normally found in the beginning of a Markup Phase and is bullish sign.These may be found at the top of an Upmove as the Smart money makes a  
last effort to move the price to the maximum","")+ 
WriteIf(eftdn,"Effort to Fall bar. This normally found in the beginning of a Markdown phase.","")+ 
  
WriteIf(nsbar,"No Supply. A no supply bar indicates supply has been removed and the Smart money can markup the price. It is better to wait for confirmation","")+ 
WriteIf(stvol,"Stopping Volume. This will be an downbar during a bearish period closing towards the Top accompanied by High volume. 
A stopping Volume normally indicates that smart money is absorbing the supply which is a Indication that they are Bullishon the MArket. 
Hence we Can expect a reversal in the down trend. ","")+ 
WriteIf(ndbar, "No Demand 
Brief Description: 
Any up bar which closes in the middle OR Low, especially if the Volume has fallen off,  
is a potential sign of weakness. 
  
Things to Look Out for: 
if the market is still strong, you will normally see signs of strength in the next few bars,  
which will most probably show itself as a: 
* Down bar with a narrow spread, closing in the middle OR High.  
* Down bar on Low Volume.","");  
_SECTION_END();  
  
//========================================================================================= 

//TITLE 
_SECTION_BEGIN("Title"); 
if( Status("action") == actionIndicator )  
( 
Title = EncodeColor(colorWhite)+ "Volume Price Analysis" + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) + 
 "  - " + Date() +" - " +EncodeColor(colorLime)+ "Volume= "+WriteVal(V)+"--"+EncodeColor(colorYellow)+ 
WriteIf (utbar, " An Upthrust Bar. A sign of weakness. ","")+ 
WriteIf (utcond1, " A downbar after an Upthrust. Confirm weakness. ","")+ 
WriteIf (utcond2 AND NOT utcond1, " A High Volume downbar after an Upthrust. Confirm weakness.","")+ 
WriteIf (utcond3, "This upthrust at very High Voume, Confirms weakness","")+ 
WriteIf (stdn1, "Strength seen returning after a down trend. High volume adds to strength. ","")+ 
WriteIf (stdn0 AND NOT stdn, "Strength seen returning after a down trend. ","")+ 
WriteIf (stdn AND NOT stdn1, "Strength seen returning after a long down trend. ","")+ 
WriteIf (Lvtbar, "Test for supply. ","")+ 
WriteIf (Lvtbar2, "An Upbar closing near High after a Test confirms strength. ","")+ 
WriteIf (bycond, "An Upbar closing near High. Confirms return of Strength. ","")+ 
WriteIf (dbar, "A High Volume Up Bar closing down in a uptrend shows Distribution. ","")+ 
WriteIf (Hutbar, "Psuedo UpThrust.   A Sign of Weakness. ","")+ 
WriteIf (Hutcond, "A Down Bar closing down after a Pseudo Upthrust confirms weakness. ","")+ 
WriteIf (Lvtbar1, "Test for supply in a uptrend. Sign of Strength. ","")+ 
WriteIf (stdn2, "High volume upbar closing on the high indicates strength. ","")+ 
WriteIf (Tcbar, "High volume Downbar after an upmove on high volume indicates weakness. ","")+ 
WriteIf (ndbar, "No Demand. A sign of Weakness. ","")+ 
WriteIf (nsbar, "No Supply. A sign of Strength. ","")+ 
WriteIf (eftup, "Effort to Rise. Bullish sign ","")+ 
WriteIf (eftdn, "Effort to Fall. Bearish sign ","")+ 
WriteIf (eftupfl, "Effort to Move up has failed. Bearish sign ","")+ 
WriteIf (stvol, "Stopping volume. Normally indicates end of bearishness is nearing. ","")+ 
("\n Volume: ")+WriteIf(V>Vp2,EncodeColor(colorLime)+"Very High",WriteIf(V>Vp1,EncodeColor(colorLime)+" High",WriteIf(V>Vrg,EncodeColor(colorLime)+"Above Average", 
WriteIf(V<Vrg AND V>Vn1,EncodeColor(colorRed)+"Less than Average",WriteIf(V<Vn1,"Low","")))))+ 
(EncodeColor(colorYellow)+"      Spread: ")+WriteIf(rg >(arg*2),EncodeColor(colorLime)+" Wide",WriteIf(rg>arg,EncodeColor(colorLime)+" Above Average",EncodeColor(colorRed)+" Narrow"))+ 
(EncodeColor(colorYellow)+"      Close:  ")+WriteIf(Vhcls,EncodeColor(colorLime)+"Very High",WriteIf(ucls,EncodeColor(colorLime)+"High",WriteIf(mcls,EncodeColor(colorYellow)+"Mid", 
WriteIf(dcls,EncodeColor(colorRed)+"Down","Very Low"))))+ 
("\n Trend: ")+WriteIf(tls>0,EncodeColor(colorLime)+"  Short Term-UP",EncodeColor(colorRed)+"  Short Term-Down")+ 
WriteIf(tlm>0,EncodeColor(colorLime)+"         MID Term-UP",EncodeColor(colorRed)+"        Mid Term-Down")+ 
WriteIf(tll>0,EncodeColor(colorLime)+"       Long Term-Up",EncodeColor(colorRed)+"         Long term-Down"));  
_SECTION_END(); 
//============================================================================================================================================================================================ 
_SECTION_BEGIN("Exploration"); 
  
Filter= utbar OR utcond2 OR utcond3 OR stdn OR stdn0 OR stdn1 OR stdn2; 
  
AddColumn(utcond3,"weekness coming in",1,colorWhite,IIf(utcond3,colorRed,colorWhite)); 
AddColumn(utcond2,"sure weakness",1,colorWhite,IIf(utcond2,colorRed,colorWhite)); 
AddColumn(utbar,"sure weakness",1,colorWhite,IIf(utbar,colorRed,colorWhite)); 
AddColumn(stdn ,"Strength after long dtrend",1,colorWhite,IIf(stdn,colorLime,colorWhite)); 
AddColumn(stdn0 ,"Strength after dtrend",1,colorWhite,IIf(stdn0,colorLime,colorWhite)); 
AddColumn(stdn1 ,"Strength stronger",1,colorWhite,IIf(stdn1,colorLime,colorWhite)); 
AddColumn(stdn2 ,"strength",1,colorWhite,IIf(stdn2,colorLime,colorWhite)); 
_SECTION_END(); 
//===================================================================== 
//background stock name (works only on Amibroker version 5.00 onwards. 
//===================================================================== 
_SECTION_BEGIN("Name"); 
//GfxSetOverlayMode(1); 
//GfxSelectFont("Tahoma", Status("pxheight")/6 ); 
//GfxSetTextAlign( 6 );// center alignment 
//GfxSetTextColor( ColorRGB( 200, 200, 200 ) ); 
//GfxSetTextColor( ColorHSB( 42, 42, 42 ) ); 
//GfxSetBkMode(0); // transparent 
//GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/12 ); 
//GfxSelectFont("Tahoma", Status("pxheight")/12 ); 
//GfxTextOut( "VPA", Status("pxwidth")/2, Status("pxheight")/3 ); 
//GfxSelectFont("Tahoma", Status("pxheight")/36 ); 
//GfxTextOut( "www.vpanalysis.blogspot.com", Status("pxwidth")/2, Status("pxheight")/2 ); 
_SECTION_END(); 
//====================================================================================== 
  
_SECTION_BEGIN("VOLUME1"); 
Codename = "Volume - 4 Color" ; 
  
 // Color Conditions 
  
 Upgreen = C > Ref( C, -1 ) AND C > O ; 
  
 DownRed = C <= Ref( C, -1 ) AND C < O; 
  
 UpPurple = C > Ref( C, -1 ) AND C < O; 
  
DownBlue = C <= Ref( C, -1 ) AND C > O; 
  
 VColor = IIf( UpGreen, colorGreen, IIf( DownRed, colorRed, IIf( UpPurple, 
 colorPlum, colorBlue ) ) ); 
  
 VStyle  = ParamStyle( "Volume Style", styleHistogram | styleOwnScale | 
 styleThick | styleNoLabel, maskHistogram ) ; 
  
 VHeight = Param( "1/N Height", 4, 1, 10, 0.5 ); 
  
 Plot( V, "   Volume", VColor, VStyle, VHeight ); 
_SECTION_END();

Title = Name()+ " Price Break Indicator." ;
//+ "  Trend is " + Trend_Text + ".  SEQUENCE IS " + Sequence_Text;
Plot(C,Title,colorBlack,styleCandle);

/////////   Parameters  ////////

nBars_To_Scan = Param("Number of bars to Scan",50, 10,480, 10);		//Number of bars to include in scan
PB_Interval = Param("Number of Bars for Price Break",3,2,3,1);

/////////  Use Array of Prices and Price Breaks to Look Back and Determine What Price Break is For Current Bar
Seedbar = nBars_To_Scan + 1;					//Need an initial value to start the PB process
if (BarCount > Seedbar) 						//Make sure there are enough bars available to evaluate
{
											
Price[0]= LastValue(Ref(C,-Seedbar));			//Seed the 0 Bar in the Array with Values
Trend[0]=1;										//1 = Long, 0=Short
Sequence[0]=0;									//Sequence counter - counts number of new price breaks
Price_Break[0] = LastValue(Ref(C,-Seedbar));
High_C1[0] = LastValue(Ref(C,-Seedbar));		//Highest Close 1 Ago
High_C2[0]= LastValue(Ref(C,-Seedbar));			//Highest Close 2 Ago
High_C3[0]= LastValue(Ref(C,-Seedbar));			//Highest Close 3 Ago
Low_C1[0] = LastValue(Ref(C,-Seedbar));			//Lowest Close 1 Ago
Low_C2[0] = LastValue(Ref(C,-Seedbar));			//Lowest Close 2 Ago
Low_C3[0] = LastValue(Ref(C,-Seedbar));			//Lowest Close 3 Ago
											
for ( i=1; i < Seedbar ; i++) 	 
{											
	Prior = i-1;									//Index for Prior entry in array.  Set the current array values to 
	Trend[i]=Trend[Prior];						//prior values to make sure everything that isn't changed later
	Price_Break[i] = Price_Break[Prior];			//gets carried forward to the next row in the array.
			Low_C1[i] = Low_C1[Prior]; 			//Carryover current values
			Low_C2[i] = Low_C2[Prior];
			Low_C3[i] = Low_C3[Prior];  
			High_C1[i] = High_C1[Prior];			//Carryover current values
			High_C2[i] = High_C2[Prior];
			High_C3[i] = High_C3[Prior];
			Sequence[i] = Sequence[Prior];

	Price[i] = LastValue (Ref (C,-(Seedbar-i)));	//Seedbar is the bar just in front of where I start the method.  Works since i starts at 1

	if (Price[i] >Price[Prior] AND Trend[Prior] == 1 )	// If Close is Greater than the prior close And the Trend is Long
	{		if (Price[i] >High_C1[Prior])			//If the Close is greater than the last highest close
			{									//Test For Price Break.  The IIF is there to accomodate a 2 price or 3 price break option
												//based on the PB_Interval parameter
			Price_Break[i] = IIf(PB_Interval == 3,High_C3[Prior],IIf(PB_Interval == 2,High_C2[Prior],High_C3[Prior]));	
												//The 3PB method says I take the highest close 4 ago as the new price break.
			Sequence[i] = Sequence[i] + 1;		//Increment Sequence if Price Break
			High_C3[i] = High_C2[Prior];			//Stacking the higher closes like this avoids having to go back and iterate through the.
			High_C2[i] = High_C1[Prior];			//closes to find and count the higher closes.  They are just carried forward in the stack.
			High_C1[i] = Price[i];				//When a higher close occurs, it is put on the top of the stack, each close below is
			}									//pushed down in sequence, and the earliest (farthest back) close goes away.
	}		

	if (Price[i] >Price[Prior] AND Trend[Prior] == 0 )	// If Close is Greater than the prior close And the Trend is Short
	{		if (Price[i] >Price_Break[Prior])		//If Close > Price Break in trend is Short, Reverse and go Long
			{
			High_C1[i] = High_C2[i] = High_C3[i] = Price[i];				//Initialize sequence of new Highs
			Price_Break[i] = Price[i];				//Set new value for Price Break
			Trend[i] = 1;							//Set the trend Long
			Sequence = 0;
			}
	}		

	if (Price[i] <Price[Prior] AND Trend[Prior] ==0)	// If The Close is less than the prior close And the Trend is Short
	{		if (Price[i] <Low_C1[Prior])			//If the Close is less than the last lowest close
			{
			Price_Break[i] = IIf(PB_Interval == 3,Low_C3[Prior],IIf(PB_Interval == 2,Low_C2[Prior],Low_C3[Prior]));	//Test For Price Break
			Sequence[i] = Sequence[i] + 1;		//Increment Sequence if Price Break
			Low_C3[i] = Low_C2[Prior];			//Update sequence of new Lows
			Low_C2[i] = Low_C1[Prior];
			Low_C1[i] = Price [i];
			}
	}		

	if (Price[i] <Price[Prior] AND Trend[Prior] ==1)	// If The Close is less than the prior close And the Trend is Long
	{		if (Price[i] < Price_Break[Prior])				//If Close < Price Break in Long Trend, reverse and go Short
			{
			Low_C1[i] = Low_C2[i] = Low_C3[i] = Price[i];	//Initialize sequence of new Lows
			Price_Break[i] = Price[i];							//Set new value for Price Break
			Trend[i] = 0;								//Set Trend Short
			Sequence = 0;
			}
	}		

////  Plot the Price Breaks.
Bar_x1=BarCount - (nBars_To_Scan - Prior );
Bar_x2=BarCount - ( nBars_To_Scan - i);
PB_Color = IIf(Trend[i] == 1,colorGreen, colorRed);
Plot(LineArray(Bar_x1,Price_Break[i],Bar_x2,Price_Break[i],extend=0),"",PB_Color,styleThick);
Sequence_Text = NumToStr(Sequence,format=1.0);
Trend_Text = WriteIf(Trend[i] > 0, "Long","Short");

}			

}										

PositionSize = MarginDeposit = 1; 
CommissionMode = 1; 
MA1Length = Optimize("MA fast",Param("MA SZYBKA",27,3,60,1),3,60,1); 
MA2Length = Optimize("MA medium",Param("MA SREDNIA",60,40,135,1),40,135,2); 
MA3Length = Optimize("MA slow",Param("MA WOLNA",95,40,350,1),50,250,3); 
XXLength =1; //Optimize("MnoznikMA11",Param("mnoznikMA1",1,0.90,1.1,0.005),0.9,1.1,0.005); 
ma_type = ParamList("Rodzaj rednich", "TEMA|MA|EMA|DEMA|WMA|TSF|Wilders|LinearReg|Hull", 0); 
if(ma_type == "Hull") { MA1 = WMA(2*(WMA(C, MA1Length/2))-WMA(C, MA1Length) ,4 ); MA2 = WMA(2*(WMA(C, MA2Length/2))-WMA(C, MA2Length) ,4 ); MA3 = WMA(2*(WMA(C, MA3Length/2))-WMA(C, MA3Length) ,4 ); } 
if(ma_type == "MA") { MA1 = MA(C,MA1Length); MA2 = MA(C,MA2Length); MA3 = MA(C,MA3Length); } 
if(ma_type == "LinearReg") { MA1 = LinearReg(C,MA1Length); MA2 = LinearReg(C,MA2Length); MA3 = LinearReg(C,MA3Length); } 
if(ma_type == "EMA") { MA1 = EMA(C,MA1Length); MA2 = EMA(C,MA2Length); MA3 = EMA(C,MA3Length); } 
if(ma_type == "DEMA") { MA1 = DEMA(C,MA1Length); MA2 = DEMA(C,MA2Length); MA3 = DEMA(C,MA3Length); } 
if(ma_type == "WMA") {MA1 = WMA(C,MA1Length); MA2 = WMA(C,MA2Length); MA3 = WMA(C,MA3Length); } 
if(ma_type == "TSF") { MA1 = TSF(C,MA1Length); MA2 = TSF(C,MA2Length); MA3 = TSF(C,MA3Length); } 
if(ma_type == "TEMA") { MA1 = TEMA(C,MA1Length); MA2 = TEMA(C,MA2Length); MA3 = TEMA(C,MA3Length); } 
if(ma_type == "Wilders") { MA1 = Wilders(C,MA1Length); MA2 = Wilders(C,MA2Length); MA3 = Wilders(C,MA3Length); } 
cond1 = Flip( MA1 < MA2 AND MA1 < MA3 , MA1 > MA2 AND MA1 > MA3 ); 
cond2 = Flip(MA1 > MA2 AND MA1 > MA3, MA1 < MA2 AND MA1 < MA3); 
Buy = MA1 > MA2 AND MA1 > MA3 AND Ref(Cond1,-1);  
Sell = MA1 < MA2 OR MA1 < MA3 ;  
Short = MA1 < MA2 AND MA1 < MA3 AND Ref(Cond2,-1);  
Cover = MA1 > MA2 OR MA1 > MA3; 
Buy = ExRem (Buy,Sell); Sell = ExRem(Sell,Buy); Short = ExRem(Short, Cover); Cover = ExRem(Cover, Short); 

// 
_SECTION_BEGIN("price style"); 
SetChartOptions(0,chartShowArrows|chartShowDates); 
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " + 
WriteVal( V, 1.0 ) + 
" {{VALUES}}",  
O, H, L, C, SelectedValue( ROC( C, 1 )) )); 
Plot( C, "Close", ParamColor("Color", colorBlack ),  
ParamStyle("Style",styleNoTitle|styleCandle,maskAll) ); 
_SECTION_END(); 
  
_SECTION_BEGIN(); 
  
//eliminacja powtarzajacych sie sygnalow 
//Buy = ExRem (Buy,Sell); Sell = ExRem(Sell,Buy); Short = ExRem(Short, Cover); Cover = ExRem(Cover, Short); 
ShowTriangles = ParamToggle( "Pokaz sygnaly", "HIDE|SHOW", 1 ); 
if ( showTriangles ) { 
PlotShapes(Buy * shapeUpArrow, colorGreen, 0, Low);  
PlotShapes(Short * shapeDownArrow, colorRed, 0, High);  
PlotShapes(Sell * shapeSmallDownTriangle, colorRed, 0, High);   
PlotShapes(Cover * shapeSmallUpTriangle, colorGreen, 0, Low); } 
/////////////////// 
_SECTION_END(); 

5 comments

1. rajaswamy

not working

2. godbeest

NOT WORKING
ADMINISTRATOR !!!!!!!!!
ERORRRRRRRRR

3. rh0390

temp = temp + data_centred[j]*data_centred[j+i];
Line 772 (from above line) it sows error msg

4. godbeest

Review CODE
TANKS .

5. szgolyas

line 1667 error

Leave Comment

Please login here to leave a comment.

Back