Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 182

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
And you haven't shown a single piece of your code - it's not clear why you're showing an example.
struct p{
double trailingProfit;
int orders[10];
bool flagOpen;// флаг , указывающий на открытость позиции
//тут еще куча связанных параметров
};
p order[];
int OrderN=-1;
int OnInit()
{
ArrayResize(pair,1,1000);
return(INIT_SUCCEEDED);
}
void openOrder(price){
OrderN++;
int t;
ArrayResize(orders,order+1);
t=OrderSend(Symbol(),OP_BUYSTOP,2,(NormalizeDouble(price,Digits)),3,0,0,"pair",MAGICN,0,Blue);
if(t==0) Print("не удалось выставить ордер BUYSTOP ", price);
for(intj=0,j<10,++j){
if(orders[OrderN].orders==0) orders[OrderN].orders=t;
break;
}
orders[OrderN].flagOpen=1;
}
//...... тут идет обработка позиций...
void massCut(){
// нужна вот такая функция
}
What happens to the array of structures when the EA is restarted?
What happens to the structure array when the EA is restarted?
The array will be deleted, this issue has not been solved.
There. And this should have been considered in the first place.
The conclusion is obvious: the array has to be zeroed out and re-filled with the current state of orders and positions. But this should only be done when you catch changes in the amount of orders or positions in the account.
You will always have at hand only the current state of orders and positions, and there will be no need to bother eliminating non-existing orders/positions from the array. And the list of orders/positions will have to be scrolled through completely, or for a given period of history, but only in specific cases - when the number of orders/positions in the account changes.
Why do you need such a perversion?
So that OnInit would not spin at each reinitialization and reduce the static array into a single instance because in some places it is written twice... in general, this is resource optimization
... I'll leave it as it is, it's simpler at the moment
You declare a global array without specifying a size. Your function sets its size by ArrayResize. And it's visible globally, and OnInit is released...
Not quite right, the array is static with clearly defined values, it doesn't make sense to initialize it separately(
to prevent OnInit from spinning at every reinitialization and to reduce the static array to one instance because in some places it is written twice... in general this is resource optimization
... I'll leave it the way it is now.
Are commissions not taken into account in the MT4 tester?
Question on the function Print(); how to make Print() print the data plus the date (day) in the EA ? help a beginner to understand the plz, put the code remade for the sake of experiment, induke "pivot" beforehand cbs!
the code itself: PivotsDaily v2.mq4
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Blue
#property indicator_color3 Red
//---- input parameters
extern inttern CountBars=300;
//---- buffers
double PBuffer[];
double S1Buffer[];
double R1Buffer[];
string Pivot="P", Sup1="S 1", Res1="R 1";
int fontsize=10;
double P,S1,R1,S2,R2,S3,R3;
double LastHigh,LastLow,x;
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("Pivot");
ObjectDelete("S1");
ObjectDelete("R1");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
IndicatorBuffers(7);
//---- indicator line
SetIndexStyle(0,DRAW_ARROW,2,1,Lime);
SetIndexArrow(0,158);
SetIndexStyle(1,DRAW_ARROW,2,1,Blue);
SetIndexArrow(1,158);
SetIndexStyle(2,DRAW_ARROW,2,1,Red);
SetIndexArrow(2,158);
SetIndexBuffer(0,PBuffer);
SetIndexBuffer(1,S1Buffer);
SetIndexBuffer(2,R1Buffer);
//---- name for DataWindow and indicator subwindow label
short_name="Pivot";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
short_name="R1";
IndicatorShortName(short_name);
SetIndexLabel(2,short_name);
short_name="S1";
IndicatorShortName(short_name);
SetIndexLabel(1,short_name);
SetIndexDrawBegin(0,6);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit, i;
//---- indicator calculation
if (counted_bars==0)
{
x=Period();
if (x>CountBars) return(-1);
ObjectCreate("Pivot", OBJ_TEXT, 0, 0,0);
ObjectSetText("Pivot", " Pivot",10, "Arial",Lime);
ObjectCreate("S1", OBJ_TEXT, 0, 0, 0);
ObjectSetText("S1", " S1",10, "Arial",Blue);
ObjectCreate("R1", OBJ_TEXT, 0, 0, 0);
ObjectSetText("R1", " R1",10, "Arial",Red);
}
if(counted_bars<0) return(-1);
limit=(Bars-counted_bars)-1;
for (i=limit; i>=0;i--)
{
if (TimeDayOfWeek(Time[i]) != 0)
{
if (High[i+1]>LastHigh) LastHigh=High[i+1];
if (Low[i+1]<LastLow) LastLow=Low[i+1];
}
if (
TimeDay(Time[i])!=TimeDay(Time[i+1]) && TimeDayOfWeek(Time[i])!=0
)
{
P=Close[i+1];
R1 = LastLow;
S1 = LastHigh;
S2=High[i]-Low[i];
S3=High[i]-Open[i+1];
if(S3==0)
{R2 = S3;} else {R2 = S2/S3;}
Print("R2 ",R2); // <= how do I get the printer plus the data to print the date?
LastLow=Open[i]; LastHigh=Open[i];
ObjectMove("Pivot", 0, Time[i],P);
ObjectMove("S1", 0, Time[i],S1);
ObjectMove("R1", 0, Time[i],R1);
}
PBuffer[i]=P;
S1Buffer[i]=S1;
R1Buffer[i]=R1;
}
//----
return(0);
}