How can I set buy limit and sell limit on fibonacci levels?

 

Hi, I codding a custom fibo levels but when i set orders i do not take an answer.

The code is here:

   if( Fibonacci() == 0.78)
     {
      OrderSend(Symbol(), OP_BUYLIMIT, lot, Bid, 3, StopLoss, TakeProfit, NULL, 0, 0, Green);
     }

   if( Fibonacci() == 0.618)
     {
      OrderSend(Symbol(), OP_SELLLIMIT, lot, Ask, 3, StopLoss, TakeProfit, NULL, 0, 0, Red);
     }

I already define lot,...

Can anyone help ME?

 
  1. Hello and a warm welcome :)
  2. Check in case of an error in the program with _LastError and/or in the logs: Expert and Journal.
  3. Look at the example of the MQL4-Reference or here: https://docs.mql4.com/trading/ordersend
  4. MQL4 questions belong the MQL4 section below!
OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function. At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a...
 

It appears your Fibonacci() function detects when price is on those levels .
If yes ,then send OP_BUY on the first case ,and OP_SELL on the second case.(instant trade)

If not , then send the price at the fibonacci level instead of the Bid or Ask prices.(pending trade)

 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2.    if( Fibonacci() == 0.78)
         {
          OrderSend(Symbol(), OP_BUYLIMIT, lot, Bid, 3, StopLoss, TakeProfit, NULL, 0, 0, Green);

    You can't create pending orders at market prices.

    Check your return codes, and report your errors. Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.

              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  3. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

 
Carl Schreiber:
  1. Hello and a warm welcome :)
  2. Check in case of an error in the program with _LastError and/or in the logs: Expert and Journal.
  3. Look at the example of the MQL4-Reference or here: https://docs.mql4.com/trading/ordersend
  4. MQL4 questions belong the MQL4 section below!

Thank you.

The error is -->  Fibonacci: failed to create => Fibo object! Error code = 4200 and I don't know what is that for.

I am new member & I don't know about that section.
 
Lorentzos Roussos:

It appears your Fibonacci() function detects when price is on those levels .
If yes ,then send OP_BUY on the first case ,and OP_SELL on the second case.(instant trade)

If not , then send the price at the fibonacci level instead of the Bid or Ask prices.(pending trade)

I change the Bid & Ask, But the error is -->  Fibonacci: failed to create => Fibo object! Error code = 4200 and I don't know what is that for.

OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • www.mql5.com
Before we start developing, let's get acquainted with some features of the OOP, which will be used in this article.  Of course, we will use structures and classes. These are the basics of object oriented languages. A structure is a construction that allows containing a set of variables and functions of different types (except void). A class as...
 
Ali Azizifar:
I change the Bid & Ask, But the error is -->  Fibonacci: failed to create => Fibo object! Error code = 4200 and I don't know what is that for.

I understand that you have a function which scans the Fibonacci Retracement object that was placed on the chart manually ? 

try measuring with this if you know the fibonacci swing points

double WhereIsPriceInFibonacciRetracement(double past_swing_point,
                                          double recent_swing_point,
                                          double current_price)
{
double fib_where=0;
double unit=MathAbs(past_swing_point-recent_swing_point)/100;
if(unit>0)
{
fib_where=100-((current_price-past_swing_point)/unit);
}
return(fib_where);
}
 
William Roeder:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. You can't create pending orders at market prices.

    Check your return codes, and report your errors. Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.

              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  3. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

Hi, sorry for post it in the wrong place.

Your tip help me but I still have problem.

The error is -->  Fibonacci: failed to create => Fibo object! Error code = 4200 and I don't know what is that for.

OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • www.mql5.com
Before we start developing, let's get acquainted with some features of the OOP, which will be used in this article.  Of course, we will use structures and classes. These are the basics of object oriented languages. A structure is a construction that allows containing a set of variables and functions of different types (except void). A class as...
Reason: