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

William Roeder  
Paul Vergara #: Hope someone can help.
  1. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

  2. GetLotSize doesn't compute correctly.

    Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin and leverage. No SL means you have infinite risk (on leveraged symbols). Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.

    1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce, the stop goes below the support.

    2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/PIP, but it takes account of the exchange rates of the pair vs. your account currency.)

    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum (2017)
                Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum (2018)
                Lot value calculation off by a factor of 100 - MQL5 programming forum (2019)

    4. You must normalize lots properly and check against min and max.

    5. You must also check Free Margin to avoid stop out

    6. For MT5, see 'Money Fixed Risk' - MQL5 Code Base (2017)

    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

  3. GetDecimalPip is broken for JPY
Paul Vergara  
William Roeder #:
  1. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

  2. GetLotSize doesn't compute correctly.

    Risk depends on your initial stop loss, lot size, and the value of the symbol. It does not depend on margin and leverage. No SL means you have infinite risk (on leveraged symbols). Never risk more than a small percentage of your trading funds, certainly less than 2% per trade, 6% total.

    1. You place the stop where it needs to be — where the reason for the trade is no longer valid. E.g. trading a support bounce, the stop goes below the support.

    2. AccountBalance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the spread, and DeltaPerLot is usually around $10/PIP, but it takes account of the exchange rates of the pair vs. your account currency.)

    3. Do NOT use TickValue by itself - DeltaPerLot and verify that MODE_TICKVALUE is returning a value in your deposit currency, as promised by the documentation, or whether it is returning a value in the instrument's base currency.
                MODE_TICKVALUE is not reliable on non-fx instruments with many brokers - MQL4 programming forum (2017)
                Is there an universal solution for Tick value? - Currency Pairs - General - MQL5 programming forum (2018)
                Lot value calculation off by a factor of 100 - MQL5 programming forum (2019)

    4. You must normalize lots properly and check against min and max.

    5. You must also check Free Margin to avoid stop out

    6. For MT5, see 'Money Fixed Risk' - MQL5 Code Base (2017)

    Most pairs are worth about $10 per PIP. A $5 risk with a (very small) 5 PIP SL is $5/$10/5 or 0.1 Lots maximum.

  3. GetDecimalPip is broken for JPY

Hi Sorry it wasnt my code I just took it on the free EAs on the site and I dont really understand the code. But thanks a lot for this!
emadatar  
Hey,  I'm using MT4 and while switching into an Demo account, i only can see and use the Crypto symbols, i want to know that how can i see and trade in all other symbols.
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
Account Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
Demo_Cryp.jpg  105 kb
Fernando Carreiro  
emadatar #: Hey,  I'm using MT4 and while switching into an Demo account, i only can see and use the Crypto symbols, i want to know that how can i see and trade in all other symbols.

You can only trade what your account offers. So choose a broker and a type of account that offers the symbols you want to trade.

oandapandasd  
Can someone please help me i turned off autotrading and trades keep getting made and they are all losing and my account is getting drained and Oanda wont get back to me
andrew4789  
oandapandasd #:
Can someone please help me i turned off autotrading and trades keep getting made and they are all losing and my account is getting drained and Oanda wont get back to me
Are you running on a VPS or just on your own PC? If VPS you'd need to remove EAs then synchronize. 
Nelson3056  

hello

My name is nelson I am new programmer I was asking if it possible to make Depth of market indicator using mql4. if there is any please help with that.

Fernando Carreiro  
Nelson3056 #: hello My name is nelson I am new programmer I was asking if it possible to make Depth of market indicator using mql4. if there is any please help with that.

Not possible on MQL4! Consider moving to MT5.

Nelson3056  
Fernando Carreiro #:

Not possible on MQL4! Consider moving to MT5.

OK THANK YOU SIR

TeoDeo  

Hello! Can you tell me why my  integer 'Prevent Order' is not being revalued to '0' in the bottom section? Everything else works fine.


   double LinePrice      = iMA(NULL, 0, 1,    0, MODE_LWMA, PRICE_WEIGHTED, 0);
   double LineAxis       = iMA(NULL, 0, 10/3, 0, MODE_LWMA, PRICE_WEIGHTED, 0);
   double LineCeiling    = iMA(NULL, 0, 10/3, 0, MODE_LWMA, PRICE_HIGH + (PRICE_HIGH / 3000), 0);
   double LineFloor      = iMA(NULL, 0, 10/3, 0, MODE_LWMA, PRICE_LOW  - (PRICE_LOW  / 3000), 0);
   double NeutralCeiling = iMA(NULL, 0, 70/3, 0, MODE_LWMA, PRICE_HIGH + (PRICE_HIGH / 3000), 0);
   double NeutralFloor   = iMA(NULL, 0, 70/3, 0, MODE_LWMA, PRICE_LOW  - (PRICE_LOW  / 3000), 0);
   static int PreventOrder = 0;

//--------------------------------
//Orders

   //-Send Order Outside of Neutral and Prevent New Order
   if((OrdersTotal() == 0) && (PreventOrder == 0))
   {
      if(LineFloor   > NeutralCeiling)
      {
         if(LinePrice > LineAxis)
            {  OrderSend(_Symbol, OP_BUY,  0.01, Ask, 0, 0, 0, NULL, 0, 0, clrRed);   }
      }
      if(LineCeiling < NeutralFloor  )
      {
         if(LinePrice < LineAxis)
            {  OrderSend(_Symbol, OP_SELL, 0.01, Bid, 0, 0, 0, NULL, 0, 0, clrViolet);}
      }
      PreventOrder = 1;
   }
   
   //-Close Order on Crossover
//   if((OrdersTotal() == 1)
//   {
//      if((OrderType() == OP_BUY)  && (LinePrice < LineAxis))
//      {  CeaseOrder();}
//      if((OrderType() == OP_SELL) && (LinePrice > LineAxis))
//      {  CeaseOrder();}
//   }

   //-Close Order in Neutral and Allow New Order
   if((LineAxis < NeutralCeiling) && (LineAxis > NeutralFloor))
   {  CeaseOrder(); PreventOrder = 0;}
Reason: