[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 598

 
alsu:

Take apart the logic of the indicator completely.

Replace it first.

at

Also,

Without else the first block is executed first, then the second. With else - either the first or the second.



ooo! logic is missing else!) I'll change it soon! yes, and on the fly: if I write everywhere in the text not with the 4th but with the 3rd, like this:
iFractals(Symbol(),PERIOD_H1,MODE_UPPER,3);

I have no trades, although the bars to the 3rd seem to be enough for everything to work, what's the problem?

And as for the logic of the indicator, I'm a bit confused. I know how the indicator works, I just need the algorithm to ensure that ifractals is not equal to zero, and you offer me to remove this condition, it is superfluous? Why do I write it twice?

 
alsu:

Take apart the logic of the indicator completely.

Replace it first.

at

In addition,

Without else the first block is executed first, then the second. With else - either the first or the second.



I replaced everything, but it's still skipping the same way for some reason...((((((
 
Vinin:

It is possible to fight, and the work of the EA can be interrupted. We just need to change the approach.


How?

At the beginning of the code, go through all open orders, find and assign ticket values to orders, or is there some other way?

 
Cruc:


At the beginning of the code, go through all open orders, find and assign ticket values to orders, or is there some other way?


You can do this if the EA opens one or two positions.
 
Who knows what causes the EA to stop working in the tester?
 
Vinin:

You can do this, as long as the advisor opens one or two positions.

The EA is multi-currency, so simple operations do not always seem to be solved at once ((. And there is no experience.
 
Cruc:

My Expert Advisor is multicurrency, and simple operations do not always seem to be solved at once ((. And there is no experience.


You just have to do the order accounting correctly. There are a lot of examples.

And experience. Experience comes with the territory. It will not go anywhere.

 
Vinin:


You just have to make sure that the orders are recorded correctly. There are plenty of examples.

And experience. Experience comes with the territory. It's not going anywhere.


Thanks for the answers, I will dig through the archives.
 
skyjet:

Good evening, I'm asking for help with a multicurrency MACD Expert Advisor. The EA follows the position opening criteria correctly, but closing "on condition" does not work. I have certainly started to use a trailing stop, but the correct close does not give me a break.

This is what the main part looks like

And this is a close block. Please help me to find the error!


Sorry to repeat myself, but no matter how much I struggle, I can't find the error!

//+------------------------------------------------------------------+
string lSymbol;
int init ()
{ 
 lSymbol = Symbol();
 return (0);
}
int deinit()
{return(0);}
int start()
  {
   double MacdCurrent, MacdPrevious, SignalCurrent;
   double SignalPrevious, MaCurrent, MaPrevious;
   double bid, ask, point, digits;
   int cnt, ticket, total;
   
  total = SymbolOrdersTotal (lSymbol);
  
  if (total<1);
  {
    bid   = MarketInfo(lSymbol,MODE_BID);
    ask   = MarketInfo(lSymbol,MODE_ASK);
    point = MarketInfo(lSymbol,MODE_POINT);
    digits= MarketInfo(lSymbol,MODE_DIGITS);



Так выглядит оснавная часть, а это злопалучный блок закрытия



 for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==lSymbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
            if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
               MacdCurrent>(MACDCloseLevel*point))
                {
                 OrderClose(OrderTicket(),OrderLots(),bid,3,Violet); // close position
                 return(0); // exit
                }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(bid-OrderOpenPrice()>point*TrailingStop)
                 {
                  if(OrderStopLoss()<bid-point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),bid-point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // should it be closed?
            if(MacdCurrent<0 && MacdCurrent>SignalCurrent &&
               MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*point))
              {
               OrderClose(OrderTicket(),OrderLots(),ask,3,Violet); // close position
               return(0); // exit
              }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-ask)>(point*TrailingStop))
                 {
                  if((OrderStopLoss()>(ask+point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),ask+point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                }
              }
           }
        }
     }
   return(0);
  }
  
   
  int SymbolOrdersTotal(string lSymbol)
{
   int Res=0;
   int total=OrdersTotal();
   for (int i=0;i<total;i++) 
   {
      if (OrderSelect(i, SELECT_BY_POS))
      {
         if (OrderSymbol()==lSymbol)
         {
            Res++;
         }
      }
   }
   return(Res);
}
// the end.
 
Qwertee:
I replaced everything, but it's still skipping the same way for some reason...((((((
write down what you get and what messages you output to the log
Reason: