Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 218
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
I completed your code with block to open order with volume 0.1 (right after void start() function)
But for some reason the program does not open any orders of increased volume (0.3 lots each) in response to closure of these orders
THE THINGS I DO NOT UNDERSTAND IN YOUR CODE
1. If I understood correctly, you are assigning МН=123 only to orders with 0.3 lot volume.
In the datetime function SearTim (int s) you are looking for an order with MH=123 but with a volume of 0.1.
But the order with volume 0.1 cannot have МН=123, because this MM is assigned only to orders with volume 0.1
In the bodies of the datetime SearTim(int s) and int sear() functions, and specifically in the comments, it is necessary to open an order with a volume of 0.3
I do not understand why I have to open an order with a larger volume under the same conditions more than once.
You have already opened orders with increased volume in the first block.
I would be very grateful to you if you could write some code which would open an order with 0.3 volume after closing each 0.1 order and keep the value of 0.1.
In this case, I will do my best to find all answers to my questions in your code with the help of the Print () function, my modest knowledge and reference books.
NOTE:
I have the same type of orders with 0.1 and 0.3 volume - only SEL. That is why if I am not mistaken, we don't have to calculate the order type (BAY or SEL) in the int sear() function.
I would like to remind you once again that the final goal of my program is to memorize the hour value (not a minute, not a second, but only an hour) of the opening of 0.1 order after it was closed at its close price by a 0.3 order that closed at the SL
I apologize that I cannot explain much to you, because you must know the programming language. I think you are a programmer already and I was relying on someone who knows programming.
You have to learn programming first. If I explain to you what and how, it will be learning a programming language.
Look at examples of EAs, how they are written and try to write programs from the very beginning. And you are trying to write a program that is already complicated.
Look at the tutorial and examples of how to write commands and example modules.
I address this uncomplicated question, here is the closing block.
When the profit of an order becomes positive, it closes that order and on that entire profit how much of a losing position is possible. If Perekr is enabled.
We have to change it so it closes both positions only when the profit of a profitable position covers ALL the loss of a losing position, i.e. so that the profit of one order is equal to or greater than the loss of the other.
if(Mas_Tip[1]>0)
{
if(Bidt-step*Point>=NormalizeDouble(Bid,Digits))
{
Profit=AccountBalance()-StartProfit;
Askt=NormalizeDouble(Ask,Digits);
Bidt=NormalizeDouble(Bid,Digits);
for(int i=1; i<=OrdersTotal(); i++)
{
if(OrderSelect(i-1,SELECT_BY_POS)==true && OrderType()==OP_SELL &&
OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(Razn<2)
{
if(Perekr && OrderProfit()>0 && max_lot>=Lots_per) //перекрытие
{
double profit=OrderProfit();
Print("закрываю по перекрытию");
ClosePosBySelect(OrderLots());
for(int f=OrdersTotal()-1;f>=0;f--)
{
if(OrderSelect(f,SELECT_BY_POS)==true && OrderType()==OP_BUY &&
OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()<0)
{
if(profit>=MathAbs(OrderProfit()))
{
Print("закрываю по перекрытию");
ClosePosBySelect(OrderLots());
}
Friends, hello. I need some help from a newbie.
I want to be notified by email about crossover of some indicator by price. I have understood how to do it, but as soon as the price-crossing happens, I get hundreds of emails, and they keep sending it indefinitely until the current candle closes. What to make to send only one message? Here is an example:
if((iSAR(NULL, 0,Step,Maximum, 1)<iClose(NULL,0,1))&&(iSAR(NULL, 0,Step,Maximum, 2)>iClose(NULL,0,2))){
bool res = SendMail("Buy Signal", "Buy Signal");
}
if((iSAR(NULL, 0,Step,Maximum, 1)>iClose(NULL,0,1))&&(iSAR(NULL, 0,Step,Maximum, 2)<iClose(NULL,0,2))){
SendMail("Sell Signal", "Sell Signal");
}
Friends, hello. I need some help from a newbie.
I want to be notified by email about crossover of some indicator by price. I have understood how to do it, but as soon as the price-crossing happens, I get hundreds of emails, and they keep sending it indefinitely until the current candle closes. What to make to send only one message? Here is an example:
if((iSAR(NULL, 0,Step,Maximum, 1)<iClose(NULL,0,1))&&(iSAR(NULL, 0,Step,Maximum, 2)>iClose(NULL,0,2))){
bool res = SendMail("Buy Signal", "Buy Signal");
}
if((iSAR(NULL, 0,Step,Maximum, 1)>iClose(NULL,0,1))&&(iSAR(NULL, 0,Step,Maximum, 2)<iClose(NULL,0,2))){
SendMail("Sell Signal", "Sell Signal");
}
It's simple with parabolic, put a flag in the condition. Or a simple variable of int type and the value changes with every signal.
Good day everyone, could you please help me with Trailing Stop. I've written a Trailing Stop on the condition that I initially have SL = 100 and Trailing Stop should be triggered when price is 30 pips above the position opening. But it modifies immediately after the position is opened and changes the standard SL to 30 and then moves it.
void Trailing()
{
int SLoss = 1;
double StopL = NormalizeDouble (OrderOpenPrice() + SLoss*Point, Digits);
double StopL2 = NormalizeDouble (OrderOpenPrice() - SLoss*Point, Digits);
for (int i=OrdersTotal() - 1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if (OrderType() == OP_BUY && OrderStopLoss() >= StopL)
{
if (Bid - StopL > TrailingStop*Point)
{
if (OrderStopLoss() < Bid-(TrailingStop+TrailingStep)*Point)
{
if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*Point, Digits), 0, 0))
Print(" Ordermodification error!");
}
}
}
if (OrderType() == OP_SELL && OrderStopLoss() <= StopL2)
{
if (StopL2 - Ask > TrailingStop*Point)
{
if (OrderStopLoss() > Ask+(TrailingStop+TrailingStep)*Point)
{
if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*Point, Digits), 0, 0))
Print("Order modification error!");
}
}
}
}
}
}
}
With parabolic it's simple, put a flag in the condition. Or a simple variable of int type and the value changes with each signal.
Good day everyone, could you please help me with Trailing Stop. I've written a Trailing Stop on the condition that I initially have SL = 100 and Trailing Stop should be triggered when price is 30 pips above the position opening. It will modify it right after opening position and change standard SL to 30 and then move it.
...Just forgot about else - otherwise the static variable stays true after the first signal
What's the point of the elza in there? I think flag == true; or flag == false; which is in the code
If there is an intersection to one side, we wait for an intersection to the other... And so the loop is closed. But how to connect it correctly at first start, let him think for himself. Or ask him later...
Why is there a jelza in there? I think flag == true; or flag == false; which is in the code
When crossing to one side, we wait for the crossing to the other side... ...and so the cycle is closed. But how to connect it correctly at the first start, let him think for himself. Or ask him later...
If there are two signals on different bars in one direction?
You have only swing.
But the signals should always be sent when there is a signal, but the decision to signal is made separately.
It seems to me that for each direction it would be optimal to have its own flag, and switch it back and forth. But not so that signals of one direction depend on signals of the opposite direction.
If the two signals are on different bars in the same direction?
You only get a swing.
But the signals should always be sent when there is a signal, but the decision to signal is made separately.
It seems to me that for each direction it is optimal to have its own flag, and to switch it back and forth. But not so that the signals of one direction depend on the signals of the opposite direction.
Artem, I started my reply to you with the following words
This is the forum for trading, automated trading systems and trading strategies testing.
Any questions from beginners on MQL4, help and discussion on algorithms and codes
Alexey Viktorov, 2017.05.29 08:09
With parabolic it's simple,
The parabolic has a strict alternation, two signals in one direction are impossible even on different bars. And there is no need to invent anything at all for that, it does not rattle even on zero bars like the MA.