ryan_jones_sm
Download scriptThis script is designed as a technical analysis tool for the MetaTrader platform. It automatically identifies specific trading opportunities by comparing current price trends and historical price points against defined moving averages.
The logic operates by monitoring two primary user-adjustable settings: X (a short-term period) and Y (a secondary shift period). By utilizing these, the script creates a "snapshot" of the market to see if current momentum aligns with specific historical patterns.
How the Logic Works
The script constantly scans the price history and evaluates two distinct types of signals:
1. Purchase Signals (Buy)
To trigger a buy recommendation, the script looks for three specific conditions to be met simultaneously:
- Trend Comparison: The current moving average (based on period X) must be higher than the moving average from Y periods ago. This suggests an upward trend is gaining strength.
- Recent Price Drop: The current closing price must be lower than the price recorded Y periods ago. This helps identify a potential "dip" in the market.
- Historical Floor: The current closing price must be higher than the price recorded from Y + X periods ago. This ensures the price is still trading above a significant historical baseline.
If all three conditions are true, the script marks a signal on the chart, suggesting a potential buy entry for the next opening period.
2. Sale Signals (Sell)
To trigger a sell recommendation, the script looks for the inverse of the buy logic:
- Trend Comparison: The current moving average (based on period X) must be lower than the moving average from Y periods ago. This suggests a downward trend is dominating.
- Recent Price Rise: The current closing price must be higher than the price recorded Y periods ago. This helps identify a potential "rally" or temporary peak.
- Historical Ceiling: The current closing price must be lower than the price recorded from Y + X periods ago. This ensures the price has remained below a significant historical ceiling.
If all three conditions are met, the script marks a signal on the chart, suggesting a potential sell entry for the next opening period.
Visual Output
The script provides visual feedback directly on your trading chart:
- Trend Lines: It plots various moving averages and historical price points so you can see the data it is using to make decisions.
- Arrows: When the specific logic conditions are met, the script places arrows on the chart to clearly highlight where a Buy or Sell signal has been generated.
//+------------------------------------------------------------------+
//| ryan_jones_sm.mq4 |
//| Copyright © 2007, Sergan |
//| |
//+------------------------------------------------------------------+
// Âåðñèÿ 1.0 03.11.07
// ïðàâèëà:
/* Ìåòîä, êîòîðûé äàåò ýòè öèôðû, óäèâèòåëüíî ïðîñò. Ïðàâèëà òàêîâû:
Ïîêóïêà:
1. Ñðåäíåå ïî çàêðûòèþ, ðàññ÷èòàííîå ïî "X"- äíåâíîìó ïåðèîäó, äîëæíî áûòü âûøå, ÷åì àíàëîãè÷íîå ñðåäíåå "Y" äíåé òîìó íàçàä.
2. Öåíà ïðè çàêðûòèè äîëæíà áûòü ìåíüøå, ÷åì àíàëîãè÷íàÿ öåíà "Y" äíåé òîìó íàçàä.
3. Öåíà ïðè çàêðûòèè äîëæíà áûòü âûøå, ÷åì öåíà íà çàêðûòèå "Y+X" äíåé òîìó íàçàä.
Åñëè ñîáëþäåíû âñå òðè óñëîâèÿ, òî íóæíî îñóùåñòâëÿòü ïîêóïêó ïðè îòêðûòèè íà ñëåäóþùèé äåíü
Ïðîäàæà:
1. Ñðåäíåå ïî çàêðûòèþ, ðàññ÷èòàííîå ïî "X"- äíåâíîìó ïåðèîäó äîëæíî áûòü ìåíüøå, ÷åì àíàëîãè÷íîå ñðåäíåå "Y" äíåé òîìó íàçàä.
2. Öåíà ïðè çàêðûòèè äîëæíà áûòü áîëüøå, ÷åì àíàëîãè÷íàÿ öåíà "Ó äíåé òîìó íàçàä.
3. Öåíà ïðè çàêðûòèè äîëæíà áûòü ìåíüøå, ÷åì öåíà íà çàêðûòèå "Y+X" äíåé òîìó íàçàä.
Íàïðèìåð, åñëè "Õ"= 20 è "Y"=3
*/
#define LOW 0
#define HIGH 1
#define OP_NONE -1 //òèï îðäåðà - íåò îðäåðà OP_BUY, OP_SELL è ò.ï. èñïîëüçóþòñÿ èç ìò
#define OP_CLOSEORDER -2 //òèï ñèãíàëà - çàêðûòü îðäåð
#define UP 1
#define DOWN -1
//----
#define MAGICMA 031107
#include <stdlib.mqh>
#include <WinUser32.mqh>
//----
#property copyright "Copyright © 2007, Sergan"
#property link "SerganMT@hotbox.ru"
//----
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Red
#property indicator_color2 Gold
#property indicator_color3 DarkBlue
#property indicator_color4 Black
#property indicator_color5 Blue
#property indicator_color6 Blue
//----
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 3
#property indicator_width6 3
//---- input parameters
extern int ParY=3; //ïàðàìåòð "Y"
extern int ParX=20; // ïàðàìåòð "X"
//---- buffers
double ExtMapBuffer1[]; // ìà ïåðèîä ïàðàìåòð "X"
double ExtMapBuffer2[]; // ìà ïåðèîä "X" ñìåùåíèå "Y"
double ExtMapBuffer3[]; //öåíà çàêðûòèÿ "Y" äíåé íàçàä
double ExtMapBuffer4[]; //öåíà çàêðûòèÿ "Y+X" äíåé òîìó íàçàä
//----
double BuyBuffer[]; //áóôåð ñèãíàëû áàé
double SellBuffer[]; //áóÿåð ñèãíàëû ñåëë
double BufferSignalType[]; // áóôåð òèïîâ ñèãíàëîâ, íåîáõîäèìî äëÿ ïåðåäà÷è â ñîâåòíèê
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexLabel(0, "ma("+ParX+")" );
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexLabel(1, "ma("+ParX+","+ParY+")" );
//----
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexLabel(2, "close("+ParY+")" );
//----
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexLabel(3, "close("+(ParY+ParX)+")" );
//----
SetIndexStyle( 4, DRAW_ARROW, EMPTY );
SetIndexArrow( 4, 233 );
SetIndexStyle( 5, DRAW_ARROW, EMPTY );
SetIndexArrow( 5, 234 );
//----
SetIndexBuffer( 4, BuyBuffer );
SetIndexEmptyValue(4,0);
SetIndexBuffer( 5, SellBuffer );
SetIndexEmptyValue(5,0);
ArrayInitialize(BuyBuffer, 0 );
ArrayInitialize(SellBuffer, 0 );
//----
int drawtype=DRAW_ARROW ;
SetIndexBuffer(6,BufferSignalType );
SetIndexStyle( 6, DRAW_NONE);
SetIndexEmptyValue(6,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
bool ShowSignals(int i )
{
BuyBuffer[i]=0; SellBuffer[i]=0; BufferSignalType[i]=OP_NONE;
int cmd=OP_NONE;
if(i>Bars-100)return(false);
/*
double ExtMapBuffer1[]; // ìà ïåðèîä ïàðàìåòð "X"
double ExtMapBuffer2[]; // ìà ïåðèîä "X" ñìåùåíèå "Y"
double ExtMapBuffer3[]; //öåíà çàêðûòèÿ "Y" äíåé íàçàä
double ExtMapBuffer4[]; //öåíà çàêðûòèÿ "Y+X" äíåé òîìó íàçàä
Ïðîäàæà:
1. Ñðåäíåå ïî çàêðûòèþ, ðàññ÷èòàííîå ïî "X"- äíåâíîìó ïåðèîäó äîëæíî áûòü ìåíüøå, ÷åì àíàëîãè÷íîå ñðåäíåå "Y" äíåé òîìó íàçàä.
2. Öåíà ïðè çàêðûòèè äîëæíà áûòü áîëüøå, ÷åì àíàëîãè÷íàÿ öåíà "Ó äíåé òîìó íàçàä.
3. Öåíà ïðè çàêðûòèè äîëæíà áûòü ìåíüøå, ÷åì öåíà íà çàêðûòèå "Y+X" äíåé òîìó íàçàä.
Ïîêóïêà:
1. Ñðåäíåå ïî çàêðûòèþ, ðàññ÷èòàííîå ïî "X"- äíåâíîìó ïåðèîäó, äîëæíî áûòü âûøå, ÷åì àíàëîãè÷íîå ñðåäíåå "Y" äíåé òîìó íàçàä.
2. Öåíà ïðè çàêðûòèè äîëæíà áûòü ìåíüøå, ÷åì àíàëîãè÷íàÿ öåíà "Y" äíåé òîìó íàçàä.
3. Öåíà ïðè çàêðûòèè äîëæíà áûòü âûøå, ÷åì öåíà íà çàêðûòèå "Y+X" äíåé òîìó íàçàä.
Åñëè ñîáëþäåíû âñå òðè óñëîâèÿ, òî íóæíî îñóùåñòâëÿòü ïîêóïêó ïðè îòêðûòèè íà ñëåäóþùèé äåíü
*/
if(ExtMapBuffer1[i]<ExtMapBuffer2[i])
{
if(Close[i]>ExtMapBuffer3[i] && Close[i] < ExtMapBuffer4[i])
{
cmd=OP_SELL;
SellBuffer[i]= Close[i];
}
}
if(ExtMapBuffer1[i]>ExtMapBuffer2[i])
{
if(Close[i]<ExtMapBuffer3[i] && Close[i] > ExtMapBuffer4[i])
{
cmd=OP_BUY;
BuyBuffer[i]= Close[i];
}
}
BufferSignalType[i]=cmd;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit=Bars-counted_bars-1;
//int oldertimeframe = getoldertimeframe();
for( int i=limit; i>0; i -- )
{
ExtMapBuffer1[i]=iMA(NULL,0,ParX,0,MODE_SMA,PRICE_CLOSE,i);
ExtMapBuffer2[i]=iMA(NULL,0,ParX,ParY,MODE_SMA,PRICE_CLOSE,i);
ExtMapBuffer3[i]=Close[ParY+i]; //öåíà çàêðûòèÿ Y äíåé íàçàä
ExtMapBuffer4[i]=Close[ParY+ParX+i];//öåíà çàêðûòèÿ "Y+X" äíåé òîìó íàçàä
ShowSignals(i);
}
return(0);
}
//+------------------------------------------------------------------+
Comments