Author: Lukas1+Silver+CrazyChart
lukas1

This script is a technical analysis tool designed to identify market trends and generate specific trading signals (Buy and Sell) based on price action, volatility, and structural boundaries. Instead of looking at simple moving averages, it uses a combination of "Sky Channels" and dynamic price zones to determine when the market is shifting direction.

Here is a breakdown of the logic used by the script:

1. Dynamic Channel Construction (Sky Channels)

The tool first establishes two primary boundary lines on the chart. It calculates these based on the highest highs and lowest lows over a specific look-back period (defined by the user).

  • Upper and Lower Bounds: It creates "Sky Channels" by calculating a percentage offset from the extreme high and low prices.
  • Visual Mapping: These lines act as the structural "walls" of the current market price action, helping to visualize the territory where the price is currently trading.

2. Volatility and Range Analysis

To ensure the signals are relevant to the current market speed, the script calculates a Range Value. It looks at the average size of the candles (the distance between high and low prices) over a set number of bars. This helps the tool understand how much the market is "moving" at any given moment, allowing it to adjust its signal placement accordingly.

3. Risk-Adjusted Trend Detection

The core logic relies on identifying when the price breaks out of specific zones.

  • The Risk Factor: The script uses a "Risk" percentage to create a buffer zone. It calculates a maximum and minimum level based on recent price history, but it adjusts these levels using the risk parameter. This prevents the tool from triggering signals on minor, insignificant price fluctuations (market noise).
  • Trend State: The script maintains an internal memory of the current trend state (Up or Down). It continuously compares the closing price against the calculated risk-adjusted boundaries.

4. Signal Generation (Arrows and Global Variables)

The script generates visual and data signals based on "State Changes"—specifically, when the market flips from one trend to another.

  • Buy Signal: When the price closes above the upper risk boundary after being in a downtrend, it marks a "True" uptrend. A blue arrow is plotted on the chart at the bottom of that candle, and a global variable is updated to notify other systems (like automated robots) that a Buy signal has occurred.
  • Sell Signal: When the price closes below the lower risk boundary after being in an uptrend, it marks a "False" uptrend (downtrend). A red arrow is plotted at the top of that candle, and a global variable is updated to signal a Sell.

Summary for the User

In simple terms, this tool watches the market's boundaries and its current volatility. When the price "breaks out" of these boundaries with enough force to overcome the risk buffer, the script identifies a trend reversal. It then paints an arrow on your chart to highlight the entry point and sends a signal to the platform that a trade opportunity has been identified.

Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
lukas1
//+------------------------------------------------------------------+
//|                                       lukas1 arrows & curves.mq4 |
//|            Èäåÿ from Silver, Ramdass  åùå è Lukas1 ðóêó ïðèëîæèë |
//|                                                       ..... v3e  |
//|          Ãëîáàëüûå ïåðåìåííûå åñòü. ïî íèì òîðãóåò ñîâåòíèê Rosa |
//+------------------------------------------------------------------+
#property copyright "Lukas1+Silver+CrazyChart"
#property link      "http://viac.ru/"
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Green
//---- input parameters
extern int SSP       = 19;    //ïåðèîä ëèíåéíîãî ðàçâîðîòà èíäèêàòîðà
extern int RISK      = 3;
extern int CountBars = 18250; //ðàñ÷åòíûé ïåðèîä - äëÿ 30 ìèí áîëüøå ãîäà
extern double SkyCh = 23.6;
//----
int Shift = 0;
int TSP = 9;
int PrevAlertTime;
double smin, smax;
//---- buffers
double val1[];      // áóôåð äëÿ áàé
double val2[];      // áóôåð äëÿ ñåëë
double Sky_BufferH[];
double Sky_BufferL[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 233);        // ñòðåëêà äëÿ áàé
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 234);        // ñòðåëêà äëÿ ñåëë
   SetIndexBuffer(0, val1);      // èíäåêñ áóôåðà äëÿ áàé
   SetIndexBuffer(1, val2);      // èíäåêñ áóôåðà äëÿ ñåëë
//----
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, Sky_BufferH);
   SetIndexShift(2, Shift);
   SetIndexLabel(2, "Sky-channel High");
//----
   SetIndexStyle(3, DRAW_LINE);
   SetIndexBuffer(3, Sky_BufferL);
   SetIndexShift(3, Shift);
   SetIndexLabel(3, "Sky-channel Low");
//----
   if(CountBars >= Bars) 
       CountBars=Bars;     // CountBars ðàâíî êîëè÷åñòâó áàðîâ íà ãðàôèêå
// äëÿ êðèâîé "0"- ñàìî ðèñîâàíèå; íå ðàñ÷èòûâàòü ïåðâûå SSP áàðîâ (ñíà÷àëà SSP=9)
   SetIndexDrawBegin(0, Bars - CountBars + SSP);
// äëÿ êðèâîé "1"- ñàìî ðèñîâàíèå; íå ðàñ÷èòûâàòü ïåðâûå SSP áàðîâ (ñíà÷àëà SSP=9)
   SetIndexDrawBegin(1, Bars - CountBars + SSP);
   SetIndexDrawBegin(2, SSP + Shift - 1);
   SetIndexDrawBegin(3, SSP + Shift - 1);      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| SilverTrend_Signal                                               |
//+------------------------------------------------------------------+
int start()
  {   
   int    i;
   int    shift;                             // ðàñ÷åòíîå ñìåùåíèå
   int    counted_bars = IndicatorCounted(); // òåêóùèé áàð äëÿ ðàñ÷åòà èíäèêàòîðà
   int    i1;
   int    i2;
   int    K, k;
   double Range, AvgRange, SsMax, SsMin, price;
   bool   uptrend, old;
   double high, low;
//----
   if(Bars <= SSP + 1) 
       return(0);
//---- initial zero
   if(counted_bars < SSP + 1) 
     {
       for(i = 1; i <= SSP; i++) 
           val1[CountBars-i] = 0.0;   // îáíóëèëè ìàññèâ val1
       //----
       for(i = 1; i <= SSP; i++) 
           val2[CountBars-i]=0.0;     // îáíóëèëè ìàññèâ val2
       //----
       for(i = 1; i <= SSP; i++) 
         {
           Sky_BufferH[Bars-i] = 0; 
           Sky_BufferL[Bars-i] = 0;
         }                 
     }
   GlobalVariableSet("xSELL", 0); // çàäàëè ñóùåñòâîâàíèå è îáíóëèëè xSELL=0
   GlobalVariableSet("xBUY", 0);  // çàäàëè ñóùåñòâîâàíèå è îáíóëèëè xBUY =0
// ñòàíäàðòíûå âû÷èñëåíèÿ äî 0-ãî áàðà
   i = Bars - SSP;
//----
   if(counted_bars > SSP) 
       i = Bars - counted_bars - 1;
//----
   while(i >= 0)
     {
       high = High[i]; 
       low = Low[i]; 
       k = i - 1 + SSP;
       //----
       while(k >= i)
         {
           price = High[k];
           //----
           if(high < price) 
               high = price;
           price = Low[k];
           //----
           if(low > price)  
               low = price;
           k--;
         } // âñå ïîñ÷èòàëè - çàïèñûâàåì çíà÷åíèÿ òî÷êè â ìàññèâ èíäèêàòîðà
       Sky_BufferL[i+Shift] = low + (high - low)*SkyCh / 100;
       Sky_BufferH[i+Shift] = high - (high - low)*SkyCh / 100;
       i--;       // äâèãàåì ñ÷åò÷èê
     } 
   i = Shift - 1; // Ñ÷èòàåì òî÷êè ñäâèãà - ñïðàâà îò íóëåâîãî i=Shift-1;
//----
   while(i >= 0)
     {
       high = High[0]; 
       low = Low[0]; 
       k = SSP - Shift - 1 + i; // êàæäûé ñëåäóþùèé óìåíüøàåò ïåðèîä k=SSP-Shift+i;
       //----
       while(k >= 0)
         {
           price = High[k];
           //----
           if(high < price) 
               high = price;
           price = Low[k];
           //----
           if(low > price)  
               low = price;
           k--;
         } // çàïèñûâàåì çíà÷åíèÿ â ìàññèâ
       Sky_BufferL[i] = low + (high - low)*SkyCh / 100;
       Sky_BufferH[i] = high - (high - low)*SkyCh / 100;
       i--;
     }
   K = 33 - RISK; 
//----
   for(shift = CountBars - SSP; shift >= 0; shift--) // óìåíüø çíà÷åíèå shift íà 1 çà ïðîõîä;
     { 
	      Range = 0;
	      AvgRange = 0;
	      //----
       for(i1 = shift; i1 <= shift + SSP; i1++) // óâåëè÷ "i1" îò shift äî (shift+SSP)
		         // ñðåäíèå êîëåáàíèÿ òåêóùèõ öåí
		         AvgRange = AvgRange + MathAbs(High[i1] - Low[i1]);   
	      Range = AvgRange / (SSP + 1); // äèàïàçîí êîëåáàíèÿ òåêóùèõ öåí
       SsMax = High[shift];          // çàäàòü SsMax
       SsMin = Low[shift];           // çàäàòü SsMin
       //----
       for(i2 = shift; i2 <= shift + SSP - 1; i2++) // óâåëè÷ "i2" îò shift äî (shift+SSP)
         {
           price = High[i2];  // çàäàòü price
           //----
           if(SsMax < price) 
               SsMax = price; // ïîäòÿíóëè SsMax äî óðîâíÿ High[i2]
           price = Low[i2];
           //----
           if(SsMin >= price)  
               SsMin = price; // ïîíèçèëè SsMin äî óðîâíÿ Low[i2]
         }
       smin = SsMin + (SsMax - SsMin)*K / 100; // smin âûøå SsMin ñ ó÷åòîì êîýôô.ðèñêà
       smax = SsMax - (SsMax - SsMin)*K / 100; // smax íèæå SsMax ñ ó÷åòîì êîýôô.ðèñêà
	      val1[shift] = 0;  // áóôåð äëÿ áàé
	      val2[shift] = 0;  // áóôåð äëÿ ñåëë
	      //----
       if(Close[shift] < smin)
		         uptrend = false;
	      //----
       if(Close[shift] > smax)
		         uptrend = true;
       //----
       if(uptrend != old && uptrend == true)
         {
           val1[shift] = Low[shift] - Range*0.5; // åñëè óñëîâèÿ âûïîëíåíû òî âû÷èñëÿåì val1
           //----
           if(shift == 0) 
               GlobalVariableSet("xBUY",1);
         }
       //----
       if(uptrend != old && uptrend == false) 
         {
           val2[shift] = High[shift] + Range*0.5; // åñëè óñëîâèÿ âûïîëíåíû òî âû÷èñëÿåì val2
           //----
           if(shift == 0) 
               GlobalVariableSet("xSELL",1);
         }
       old=uptrend;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments