Download MetaTrader 5

Live Data Feed from Tradestation to Metatrader - Demonstration

To add comments, please log in or register
Taskin Osman
838
Taskin Osman  

Do you want to transfer data (does not matter what kind) to from 1 application/chart to x applications/charts inside different/same window? Here is a demonstration how this can be realised. We have a free tool called "PermVar" since 2 years now but it does not get much attention among coders because they cannot estimate real power of that tool.

You can read all functions of PermVar under <link removed>

you may also watch the demonstration video here: <link removed>

Source code on MT4 side which has been used:

#include <libvisual.mqh>
#include <libpv.mqh>

int   pv = 0;

int init()
  {
   ObjectsDeleteAll();
   pObjectName("ihasd"); pDefaultColor(Yellow);
   pv=PVInit("QuoteSender1");
  
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   string s=StringSubstr(Symbol(),0,6)+"/"+Period();
   pReset();
   p("-"+s+"-",DarkOrchid,true);
   if (pv>0) 
      {
      p("ws137 is running");      
      p(Symbol(),Tomato);

      // GET OHLC Data from Last 10 Bars
      for (int i=0;i<=10;i++)
         {
         double _o = PVGetDouble(pv,s+"+open+"+i);          
         double _h = PVGetDouble(pv,s+"+high+"+i);          
         double _l = PVGetDouble(pv,s+"+low+"+i);                   
         double _c = PVGetDouble(pv,s+"+close+"+i);          

         DrawCandle(_o,_h,_l,_c,i);
         if (i==0)
               {
               //void DrawTrendLine(string name,datetime firsttime,double firstprice,datetime secondtime, double secondprice,color color)
               DrawTrendLine("TL0",Time[0],_c,Time[0]+Period()*60*20,_c,Yellow);
               ObjectSet("TL0",OBJPROP_STYLE,STYLE_DOT);
               //void DrawLabel(string namebox,string content,int fntsize,datetime firsttime,double firstprice,color lblcolor, string font="Times New Roman")
               DrawLabel("LB0",DoubleToStr(_c,Digits),16,Time[0]+Period()*60*3,_c,Yellow);
               }
         }
      
  
      
      }
      else
      {
      Alert("PermVar error");
      
      }
   return(0);
  }



// DRAW CANDLE
int DrawCandle(double o,double h,double l,double c,int shift)
{
int clr=Brown;
int fromtime,totime;
//void DrawBox(string namebox,datetime firsttime,double firstprice,datetime secondtime, double secondprice,color boxcolor,bool isbackground=false)
if (c>o) clr=Green ;

if (shift>0) { fromtime=Time[shift]; totime=Time[shift-1]; }
else
   {
   fromtime=Time[shift]; totime=Time[0]+Period()*60;
   }

DrawBox("bx"+shift,fromtime,h,totime,l,clr,false);
DrawBox("bx2"+shift,fromtime,o,totime,c,clr,true);

}

And here is the code used on Tradestation side:

// taskin 19.05.2011
// sends quotes through PV
// 
// Function imports
// You require to import only functions you use
// 
external: "permvar.dll", int, "PVInit",LPSTR;   
external: "permvar.dll", int, "PVError";  
external: "permvar.dll", int, "PVString",int,LPSTR,LPSTR;
external: "permvar.dll", int, "PVValue",int,LPSTR,int;  
external: "permvar.dll", int, "PVDouble",int,LPSTR,double;
external: "permvar.dll", int, "PVWipe",LPSTR;
external: "permvar.dll", LPSTR, "PVGetString",int,LPSTR;
external: "permvar.dll", int, "PVGetValue",int,LPSTR;
external: "permvar.dll", double, "PVGetDouble",int,LPSTR;
external: "permvar.dll", int, "PVRelease";
external: "permvar.dll", int, "UnixTime";
external: "permvar.dll", LPSTR, "PVVersion";



// VARS
Vars: PV(0),name(""),Intrabarpersist LastBar(0),q(0),BI(-1);

If (BarNumber=1) then PV=PVInit("QuoteSender1");

if BarType=1 then BI=BarInterVal;
if BarType=2 then BI=24*60; 
if BarType=3 then BI=24*60*7;
if BarType=4 then BI=24*60*30; 

name=Getsymbolname+"/"+NumToStr(BI,0);

// we need live data and it must be last chart
If (LastBarOnChart and LastBar<>Time[0]) then
begin
        // Lets send last 30 bars OHLC
        For q=0 to 10 
        Begin
        // OHLC
        PVDouble(PV,name+"+open+"+Numtostr(q,0),Open[q]);
        PVDouble(PV,name+"+high+"+Numtostr(q,0),High[q]);
        PVDouble(PV,name+"+low+"+Numtostr(q,0),low[q]);
        PVDouble(PV,name+"+close+"+Numtostr(q,0),Close[q]);
        
        // Momentum
        PVDouble(PV,name+"+momClose10+"+Numtostr(q,0),Momentum(Close[q],10));           
         
        // Add others here      
        end;
        //LastBar=Time[0];
        Print("updated quotes for ",name); 
end; 
Lee Bryant
2097
Lee Bryant  
Thanks for this useful article!
To add comments, please log in or register