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

 
Artyom Trishkin:

No one called you a "dummy", that's not true. But 4-6 lines of code also, you know, cause bewilderment - because if a person learns something, he must already be trying something, he has tried to write something, and clearly already sees that 4-6 lines do not fit into it.

Show us what you tried to do - let's try to understand.

I can offer an alternative, simplified variant - do not look for a price level crossing by ticks, but look for it by MA(1) - then the MA on bar 1 and the MA on bar 0 will be used as an indicator of the necessary level crossing.


Sorry for the long delay in responding. I'm glad it turned out to be a mere bewilderment, I got flustered. And as for my question, I managed to write a code that would open a normal order when it reaches the price and that it would not open again after crossing that price. But I did it this way:
double b = 5;
int start()
{
double bid = Bid;
if (bid==0.7777 && b==5)
{
b=b+1;
OrderSend(Symbol(), OP_BUY, 0.1, Ask, 0,0,0);
}

return;

I have already understood that this is a "kindergarten" method and it cannot be used because there are too many nuances and it's not practical at all. Can you tell in which situation this code won't work or how can you change it to make it work? P.s. "look for it on MA(1) - then MA on bar 1 and MA on bar 0 will serve you as an indicator of crossing the level you want. "I don't really know what it's about, so I can put it off for now until I've studied more material


 
maxon777:

Sorry for taking so long to reply. I'm glad it turned out to be just a bewilderment, I got flustered. And as for my question, I managed to write a code that would open a normal order when it reaches the price and that it would not open again after crossing this price. But I did it this way:
double b = 5;
int start()
{
double bid = Bid;
if (bid==0.7777 && b==5)
{
b=b+1;
OrderSend(Symbol(), OP_BUY, 0.1, Ask, 0,0,0);
}

return;

I have already understood that this is a "kindergarten" method and it cannot be used because there are too many nuances and it's not practical at all. Can you tell in which situation this code won't work or how can you change it to make it work? P.s. "look for it on MA(1) - then MA on bar 1 and MA on bar 0 will serve you as an indicator of crossing the level you want. " I don't really know what this is about, so this can be postponed for now until I learn more material



Comparison on equality of two numbers, type double, this is not a good operation.

Like,NormalizeDouble(A - B , 5)==0, I guess.

 

Good evening everyone!

Please help, I can't find a bug in the code.

I need to determine if i had a profit on my pair and if i did, i should not continue trading and close the EA.

put a pending order.

The problem is that when I run the EA, it immediately deletes it, i.e.ExpertRemove() triggers, although I haven't had a profit yet.

Below is some code:

void OnTick()

{

if (TakeProfit ()>0)

{

ExpertRemove();

}

if (TakeProfit ()<=0)

{

Here we put a pause

}

}

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

////////Looking to see if there were any trades closed here with a profit!!!!!!!!

int TakeProfit ()

{

int count = 0;

for(int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect (i,SELECT_BY_POS,MODE_HISTORY) == true && OrderMagicNumber() == Magic && OrderSymbol () == Symbol () && OrderProfit()>0.0)

{

count ++;

}

}

return (count);




 
yaaarik777:

Good evening everyone!

Please help, I can't find a bug in the code.

I need to determine if i had a profit on my pair and if i did, i should not continue trading and close the EA.

put a pending order.

The problem is that when I run the EA, it immediately deletes it, i.e. ExpertRemove() triggers, although I haven't had a profit yet.

Below is a part of the code:

////////Looking for whether there were ... closed with profit!!!!!!!!

int TakeProfit ()

{

int count = 0;

for(int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect (i,SELECT_BY_POS,MODE_HISTORY) == true && OrderMagicNumber() == Magic && OrderSymbol () == Symbol () && OrderProfit()>0.0)

{

count ++;

}

}

return (count);

What are you looking for with this code?

It looks at the profit of the entire history, not exactly of a closed position, and if the entire history is positive, then you get OrderProfit()>0 in any case

 
Vitaly Muzichenko:

What are you looking for with this code?

It looks for a profit on the entire history, not specifically a closed position, and if the entire history is positive, then you will get OrderProfit()>0 on the output at any scenario


How can I make it search not by the entire history, but by closed positions from the moment of advisor's work?

I do not understand.

I do not understand.

 
yaaarik777:


How can I make it search not the whole EA, but the closed ones from the moment of the EA's work?

I do not understand.

Thanks for the help.

Find the last closed position, which was closed later than the time of EA start, or the last closed on this day, and see its profit: OrderProfit()+OrderComission()+OrderSwap()
 
yaaarik777:


How do I make it search not the whole EA, but the closed ones from the moment of the EA's work?

I don't get it.

Thank you for your help.


How do you determine when the EA is working?

Here is my suggestion;

double TakeProfit ()
{
 datetime момент работы советника=0;
 double p=0;
  for(int i=OrdersHistoryTotal()-1; i>=0; i--){
    if (OrderSelect (i,SELECT_BY_POS,MODE_HISTORY)){
       if (OrderMagicNumber() == Magic){
          if(OrderSymbol () == Symbol ()){
            if(момент работы советника<OrderCloseTime()){
               p+=OrderProfit()+OrderCommission()+OrderSwap();
            }
          }
        }
      }
    }
 return(p);
}
   
 
Artyom Trishkin:
Find the last closed position, which was closed later than the time of EA start, or the last closed on this day, and see its profit: OrderProfit()+OrderComission()+OrderSwap()


Why do I need it to search for all closed positions later than the start time of the EA?

I want it to search from the start of the EA, not before.

 
yaaarik777:


Why later than the start time of the EA? I already have it looking for all closed positions.

you need it to search from the beginning of the EA, not before.


If you think about it, "from the beginning and beyond" is after the start time of the EA ;)

Don't be lazy to use the interaural organ.

 

Hello.

Please help me to display data from a file as a histogram.

In the file "file.txt" a date corresponds to a number.

I receive data from the file and print it out,
Reason: