look4trend
Download scriptThis script is designed as a visual trading indicator for the MetaTrader platform. Its primary purpose is to identify specific patterns in price movement by analyzing the relationship between consecutive price bars (candles) on a chart. Instead of just looking at individual price points, it evaluates a sequence of four bars to determine potential momentum shifts.
Core Logic Overview
The tool scans the market history to find two distinct types of price "engulfing" patterns:
1. Sell Signals (Bearish Patterns) The script looks for a specific sequence where a significant downward move occurs immediately following three upward moves. Specifically, it identifies a situation where:
- The most recent bar shows a clear price drop.
- The three bars preceding it were all upward moves.
- Crucially, the magnitude of the recent drop is greater than or equal to the total movement of the previous three bars combined.
When these conditions are met, the script places a Red Arrow on the chart to alert the user to a potential downward trend or "sell" opportunity.
2. Buy Signals (Bullish Patterns) Conversely, the script looks for the opposite dynamic to identify buying opportunities. It searches for:
- A recent bar showing a significant price increase.
- Three preceding bars that were all downward moves.
- The script confirms the signal by checking if the size of this new upward move is greater than or equal to the total movement of the three previous drops combined.
When this occurs, the script places a Blue Arrow on the chart to signal a potential upward trend or "buy" opportunity.
Visual Representation
To make these signals easy for a trader to see at a glance, the script handles the visual placement automatically:
- Sell Signals: The Red arrow is positioned at the high point of the candle where the price reversal was confirmed.
- Buy Signals: The Blue arrow is positioned at the low point of the candle where the price reversal was confirmed.
By filtering for these specific "engulfing" behaviors, the indicator aims to highlight moments where a new trend is strong enough to completely overwhelm the preceding price action.
//+------------------------------------------------------------------+
//| sample.mq4 |
//| yzacarias |
//| yzacarias |
//+------------------------------------------------------------------+
#property copyright "yzacarias"
#property link "yzacarias"
#property version "1.70"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
double BufferSell[];
int Symbol_3_Kod=234;
double BufferBuy[];
int Symbol_4_Kod=233;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexStyle(0,DRAW_ARROW,0,1);
SetIndexArrow(0,Symbol_3_Kod);
SetIndexBuffer(0,BufferSell);
SetIndexStyle(1,DRAW_ARROW,0,1);
SetIndexArrow(1,Symbol_4_Kod);
SetIndexBuffer(1,BufferBuy);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int limit=rates_total-prev_calculated;
//---
for(int i=0; i<limit - 4; i++)
{
if(open[i+1]-close[i+1] >= 0 && //Bajada
open[i+2]-close[i+2] <= 0 && //Subida
open[i+3]-close[i+3] <= 0 && //Subida
open[i+4]-close[i+4] <= 0 && //Subida
MathAbs(open[i+1]-close[i+1]) >= MathAbs(close[i+2]-open[i+4])) //La Bajada engloba las tres subidas anteriores
BufferSell[i+1]=high[i+1];
if(open[i+1]-close[i+1] <= 0 && //Subida
open[i+2]-close[i+2] >= 0 && //Bajada
open[i+3]-close[i+3] >= 0 && //Bajada
open[i+4]-close[i+4] >= 0 && //Bajada
MathAbs(open[i+1]-close[i+1]) >= MathAbs(close[i+2]-open[i+4])) //La subida engloba las tres bajadas anteriores
BufferBuy[i+1]=low[i+1];
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments