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

 

> err=StringToInteger((string)err)

this should go down in the annals ;-)

originally in err you obviously got int from GetLastError(). Convert error code into readable description ErrorDescription(err); provided that #include <stdlib.mqh> is enabled.

but the way it's written is a bummer.

PS/ And don't learn MQL programming. MQL 4 and 5 are target languages for a particular platform.

 

Can you please tell me if you can write it this way. it does not want to open transactions. maybe the format of the calculated numbers is wrong? or other defects in the code?


double TakeLong(double shp)

{

int CurrentDayRange=0, fiveDayATR=0, take=0;

double TP_ATR=0;

//////Pivot inputs

double P, S1, R1, S2, R2, S3, R3;

double LastHigh, LastLow, x;

int counted_bars = IndicatorCounted();

int limit, i;

shp=iHigh(Symbol(),PERIOD_D1,0);


//---- Pivot indicator calculation

if(counted_bars == 0)

{

x = Period();

if(x > 240)

return(-1);

}

if(counted_bars < 0)

return(-1);

limit = (Bars - counted_bars) - 1;

//----

for(i = limit; i >= 0; i--)

{

if(High[i+1] > LastHigh)

LastHigh = High[i+1];

//----

if(Low[i+1] < LastLow)

LastLow=Low[i+1];

if(TimeDay(Time[i]) != TimeDay(Time[i+1])

{

P = (LastHigh + LastLow + Close[i+1]) / 3;

R1 = (2*P) - LastLow;

S1 = (2*P) - LastHigh;

R2 = P + (LastHigh - LastLow);

S2 = P - (LastHigh - LastLow);

R3 = (2*P) + (LastHigh - (2*LastLow));

S3 = (2*P) - ((2* LastHigh) - LastLow);

LastLow = Open[i];

LastHigh = Open[i];

}

}

////ATR calculation

for (i=1;i<6;i++)

{ if(iHigh(NULL, PERIOD_D1, i)-iLow(NULL, PERIOD_D1, i)>0) FiveDayATR += (iHigh(NULL, PERIOD_D1, i)-iLow(NULL, PERIOD_D1, i));}

FiveDayATR = NormalizeDouble(FiveDayATR/5,Digits());

CurrentDayRange = (iHigh(NULL, PERIOD_D1, i)-iLow(NULL, PERIOD_D1, i));

if(FiveDayATR-CurrentDayRange>0) TP_ATR=Ask+FiveDayATR-CurrentDayRange; else TP_ATR=0;


if (Bid>R1 && TP_ATR==0) take=shp;

else if (Bid<R1 && R1<TP_ATR) take=R1;

else take=TP_ATR;

return(take);

}

 
forexpipsrunner: please tell me if you can write it like this. it doesn't want to open trades

The suggested code looks like an indicator. The deals are opened by an Expert Advisor or a script. The OrderSend function call is not allowed in the indicator. The indicator can alarm - insert the Alert function call or sound in the appropriate place

 
STARIJ:

The proposed code is similar to the indicator. The deals are opened by an Expert Advisor or a script. The OrderSend function call is prohibited in the indicator. The indicator may signal - insert the Alert function call or sound in the appropriate place


This is the TP definition code, which sends the result to OrderSend. without this complex algorithm, the trades are sent, but there is no way to send them. I call the function TP = TakeLong(SHP);

 
forexpipsrunner: this is the TP definition code which gives the result to OrderSend . without this algorithm trades are sent, there is no way with it

There are many ways of debugging - the process of finding an error when it is established that there is one. The first is F5 - start debugging in MetsEditor. 2) use Alerts to trace the execution. 3 and 4) output debugging information to text labels and Comment function. Choose the convenient way and debug this simple function - then you will become a programmer. A program with thousands of lines is considered complex.

 
forexpipsrunner:

Can you please tell me if you can write it that way. it doesn't want to open transactions. maybe the format of the calculated numbers is wrong? or some other defect in the code?


int take=0 - you return an integer, shouldn't this variable be a double?
 
Hello! I want to make a "rail" pattern, but I can't figure out the size of the candlestick's body....

I calculate the size of candlestick body as follows:
MathAbs( Close1[i] - Open1[i] ) / Point + 1
MathAbs( Close2[i] - Open2[i] ) / Point + 1

In full code it looks like this

double Close1 = iClose(Symbol(), 0, i);
double Open1 = iOpen(Symbol(), 0, i);
double Close2 = iClose(Symbol(), 0, i+1);
double Open2 = iOpen(Symbol(), 0, i+1);

MathAbs( Close1[i] - Open1[i] ) / Point + 1
MathAbs( Close2[i] - Open2[i] ) / Point + 1

if (Close1 < Open1 && Close2 > Open2){
BUY();
}
if (Close1 > Open1 && Close2 < Open2){
SELL();
}

Is it correct? How do I make it work?
 
sviter-pro:   Hello, I want to make a "rail" pattern, but I can't figure out the size of the candle's body....

Have you tried it on M1 demo account? What do you get?

 
STARIJ:

Have you tried it on an M1 demo account? What's the result?

Nothing works....(((
 
void trailing(string symbol,string comment,int magic,int trail_p)
  {
   if(symbol==NULL) symbol=Symbol();
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==symbol && OrderComment()==comment && OrderMagicNumber()==magic)
           {
            switch(OrderType())
              {
               case OP_BUY:
                  if(OrderOpenPrice()+(trail_p*Point)<Ask && OrderStopLoss()+(trail_p*Point)<Ask)
                    {
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+(trail_p*Point),OrderTakeProfit(),OrderExpiration(),clrNONE))
                       {
                        Print("OrderModify завершилась с ошибкой #",GetLastError());
                       }
                    }
                  break;
               case OP_SELL:
                  if(OrderOpenPrice()-(trail_p*Point)>Bid && OrderStopLoss()-(trail_p*Point)>Bid)
                    {
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()-(trail_p*Point),OrderTakeProfit(),OrderExpiration(),clrNONE))
                       {
                        Print("OrderModify завершилась с ошибкой #",GetLastError());
                       }
                    }
                  break;
              }
           }
        }
        Comment("StopLoss=",OrderStopLoss());
     }
  }

Can you tell me why the trawl is triggered on every tick?

Reason: