[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 476

 
If you need it, I'll post the jma as well. Change indicator name to JMA[i]
Files:
jmaxvib.mq4  11 kb
 
for(i = 0; i < limit; i++)
     {
       if(dBuffer[i+1]>80 && dBuffer[i]<80) DN[i] = 70; Fd=-1; Fu=0;               //пересекла 80   --> 1
       if(dBuffer[i+1]<20 && dBuffer[i]>20) UP[i] = 30; Fu=1;  Fd=0;               //пересекла 20   --> 1
       
       if(dBuffer[i+1]>rsi[i+1] && dBuffer[i]<rsi[i]) dn[i] = 60; fd=-1; fu=0;     //пересечение двух  -->  2
       if(dBuffer[i+1]<rsi[i+1] && dBuffer[i]>rsi[i]) up[i] = 40; fu=1;  fd=0;     //пересечение двух     -->  2
       
       if(Fd==-1 && fd==-1) dot[i]=90; Fd=0; Fu=0; fd=0; fu=0;
       if(Fu==1 && fu==1)   dot[i]=10; Fd=0; Fu=0; fd=0; fu=0;

You are going through bars from the current time to the past time.

The array is searched until the last one.

Therefore, all variables will give values for the most recent case (in this case -- long ago).

Therefore, you need to do a lookup from the past to the present.

for(i = limit; i >= 0; i--)
And the variables
int fd, fu,Fd, Fu;

declare at the top level, i.e. before Start and Init.

And there is no need to zero them at Start. Leave zeroing only at the place where you have them zeroed

if(Fd==-1 && fd==-1) dot[i]=90; Fd=0; Fu=0; fd=0; fu=0;
       if(Fu==1 && fu==1)   dot[i]=10; Fd=0; Fu=0; fd=0; fu=0;
 
rlx Thank you, Vce is working.
 
PapaYozh:


First, OrderSend() occurs 2 times there, and both times outside the condition you specified.

Secondly, non-normalized price is passed to OrderSend().

Third, analyze the result returned by the OrderSend() function, write a message to the log in case of errors when opening/modifying/closing the order and analyze the log.


Can someone post the corrected version of Experrement 1?
 

Good afternoon!

Thank you for your replies - you have been very helpful ))))

Guys! The Expert Advisor makes trades when the two muwings cross. And when they cross back, it closes trades and opens in the opposite direction, losing profits.

1. How do I write that it closes deals when the lines have just started converging? And it would not open a new deal in the same direction, but waited until they cross in the opposite direction?

2. or closing a trade when r.c.i. crosses the 80 level downwards on buy, and the 20 level downwards on sell. and when closing a trade, when conditions are met, it would not open a trade in the same direction, but wait for them to cross in the opposite direction?

If there are any similar threads on the forum, please give me a link!

Many thanks in advance!

Have a nice trade!

Profitable trades!

 

Hello all!

Please tell me what this means:

Order buy ...... failed [Trade timeout]

Specifically interested in what this timeout is

 
smartemiy:

Good afternoon!

Thank you for your replies - you have been very helpful ))))

Guys! The Expert Advisor makes trades when the two muwings cross. And when they cross back, it closes trades and opens in the opposite direction, losing profits.

1. How do I write that it closes deals when the lines have just started converging? And it would not open a new deal in the same direction, but waited until they cross in the opposite direction?

2. or closing a trade when r.c.i. crosses the 80 level downwards on buy, and the 20 level downwards on sell. and when closing a trade, when conditions are met, it would not open a trade in the same direction, but wait for them to cross in the opposite direction?

If there are any similar threads on the forum, please give me a link!

Many thanks in advance!

Have a nice trade!

Profitable trades!


https://www.mql5.com/ru/code has a warehouse full of similar ones
 
Another question: what function can be used to pull out the cost per tool point?
 
PapaYozh:


First, OrderSend() occurs 2 times there and both times outside the condition you specified.

I don't want to be a pain in the ass, however.

if(OrdersTotal()>0&&tral>0&&OrderMagicNumber()==MAGIC&&(OrderType()==OP_SELL||OrderType()==OP_BUY)){
     if(ObjectFind(NamePrice)==-1)
      {
        ObjectCreate(NamePrice,OBJ_HLINE,0,0,Ask);
        ObjectSet(NamePrice,OBJPROP_COLOR,LineColor);
      }
      double n= ObjectGet( NamePrice, OBJPROP_PRICE1); 
      double p1= ObjectGet( NamePrice1, OBJPROP_PRICE1);
      double p2= ObjectGet( NamePrice2, OBJPROP_PRICE1);
//....................................................................... 
      double d= AccountEquity()-AccountBalance();                 
       if(ObjectFind(NamePrice1)==-1&&d>0)
      {       
        ObjectCreate(NamePrice1,OBJ_HLINE,0,0,n+d*Point*10);
        ObjectSet(NamePrice1,OBJPROP_COLOR,LineColor1);
      }
      if(n+d*Point*10>p1)ObjectSet(NamePrice1,OBJPROP_PRICE1,n+d*Point*10);
      if(ObjectFind(NamePrice2)==-1&&n+d*Point*10<p1)
      {       
        ObjectCreate(NamePrice2,OBJ_HLINE,0,0,n+d*Point*10);
        ObjectSet(NamePrice2,OBJPROP_COLOR,LineColor2);
      } 
      if(p2!=n+d*Point*10)ObjectSet(NamePrice2,OBJPROP_PRICE1,n+d*Point*10);  
      if(nb+ns==2&&tral<20&&p1-p2>=(p1-n)/tral&&p2>n&&p2-n>dohod*Point/10)CloseALL(); 
      if(nb+ns==2&&tral>20&&p1-p2>=tral*Point&&p2>n)CloseALL();  
      }
//..........................................................................
    if(ob==0||OrderOpenTime()<iTime(Symbol(),TF,0))
       { 
     
      if( R==1&&zb==0&&C1>O1&&iVolume(Symbol(),TF,0)<2)
         {
         if(ob==0||OrderOpenTime()<iTime(Symbol(),TF,0))
         {
         OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+dist*Point,3,0,0,"ko",MAGIC,TimeCurrent()+60*experation,Green);
         }
         }
      
      }
    if(os==0||OrderOpenTime()<iTime(Symbol(),TF,0))
        {      
      if(R==1&&zs==0&&C1<O1&&iVolume(Symbol(),TF,0)<2)
        {        
         if(os==0||OrderOpenTime()<iTime(Symbol(),TF,0))
         {
         OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-dist*Point,3,0,0,"ko",MAGIC,TimeCurrent()+60*experation,Red);
         }
         }
      return(0);
     }
   

   
  }

Explain to me how an order will open if OrderTotal() is zero.

Thank you.

 

Please tell me which code should be written in the EA to make the EA trade only once an hour

e.g., the EA has triggered, an order is opened (not interested in further), I would like the order not to open on the current bar on hourly timeframe

everything looks something like this

int hh;
int CurrentHour;
CurrentHour=TimeHour(TimeCurrent());
if (CurrentHour!=hh)
{
OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Bid-3*Point,Bid+3*Point);
hh=TimeHour(TimeCurrent());
}

but I have countless orders open