SVM_train_v01
Download scriptThis script functions as an advanced analytical tool designed to process historical market data and provide visual feedback on price trends. Instead of relying on traditional, static indicators (like simple moving averages), this tool utilizes a sophisticated "training" methodology to interpret market behavior.
Core Logic and Methodology
1. Data Collection and Preparation The script begins by gathering a substantial amount of historical market information—specifically looking at 4,000 individual data points. It captures the essential building blocks of price action:
- Time Stamps: To organize data chronologically.
- Closing Prices: To understand where the market finished each period.
- Highs and Lows: To measure the volatility and range of price movements.
2. The Training Phase One of the most distinct features of this script is its "Training" mechanism. Upon startup, the tool doesn't just look at the current price; it runs an automated training cycle. It feeds the collected historical data into a specialized processing engine to identify patterns. During this phase, the script evaluates the market based on specific parameters:
- Look-ahead Window: It analyzes a specific "future window" to anticipate potential trends.
- Risk Parameters: It incorporates predefined Stop Loss and Take Profit levels to understand how price actions align with standard trading goals.
3. Results Processing After the training is complete, the script stores the results in an internal memory bank. It maps these results back to specific points in time. The goal is to identify significant signals where the "trained" model recognizes a high-probability market movement.
4. Visual Representation The final output is presented as a Histogram on a separate window within your trading platform. Rather than cluttering your main price chart, this tool provides a dedicated space where:
- Only the most relevant signals (the "results") are displayed.
- The histogram acts as a visual map, highlighting the specific strengths or directions identified by the model's training logic.
Summary for the User
In simple terms, think of this script as a "Market Analyst." Instead of you having to look at dozens of lines and indicators to guess where the price might go next, this script "studies" 4,000 past candles every time it starts up. It then produces a visual histogram that shows you the summarized results of its study, helping you identify potential trends based on complex historical patterns rather than simple math.
//+------------------------------------------------------------------+
//| SVM_v04.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen
#property indicator_level1 0
#define NR_OF_SAMPLE_LINES 4000
//#define NR_OF_TEST_LINES 100
//#define NR_OF_ATTRIB 9
#define FUTURE_WINDOW 100
#import "Project2.dll"
int Train(double t[],double c[],double l[],double h[],int,int,int,int,double,double &train_result[],double &train_time[]);
#import
double t[NR_OF_SAMPLE_LINES];
double c[NR_OF_SAMPLE_LINES];
double l[NR_OF_SAMPLE_LINES];
double h[NR_OF_SAMPLE_LINES];
/*
double ma5_M5[NR_OF_SAMPLE_LINES];
double ma10_M5[NR_OF_SAMPLE_LINES];
double ma15_M5[NR_OF_SAMPLE_LINES];
double ma5_H1[NR_OF_SAMPLE_LINES];
double ma10_H1[NR_OF_SAMPLE_LINES];
double ma15_H1[NR_OF_SAMPLE_LINES];
double ma5_H4[NR_OF_SAMPLE_LINES];
double ma10_H4[NR_OF_SAMPLE_LINES];
double ma15_H4[NR_OF_SAMPLE_LINES];
*/
//double test_example_dyn_1[NR_OF_ATTRIB];
//double test_example_dyn_2[NR_OF_ATTRIB];
//double test_example_dyn_3[NR_OF_ATTRIB];
double train_result[NR_OF_SAMPLE_LINES];
double train_time[NR_OF_SAMPLE_LINES];
int StopLoss=50;
int TakeProfit=50;
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
int xx;
//----
IndicatorBuffers(1);
SetIndexBuffer(0, Buffer);
SetIndexStyle(0, DRAW_HISTOGRAM);
for(int i=0;i<NR_OF_SAMPLE_LINES;i++)
{
t[i]=iTime(NULL,PERIOD_M1,i);
c[i]=iClose(NULL,PERIOD_M1,i);
l[i]=iLow(NULL,PERIOD_M1,i);
h[i]=iHigh(NULL,PERIOD_M1,i);
//t[i]=iTime(NULL,PERIOD_H1,i);
//c[i]=iClose(NULL,PERIOD_H1,i);
//l[i]=iLow(NULL,PERIOD_H1,i);
//h[i]=iHigh(NULL,PERIOD_H1,i);
/*
ma5_M5[i]=iMA(NULL,PERIOD_M5,5,0,MODE_SMA,PRICE_CLOSE,i);
ma10_M5[i]=iMA(NULL,PERIOD_M5,10,0,MODE_SMA,PRICE_CLOSE,i);
ma15_M5[i]=iMA(NULL,PERIOD_M5,15,0,MODE_SMA,PRICE_CLOSE,i);
ma5_H1[i]=iMA(NULL,PERIOD_H1,5,0,MODE_SMA,PRICE_CLOSE,i);
ma10_H1[i]=iMA(NULL,PERIOD_H1,10,0,MODE_SMA,PRICE_CLOSE,i);
ma15_H1[i]=iMA(NULL,PERIOD_H1,15,0,MODE_SMA,PRICE_CLOSE,i);
ma5_H4[i]=iMA(NULL,PERIOD_H4,5,0,MODE_SMA,PRICE_CLOSE,i);
ma10_H4[i]=iMA(NULL,PERIOD_H4,10,0,MODE_SMA,PRICE_CLOSE,i);
ma15_H4[i]=iMA(NULL,PERIOD_H4,15,0,MODE_SMA,PRICE_CLOSE,i);
*/
train_result[i]=0;
train_time[i]=0;
}
xx=Train(t,c,l,h,NR_OF_SAMPLE_LINES,FUTURE_WINDOW,StopLoss,TakeProfit,Point,train_result,train_time);
Print("Train: ",xx);
/*
string s1=""+
train_result[0]+"\n"+
train_result[1]+"\n"+
train_result[2]+"\n"+
train_result[3]+"\n"+
train_result[4]+"\n"+
train_result[53]+"\n"+
train_result[16];
Comment(s1);
*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
for(int i = 0; i < NR_OF_SAMPLE_LINES; i++)
if(train_result[i]>-2)
if(train_time[i]==Time[i])
Buffer[i] = train_result[i];
// Comment("");
Comment("Time[500]:",Time[500]," train_time[500]:",(Period() * train_time[500]));
//----
return(0);
}
//+------------------------------------------------------------------+
Comments