How to start with MQL5 - page 40

 
DroidM #: I can't figure out what I'm doing wrong, but it doesn't return true.
  1.    CopyRates(_Symbol,_Period,0,Candles,rates);
    

    You read [0 … Candles-1] values into rates.

  2.    for(int i=5; i<Candles; i++)
    

    Variable i goes up to Candles -1.

  3.    for(int l=i; l<i+candles; l++)
    

    Therefor, variable l goes to Candles-1+Candles-1.

  4.       if(rates[l+1].close>rates[l+1].open && rates[l+1].low>rates[l+2].low)

    Therefor, l+2 reaches [Candles … Candles-1+Candles-1+2]. Array exceeded. Crash.

 

Creating a ticker tape panel: Basic version

Creating a ticker tape panel: Basic version

Some people may find price tape panels that are built into some platforms and that display individual asset quotes pretty cool.
This idea is quite interesting to implement and develop and it can also be a very useful resource for many, which is why I decided to show how to create the code for such a panel.
Creating a ticker tape panel: Basic version
Creating a ticker tape panel: Basic version
  • www.mql5.com
Here I will show how to create screens with price tickers which are usually used to display quotes on the exchange. I will do it by only using MQL5, without using complex external programming.
 

Creating a ticker tape panel: Improved version

Creating a ticker tape panel: Improved version

In the previous article Creating a ticker panel: Basic version, we have seen how to create an indicator in the form of a panel displaying a tape of real-time symbol prices. However, in the previous article we did not implement the indicator completely, not because it was impossible, but because our goal was to show the process of creating the indicator, to see how to make it work with the least amount of code in order to give the impression that it moves.
But this data is not always enough and does not always reflect what people really want to see on the panel. It would be great to have some more details. This is what we are going to implement here.
Creating a ticker tape panel: Basic version
Creating a ticker tape panel: Basic version
  • www.mql5.com
Here I will show how to create screens with price tickers which are usually used to display quotes on the exchange. I will do it by only using MQL5, without using complex external programming.
 

PositionGetInteger(POSITION_TYPE) problem


Hi, I'm trying to use if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) to work on the sell order but i found out that it doesn't work because it always return POSITION_TYPE_BUY no matter the order is sell or buy........ really don't understand what's happened or is there any bug anyone encountered?


Here are my sample code and the print out log showing both sell and buy order return  POSITION_TYPE_BUY. Thanks a lot if anyone could help. Thanks.

void OnTick(){

   if(PositionsTotal()==0){
      trade.Buy(0.01);
      Print("Pos type is ", EnumToString((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)));
      trade.Sell(0.02);
      Print("Pos type is ", EnumToString((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)));
   }
}
 
Dennis Wong #:

PositionGetInteger(POSITION_TYPE) problem


Hi, I'm trying to use if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) to work on the sell order but i found out that it doesn't work because it always return POSITION_TYPE_BUY no matter the order is sell or buy........ really don't understand what's happened or is there any bug anyone encountered?


Here are my sample code and the print out log showing both sell and buy order return  POSITION_TYPE_BUY. Thanks a lot if anyone could help. Thanks.

It doesn't return POSITION_TYPE_BUY each time, it returns 0.

What are trying to do will never work, because you sent a trade request on the server, that doesn't mean you already have a position. It needs some time to be executed and the Terminal notified about it.

 
Vladimir Karputov #:

Calculate Positions and Pending Orders

Code:  Calculate Positions and Pending Orders.mq5


Open positions: GBPUSD BUY 0.03 lot and USDPLN SELL 0.01

Pending orders are placed: USDPLN Sell limit 0.01 and GBPUSD Buy limit 0.03


Hi @Vladimir Karputov, thank you so much, this thread is priceless, so many useful snippets. Please, I went though all pages but I didn't find how to calculate the average price of a set of orders (hedge accounts), probably using the History, lets say that I bought 1 lot at 5.00, 2 lots at 5.5 and sold 0.5 lots at 5.80, then I would expect 3 lots averaging (1*5 + 2*5.5)/3 of average buy price and 0.5 lot averaging 5.80 for sell price, would you have such snippet around? thanks!
 
i am new and i am working on  exponential moving average kindly help me to provide EA in which two moving average cross over take buy and sell and  take profit  and noted there is no stop loss concept just buy then buy close then sell open and take profit 
 
mohammadengineer anas #:
open and take
You can try to find it by yourself - read this thread about HowTo:
How can I search for indicators and other elements in this forum?
How can I search for indicators and other elements in this forum?
  • 2017.05.29
  • www.mql5.com
How can I search for indicators in this forum? I need the Hodrick Prescott Filter for MT4. Please, if anyone can help me, I thank you in advance...
 

Everything you need to learn about the MQL5 program structure

Everything you need to learn about the MQL5 program structure

Every software in any programming language has a structure, after understanding this structure we can create or develop our software smoothly. MQL5 language's programs are the same as any other programming language has their structure and it is supposed to be understood by the developer to achieve the objectives of his project smoothly and effectively. In this article, we will provide information in this context to try to deliver its content easily as possible.

Everything you need to learn about the MQL5 program structure
Everything you need to learn about the MQL5 program structure
  • www.mql5.com
Any Program in any programming language has a specific structure. In this article, you will learn essential parts of the MQL5 program structure by understanding the programming basics of every part of the MQL5 program structure that can be very helpful when creating our MQL5 trading system or trading tool that can be executable in the MetaTrader 5.
 
Vladimir Karputov #:

An example of get values from the iStochastic indicator

Code: iStochastic get value.mq5

Do not forget the rules: create the indicator handle ONCE in OnInit, use CopyBuffer to get the data.


Result:


Thank you.

Reason: