MQL4 Problem with simple function (Order open...)

 

Hey,

If i set previously in the ' int Start '

Wysoka=iHigh("EURUSD",PERIOD_M1,n+2);

and

Niska=iLow("EURUSD",PERIOD_M1,n+2);

The indicator appears on the chart, so i guess variables Wysoka and Niska are also set right with the High/Low price?

So I want now just to open trades while the price is breaking high (open long) or breaking low (open short) and i added a code like this:

   if (MarketInfo("EURUSD",MODE_BID) > Wysoka)
      {
         OrderSend(Symbol(), OP_BUY, 0.01, Ask, 5, Niska, 0, 0, 0, 0, DodgerBlue);
      }
   if (MarketInfo("EURUSD",MODE_ASK) < Niska)
      {
         OrderSend(Symbol(), OP_SELL, 0.01, Bid, 5, Wysoka, 0, 0, 0, 0, DodgerBlue);
      }

But, nothing is happening, seems i get it wrong. How to improve it?

I want it to open order when it reach the price 1 pips over the Wysoka or Niska.

 
grgr:

Hey,

If i set previously in the ' int Start '

Wysoka=iHigh("EURUSD",PERIOD_M1,n+2);

and

Niska=iLow("EURUSD",PERIOD_M1,n+2);

The indicator appears on the chart, so i guess variables Wysoka and Niska are also set right with the High/Low price?

So I want now just to open trades while the price is breaking high (open long) or breaking low (open short) and i added a code like this:

But, nothing is happening, seems i get it wrong. How to improve it?

I want it to open order when it reach the price 1 pips over the Wysoka or Niska.

Hi grgr,

This OrderSend (), where did you write it, is it in Indicator or is it in Expert Advisor ?

:D

 

Of course in EA. Maybe it somehow excludes itself by returns ? I moved the first part into a void.

Now it's like this:

  RefreshRates();
   if (Bid > Wysoka)
      {
         OrderSend(Symbol(), OP_BUY, 0.01, Ask, 5, Niska, 0, 0, 0, 0, DodgerBlue);
         Alert (GetLastError());
      }
   if (Ask < Niska)
      {
         OrderSend(Symbol(), OP_SELL, 0.01, Bid, 5, Wysoka, 0, 0, 0, 0, DodgerBlue);
         Alert (GetLastError());
      }

OporyWsparcia();

And the void OporyWsparcia is at the beggining:

void OporyWsparcia ()
{
      for(int n=1;n<Bars;n++)
      {
         if ((High[n]<=High[n+2]) && (High[n+1]<=High[n+2]) && (High[n+2]>=High[n+3]) && (High[n+4]<=High[n+2])) 
            {
               ObjectDelete("highLine");
               ObjectDelete("highLineV");
               ObjectCreate("highLine",OBJ_HLINE,0,0,iHigh("EURUSD",PERIOD_M1,n+2));
               ObjectCreate("highLineV",OBJ_VLINE,0,Time[n+2],0);
               ObjectSet("highLineV",OBJPROP_COLOR,LimeGreen);
               ObjectSet("highLine",OBJPROP_COLOR,LimeGreen);
               Wysoka=iHigh("EURUSD",PERIOD_M1,n+2);
            }
         if ((Low[n]>=Low[n+2]) && (Low[n+1]>=Low[n+2]) && (Low[n+2]<=Low[n+3]) && (Low[n+2]<=Low[n+4]))  
            {
               ObjectDelete("lowLine");
               ObjectDelete("lowLineV");
               ObjectCreate("lowLine",OBJ_HLINE,0,0,iLow("EURUSD",PERIOD_M1,n+2));
               ObjectCreate("lowLineV",OBJ_VLINE,0,Time[n+2],0);
               ObjectSet("lowLineV",OBJPROP_COLOR,Red);
               ObjectSet("lowLine",OBJPROP_COLOR,Red);
               Niska=iLow("EURUSD",PERIOD_M1,n+2);
            }
            return (0);
      }
}


The void seems to be working, but orders still won't open.

Those horizontal and vertical lines are useless i know, but firstly i need to take a look if it's working right. But why it's not working (the orders), maybe the Niska and Wysoka are not being set properly ?

 
grgr:

Of course in EA. Maybe it somehow excludes itself by returns ? I moved the first part into a void.

Now it's like this:

And the void OporyWsparcia is at the beggining:

The void seems to be working, but orders still won't open.

Those horizontal and vertical lines are useless i know, but firstly i need to take a look if it's working right. But why it's not working (the orders), maybe the Niska and Wysoka are not being set properly ?

My apology for misunderstood.

1. Change to this and what is the value of n ?

Wysoka=iHigh(Symbol(),PERIOD_M1,n+2);
Niska=iLow(Symbol(),PERIOD_M1,n+2);

2. Only if you want it, add this, but they will write a lot of Prints on expert journal :(

if (Bid > Wysoka)
   {
   OrderSend(Symbol(), OP_BUY, 0.01, Ask, 5, Niska, 0, NULL, 0, 0, DodgerBlue);
   Alert (GetLastError());
   }
   else
   {
   Print ("Bid <= Wysoka (",DoubleToStr((Wysoka-Bid)/Point, Digits),")");
   }
if (Ask < Niska)
   {
   OrderSend(Symbol(), OP_SELL, 0.01, Bid, 5, Wysoka, 0, NULL, 0, 0, DodgerBlue);
   Alert (GetLastError());
   }
   else
   {
   Print ("Ask >= Niska (",DoubleToStr((Ask-Niska)/Point, Digits),")");
   }
 

Hey, thanks for replay.

I used comment instead of Print.

I thought the "else" is necessary, because it opened and opened a lot of trades, so i copied the whole code from you.

Ok, now i don't understand it. This command open pending orders? Or what? Im confused, now i got green arrow on chart with "buy" signal, where it shouldn't be anyway, and nothing was bought yet -.-

It should send the buy or sell signal only when the red/green line is broken more than 1 pips above

I got it like this right now

      if ((Niska != 0) && (Wysoka != 0)) {
      if ((Bid >= (Wysoka + 10*Point)) && (Dluga != 1))
      {
         Dluga = 1;
         OrderSend(Symbol(), OP_BUY, 1, Ask, 5, Niska, 0, NULL, 0, 0, Green);
         //Alert (GetLastError());
      }
      else
      {
         Comment("Bid <= Wysoka (",DoubleToStr((Wysoka-Bid)/Point, Digits),")");
      }
      if ((Bid <= (Niska - 10*Point)) && (Krotka != 1))
      {
            Krotka = 1;
            OrderSend(Symbol(), OP_SELL, 1, Bid, 5, Wysoka, 0, NULL, 0, 0, Red);
            //Alert (GetLastError());
      }
      else
      {
         Comment("Ask >= Niska (",DoubleToStr((Ask-Niska)/Point, Digits),")");
      }
      }
      else {
         Comment("Niska or Wysoka = 0");
      }

But the orders opens between green and red :/

I also tried:

               Niska=iLow("EURUSD",PERIOD_M1,n+2);
               Print("Niska:",Niska);

and it returns:

Niska: 1

It loses the rest of value.. ???? How do it create the horizontal line right with that iLow but Niska returns only "1" ??

 
grgr:

Hey, thanks for replay.

I used comment instead of Print.

I thought the "else" is necessary, because it opened and opened a lot of trades, so i copied the whole code from you.

Ok, now i don't understand it. This command open pending orders? Or what? Im confused, now i got green arrow on chart with "buy" signal, where it shouldn't be anyway, and nothing was bought yet -.-

It should send the buy or sell signal only when the red/green line is broken more than 1 pips above

I got it like this right now

But the orders opens between green and red :/

I also tried:

and it returns:

Niska: 1

It loses the rest of value.. ???? How do it create the horizontal line right with that iLow but Niska returns only "1" ??

Comment is good one instead of prints.

The Niska and Wysoka, are they integer (int) or double ?, they should be double.

And what is the value of n in iLow and iHigh ?

 

They wre integer, so here was the problem. Now it returns normal values !! I love you =P

I don't understand the question about n. It's the center bar out of 5 and it's from a loop. It should look out for last 5 bars that the center is the biggest or the lowest one (at minimum/maximum). However, I'm not sure if those parameters are set right, but seems working.

One question i have right now is about the *Point parameter. Niska and Wysoka shows at 4 digits price, while i got demo on 5 digit broker. So should the < > values be increased by 10*Point or 1*Point if i want 1 pip difference?

Seems i still have sth wrong. Now the price was broken, but nothing happening.. :x

 
grgr:

They wre integer, so here was the problem. Now it returns normal values !! I love you =P

I don't understand the question about n. It's the center bar out of 5 and it's from a loop. It should look out for last 5 bars that the center is the biggest or the lowest one (at minimum/maximum). However, I'm not sure if those parameters are set right, but seems working.

One question i have right now is about the *Point parameter. Niska and Wysoka shows at 4 digits price, while i got demo on 5 digit broker. So should the < > values be increased by 10*Point or 1*Point if i want 1 pip difference?

You need to take heed of what WHRoeder posted . . . unless you want to stay happy in your ignorance . . . it is always an option.

What are Function return values ? How do I use them ? - MQL4 forum
 
grgr:

They wre integer, so here was the problem. Now it returns normal values !! I love you =P

I don't understand the question about n. It's the center bar out of 5 and it's from a loop. It should look out for last 5 bars that the center is the biggest or the lowest one (at minimum/maximum). However, I'm not sure if those parameters are set right, but seems working.

One question i have right now is about the *Point parameter. Niska and Wysoka shows at 4 digits price, while i got demo on 5 digit broker. So should the < > values be increased by 10*Point or 1*Point if i want 1 pip difference?

Great ! :D

Read about 3 and 5 digit here https://www.mql5.com/en/forum/138975

 

Now i have problem with iMA.

extern int LongH1 = 50;

...
      
for(int n=1;n<Bars;n++)
{
Print(iMA(NULL,PERIOD_H1,LongH1,0,MODE_SMA,PRICE_TYPICAL,n));

...

}

LongH1 is defined, it's in a loop.

However, it works for n = 263, but then (like n = 950) it returns 0 .. I have no idea why ?