Invalid price on multiple paris

Back to topics list To post a new topic, please log in or register
avatar
5
hsharghi 2015.08.11 22:40
 

Hi,

 My expert works fine when I use it on one pair. I mean drag the expert on the chart and let it execute. But when I use an array of pairs to open position on multiple pairs, It doesn't work. It seems still tries to open position on some other pair. It returns error 129 (Invalid price)

static string pairs[]={"GBPUSD","EURUSD","EURGBP","AUDUSD"};//, "EURJPY"};

   if((OrdersTotal()==0) && (OKToTrade))
     {
      initialBalance=AccountBalance();
      OKToTrade=false;

      for(int p=0; p<ArraySize(pairs); p++)
        {
           string currentSymbol=pairs[p];  // when use this line of code and try to open positions on multiple pairs, doesn't work
 //        string currentSymbol=_Symbol;   // when use this line of code and run it on any chart it works.
         double point=MarketInfo(currentSymbol,MODE_POINT);//Request for Point
         int digits=MarketInfo(currentSymbol,MODE_DIGITS);
         int cTP=(digits==5 || digits==3 ? 10 : 1);

         for(int i=1; i<=MaxOpenPositions; i++)
           {
            double spread=MarketInfo(currentSymbol,MODE_SPREAD);//Request for Spread
            double bid=MarketInfo(currentSymbol,MODE_BID); // Request for the value of Bid
            double ask=MarketInfo(currentSymbol,MODE_ASK); // Request for the value of Ask
            int tp=i*TakeProfit*cTP;
            double buyPrice=ask;
            double sellPrice=bid+spread*point;
 //         int buyRes  = OrderSend(currentSymbol,OP_BUY,LotSize,NormalizeDouble(buyPrice,digits),30,0,NormalizeDouble(buyPrice+tp*point, digits),buyComment,44444);
 //         int sellRes = OrderSend(currentSymbol,OP_SELL,LotSize,NormalizeDouble(sellPrice,digits),30,0,NormalizeDouble(sellPrice-tp*point-spread*point, digits),sellComment,44444);
            buyComment  = "Buy \nLot: " + LotSize + "\nPrice: " + NormalizeDouble(buyPrice,digits) + "\nTP: " + NormalizeDouble(buyPrice+tp*point, digits);
            sellComment = "Sell \nLot: " + LotSize + "\nPrice: " + NormalizeDouble(sellPrice,digits) + "\nTP: " + NormalizeDouble(sellPrice-tp*point-spread*point, digits);
            OrderSendReliable(currentSymbol,OP_BUY,LotSize,NormalizeDouble(buyPrice,digits),3,0,NormalizeDouble(buyPrice+tp*point,digits),buyComment,44444);             OrderSendReliable(currentSymbol,OP_SELL,LotSize,NormalizeDouble(sellPrice,digits),3,0,NormalizeDouble(sellPrice-tp*point-spread*point,digits),sellComment,44444);            }         }      }

  

I tried OrderSend() and OrderReliable helper class. Both fail at opening positions on multiple pairs.

 

 

 

 

avatar
13009
WHRoeder 2015.08.11 23:09 #
 
double buyPrice=ask;  // Ask is one of the predefined variables
    • Do not trade multiple currencies, you can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
    • Code it to trade the chart pair only. Look at the others if you must.
    • Then put it on other charts to trade the other pairs. Done.

  1. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong

Back to topics list  

To add comments, please log in or register