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

 

Maybe I didn't understand my question.

Being on the M1 period chart I want to fill the buffer if on the M5 period, the " Stochastic" indicator line is now above the 55 level.

input ENUM_TIMEFRAMES   TimeFrame2  =  PERIOD_M5; //ЭТО ВО ВНЕШНИХ Н
////////////////////////////////////////////////
       for(int i=limit; i>=0; i--) {
      int bar_sto2_0=iBarShift(Symbol(),TimeFrame2,iTime(Symbol(),TimeFrame2,i));
      int bar_sto2_1=iBarShift(Symbol(),TimeFrame2,iTime(Symbol(),TimeFrame2,i+1));
    
      double sto2_0=iStochastic(Symbol(),TimeFrame2,kperiod2,dperiod2,slowing2,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,bar_sto2_0);
      double sto2_1=iStochastic(Symbol(),TimeFrame2,kperiod2,dperiod2,slowing2,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,bar_sto2_1);
    
      if(sto2_0>55.0)
       {
      BufferUP[i]=low[i]-distance*MyPoint;
       }
      
      if(sto2_0<44.0)
       {
      BufferDN[i]=high[i]+distance*MyPoint;
       }

      Comment(sto2_0);
       }

In the comment the current value is correct with M5, but on the history the arrows put not on condition, chaos.

What can it be?

In the " basement" the stochastic from M5

The arrows are circled not according to the signal



xaoc
 

I am writing an Expert Advisor that simultaneously places two StopOrders, one to sell and one to buy.

How do I write the condition that when one StopOrder triggers, the second (opposite) one is deleted?

Thank you.

 
RichLux:

I am writing an Expert Advisor that simultaneously places two StopOrders, one to sell and one to buy.

How do I write the condition that when one StopOrder triggers, the second (opposite) one is deleted?

Thank you.

The condition is simple. When a StopOrder triggers, a position appears in the market, it means that we should track the position and if it exists, we should delete the opposite order.

This is a piece of code for thought)

void DeleteOppositeOrders(string sy="", int op=-1, int mn=-1, color cl=clrOliveDrab) {
  bool b, s;
  switch(op) {
    case OP_BUY : b=ExistPositions(sy, OP_BUY , mn); break;
    case OP_SELL: s=ExistPositions(sy, OP_SELL, mn); break;
  }

  if(b) {
    DeleteOrders(sy, OP_SELLLIMIT, mn, cl);
    DeleteOrders(sy, OP_SELLSTOP , mn, cl);
  }
  if(s) {
    DeleteOrders(sy, OP_BUYLIMIT, mn, cl);
    DeleteOrders(sy, OP_BUYSTOP , mn, cl);
}}
 
Vitaly Muzichenko, as far as I understand, you now need to add theExistPositions andDeleteOrders functions
 
RichLux:
Vitaly Muzichenko, as far as I understand, now we need to add theExistPositions andDeleteOrders functions
Yes, you do.
 
RichLux:
Vitaly Muzichenko, as far as I understand, now we need to write theExistPositions andDeleteOrders functions
You don't have to write them, they are bothready-made
 
Vitaly Muzichenko:
You don't have to write them, they're bothready-made.

Well ..., for educational purposes it's quite useful ...

For practical purposes, it's very expensive to run cycles in each function.

 
Artyom Trishkin:

Well ..., for training purposes it's very useful...

For practical purposes, it is very costly to run cycles in every function.

Therefore I have not attached at once and have described and attached only the logic of the "closing of the opposite" )
 

What to do if the stop/stop is 200

but

tp=NormalizeDouble((price+(TakeProfit*_Point)),Digits);

on a dollar-yen will yield 317.000 at the exchange rate of 117.000

the expected result is 117.200

 
trader781:

What to do if the stop/stop is 200

but

tp=NormalizeDouble((price+(TakeProfit*_Point)),Digits);

on a dollar-yen will yield 317.000 at the exchange rate of 117.000

the expected result is 117.200

Why so many brackets? It's a matter of taste, of course, but still too much.

tp=NormalizeDouble(price+TakeProfit*_Point,_Digits);

Values are substituted incorrectly if the result is incorrect in the output, because this line of code will calculate everything correctly, even with extra parentheses.