Problem with my code !!!

 

Hello everyone,


Here is my codes in the below for MQL 4. Whem it is compiled, there is no error but aside from some warnings. Since there is no error, i expect my code to work. However, it does not work, not send the order.

"

     RefreshRates();    

     double PendingPrice = FASTma-40*UsePoint ;

     double SELLSTOP_STOPLOSS_LEVEL = PendingPrice + 20*UsePoint;

     double SELLSTOP_TAKEPROFIT_LEVEL = PendingPrice - TakeProfit*UsePoint ; ///????

///////////////////////////////

if( x_FASTma_pre1 > y_FASTma_pre1 && x_FASTma < y_FASTma)

SellTicket = OrderSend ( Symbol(), OP_SELLSTOP, 0.01, PendingPrice , UseSlippage, SELLSTOP_STOPLOSS_LEVEL, SELLSTOP_TAKEPROFIT_LEVEL, NULL, 0 ,0, clrDodgerBlue);



"


Is there anyone who knows why and how to fix it ? Any of your help will be appreciated. Thank you in advance for your time and support.


Best Regards.

 
emsahii:

Hello everyone,

Here is my codes in the below for MQL 4. Whem it is compiled, there is no error but aside from some warnings. Since there is no error, i expect my code to work. However, it does not work, not send the order.

Is there anyone who knows why and how to fix it ? Any of your help will be appreciated. Thank you in advance for your time and support.

Best Regards.

Should resolve all compilation warnings as well, and check for any run time error messages.

Instead of 40, 20 and TakeProfit, experiment with larger values to see if there's any issue with your program's logic. If larger values work, that probably means 40, 20 and TakeProfit may be too small for your account (in which case, check the values of MODE_SPREAD and MODE_STOPLEVEL - refer to https://docs.mql4.com/constants/environment_state/marketinfoconstants).

Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
A zero value of MODE_STOPLEVEL means either absence of any restrictions on the minimal distance for Stop Loss/Take Profit or the fact that a trade server utilizes some external mechanisms for dynamic level control, which cannot be translated in the client terminal. In the second case, GetLastError() can return error 130, because MODE_STOPLEVEL...
 
Please edit your post press Alt+S and post your. Code in the box that appears
 
  1. Why did you post your MT4 question in the Root / 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. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  3. Post all relevant code and variable values. We have no Idea what type FASTma, UsePoint, TakeProfit is or their values.

  4. Why are you calling RefresRates? Does that mean that FASTma is invalid? Post all relevant code.

  5. emsahii: , there is no error but aside from some warnings. Since there is no error, i expect my code to work. 
    Just because it compiles doesn't mean it will work. Use the debugger or print out your variables, including _LastError and prices and . Do you really expect us to debug your code for you?

  6. If you had checked your return codes for errors, and reported them including GLE/LE, your variable values and the market, we would know that at least you are calling your code. 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

  7.      double PendingPrice = FASTma-40*UsePoint ;
         double SELLSTOP_STOPLOSS_LEVEL = PendingPrice + 20*UsePoint;
         double SELLSTOP_TAKEPROFIT_LEVEL = PendingPrice - TakeProfit*UsePoint ; ///????
    
    You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP would be longer. Don't you want the same/specified amount for either direction?
    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25
    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)