#SVM_b4_dd_pred2

Download script
Author:
#SVM_b4_dd_pred2

Overview of Logic and Functionality

This script is a specialized technical indicator designed to identify specific market entry points by analyzing historical data and external predictive models. Instead of relying solely on standard price action (like moving averages or RSI), it integrates pre-calculated "prediction" files into your trading platform to highlight potential opportunities.

Data Integration and Prediction

The core logic of this script revolves around fetching external datasets. It is programmed to look for specific prediction files located in a dedicated folder on your system. These files contain values generated by a Support Vector Machine (SVM) model—a type of machine learning used to recognize patterns in financial data.

By linking to these files, the script can "read" what the model predicts for specific timeframes. It dynamically adjusts its behavior based on the timeframe you are currently viewing (such as 5-minute, 1-hour, or 4-hour charts), changing its "look-ahead" windows accordingly to ensure the data remains relevant to your trading speed.

How the Logic Works

When the script runs on your chart, it performs the following steps:

  • File Synchronization: It scans for prediction results that match your current currency pair and the specific time window selected in the settings.
  • Dynamic Mapping: It searches through these results to find the exact moment in time that matches the current bar on your chart.
  • Validation Rules: Once it finds a matching time, the script applies a series of filters to decide whether to display a signal. It checks if:
    1. The prediction exists within the valid range of the data provided.
    2. The predicted value falls within a specific "neutral" threshold (between -7.1 and 7.1).
    3. The data shows a positive variance (maximum value is greater than the minimum value), indicating enough volatility or movement to be tradable.

Visual Output

If all the logic conditions above are met, the script places a visual marker (an arrow) on your chart at the specific price point identified by the model. This allows you to see "high-probability" zones where the predictive model suggests the market is primed for a move.

Summary for the User

Think of this script as a bridge between a complex machine learning brain and your trading screen. The "brain" does the heavy lifting of analyzing the math in external files, and this script acts as the messenger—filtering that information and placing an arrow on your chart only when the conditions are perfect.

Miscellaneous
Uses files from the file systemIt reads information from a fileImplements a curve of type %1
14 Views
0 Downloads
0 Favorites
#SVM_b4_dd_pred2
//+------------------------------------------------------------------+
//|                                           
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#include <stderror.mqh>
/*
SL      TP
0.006	 0.008
0.006	 0
0.006	 0.006
0.005	 0.008

*/
#define COL1 1
#define COL2 1

//  5-10, 10-15 and 5-15
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Magenta
#property indicator_color2 Lime
#property indicator_color3 Red
#property indicator_color4 Orange
#property indicator_color5 Aqua
#property indicator_color6 Blue
#property indicator_color7 Yellow
#property indicator_level1 0.0

//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
int NrBars = 1003;
int StopLoss=40;
int TakeProfit=40;
int Period1=PERIOD_M5;
int Period0=0;
int Buffers1=3;

//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
int FutureWindow1;
int FutureWindow2;
int FutureWindow3;
int FutureWindow4;
int FutureWindow5;
int FutureWindow6;
int FW;
//---- buffers
double VolBuffer1[];
double VolBuffer2[];
double VolBuffer3[];
double VolBuffer4[];
double VolBuffer5[];
double VolBuffer6[];
double VolBuffer7[];

string v[][COL1];
string vv[][COL2];
string f1,f2;
double dv[];
double dvv[];
   
string pr1(string sym1, int sig)
{
  int i,j,size,lin;
  int col=COL1;
  string nameData1 = "b4/dd/pred"+sig+"/"+sym1+".libsvm.prd";
  int handle=FileOpen(nameData1,FILE_CSV|FILE_READ,' ');
  if(handle<1)
    {
     Print("File"+nameData1+" not found, the last error is ", GetLastError());
     return(0);
    }
  else 
  {    
     FileSeek(handle, 0, SEEK_SET );
     i=0;
     while(!FileIsEnding(handle))
     {
       FileReadString(handle);
       i++;
     }
     size=i-1;//=755->0..754
     lin = size / col; //151 , usd lin=1564,col=5,size=7820
     ArrayResize(v,lin);
     FileSeek(handle, 0, SEEK_SET );
     for (i=0;i<lin;i++)
       for (j=0;j<col;j++)
         v[i][j]=FileReadString(handle);     
     FileClose(handle);    
  } 
  return (nameData1);
}


string pr2(string sym1, int sig)
{
  int i,j,size,lin;
  int col=COL2;
  string nameData1 = "b4/dd/pred"+sig+"/"+sym1+".libsvm.t";
  int handle=FileOpen(nameData1,FILE_CSV|FILE_READ,' ');
  if(handle<1)
    {
     Print("File"+nameData1+" not found, the last error is ", GetLastError());
     return(0);
    }
  else 
  {    
     FileSeek(handle, 0, SEEK_SET );
     i=0;
     while(!FileIsEnding(handle))
     {
       FileReadString(handle);
       i++;
     }
     size=i-1;//=755->0..754
     lin = size / col; //151 , usd lin=1564,col=5,size=7820
     ArrayResize(vv,lin);
     FileSeek(handle, 0, SEEK_SET );
     for (i=0;i<lin;i++)
       for (j=0;j<col;j++)
         vv[i][j]=FileReadString(handle);     
     FileClose(handle);    
  } 
  return (nameData1);
}


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|

int init()
  {
  if(NrBars==0)
    NrBars=Bars;//iBars(Symbol(),Period1);
  if (Period1==PERIOD_M5)
  {
     FutureWindow1 = 10;
     FutureWindow2 = 50;
     FutureWindow3 = 100;
     FutureWindow4 = 150;
     FutureWindow5 = 200;
     FutureWindow6 = 250;
  }
  else if(Period1==PERIOD_H1)
  {
     FutureWindow1 = 1;
     FutureWindow2 = 5;
     FutureWindow3 = 10;
     FutureWindow4 = 15;
     FutureWindow5 = 20;
     FutureWindow6 = 25;
  }
  else if(Period1==PERIOD_H4)
  {
     FutureWindow1 = 1;
     FutureWindow2 = 2;
     FutureWindow3 = 3;
     FutureWindow4 = 4;
     FutureWindow5 = 5;
     FutureWindow6 = 6;
 
  }

   IndicatorBuffers(7);
   
   SetIndexStyle(0,DRAW_ARROW,0,1);
   SetIndexBuffer(0, VolBuffer1);
   SetIndexLabel(0,"0");
   SetIndexArrow(0,158);
   
   SetIndexStyle(1,DRAW_ARROW,0,1);
   SetIndexBuffer(1, VolBuffer2);
   SetIndexLabel(1,"1");
   SetIndexArrow(1,158);
  
   SetIndexStyle(2,DRAW_ARROW,0,1);
   SetIndexBuffer(2, VolBuffer3);
   SetIndexLabel(2,"2");
   SetIndexArrow(2,158); 
   
   SetIndexStyle(3,DRAW_ARROW,0,1);
   SetIndexBuffer(3, VolBuffer4);
   SetIndexLabel(3,"3");
   SetIndexArrow(3,158);   

   SetIndexStyle(4,DRAW_ARROW,0,1);
   SetIndexBuffer(4, VolBuffer5);
   SetIndexLabel(4,"4");
   SetIndexArrow(4,158); 
      
   SetIndexStyle(5,DRAW_ARROW,0,1);
   SetIndexBuffer(5, VolBuffer6);
   SetIndexLabel(5,"5");
   SetIndexArrow(5,158); 
   
   SetIndexStyle(6,DRAW_ARROW,0,1);
   SetIndexBuffer(6, VolBuffer7);
   SetIndexLabel(6,"6");
   SetIndexArrow(6,158);    
   
   if(Buffers1==0)
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow1+" "+FutureWindow2+" "+FutureWindow3+" "+FutureWindow4+" "+FutureWindow5+" "+FutureWindow6);
   else if(Buffers1==1)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow1);     
     FW=FutureWindow1; 
   }  
   else if(Buffers1==2)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow2);     
     FW=FutureWindow2; 
   }       
   else if(Buffers1==3)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow3);     
     FW=FutureWindow3; 
   }       
   else if(Buffers1==4)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow4);     
     FW=FutureWindow4; 
   }       
   else if(Buffers1==5)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow5);     
     FW=FutureWindow5; 
   }       
   else if(Buffers1==6)
   {
     IndicatorShortName("Period:"+Period1+" FW:"+FutureWindow6);     
     FW=FutureWindow6; 
   }  
     
///////////////////////////////////////////  
   f1=pr1(Symbol(), Buffers1-1);
   f2=pr2(Symbol(), Buffers1-1);  
   Print(f1,"-> ",v[0][0]," ",v[1][0]);
   Print(f2,"-> ",vv[0][0]," ",vv[1][0]); 
   ArrayResize(dv,ArraySize(v));
   for (int k=0;k<ArraySize(v);k++)
   {
     dv[k]= StrToDouble(v[k][0]);
   }    
   ArrayResize(dvv,ArraySize(vv));
   for (k=0;k<ArraySize(vv);k++)
   {
     dvv[k]= StrToInteger(vv[k][0]);
   }
/////////////////////////////////////////////     
     
   return(0);
  }


//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

  double x1,x2,x3,x4,x5,x6,x7;
  int pos=0;
///////////////////////////////////////////  
   f1=pr1(Symbol(), Buffers1-1);
   f2=pr2(Symbol(), Buffers1-1);  
   Print(f1,"-> ",v[0][0]," ",v[1][0]);
   Print(f2,"-> ",vv[0][0]," ",vv[1][0]); 
   ArrayResize(dv,ArraySize(v));
   for (int k=0;k<ArraySize(v);k++)
   {
     dv[k]= StrToDouble(v[k][0]);
   }    
   ArrayResize(dvv,ArraySize(vv));
   for (k=0;k<ArraySize(vv);k++)
   {
     dvv[k]= StrToInteger(vv[k][0]);
   }
/////////////////////////////////////////////     
   int dayshift=-1;

  pos=NrBars;
  while(pos>=0)
  //while(pos<=NrBars)
     {  
		//PREDICT
		
      if(Buffers1!=0)
      {
      
       double max=dv[ArrayMaximum(dv)];
       double min=dv[ArrayMinimum(dv)];
       datetime d2 = Time[pos];
       dayshift=ArrayBsearch(dvv,d2,WHOLE_ARRAY,0,MODE_ASCEND);
       datetime maxt2=dvv[ArrayMaximum(dvv,WHOLE_ARRAY,0)];
       if (
            (dayshift > 0) && 
            (d2<=maxt2) && 
            StrToDouble(v[dayshift][0])<7.1 && 
            StrToDouble(v[dayshift][0])>-7.1 &&
            (max > min)           
            )
       //if ((dayshift > 0))
       {       
         VolBuffer7[pos]=StrToDouble(v[dayshift][0])+0.1; //Open
       }
       else
         VolBuffer7[pos]=EMPTY_VALUE;     		
		}
 	   //pos++;
 	   pos--;
     }
     
    //InSigNormalize(VolBuffer1);
    //InSigNormalize(VolBuffer2);
    //InSigNormalize(VolBuffer3);

  //int lasterror=0;
  //string pict_file1 = "b4/dd/shots"+(Buffers1-1)+"/"+Symbol()+".gif";
  //string pict_file1="shots\\signal"+(Buffers1-1)+"\\better"+(Buffers1-1)+".gif";
  //---- make WindowScreenShot for further checking
  //if(!WindowScreenShot("shots\\tester"+ExtShotsCounter+".gif",640,480))
  //if(!WindowScreenShot(pict_file1,640,480))
  //  lasterror=GetLastError();
    
  //if(!SendFTP(pict_file1))
  //  lasterror=GetLastError();
  // Print("error(",lasterror,"): ");      
   return(0);
  }
//+------------------------------------------------------------------+

Comments