[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 750

 
ToLik_SRGV:

That's right, I think Rustam hinted at that

Yes, I read it after I posted it :)
 
Thank you all, I'll get back to work :)
 

I DON'T UNDERSTAND WHY THERE ARE GLOBAL VARIABLES

#property copyright "Copyright © 2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

bool
b,s, 
bs,
ss,
bt,
st;
double 
bl,sl;  
//+------------------------------------------------------------------+

THEY ARE USED TO OPEN ORDERS

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
if(bs==1&&bl==1)
{
    NewOrder1(OP_BUYLIMIT,Lot);

Today=TimeDay(TimeCurrent())
;}

return(0);}

//+------------------------------------------------------------------+
int NewOrder1(int Cmd,double Lot)
{double TP=0; //тейкпрофит
double SL=0; //стоплосс
double PR=0; //Цена
double LT=0; //Лот
while(!IsTradeAllowed()) Sleep(100);
if(Cmd==OP_BUYLIMIT)
   {PR=Ask-Point*h;
    if(TakeProfit>0) TP=PR+TakeProfit*Point;
    if(StopLoss>0) SL=PR-StopLoss*Point;
    if(Lot>0) LT=3*Lot;
        }
int tic=OrderSend(Symbol(),Cmd,LT,PR,3,SL,TP,0,mag,0,CLR_NONE);
if(tic<0) {Print(GetLastError());
        }else
        {
b=0;s=0;  
bs=0;
ss=0;
bt=0;
st=0;    
bl=0;sl=0; }
return(tic);}

IF AN ORDER HAS A TICKET LARGER THAN 0, THIS FUNCTION SHOULD WORK

else
        {
b=0;s=0; 
bs=0;
ss=0;
bt=0;
st=0;   
bl=0;sl=0; }

WHICH SHOULD CHANGE ALL VALUES OF GLOBAL VARIABLES TO 0 AND NOT OPEN A NEW ORDER AGAIN,

BUT IT SOMEHOW GOES BACK TO THE ORDER OPENING AND OPENS NEW ORDERS ON EVERY NEW TICK.

WHAT IS THE REASON OF THIS STRANGE PHENOMENON?

GLOBAL VARIABLES ARE SET FROM HERE WHEN CLOSING A MARKET ORDER

for(int cnt=OrdersHistoryTotal();cnt>0;cnt--)
     {
OrderSelect(cnt, SELECT_BY_POS, MODE_HISTORY);
{if(OrderMagicNumber()== mag &&
OrderSymbol()==Symbol()) 
{ if (OrderType() == OP_BUY )  {b=1; if (OrderClosePrice()==OrderTakeProfit()) bt=1; 
if (OrderClosePrice()==OrderStopLoss()) bs=1; bl=OrderLots()*100; break;}
if (OrderType() == OP_SELL)  {s=1; if (OrderClosePrice()==OrderTakeProfit()) st=1; 
if (OrderClosePrice()==OrderStopLoss()) ss=1; sl=OrderLots()*100; break;}
            }
       
         }
      }

ALSO HERE IS THE COMPLETE EXPERT ADVISOR

Files:
test8_2.mq4  7 kb
 
FoxUA:

PEOPLE, HELP ME, I DON'T UNDERSTAND...


Where is the block that fills these variables with values?
I would like to see the exact code of your Expert Advisor in one piece, in the form in which it is compiled and tested.
Not in pieces, because this question has been hanging around for quite a long time, and it has been answered more than once, but because of these pieces, no one can fully understand the whole picture of the problem.

So please show the whole picture so there is no confusion.

 
ToLik_SRGV:

Where is the block that fills these variables with values?
I would like to see the exact code of your EA in one piece, in the form in which it is compiled and tested.
Not in pieces, because this question has been hanging around for quite a long time, and it has been answered many times, but nobody can completely understand the whole picture of the problem because of these pieces.

So please show the whole picture so there is no confusion.

HERE IS THE WHOLE EA

Files:
test8_1.mq4  7 kb
 

asking in the "I'll write an EA for free" thread doesn't always get a response?

 
diaspar:

asking in the "I'll write an EA for free" thread doesn't always get a response?

Let me ask you, how often do you go to work for free?
That's about how often they respond.
 
diaspar:

asking in the "I'll write an EA for free" thread doesn't always get a response?

The topic was started by the topic-starter. However, he received far more requests than he is able to digest. Logic dictates that he should respond - he is the one to demand. What did you expect?
 
FoxUA:

I DONT KNOW WHAT'S WRONG WITH MY EA, I'VE TRIED EVERYTHING AND THE ONLY RESULT IS 1 FOR EVERY TICK + 1 PENDING ORDER THE ONLY THING IS WHEN I CLOSE ANOTHER MARKET ONE CHANGES THE VARIABLE OPENS ANOTHER ONE AND OPENS A NEW ONE WITH EVERY TICK

In progress...

Most probably, the bug is in the block filling these variables with values (in the for loop), I've already found one error (in OrderSelect()) there, but the result has not changed yet. It seems to be a bug somewhere in the logic of the block.

P.S.
Please change to normal symbol case.

 
FoxUA:

The bug is obvious, of course, it opens positions on every tick, since the losing order in the history does not go anywhere, so it finds it on every tick and fills the values of control variables with the same values, and then the block of opening deals triggers.