Technical Logic Overview: JJN-AutoPitchforx
This script is an automated charting tool designed to identify and draw "Pitchfork" trend lines on a financial chart. It simplifies the process of technical analysis by automatically detecting significant price movements and projecting them into geometric structures without requiring manual drawing.
Core Functionality
The primary purpose of this tool is to automate the identification of market structural points (swings) and connect them based on three specific mathematical models: Andrews, Schiff, and Modified Schiff. By using these predefined methods, the script helps traders visualize potential support and resistance zones automatically.
Key Operational Steps
-
Data Gathering (ZigZag Integration): The logic begins by scanning historical price data to find "swing" points—the significant highs and lows of a market move. It uses a secondary calculation (ZigZag) to filter out minor market noise, ensuring that the pitchforks are anchored on meaningful price turns rather than every small fluctuation.
-
Automated Calculation & Projection: Once the swing points are identified, the script calculates the trajectory of the pitchfork based on the user's chosen style:
- Andrews: Anchors the lines based on a specific sequence of recent price peaks and valleys.
- Schiff / Modified Schiff: Uses mathematical averages to determine the "trend price" midpoints, creating a different geometric spread compared to the standard Andrews model.
-
Dynamic Visualization: The script is designed to refresh automatically. It constantly cleans the chart by removing old drawings and redrawing updated pitchforks as new price data arrives. This ensures that the visual information remains current with live market conditions.
-
Customizable Aesthetics: While the logic handles the heavy lifting of the calculations, it allows for high levels of visual customization. Users can define exactly how many pitchforks to display (up to 100), adjust the thickness and colors of specific lines, and modify the depth of the historical data the script analyzes.
User Experience Summary
For a non-technical user, this tool acts as an automated technical analyst. Instead of manually identifying highs and lows and drawing complex intersecting lines to find trends, the script "looks" at the history for you, identifies the major turning points, and instantly maps out multiple trend scenarios across your chart.
//+------------------------------------------------------------------+
//| JJN-AutoPitchforx.mq4 |
//| Copyright © 2010, JJ Newark |
//| http://jjnewark.atw.hu |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, JJ Newark"
#property link "http://jjnewark.atw.hu"
#property indicator_chart_window
extern string _Copyright_ = "http://jjnewark.atw.hu";
extern string _IndicatorSetup_ = ">>> Indicator Setup:<<<";
extern bool AutoRefresh = true;
extern string Help_For_Number_of_Pitchforks = "Maximum: 100";
extern int Number_of_Pitchforks = 4;
extern string Help_For_Pitchfork_Type = "Andrews: 0; Schiff: 1; Mod.Schiff: 2";
extern int Pitchfork_Type = 0;
extern int ZZ_TimeFrame = 0;
extern int ZZ_ExtDepth = 12;
extern int ZZ_ExtDeviation = 5;
extern int ZZ_ExtBackstep = 3;
extern string _DisplaySetup_ = ">>> Display Setup:<<<";
extern int Line1_Width = 2;
extern int Line2_Width = 1;
extern int Line3_Width = 1;
extern int Line4_Width = 1;
extern int Line5_Width = 1;
extern color Last1_Color = Tomato;
extern color Last2_Color = CornflowerBlue;
extern color Last3_Color = LimeGreen;
extern color Last4_Color = DarkOrange;
extern color Last5_Color = Orchid;
extern int MoreLine_Width = 1;
color P_Color[];
//int UniqueId;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Number_of_Pitchforks>100) Number_of_Pitchforks=100;
ArrayResize(P_Color,Number_of_Pitchforks+1);
MathSrand(TimeLocal());
//UniqueId=MathRand();
for(int i=1; i<=Number_of_Pitchforks; i++)
{
int R=MathFloor(MathRand()/128);
int G=MathFloor(MathRand()/128);
int B=MathFloor(MathRand()/128);
P_Color[i]=rgb2int(R,G,B);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
for(int i=1; i<=Number_of_Pitchforks; i++)
{
ObjectDelete("_Pitch"+i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
if(AutoRefresh)
{
double swingprice[];
datetime swingdate[];
double trendprice[];
datetime trenddate[];
ArrayResize(swingprice,Number_of_Pitchforks+3);
ArrayResize(swingdate,Number_of_Pitchforks+3);
ArrayResize(trendprice,Number_of_Pitchforks+3);
ArrayResize(trenddate,Number_of_Pitchforks+3);
for(int i=1; i<=Number_of_Pitchforks; i++)
{
swingprice[i]=0;
swingdate[i]=0;
trendprice[i]=0;
trenddate[i]=0;
}
int found=0;
i=0;
while(found<Number_of_Pitchforks+3)
{
if(iCustom(Symbol(),ZZ_TimeFrame,"ZigZag",ZZ_ExtDepth,ZZ_ExtDeviation,ZZ_ExtBackstep,0,i)!=0)
{
swingprice[found]=iCustom(Symbol(),ZZ_TimeFrame,"ZigZag",ZZ_ExtDepth,ZZ_ExtDeviation,ZZ_ExtBackstep,0,i);
swingdate[found]=iTime(Symbol(),ZZ_TimeFrame,i);
found++;
}
i++;
}
///////////////////////
for(i=1; i<=Number_of_Pitchforks; i++)
{
ObjectDelete("_Pitch"+i);
}
if(Pitchfork_Type==1) // Schiff
{
for(i=1; i<=Number_of_Pitchforks; i++)
{
trendprice[i]=(swingprice[i+1]+swingprice[i+2])/2;
trenddate[i]=swingdate[i+1]-((swingdate[i+1]-swingdate[i+2])/2);
ObjectCreate("_Pitch"+i,OBJ_PITCHFORK,0,trenddate[i],trendprice[i],swingdate[i],swingprice[i],swingdate[i+1],swingprice[i+1]);
ObjectSet("_Pitch"+i,OBJPROP_COLOR,P_Color[i]);
ObjectSet("_Pitch"+i,OBJPROP_WIDTH,MoreLine_Width);
//ObjectSet("_Pitch"+i,OBJPROP_BACK,TRUE); // obj in the background
}
}
if(Pitchfork_Type==2) // Modified Schiff
{
for(i=1; i<=Number_of_Pitchforks; i++)
{
ObjectCreate("_Pitch"+i,OBJ_PITCHFORK,0,swingdate[i+2],swingprice[i],swingdate[i],swingprice[i],swingdate[i+1],swingprice[i+1]);
ObjectSet("_Pitch"+i,OBJPROP_COLOR,P_Color[i]);
ObjectSet("_Pitch"+i,OBJPROP_WIDTH,MoreLine_Width);
//ObjectSet("_Pitch"+i,OBJPROP_BACK,TRUE); // obj in the background
}
}
else // Andrews
{
for(i=1; i<=Number_of_Pitchforks; i++)
{
ObjectCreate("_Pitch"+i,OBJ_PITCHFORK,0,swingdate[i+2],swingprice[i+2],swingdate[i],swingprice[i],swingdate[i+1],swingprice[i+1]);
ObjectSet("_Pitch"+i,OBJPROP_COLOR,P_Color[i]);
ObjectSet("_Pitch"+i,OBJPROP_WIDTH,MoreLine_Width);
//ObjectSet("_Pitch"+i,OBJPROP_BACK,TRUE); // obj in the background
}
}
ObjectSet("_Pitch1",OBJPROP_COLOR,Last1_Color);
ObjectSet("_Pitch1",OBJPROP_WIDTH,Line1_Width);
ObjectSet("_Pitch2",OBJPROP_COLOR,Last2_Color);
ObjectSet("_Pitch2",OBJPROP_WIDTH,Line2_Width);
ObjectSet("_Pitch3",OBJPROP_COLOR,Last3_Color);
ObjectSet("_Pitch3",OBJPROP_WIDTH,Line3_Width);
ObjectSet("_Pitch4",OBJPROP_COLOR,Last4_Color);
ObjectSet("_Pitch4",OBJPROP_WIDTH,Line4_Width);
ObjectSet("_Pitch5",OBJPROP_COLOR,Last5_Color);
ObjectSet("_Pitch5",OBJPROP_WIDTH,Line5_Width);
//////////////////////
}
//----
return(0);
}
//+------------------------------------------------------------------+
//+----------------------------------------+
//| Color making from R,G,B |
//+----------------------------------------+
int rgb2int(int R,int G,int B)
{
return(B*65536+G*256+R);
}
Comments