Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 82
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
You'll get the last losing one, what to do with it and what parameters to adjust for yourself, I think you'll figure it out
Thanks, I think I've got it.
How do I make the lot return to its original value after take profit?
{
lot=0.1
}
Thanks, I think I've got it.
How do I get the lot to revert back to its original value after take profit?
{
lot=0.1
}
I have the following scheme
if (OrdersTotal()==0)
{
open with initial lot
}
else
...
i.e. if there are no orders, it will not open with the old lot
Of course it is possible to memorise each order, but they do not tell us how to do it.A counter should be started and reset to its initial value when a certain threshold is reached:
{
//---
int b_STOP,s_STOP,b=0,s=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS)==true)
{
if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
if (OrderType()==OP_BUY) b++;
if (OrderType()==OP_SELL) s++;
if (OrderType()==OP_BUYSTOP) b_STOP++;
if (OrderType()==OP_SELLSTOP) s_STOP++;
}
if (OrderType()==OP_BUY)
{
if(b>=1&&s==1)//бай позиций больше или 1 и появилась SELL позиция
{
OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),3,CLR_NONE);
CLOSEORDER(OP_SELL);
}
}
}
}
Explain why the OrderProfit()<0 function does not work?
{
if(OrderSelect(q,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderType()<2 && OrderMagicNumber()==magic)
{
if (OrderProfit()<0)
{
if (DayOfWeek()==1)
{
day1++;
Print ("Понедельник SL=",day1);
}
if (DayOfWeek()==2)
{
day2++;
Print ("Вторник SL=",day2);
}
}
}
}
}
i want to see how many stoplosses by day of the week
{
if(OrderSelect(l,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()<0 && OrderType()<2)
{
oldticket=OrderTicket();
}
if (oldticket>=ticket)
{
ticket=oldticket;
lot=OrderLots()*4;
}
if (OrderProfit()>0 && OrderType()<2)
{
lot=0.01;
}
}
}
and here i think it's the same reason why it doesn't work
Explain why the OrderProfit()<0 function does not work?
{
if(OrderSelect(q,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderType()<2 && OrderMagicNumber()==magic)
{
if (OrderProfit()<0)
{
if (DayOfWeek()==1)
{
day1++;
Print ("Понедельник SL=",day1);
}
if (DayOfWeek()==2)
{
day2++;
Print ("Вторник SL=",day2);
}
}
}
}
}
i want to see how many stoplosses by day of the week
{
if(OrderSelect(l,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderProfit()<0 && OrderType()<2)
{
oldticket=OrderTicket();
}
if (oldticket>=ticket)
{
ticket=oldticket;
lot=OrderLots()*4;
}
if (OrderProfit()<0 && OrderType()<2)
{
lot=0.01;
}
}
}
and here I take it it's the same reason why it doesn't work
Because DayOfWeek() returns the order number of the day of the week of the last known server time.
And you need the day of the week of the order closing time: TimeDayOfWeek(OrderCloseTime());
Because DayOfWeek() returns the order number of the day of the week of the last known server time.
And you need the day of the week of the order closing time: TimeDayOfWeek(OrderCloseTime());
But the result is the same, as if ignoringif(OrderProfit()<0) and there is a loop, variables get large values.
2017.01.19 00:42:47.883 2014.02.20 23:59:48 EURUSD,H1: Понедельник SL=963666
2017.01.19 00:42:47.883 2014.02.20 23:59:48 EURUSD,H1: Вторник SL=1430207
2017.01.19 00:42:47.883 2014.02.20 23:59:48 EURUSD,H1: Понедельник SL=963665
What about the loop with a lot? I copied it incorrectly here, corrected the signif(OrderProfit()>0&&OrderType()<2), but it doesn't change the essence, the loop works correctly without this condition.
But the result is the same, as ifif(OrderProfit()<0) is ignored and there is a loop, variables have large values.
2017.01.19 00:42:47.883 2014.02.20 23:59:48 EURUSD,H1: Понедельник SL=963666
2017.01.19 00:42:47.883 2014.02.20 23:59:48 EURUSD,H1: Вторник SL=1430207
2017.01.19 00:42:47.883 2014.02.20 23:59:48 EURUSD,H1: Понедельник SL=963665
And about the loop with a lot? I copied it incorrectly here, corrected the signif(OrderProfit()>0&&OrderType()<2), but it does not change the essence, the loop works correctly without this condition.
Where are day1 and day2 declared ?
Where are day1 and day2 declared ?
I suspect I am selecting the order incorrectly, it does not work(OrderProfit()<0), I need to be more specific about which order I need. I don't know why it skips an order when the last one closed at Take-Point and there are no others. Maybe, if I want to search through the history, the loop should be built differently?
{
if(OrderSelect(w,SELECT_BY_POS,MODE_HISTORY))
The reason is that Expert Advisors build loops with similar conditions and they work as required, but they work usingOrdersTotal().
{
if(OrderSelect(n,SELECT_BY_POS))
{
if(OrderMagicNumber()==magic)
{
if(OrderType()>OP_SELL)
{
//---
int b_STOP,s_STOP,b=0,s=0;
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS)==true)
{
if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
if (OrderType()==OP_BUY) b++;
if (OrderType()==OP_SELL) s++;
if (OrderType()==OP_BUYSTOP) b_STOP++;
if (OrderType()==OP_SELLSTOP) s_STOP++;
}
if (OrderType()==OP_BUY)
{
if(b>=1&&s==1)//бай позиций больше или 1 и появилась SELL позиция
{
OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),3,CLR_NONE);
CLOSEORDER(OP_SELL);
}
}
}
}
This cannot be solved within a single cycle. In this loop, you should memorize the tickers of orders to be deleted in the array, in the next loop, you should delete them by tickers.
In addition, you have a mess with curly brackets, you are working with orders outside theOrderSelect{} block, this is incorrect.