[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 126

 
Lisi4ka330:

Good afternoon )))) I wrote my first EA, but it turned out to be problematic))))))) This EA puts only sell orders even though the buy conditions are very simple and the EA seems not to see them.

if (ZZ2< pp1 ) { OpenPosition ("", OP_BUY, Lots_New,SLB,TPB, mn);}

if (pp1 < ZZ2) {OpenPosition("", OP_SELL, Lots_New, SLS,TPS, mn);}

If someone takes a look at the code, I'd be very grateful)))


Strange, in theory it shouldn't see the snappy SELL because you're using pa instead of pb.

double TPS= NormalizeDouble(pa-tp*po, Digits);// calculate Tp for sell
double SLS= NormalizeDouble(pa+sl*po, Digits);// calculate SL for sell

 

There is such a recalculation algorithm:

   int ic=IndicatorCounted();
   if(Bars-ic-1>1) {ic=reinit();}
   int limit=Bars-ic-1; //BarsPrev=Bars; // кол-во пересчетов
   if(History!=0 && limit>History) limit=History-1; // кол-во пересчетов по истории

   for(int i=limit; i>=1; i--) // цикл по непосчитанным и предпоследнему барам
     {
      int n;
      int iShift=i+Shift;
      
      if (i==0)
      Input[i]=iClose(Symb, Period(), iShift);
      else
      Input[i]=(iHigh(Symb, Period(), iShift)+iLow(Symb, Period(), iShift))/2;
       }

As I understand it, it counts all bars except the last one.

Can you tell me how to make it recalculate the last bar at i=0 (there is already a condition for this in the loop)?

 
Thanks so much for the answers)))) I replaced iClose with Close [0] and everything worked....though odd...))))) thanks again)))
 
Lisi4ka330:
Thanks so much for the answers)))) I replaced iClose with Close [0] and it worked out....though strangely...))))) thanks again)))
For the record, iClose(NULL, 0, 1) is Close[1] not Close[0]
 
Cmu4:

There is such a recalculation algorithm:

As I understand it, it counts all bars except the last one.

Can you tell me how to make it recalculate the last bar at i=0 (there is already a condition for this in the loop)?

no, you're writing >= 1 (greater than or equal to the 1st bar, i.e., you don't get to 0... change the condition to >=0

SZ


What's this about?

int iShift=i+Shift;
 
Aleksander:

No, you write >= 1 (Greater than or equal to 1 bar, i.e. you don't get to 0... change the condition to >=0

SZ


What's that for?

Right, totally forgot about my "experiments". Fixed 0 to 1 a while ago and it's still there. Thank you!

iShift is a shift, set in extern.

 
Cmu4:

Right, forgot all about my "experiments". I changed it from 0 to 1 a while ago and it's still there. Thank you!

iShift is a shift, set in the extern.

yeah... but you write that you need to watch the 0 bar...

then remove

f (i==0)
      Input[i]=iClose(Symb, Period(), iShift);

your shifter from there :) - put 0...

f (i==0)
      Input[i]=iClose(Symb, Period(), 0);
 
I have this question. Is the serial number of trades in the terminal assigned permanently or does it change? For example, if I opened three trades with numbers 0 - 1 - 2 and closed trade number 1, then trade numbers 0 and 2 will remain or will become 0 and 1?
 
yes, move in the queue, and not just transactions, graphical objects, and global variables behave the same way.
 

Please help. Can the conditions below be met???

We need to make so that if the current price crosses the MA, then the algorithm in { } is triggered:

if (Bid==iMA(0,0,ma_period,ma_shift,ma_method,PRICE_MEDIAN,0)
{
 ...
}

if (Ask==iMA(0,0,ma_period,ma_shift,ma_method,PRICE_MEDIAN,0)
{
 ...
}
Reason: