How to code to get MIN and MAX open price of all "Open Trade"

 

How to code to get MIN and MAX openprice of all "Open Trade"


Hi guys, I would like ask if anyone know how to code the function to get the MIN and MAX open price of all ongoing running trade of Symbol(), assume I got no magic number.


E.g I got 4 trades of EUR USD running


4 open trades 1.3040, 1.3077, 1.3129, 1.3158 & 2 closed trades in history 1.3180 and 1.3020


I want to able get the return result of getting the MIN open price and MAX open price [ ONLY ON TRADES THAT ARE ongoing and running ]


e.g


double minPrice = getMinOpenPrice(); //should return 1.3040

double maxPrice = getMaxOpenPrice(); //should return 1.3158


which the getMinOpenPrice() and getMaxOpenPrice() is a function thats return the min / max of Symbol() only applicable to all "Open & Running Trade" & not include closed order that touch tp / sl

 
baokydev:

How to code to get MIN and MAX openprice of all "Open Trade"


Hi guys, I would like ask if anyone know how to code the function to get the MIN and MAX open price of all ongoing running trade of Symbol(), assume I got no magic number.


E.g I got 4 trades of EUR USD running


4 open trades 1.3040, 1.3077, 1.3129, 1.3158 & 2 closed trades in history 1.3180 and 1.3020


I want to able get the return result of getting the MIN open price and MAX open price [ ONLY ON TRADES THAT ARE ongoing and running ]


e.g


double minPrice = getMinOpenPrice(); //should return 1.3040

double maxPrice = getMaxOpenPrice(); //should return 1.3158


which the getMinOpenPrice() and getMaxOpenPrice() is a function thats return the min / max of Symbol() only applicable to all "Open & Running Trade" & not include closed order that touch tp / sl


show us your way how you check trades you have open ....

then we say what change you have to make...

 
baokydev:

How to code to get MIN and MAX openprice of all "Open Trade"


Hi guys, I would like ask if anyone know how to code the function to get the MIN and MAX open price of all ongoing running trade of Symbol(), assume I got no magic number.


E.g I got 4 trades of EUR USD running


4 open trades 1.3040, 1.3077, 1.3129, 1.3158 & 2 closed trades in history 1.3180 and 1.3020


I want to able get the return result of getting the MIN open price and MAX open price [ ONLY ON TRADES THAT ARE ongoing and running ]

Here is some example code:

int TicketIDs[];
double OpenPrices[];
int i_maxPrice = 0, i_minPrice = 0;
for (int i = OrdersTotal() - 1; i >= 0; i--)
   if (OrderSelect(i, SELECT_BY_POS))
      if (OrderSymbol() == Symbol() && OrderType() <= OP_SELL) {  // assumes only OP_BUY and OP_SELL orders (not pending orders) 
         int index = ArraySize(TicketIDs);
         ArrayResize(TicketIDs, index + 1);
         ArrayResize(OpenPrices, index + 1);
         TicketIDs[index] = OrderTicket();
         OpenPrices[index] = OrderOpenPrice();
      }
if (ArraySize(TicketIDs) > 0) {
   i_maxPrice = ArrayMaximum(OpenPrices);
   i_minPrice = ArrayMinimum(OpenPrices);
   Print ("Minimum open price is ", DoubleToStr(OpenPrices[i_minPrice], 5), " (Ticket # ", TicketIDs[i_minPrice], ") ", 
          "and the Maximum open price is ", DoubleToStr(OpenPrices[i_maxPrice], 5), " (Ticket # ", TicketIDs[i_minPrice], ").");
}
 

Hi Guys,

it is first time I am posting here and I apologize in advance if I have posted on the wrong place. I spent a lot of time trying to figure out if I am doing it right.

I am using and EA which places orders above and below a line, ( in the conde is named zeroLINE).

The code below determines the max and min price of all open orders and it works fine. However if I put the EA on two currency pairs that have a common currency, for example GBPAUD and AUDCAD the EA takes the values from the first currency pair and applies them to the second, which messes up the performance of the EA on the second currency pair. I am not using magic, I am using order comment to distinguish the orders and I am at a loss. The EA has different orderComment on each currency pair and it still takes the values from the other. Can anyone help?

if(ordersCount(OP_BUY, orderComment)> 0 || ordersCount(OP_SELL, orderComment)> 0)
{
   for(int i=OrdersTotal()-1; i>=0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol() && OrderComment() == orderComment)
      {
         if(OrderType() == OP_BUY && limitOrdersCount(OP_BUY) == 0)
         {
            double stopPriceMAX = 0, stopPriceMIN = 999999;
            if(OrderOpenPrice() > stopPriceMAX)   stopPriceMAX = OrderOpenPrice();
            if(OrderOpenPrice() < stopPriceMIN)   stopPriceMIN = OrderOpenPrice();
            GlobalVariableSet(Symbol()+"lastBuyStopPrice", stopPriceMAX);
            GlobalVariableSet(Symbol()+"firstBuyStopPrice", stopPriceMIN);
            GlobalVariableSet(Symbol()+"zeroLINE", stopPriceMIN - Increment*Point);
            ObjectSetDouble(0, "zeroLINE", OBJPROP_PRICE, GlobalVariableGet(Symbol() + "zeroLINE"));
            GlobalVariableSet(Symbol()+"firstBuyLimitPrice", zeroLINE - limitOrderStep*Point);
            GlobalVariableSet(Symbol()+"lastBuyLimitPrice", zeroLINE - limitOrderStep*Point);
         }
         if(OrderType() == OP_SELL && limitOrdersCount(OP_SELL) == 0 )
         {
            double stopPriceMAX = 0, stopPriceMIN = 999999;
            if(OrderOpenPrice() > stopPriceMAX)   stopPriceMAX = OrderOpenPrice();
            if(OrderOpenPrice() < stopPriceMIN)   stopPriceMIN = OrderOpenPrice();
            GlobalVariableSet(Symbol()+"firstSellStopPrice", stopPriceMAX);
            GlobalVariableSet(Symbol()+"lastSellStopPrice", stopPriceMIN);
            GlobalVariableSet(Symbol()+"zeroLINE", stopPriceMAX + Increment*Point);
            ObjectSetDouble(0, "zeroLINE", OBJPROP_PRICE, GlobalVariableGet(Symbol() + "zeroLINE"));
            GlobalVariableSet(Symbol()+"firstSellLimitPrice", zeroLINE + limitOrderStep*Point);
            GlobalVariableSet(Symbol()+"lastSellLimitPrice", zeroLINE + limitOrderStep*Point);
         }
      }
   }
}