Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 341

 
Trader7777:

Folks, help please. I want to write a function so that each next open order opens with a lot 2 times bigger than the previous one. This function is giving out wrong values... What is wrong with it? Thanks in advance!



extern double LotBuy = 0.01;


double GetLotBuy()

{

for(int n = 1; n<=CountBuy(); n++)
{
LotBuy=LotBuy*2;
}
return (LotBuy);
}


For starters:

extern double LotBuy = 0.01;

double GetLotBuy()

{
double ld_Lot = LotBuy;
for(int n = 1; n<=CountBuy(); n++)
{ld_Lot = LotBuy * n * 2;}
return (ld_Lot);
}

 
Trader7777:

Folks, please help. I want to write a function so that each next open order opens with a lot 2 times the previous one. This function is giving out wrong values... What is wrong with it? Thanks in advance!



extern double LotBuy = 0.01;


double GetLotBuy()

{

for(int n = 1; n<=CountBuy(); n++)
{
LotBuy=LotBuy*2;
}
return (LotBuy);
}

Try this.

double OrderLotsSB(string sy="", int op=-1, int mn=-1) { 
 datetime o;
   int      i, k=OrdersTotal(); double r=-1;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if ( OrderType()==OP_SELL||OrderType()==OP_BUY) {
          if (op<0 || OrderType()==OP_SELL||OrderType()==OP_BUY) {
            if (mn<0 || OrderMagicNumber()==Magic) {
              r=OrderLots()*2;
            }
          }
        }
      }
    }
  }
  return(r);
}
 
TarasBY:

For a start:

extern double LotBuy = 0.01;

double GetLotBuy()

{
double ld_Lot = LotBuy;
for(int n = 1; n<=CountBuy(); n++)
{ld_Lot = LotBuy * n * 2;}
return (ld_Lot);
}



Are you kidding me?
 

Made an EA based on my own indicator.

Opening trades buy on the rise and sell on the fall of the indicator in relation to yesterday.

The problem is that trades open and close through a bar or more.

The indicator is set to ignore the movements on a certain set value.

If there is no excess, the indicator value remains as in the previous bar (I think the problem is somewhere here)

Indicator code:

//+------------------------------------------------------------------+
//|                                                         EMAF.mq4 |
//|                                                 Kamil Gazizullin |
//|                                             forexman77@yandex.ru |
//+------------------------------------------------------------------+
#property copyright "Kamil Gazizullin"
#property link      "forexman77@yandex.ru"
#property indicator_chart_window
#property indicator_buffers 1
#property  indicator_color1 Red
//--- input parameters
//--- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexBuffer(0,ExtMapBuffer1);
   IndicatorDigits(Digits+1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int counted_bars=IndicatorCounted(),                      
    limit;
    double
    raznica,raznica_static,
    MA_1_t,                                                  
    MA_2_t;
 
   if(counted_bars>0)
      counted_bars--;
   limit=Bars-counted_bars;
   for(int i=0;i<limit;i++)
   {  
      static double MA_otshet;
      MA_1_t=iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE,i+0);  
      MA_2_t=iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE,i+1); 
      raznica=MA_1_t-MA_2_t;
      raznica_static=MA_1_t-MA_otshet;
      if(raznica_static > -0.003 && raznica_static < 0.003)
      {
      ExtMapBuffer1[i]=MA_otshet;
      }
      else
      if(raznica > -0.003 && raznica < 0.003)
      {
      ExtMapBuffer1[i]=MA_2_t;
      MA_otshet=MA_2_t;
      }
      if((raznica > 0.003) || (raznica <- 0.003))
      {
      ExtMapBuffer1[i]=MA_1_t;
      }
   }
   return(0);
  }
//+------------------------------------------------------------------+

EA trading criteria:

   // Торговые критерии
EMAF_1=iCustom(NULL, 0, "EMAF",0,0,i+0);    
EMAF_2=iCustom(NULL, 0, "EMAF",0,0,i+1); 
static datetime t;
if  (EMAF_1 > EMAF_2)
          {                                          
          Opn_B=true; 
          t=Time[0];                  
          }
if  (EMAF_1 < EMAF_2)
      {
       if(Time[0]>t)
          {                                      
          Cls_B=true;              
          }
      }
 
klop:
Hello!

A script like this is needed:

was
eur/gbp / 1 lot / open 312.25 / sl 559.45 / tp 454.55
yui/ghf / 1 lot / open 3.28 / sl 5.65 / tp 4.65
.../... / 1 lot / open ...... / sl ...... / tp .......


became
eur/gbp / 1.02 lot / open 312.25 / sl 559.45 / tp 454.55
yui/ghf / 1.02 lot / open 3.28 / sl 5.65 / tp 4.65
.../... / 1.02 lot / open ...... / sl ...... / tp .......

What would close pending orders with a certain volume (lot), and open a new order with another volume, but the same entry level, stop and take.

I don't know... Maybe someone has.
If you're looking for a script with such a function, you may use a search engine on this site.
 
max020780:



I don't understand anything here...


I want the lot size to increase geometrically (with a multiplier of 2) if a second unidirectional order is opened.

 
Vinin:

Are you joking?
The solution not infrequently consists of several "steps". The 1st step is to reduce the exponential growth of the lot size. Along the way we give at least some meaning to the use of the cycle. And since we do not know "where the beginning", the further steps are left to the author. ;)
 
TarasBY:
The solution not infrequently consists of several "steps". The 1st step is to reduce the exponential growth of the lot size. At the same time we give at least some meaning to the use of the cycle. And since we do not know "where the beginning", the further steps are up to the author. ;)

This is, of course, wonderful, but still, how to express how to open the next one-directional order with lot twice more than the previous one? There are already two working functions CountBuy() and CountSell()
 
Trader7777:
What prevents you from doing such a check (script)?
Files:
 

Here's the .cpp file of the project, have a look at it and after a couple of Google and Yandex searches, I didn't find anything at all brainy, it's generally understandable. It even seems simple.

//+------------------------------------------------------------------+
//| Sample DLL for MQL4 |
//| Copyright 2001-2012, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#define  WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
//---
#define  MT4_EXPFUNC __declspec(dllexport) //это что?
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#pragma  pack(push,1)
struct RateInfo // Структура, переменные
{
unsigned int ctm;
double open;
double low;
double high;
double close;
double vol;
};
#pragma  pack(pop)
//---
struct MqlStr
{
int len;
char *string // Указатель на стринг, я плохо помню.
};
static int CompareMqlStr(const void *left,const void *right);
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)//функция 
{
//---
switch(ul_reason_for_call) // оператор что делать
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH: //что это всюду, не понял.
break;
}
//---
return(TRUE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall GetIntValue(const int ipar) // __stdcall кладет аргументы в стек справа налево
{ // MT4_EXPFUNC говорит что функция будет видима из метатрайдера, я не совсем понял.
printf("GetIntValue takes %d\n",ipar);
return(ipar);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetDoubleValue(const double dpar)
{
printf("GetDoubleValue takes %.8lf\n",dpar);
return(dpar);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC char* __stdcall GetStringValue(char *spar)
{
printf("GetDoubleValue takes \"%s\"\n",spar);
return(spar);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetArrayItemValue(const double *arr,const int arraysize,const int nitem)
{
//---
if(arr==NULL)
{
printf("GetArrayItemValue: NULL array\n");
return(0.0);
}
if(arraysize<=0)
{
printf("GetArrayItemValue: wrong arraysize (%d)\n", arraysize);
return(0.0);
}
if(nitem<0 || nitem>=arraysize)
{
printf("GetArrayItemValue: wrong item number (%d)\n", nitem);
return(0.0);
}
//---
return(arr[nitem]);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC BOOL __stdcall SetArrayItemValue(double *arr,const int arraysize,const int nitem,const double value)
{
//---
if(arr==NULL)
{
printf("GetArrayItemValue: NULL array\n");
return(FALSE);
}
if(arraysize<=0)
{
printf("GetArrayItemValue: wrong arraysize (%d)\n", arraysize);
return(FALSE);
}
if(nitem<0 || nitem>=arraysize)
{
printf("GetArrayItemValue: wrong item number (%d)\n", nitem);
return(FALSE);
}
//---
arr[nitem]=value;
return(TRUE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetRatesItemValue(const RateInfo* rates,const int rates_total,const int shift,const int nrate)
{
//---
if(rates==NULL)
{
printf("GetRatesItemValue: NULL array\n");
return(0.0);
}
//---
if(rates_total<0)
{
printf("GetRatesItemValue: wrong rates_total number (%d)\n", rates_total);
return(0.0);
}
//---
if(shift<0 || shift>=rates_total)
{
printf("GetRatesItemValue: wrong shift number (%d)\n", shift);
return(0.0);
}
//---
if(nrate<0 || nrate>5)
{
printf("GetRatesItemValue: wrong rate index (%d)\n", nrate);
return(0.0);
}
//---
int nitem=rates_total-1-shift;
switch(nrate)
{
case 0: return double(rates[nitem].ctm);
case 1: return rates[nitem].open;
case 2: return rates[nitem].low;
case 3: return rates[nitem].high;
case 4: return rates[nitem].close;
case 5: return rates[nitem].vol;
}
//---
return(0.0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall SortStringArray(MqlStr *arr,const int arraysize)
{
//---
if(arr==NULL)
{
printf("SortStringArray: NULL array\n");
return(-1);
}
if(arraysize<=0)
{
printf("SortStringArray: wrong arraysize (%d)\n", arraysize);
return(-1);
}
//---
qsort(arr,arraysize,sizeof(MqlStr),CompareMqlStr);
//---
return(arraysize);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall ProcessStringArray(MqlStr *arr,const int arraysize)
{
int len1,len2;
//---
if(arr==NULL)
{
printf("ProcessStringArray: NULL array\n");
return(-1);
}
if(arraysize<=0)
{
printf("ProcessStringArray: wrong arraysize (%d)\n", arraysize);
return(-1);
}
//---
for(int i=0; i<arraysize-1; i++)
{
if(arr[i].string==NULL) len1=0;
else len1=strlen(arr[i].string);
if(arr[i+1].string==NULL) len2=0;
else len2=strlen(arr[i+1].string);
//--- uninitialized string
if(arr[i+1].string==NULL) continue;
//--- destination string is uninitialized and cannot be allocated within dll
if(arr[i].string==NULL) continue;
//--- memory piece is less than needed and cannot be reallocated within dll
if(arr[i].len<len1+len2) continue;
//--- final processing
strcat(arr[i].string,arr[i+1].string);
}
//---
return(arraysize);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int CompareMqlStr(const void *left,const void *right)
{
MqlStr *leftstr=(MqlStr *)left;
MqlStr *rightstr=(MqlStr *)right;
//---
if(leftstr->string==NULL) return(-1); //-> вот этот знак я не знаю
if(rightstr->string==NULL) return(1);
//---
return(strcmp(leftstr->string,rightstr->string));
}
//+------------------------------------------------------------------+

But how does it work? I'm not quite sure how to refer to this ddl - from the EA's code? How? First, it looks like this #include <GetIntValue>.

2. When calling the dll, you don't have to keep studio on, right? how is it executed?

Please show the simplest example of calling this dll from mql code.

Reason: