[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 606

 
Roman.: Guys, please advise - I downloaded the terminal set-up from brokerage company site, I want to test the owls with quotes of this particular brokerage company in the strategy tester, but when I press F2 and download quotes, the tester displays this window... Is it possible to download quotes from the selected brokerage company?
Roman, I can only give you one piece of advice: go to your brokerage company web site and look for their history.
 

Good afternoon. I want to connect my .dll to a script. Tried to test this example:

#import "user32.dll"
    int    MessageBoxA(int hWnd, string lpText, string lpCaption, int uType);
#import

int start()
{
    MessageBoxA(0, "Some", "Some", 0);
   
    return;
}

It works, a window pops up. Wrote my dll:

#ifndef DLLTEST_H
#define DLLTEST_H

#pragma once

extern "C" __declspec(dllexport) int __stdcall Test()
{
    return 2;
}

#endif // DLLTEST_H

Tested it through connections to a regular program on the pros, it works, everything is fine. But when I try to connect it to a script, nothing happens, it doesn't even ask if I want to connect to my dll. Apparently it doesn't understand this export. So my question is: what kind of export does it understand? From Visual C++? Or maybe I did something wrong and some special export with diamonds is needed?

 
Good afternoon! In this version of stochastic I decided to add flat lines (on the chart)
on the overbought/oversold zones.

There was a problem with deleting "old" lines from the history. What is wrong and what should I pay attention to?

//+------------------------------------------------------------------+
//|                                              Stochastic_flat     |
//|                                         Copyright © 2012 Fox.RM  |
//|                                               fox.rm@mail.ru     |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012 Fox.RM"
#property link      "fox.rm@mail.ru"

//----
#property indicator_separate_window
#property indicator_buffers 4

//---- fan style
#property indicator_color1 Red
#property indicator_color2 Black
#property indicator_color3 Blue
#property indicator_color4 DarkGray

#property indicator_style1 0
#property indicator_style2 0
#property indicator_style3 0
#property indicator_style4 0
#property indicator_width4 2
#property indicator_level1 88.2
#property indicator_level2 11.8
 
#property indicator_levelcolor DarkGray
#property indicator_levelstyle 0

//---- basic fan indicator parameters
extern bool Show_STOCH_1=true;
extern int K_period1=13;
extern int S_period1=1;
extern bool Show_STOCH_2=true;
extern int K_period2=34;
extern int S_period2=1;
extern bool Show_STOCH_3=true;
extern int K_period3=89;
extern int S_period3=1;
extern bool Show_STOCH_4=true;
extern int K_period4=233;
extern int S_period4=1;
extern int delete=2;

//---- indicator buffers
double MainBuffer1[];
double MainBuffer2[];
double MainBuffer3[];
double MainBuffer4[];


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

int init()
  {
//---- stochastic line 1 (fast)
   if(Show_STOCH_1 ==true){Show_STOCH_1=DRAW_LINE; }
   else 
    {Show_STOCH_1=DRAW_NONE; }
   SetIndexBuffer(0,MainBuffer1);
   SetIndexStyle(0,Show_STOCH_1,0);
   SetIndexLabel(0,"fast WPR  ( "+K_period1+" )");
   
//---- stochastic line 2 (basic)
   if(Show_STOCH_2 ==true){Show_STOCH_2=DRAW_LINE; }
   else 
    {Show_STOCH_2=DRAW_NONE; }
   SetIndexBuffer(1,MainBuffer2);
   SetIndexStyle(1,Show_STOCH_2);
   SetIndexLabel(1,"basic WPR ( "+K_period2+" )");
   
//---- stochastic line 3 (flat)
   if(Show_STOCH_3 ==true){Show_STOCH_3=DRAW_LINE; }
   else 
    {Show_STOCH_3=DRAW_NONE; }
   SetIndexBuffer(2,MainBuffer3);
   SetIndexStyle(2,Show_STOCH_3,0);
   SetIndexLabel(2,"slow WPR ( "+K_period3+" )");
   
//---- stochastic line 4 (control)
   if(Show_STOCH_4 ==true){Show_STOCH_4=DRAW_LINE; }
   else
    {Show_STOCH_4=DRAW_NONE; }
   SetIndexBuffer(3,MainBuffer4);
   SetIndexStyle(3,Show_STOCH_4,0,2);
   SetIndexLabel(3,"control WPR ( "+K_period4+" )");

   
//---- name for DataWindow and indicator subwindow label   
   IndicatorShortName("Stochastic_flat");
  }

//----
   return(0);

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+

int deinit()
  {
//---- 
   ObjectsDeleteAll();
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Stochastic_fan                                                   |
//+------------------------------------------------------------------+

int start()
  {
   int    i,shift,limit,y=0,counted_bars=IndicatorCounted();
   double x1,x2;
   datetime y1,y11,y2,y22;
//---- Plot defined timeframe on to current timeframe   
 
   limit=Bars-counted_bars;
   //---stroim stohastik
   for(i=0,y=0;i<limit;i++,y++)
     {
      MainBuffer1[i]=iStochastic(NULL,0,K_period1,1,S_period1,0,0,MODE_MAIN,y);
      MainBuffer2[i]=iStochastic(NULL,0,K_period2,1,S_period2,0,0,MODE_MAIN,y);
      MainBuffer3[i]=iStochastic(NULL,0,K_period3,1,S_period3,0,0,MODE_MAIN,y);
      MainBuffer4[i]=iStochastic(NULL,0,K_period4,1,S_period4,0,0,MODE_MAIN,y);
    
     //---flat zona
  
     
     if (MainBuffer1[i] < 11.8) //---pervoe uslovie
     {
     x1=Low[i];
     y1=Time[i]; //--- opredelyaem koordinaty dlya x1,y1
     }
     if (MainBuffer1[i] > 88.2) //---vtoroe uslovie
     {
     x2=High[i];
     y2=Time[i];   //--- opredelyaem koordinaty dlya x2,y2
     }
     }
    for(i=Bars; i>0; i--)
    {
     //--- opredelyaem koordinaty dlya x11,y11 
     if (Low[i]<x1)
     {
     y11=Time[i];
     }
     //--- opredelyaem koordinaty dlya x22,y22
     if (High[i]>x2)
     {
     y22=Time[i];
     }
     }    
     
   
   string up_line = "upline";
  string down_line = "downline";
     flatlineup(up_line+TimeToStr(Time[i]), y2,x2,y22,x2,Red,1);
     flatlinedown(down_line+TimeToStr(Time[i]), y1,x1,y11,x1,Blue,1);
  
    
   dellline(up_line,i);
     
     //----
     
   return(0);
  }
//+------------------------------------------------------------------+
void flatlineup(string labebe,datetime time1,double price1,datetime time2,double price2,color colir, int W)
  {
     ObjectCreate(labebe, OBJ_TREND, 0,time1,price1,time2,price2);
   ObjectSet(labebe, OBJPROP_COLOR, colir);
   ObjectSet(labebe, OBJPROP_STYLE,0);
   ObjectSet(labebe, OBJPROP_RAY,0);
   ObjectSet(labebe, OBJPROP_WIDTH,W);   
   ObjectSet(labebe, OBJPROP_BACK, true);
   }
  void flatlinedown(string labebe1,datetime time1,double price1,datetime time2,double price2,color colir, int W)
  {
   ObjectCreate(labebe1, OBJ_TREND, 0,time1,price1,time2,price2);
   ObjectSet(labebe1, OBJPROP_COLOR, colir);
   ObjectSet(labebe1, OBJPROP_STYLE,0);
   ObjectSet(labebe1, OBJPROP_RAY,0);
   ObjectSet(labebe1, OBJPROP_WIDTH,W);   
   ObjectSet(labebe1, OBJPROP_BACK, true);
    }
   
void dellline(string name_line, int i)  //--- первый вариант с удалением линий
  {
    string name = ObjectName(i);
    if (StringFind(name,name_line)!=-1)ObjectDelete(name);

 // if (StringFind(name,name_line)!=-1)del1++;
 // if (del1>2)ObjectDelete(name);
   }
void dellline(string name_line)  //--- второй вариант с удалением линий  
{
string name, dellname; 
bool del = false;
for(int i=ObjectsTotal(); i>=0;i--)
    {
if (del == false){ //---при этом условии должна происходить идентификация первой линии 
name = ObjectName(i); //--выполняется при первом обращении к функции
dellname=name;
del = true;}
if (del == true){
if (StringFind(dellname,name_line)!=-1)ObjectDelete(dellname);
dellname=name;}
}   
} 
    //---Были и промежуточные варианты, которые также не дали желаемого результата.

In the version below, it worked. But not quite. The upper lines are deleted as new ones appear, the lower lines are deleted immediately. Why?

//------ функция удаляющая ненужные линии

void dellline(string name_line_up, string name_line_down) 
{
string name_l;
int obj=ObjectsTotal(OBJ_TREND); // --- в этой версии интуитивно добавил свойство OBJ_TREND
for (int i=obj; i>=0; i--)
{
name_l=ObjectName(i);
if(StringFind(name_l,name_line_up)!=-1)ObjectDelete(name_l);
if(StringFind(name_l,name_line_down)!=-1)ObjectDelete(name_l);
}}

Here we have an additional question why the function did not work as it should without adding

OBJ_TREND because it doesn't seem to make any fundamental changes in this case?

Then I ran some experiments with line names in the main code.

//-------------- первый вариант (рабочий)

string up_line = "upline_", down_line = "downline_";
 
     flatlineup(up_line+TimeToStr(Time[i]), y2,x2,y22,x2,Red,1);
     flatlinedown(down_line+TimeToStr(Time[i]), y1,x1,y11,x1,Blue,1);
     dellline(up_line, down_line);

//---TimeToStr(Time[i]) указывал в имени тренд лайн в теле функции

//--------------- второй вариант (нерабочий)

string up_line = "upline_"+TimeToStr(Time[i]); //--или пробовал StringConcatenate()
string down_line = "downline_"+TimeToStr(Time[i]); //--или пробовал StringConcatenate()
 
     flatlineup(up_line, y2,x2,y22,x2,Red,1);
     flatlinedown(down_line, y1,x1,y11,x1,Blue,1);
     dellline(up_line, down_line);

TimeToStr(Time[i]) was specified in a variable in the main code.


Question. Why did the second variant not work (meaning that the function

dellline(), when applied to the second variant, did not remove lines with names assigned to

to up_line and down_line variables?

И last question I'm going to duplicate it from a previous post, it's on the screenshot. The answer to it can be found

could not.

Thank you!

 
rustein:

Thank you, I tried it with the condition:

It still gives an error.

Try it like this

if( SummBullLots() >0){double BullAveragePrice = NormalizeDouble(BullSummOpenPrice()/SummBullLots(),Digits);}



 
yosuf:
Could you please tell me if there is an indicator that displays the number of open positions at a given time? Even better, if it shows how many of them are BAY and how many are SELL.
There is.
Files:
iexposure4.mq4  11 kb
 
Solree:

Good afternoon. I want to connect my .dll to a script. Tried to test this example:

It works, a window pops up. I have written my dll:

I checked it by connecting to regular program on plusses, everything works, all is well. But when I try to connect it to a script, nothing happens, it doesn't even ask if I want to connect to my dll. Apparently it doesn't understand this export. So my question is: what kind of export does it understand? From Visual C++? Or maybe I did something wrong and some special export with diamonds is needed?

In MT4 folder there is a sample code of C++ for all cases in MQL4. Compile that code and paste your own code in it. You will immediately see the difference between yours and the example.

 
I want to record EA actions in a file
I took an example from the MQL editor's handbook and slightly modified it to suit my needs
int init()  {
    int handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
  if(handle<0) return(0);
  // запишем заголовок в файл
  FileWrite(handle,"#","Цена открытия","Время открытия","Символ","Лоты");
   return(0);  }

int deinit()  {   return(0);  }

int start()  {
  .........................
...........................
  int handle=FileOpen("OrdersReport.csv",FILE_READ | FILE_WRITE,"\t");
  if(handle<0) return(0);
 
     // записываем в файл только открытые ордера
  for(int pos=0;pos<OrdersTotal();pos++)
    {
     if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)==false) continue;
     FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots());
    }
     FileClose(handle);   //Закрытие файла, ранее открытого функцией FileOpen().
}
   return(0);
  }


As a result, the file OrdersReport.csv is empty, although the orders are opened.
 
griha:
I want to record EA's actions in a file
I took an example from the MQL editor's handbook, slightly remade it for my own needs


As a result, the file OrdersReport.csv is empty, although the orders are opened.

Try it this way:

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
int handle;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init() 
  {
   handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
   if(handle<0) return(0);
// запишем заголовок в файл
   FileWrite(handle,"#","Цена открытия","Время открытия","Символ","Лоты");
   return(0);  
  }

int deinit() { 
   FileClose(handle);   //Закрытие файла, ранее открытого функцией FileOpen().
 return(0);  
 }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start() 
  {
   if(handle<0) return(0);
// записываем в файл только открытые ордера
   for(int pos=0;pos<OrdersTotal();pos++)
      if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) 
         FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots());
   return(0);
  }
//+------------------------------------------------------------------+
 
Fox_RM:
Good afternoon! In this version of stochastic I decided to add the construction of flat lines (on the chart)

Could not.

Thank you!

//------ функция удаляющая ненужные линии

void dellline(string name_line_up,string name_line_down)
  {
   string name_l;
   int obj=ObjectsTotal(); // найдем количество объектов 
   for(int i=obj-1; i>=0; i--) // obj-1 т.к. >=0 
     {
      name_l=ObjectName(i); // узнаем имя
      if(ObjectType(name_l)!=OBJ_TREND)continue; // если не трендлиния продолжим цикл * for(int i=obj-1; i>=0; i--)
      if(StringFind(name_l,name_line_up)!=-1)ObjectDelete(name_l);
      if(StringFind(name_l,name_line_down)!=-1)ObjectDelete(name_l);
     }
   }
//+------------------------------------------------------------------+
Create trendlines with name = time1+price1+time2, easy to delete in deinit.
 
Mathemat:
Roman, I can only give you one piece of advice: go to the DC website and look for their history.
I did. Already wrote to their customer support. Thank you, Mathemat.
Reason: