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!
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!
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()
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// Указатель на стринг, я плохо помню.
};
staticint CompareMqlStr(constvoid *left,constvoid *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(constint ipar) // __stdcall кладет аргументы в стек справа налево
{ // MT4_EXPFUNC говорит что функция будет видима из метатрайдера, я не совсем понял.printf("GetIntValue takes %d\n",ipar);
return(ipar);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetDoubleValue(constdouble 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(constdouble *arr,constint arraysize,constint 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,constint arraysize,constint nitem,constdouble 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,constint rates_total,constint shift,constint 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)
{
case0: returndouble(rates[nitem].ctm);
case1: return rates[nitem].open;
case2: return rates[nitem].low;
case3: return rates[nitem].high;
case4: return rates[nitem].close;
case5: return rates[nitem].vol;
}
//---return(0.0);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall SortStringArray(MqlStr *arr,constint 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,constint 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 stringif(arr[i+1].string==NULL) continue;
//--- destination string is uninitialized and cannot be allocated within dllif(arr[i].string==NULL) continue;
//--- memory piece is less than needed and cannot be reallocated within dllif(arr[i].len<len1+len2) continue;
//--- final processing
strcat(arr[i].string,arr[i+1].string);
}
//---return(arraysize);
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+int CompareMqlStr(constvoid *left,constvoid *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.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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);
}
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.
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:
EA trading criteria:
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.
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.
Are you joking?
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()
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.
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.