SVM_train_v02

Author: Copyright � 2007, MetaQuotes Software Corp.
SVM_train_v02
Price Data Components
Series array that contains close prices for each barSeries array that contains the lowest prices of each barSeries array that contains the highest prices of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
SVM_train_v02
//+------------------------------------------------------------------+
//|                                                      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

extern int     TrainTimeFrame=PERIOD_M5;

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];


extern int StopLoss=60;
extern int TakeProfit=60;

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,TrainTimeFrame,i);
      c[i]=iClose(NULL,TrainTimeFrame,i);
      l[i]=iLow(NULL,TrainTimeFrame,i);
      h[i]=iHigh(NULL,TrainTimeFrame,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];
           
  int x1,x2,x3;         
  int pos=0;
  pos=NR_OF_SAMPLE_LINES;
  while(pos>=0)
  //while(pos<=Bars)
   {  
       
      int pos1 = iBarShift(Symbol(), TrainTimeFrame, iTime(NULL,0,pos), true);
		if (iTime(Symbol(), TrainTimeFrame, pos1) == iTime(NULL,0,pos))  // have to be sure the times match.
		{ 
		  x1=train_result[pos];
		  if(x1>-2)
		    Buffer[pos]=x1; 
		}
		else
		{
		   if(x1>-2) 
			  Buffer[pos]=x1;   
		}
		   pos--;
	}	
           
  // Comment("");
  // Comment("Time[500]:",Time[500],"  train_time[500]:",(Period() * train_time[500]));
           
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---