[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 567
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
Another question from a beginner.
I use several user-defined functions in my Expert Advisor. How can I make these functions be combined into a library, and in the body of the Expert Advisor just call them from there.
I am not familiar with language syntax in this regard.
Please refer to documentation or tutorial section. I haven't found it there.
https://book.mql4.com/ru/build/structure
https://www.mql5.com/ru/articles/1462
+ to top it off... https://book.mql4.com/ru/appendix/examples
How to write a function that checks if a position is or has been opened on zero bar (preferably a choice of timeframe. OpenPosLastBar(string sym="", int tf=0, int op=-1, int mn=-1), or this function does that. As I understood it, it will only open positions at the moment, but if it was open and already closed, it will return -1.
//+----------------------------------------------------------------------------+
//| Returns the bar number of the last position opened or -1. |
//| Parameters: |
//| sym - instrument name ("" - current symbol) |
//| tf - timeframe ( 0 - current timeframe) |
//| op - operation (-1 - any position) |
//| mn - MagicNumber (-1 - any magik) |
//+----------------------------------------------------------------------------+
int NumberOfBarLastPos(string sym="", int tf=0, int op=-1, int mn=-1)
{
datetime oot;
int i, k=OrdersTotal();
if(sym=="")
sym=Symbol();
for(i=0; ik; i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol()==sym)
{
if(OrderType()==OP_BUY || OrderType()==OP_SELL)
{
if(op0 || OrderType()==op)
{
if(mn0 || OrderMagicNumber()==mn)
{
if(ootOrderOpenTime()) oot=OrderOpenTime();
}
}
}
}
}
}
return(iBarShift(sym, tf, oot, True));
}
//+----------------------------------------------------------------------------+
Нужно два цикла. В первом проходим по истории ордеров, во втором - по текущим ордерам. В обоих случаях если время открытия ордера больше или равно Time[0], то ордер был открыт на текущей свече. Это справедливо для всех таймфреймов.
Thank you for clicking. Could you ask for this in the code
Спадибо, что аткликнулся. А можно попросить это в коде
Here is an example of a history passage
Try to come up with your own code, especially since you have the algorithm and a ready-made example in front of you.
ObjectDelete(a_name_0);
ObjectCreate(a_name_0, OBJ_ARROW, a_window_8, a_datetime_12, a_price_20);
ObjectSet(a_name_0, OBJPROP_ARROWCODE, ai_28);
ObjectSet(a_name_0, OBJPROP_COLOR, a_color_32);
ObjectSet(a_name_0, OBJPROP_WIDTH, a_width_36);
}
void _setabuy(string as_0) {
g_str_concat_356 = StringConcatenate(as_0, gi_120);
seta(g_str_concat_356, 0, TimeCurrent(), Bid + 15.0 * Point, SYMBOL_ARROWUP, Blue, 2);
gi_120++;
}
void _setasell(string as_0) {
g_str_concat_356 = StringConcatenate(as_0, gi_120);
seta(g_str_concat_356, 0, TimeCurrent(), Bid - 15.0 * Point, SYMBOL_ARROWDOWN, Red, 2);
gi_120++;
}
Вот пример прохода по истории
Попробуйте самостоятельно придумать код, тем более, что алгоритм и готовый пример у Вас перед глазами.
Thank you. I'll give it a try.
Вот пример прохода по истории
Попробуйте самостоятельно придумать код, тем более, что алгоритм и готовый пример у Вас перед глазами.
Or here is a function that checks if a position was opened on the current bar (with a check on OrdersTotal() and OrdersHistoryTotal() ). Returns true if a Type order was opened.
Please tell me how to implement the condition.
If( there are pending orders) then do this and that ;