arrows_&_curves_v.28_lukas1
Download scriptThis script functions as a visual trading assistant designed to identify market trends and provide specific entry and exit signals on a price chart. It operates by analyzing the relationship between current price action and historical highs and lows over a defined period.
Core Logic and Methodology
Dynamic Channel Analysis The script calculates "channels" based on the highest high and lowest low of the market over a specific number of bars (the Lookback Period). Rather than just looking at the extreme points, it creates boundaries—essentially corridors—around these prices. By adjusting the "Channel" parameters, users can determine how tightly or loosely these boundaries hug the price action.
Trend Identification The logic distinguishes between two types of trends:
- Primary Trend: This is determined by comparing the closing price against the primary channel boundaries. When the price breaks out of these limits, the script identifies a shift in the general market direction.
- Extended/Stop Channel: The script also calculates a secondary, wider set of boundaries (a "Stop Channel"). This acts as a buffer to help differentiate between minor price fluctuations and significant trend reversals.
Visual Signal Generation The script translates these mathematical calculations into several visual elements on the chart:
- Directional Arrows: These appear when the price breaks through the primary channel boundaries. They serve as the main signals for potential "Buy" or "Sell" opportunities.
- Trend Lines: The script draws constant lines representing the current high and low boundaries of the channels, allowing traders to see the "ceiling" and "floor" of the current market move in real-time.
- Crosses (Markers): These symbols serve two distinct purposes:
- They mark specific points where a trade signal is triggered based on the secondary "Stop Channel."
- They act as markers for repeating signals, helping traders identify instances where the price remains in a specific direction without a full trend reversal.
Technical Refinements To ensure the signals are as reliable as possible, the script includes a "Relay" logic. This slightly offsets the data calculation to smooth out minor noise and prevent the indicator from reacting too aggressively to instantaneous price spikes. It also uses internal memory (Global Variables) to track the current state of the market, ensuring that it recognizes whether a trend is already active or if a new move is beginning.
//+------------------------------------------------------------------+
//| lukas1 arrows & curves.mq4 v.28
//| Copyright © 2007, Ëóêàøóê Âèêòîð Ãåííàäüåâè÷ aka lukas1
//+------------------------------------------------------------------+
//1. Äëÿ ëèíèé ââåäåíà çàäåðæêà, ïðèâîäÿùàÿ ê ñìåùåíèþ âïðàâî ("relay")
//2. Ïîÿâèëèñü êðåñòèêè, îáîçíà÷àþùèå çàêðûòèå ñäåëêè
//3. Ïîâòîðíûå îðäåðà â òîì æå íàïðàâëåíèè îòìå÷åíû òàê æå êðåñòèêàìè
#property copyright "Copyright © 2007, MetaQuotes Software Corp.+lukas1"
#property link "lukas1@ngs.ru"
//----
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Red
#property indicator_color3 Orange
#property indicator_color4 Orange
#property indicator_color5 MediumSeaGreen
#property indicator_color6 MediumSeaGreen
#property indicator_color7 DeepSkyBlue
#property indicator_color8 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width7 2
#property indicator_width8 2
//---- input parameters
extern int SSP = 20; //ïåðèîä ëèíåéíîãî ðàçâîðîòà èíäèêàòîðà
extern int Channel = 0; //óìåíüøåíèå äèàïàçîíà êàíàëà. Ä.á. â äèàïàçîíå 0-50
extern int Ch_Stop = 30; //óìåíüøåíèå ñòîïîâîãî êàíàëà (ñóììèðóåòñÿ ñ îñíîâíûì)
extern int relay = 10; //ñìåùåíèå ëèíèé âãëóáü èñòîðèè íà 4 áàðà
extern int CBars = 2000; //ðàñ÷åòíûé ïåðèîä
int i;
double high, low, smin, smax, smin2, smax2;
double val1[]; // áóôåð äëÿ áàé
double val2[]; // áóôåð äëÿ ñåëë
double BufferH[];
double BufferL[];
double BufferHS[];
double BufferLS[];
double valX1[],valX2[]; // áóôåð äëÿ X
bool uptrend, old, uptrend2, old2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0, DRAW_ARROW,0,1);
SetIndexArrow(0, 233); // ñòðåëêà äëÿ áàé
SetIndexBuffer(0, val1); // èíäåêñ áóôåðà äëÿ áàé
SetIndexLabel(0, "BUY");
SetIndexDrawBegin(0, Bars-CBars-2*SSP);
SetIndexStyle(1, DRAW_ARROW,0,1);
SetIndexArrow(1, 234); // ñòðåëêà äëÿ ñåëë
SetIndexBuffer(1, val2); // èíäåêñ áóôåðà äëÿ ñåëë
SetIndexLabel(1, "SELL");
SetIndexDrawBegin(1, Bars-CBars-2*SSP);
SetIndexStyle(2, DRAW_LINE,0,1);
SetIndexBuffer(2, BufferH);
SetIndexLabel(2, "BUY from here");
SetIndexDrawBegin(2, Bars-CBars-2*SSP);
SetIndexStyle(3, DRAW_LINE,0,1);
SetIndexBuffer(3, BufferL);
SetIndexLabel(3, "SELL from here");
SetIndexDrawBegin(3, Bars-CBars-2*SSP);
SetIndexStyle(4, DRAW_LINE,0,1);
SetIndexBuffer(4, BufferHS);
SetIndexLabel(4, "BuyStop");
SetIndexDrawBegin(4, Bars-CBars-2*SSP);
SetIndexStyle(5, DRAW_LINE,0,1);
SetIndexBuffer(5, BufferLS);
SetIndexLabel(5, "SellStop");
SetIndexDrawBegin(5, Bars-CBars-2*SSP);
SetIndexStyle(6, DRAW_ARROW,0,2);
SetIndexArrow(6, 251); // êðåñòèê ñèíèé
SetIndexBuffer(6, valX1); // èíäåêñ áóôåðà äëÿ êðåñòèêà
SetIndexDrawBegin(6, Bars-CBars-2*SSP);
SetIndexStyle(7, DRAW_ARROW,0,2);
SetIndexArrow(7, 251); // êðåñòèê êðàñíûé
SetIndexBuffer(7, valX2); // èíäåêñ áóôåðà äëÿ êðåñòèêà
SetIndexDrawBegin(7, Bars-CBars-2*SSP);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Calculation of Channel lines
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
//---- ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
if(counted_bars > 0) counted_bars--;
//----
if(Bars <= SSP + 1) return(0);
//----
uptrend =false;
old =false;
uptrend2 =false;
old2 =false;
GlobalVariableSet("goSELL", 0); // çàäàëè ñóùåñòâîâàíèå è îáíóëèëè goSELL=0
GlobalVariableSet("goBUY", 0); // çàäàëè ñóùåñòâîâàíèå è îáíóëèëè goBUY =0
GlobalVariableSet("stSELL", 0); // çàäàëè ñóùåñòâîâàíèå è îáíóëèëè stSELL=0
GlobalVariableSet("stBUY", 0); // çàäàëè ñóùåñòâîâàíèå è îáíóëèëè stBUY =0
//----
for(i = CBars - SSP; i >= 0; i--) // óìåíüø çíà÷åíèå shift íà 1 çà ïðîõîä;
{
high = High[Highest(Symbol(),0,MODE_HIGH,SSP,i+relay)];
low = Low[Lowest(Symbol(),0,MODE_LOW,SSP,i+relay)];
smax = high - (high - low)*Channel / 100; // smax íèæå high ñ ó÷åòîì êîýôô.Channel
smin = low + (high - low)*Channel / 100; // smin âûøå low ñ ó÷åòîì êîýôô.Channel
smax2= high - (high - low)*(Channel+Ch_Stop) / 100; // smax íèæå high ñ ó÷åòîì êîýôô.Chan+Ch_Stop
smin2= low + (high - low)*(Channel+Ch_Stop) / 100; // smin âûøå low ñ ó÷åòîì êîýôô.Channel
val1[i] = 0;
val2[i] = 0;
valX1[i] = 0;
valX2[i] = 0;
//-----------------------
if(Close[i] < smin && Close[i] < smax && uptrend2 == true && i!=0 ) // âûêëþ÷åíî ìåðöàíèå ñòðåëîê (i!=0)
{
uptrend = false;
}
if(Close[i] > smax && Close[i] > smin && uptrend2 == false && i!=0 ) // âûêëþ÷åíî ìåðöàíèå ñòðåëîê (i!=0)
{
uptrend = true;
}
if((Close[i] > smax2 || Close[i] > smin2) && uptrend == false && i!=0 ) // âûêëþ÷åíî ìåðöàíèå ñòðåëîê (i!=0)
{
uptrend2 = false;
}
if((Close[i] < smin2 || Close[i] < smax2) && uptrend == true && i!=0 ) // âûêëþ÷åíî ìåðöàíèå ñòðåëîê (i!=0)
{
uptrend2 = true;
}
//---- ïîâòîðíûé ñèãíàë íå ïåðåêëþ÷àåò ðåæèìû "uptrend"
//---- íî èñïîëüçóåòñÿ ñèãíàë ïî êðåñòèêàì
if(Close[i] < smin && Close[i] < smax && uptrend2 == false && i!=0 ) // âûêëþ÷åíî ìåðöàíèå ñòðåëîê (i!=0)
{
val2[i] = low; // åñëè óñëîâèÿ âûïîëíåíû òî ðèñóåì val2
if(i == 0) GlobalVariableSet("goSELL",1);
uptrend2 = true;
}
//---- ïîâòîðíûé ñèãíàë íå ïåðåêëþ÷àåò ðåæèìû "uptrend"
//---- íî èñïîëüçóåòñÿ ñèãíàë ïî êðåñòèêàì
if(Close[i] > smax && Close[i] > smin && uptrend2 == true && i!=0 ) // âûêëþ÷åíî ìåðöàíèå ñòðåëîê (i!=0)
{
val1[i] = high; // åñëè óñëîâèÿ âûïîëíåíû òî ðèñóåì val1
if(i == 0) GlobalVariableSet("goBUY",1);
uptrend2 = false;
}
//----
if(uptrend != old && uptrend == false)
{
val2[i] = low; // åñëè óñëîâèÿ âûïîëíåíû òî ðèñóåì val1
if(i == 0) GlobalVariableSet("goSELL",1);
}
if(uptrend != old && uptrend == true)
{
val1[i] = high; // åñëè óñëîâèÿ âûïîëíåíû òî ðèñóåì val2
if(i == 0) GlobalVariableSet("goBUY",1);
}
//----
if(uptrend2 != old2 && uptrend2 == true)
{
valX1[i] = smax2; // åñëè óñëîâèÿ âûïîëíåíû òî ðèñóåì valX1
if(i == 0) GlobalVariableSet("stBUY",1);
}
if(uptrend2 != old2 && uptrend2 == false)
{
valX2[i] = smin2; // åñëè óñëîâèÿ âûïîëíåíû òî ðèñóåì valX2
if(i == 0) GlobalVariableSet("stSELL",1);
}
//-----------------------
old=uptrend;
old2=uptrend2;
//-----------------------
BufferH[i]=smax;
BufferL[i]=smin;
BufferHS[i]=smax2;
BufferLS[i]=smin2;
}
return(0);
}
//+------------------------------------------------------------------+
Comments