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

 
Igor Makanu:

there are many errors in your example

there should be:

here prices are not normalized OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-SL*Point,Bid+TP*Point,"My order",MagicNumber,0,clrGreen);

Here I don't understand the logic why the exit from OnTick() is necessary if the condition is false.

perhaps, we should go on with the loopand simply calculate how many orders there are

Your example is very simple in logic and it would be difficult to modify it for other tasks... maybe he'll want to do some trailing.

It's still early)))) There will be a lot at once. There's not much sense there))))) And so yes, of course after calculations for all that sendorder normalization is necessary))))

There the condition by order, if there are no orders on the current instrument with our magik, we put the order. And then the condition will not reach the order until it closes.

PS don't like the condition If not.

 

Greetings, could you tell me how to read the expression

string sym=(symbol==NULL ? Symbol() : symbol);
 
Galim_V:

Greetings, could you tell me how to read this expression correctly?

Ifsymbol is empty, return the value of the current symbol to the sym variable, and if it's not empty, return the value to the sym variable

 
Vladimir Pastushak:

If symbol variable is empty, then return the value of the current chart symbol to the sym variable, and if it is not empty, then pass its value to the sym variable

Thank you!

 
Galim_V:

Greetings, could you tell me how to read this expression correctly?

It reads: Assign Symbol() to the variable if symbol is NULL, otherwise assign symbol to the variable.

This entry's equivalent

string sym;
if(symbol == NULL)
sym = Symbol();
else
sym = symbol;
The only difference is the number of lines.
 
Alexey Viktorov:

Reads as follows: Assign a variable to Symbol() if symbol is NULL otherwise assign a value to symbol.

Equivalent to this entry

The only difference is the number of lines.

Thank you!

 
Valeriy Yastremskiy:

What then, for example, you have a window open not Eurobucks, but Eurofunt, you compare the symbol of the selected order with Eurobucks, if true, then there is an order on Eurobucks, and if our magik, then return from the Onstart function, and if not, then set an order on Eurobucks, but Kloz, High, Asc, Bid you will have for Eurofunt. will be an error when opening orders because bid and ask for these instuents different. And Symbol() will return the symbol of the current window and no error will occur.

Use the template from the meta editor, there is a New button at the top left. OnStart function is still used, but it's not right, and OnStart is for scripts. The right template.

The correct code. Your order comment is missing, and the magician is not accounted for in your code. In the warnings to the opening line note Implicit type conversion of a number to a string!!!

Yes, it works as it should. Thanks!!!

Didn't know it was so important to create by template. OnStart indeed. I had the basic structure wrong. Well, I'll know that now.

 
Alexey Belyakov:

Yes, it works as it should. Thank you! (Laughs)

I didn't know it was so important to create from a template. OnStart, indeed. I had the basic structure wrong. Well, I'll know that now.

Well, and everything that you put in the functions of working with orders should be normalized. If the decimal point is followed by 6 digits, the order will not be placed and will generate an error.

Search the topic with "Only useful functions from KimIV" or look it up in KodoBase.

Igor Makanu wrote above more errors. And Kim's functions are really useful to start with. The comments are clear.

 

Please help. Why does testing give an error - "" 2020.08.13 13:09:11.393 2018.08.01 00:00:123456 GBPUSD,M30: array out of range in '123456.mq4' (59,13)"" ????


#property link "2020, Grey."

#property link "uirnP0215@mail.ru"

#property version "1.00"

#property strict


input double lots = 0.01;

input int Magic = 1546;



double ibufUP[];

double ibufDN[];


//+------------------------------------------------------------------+

//| Expert initialisation function |

//+------------------------------------------------------------------+

int OnInit()

{


return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---


}

//+------------------------------------------------------------------+

//| expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

CountFractals();

if(ibufUP[3]>0)

{

if(!OrderSend(Symbol(), OP_SELL, lots, Bid, 30, 0, 0, "", Magic, 0, clrRed))

Print("Failed to open sell order");

}

if(ibufDN[3]>0)

{

if(!OrderSend(Symbol(), OP_BUY, lots, Bid, 30, 0, 0, "", Magic, 0, clrGreen))

Print("Failed to open a Buy order");

}



}

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

void CountFractals()

{

for(int i=150; i>=0; i--)

{

ibufUP[i] = iFractals(NULL, 0, MODE_UPPER, i);

ibufDN[i] = iFractals(NULL, 0, MODE_LOWER, i);

}

}

//+------------------------------------------------------------------+



 
Madmas:

Please help. Why does testing give an error - "" 2020.08.13 13:09:11.393 2018.08.01 00:00:123456 GBPUSD,M30: array out of range in '123456.mq4' (59,13)"" ????


#property link "2020, Grey."

#property link "uirnP0215@mail.ru"

#property version "1.00"

#property strict


input double lots = 0.01;

input int Magic = 1546;



double ibufUP[];

double ibufDN[];


//+------------------------------------------------------------------+

//| Expert initialisation function |

//+------------------------------------------------------------------+

int OnInit()

{


return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

//---


}

//+------------------------------------------------------------------+

//| expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

CountFractals();

if(ibufUP[3]>0)

{

if(!OrderSend(Symbol(), OP_SELL, lots, Bid, 30, 0, 0, "", Magic, 0, clrRed))

Print("Failed to open sell order");

}

if(ibufDN[3]>0)

{

if(!OrderSend(Symbol(), OP_BUY, lots, Bid, 30, 0, 0, "", Magic, 0, clrGreen))

Print("Failed to open a Buy order");

}



}

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

void CountFractals()

{

for(int i=150; i>=0; i--)

{

ibufUP[i] = iFractals(NULL, 0, MODE_UPPER, i);

ibufDN[i] = iFractals(NULL, 0, MODE_LOWER, i);

}

}

//+------------------------------------------------------------------+



Add a decrement counter in theCountFractals function for a start.