Questions from a "dummy" - page 273

 
bagdarino:

the cost of e.g. 20 credits per month, what is credit and its cost.

1 credit = $1
 

A pair needs to be coded into a number. On MT4 I get out of the situation by first initialising the array:

string CurrName [35]={"","","","","","","","","","","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

then write the pair to the number by running it through the array:

for(int i=0; i<=6; i++)
  {string letter = StringSubstr(Symb,i,1);
   for(int j=10; j<=35;j++)
    {if(letter == CurrName[j])
     {text1=StringConcatenate(text1, j);
      break;
      }}}

I would be glad to know. It does not work with MT5 because I got an error message already when trying to initialize the array:

'Z' - too many initializers

Unfortunately, there is a gap in my knowledge at this point.

Please suggest possible solutions to this problem. Maybe there is a faster way for MT4 as well, I will be glad to learn.


Документация по MQL5: Операции с массивами / ArrayInitialize
Документация по MQL5: Операции с массивами / ArrayInitialize
  • www.mql5.com
Операции с массивами / ArrayInitialize - Документация по MQL5
 
Heroix:

A pair needs to be coded into a number. On MT4 I get out of the situation by first initialising the array:

then I write the pair into the number by running it through the array:

.........

It doesn't work in MT5 because I got an error message already when trying to initialize the array:

'Z' - too many initializers

Wapchepa 10+26 = 36. And you have an array with size [35]. The letter 'Z' doesn't fit into it, which is what the compiler is telling you.

Unfortunately, there is a gap in my knowledge at this point.

Please suggest possible solutions to this problem. Maybe there is a faster way for MT4 too, will be glad to know.

About fast ways. Programming is like poetry. You don't need to know anything except letters. The rest is creativity. You have a problem - you invent a solution.

And you're insulting me by insinuating that a good programmer differs from a bad one only by the thickness of a well-remembered reference book .... :) I don't even feel like helping...

Fi!

 
MetaDriver:

Vapchepa 10+26 = 36. And you have an array of size [35]. The letter 'Z' doesn't fit through, which is what the compiler tells you.

Programming is like poetry. You don't need to know anything but letters. The rest is creativity. You have a problem - you invent a solution.

And you're insulting me by insinuating that a good programmer differs from a bad one only by the thickness of a well-remembered reference book .... :) I don't even feel like helping...

Fi!

Strange, but somehow the code works on MT4. In the loop there, yes, j<=36 is in the original, this is here "drawn" 35.

Thank you, the matter was indeed in the array value declaration. I declare arrays this way once every 100 years, figuratively... don't judge it too harshly.

You have on the last lines, speculation, nothing more. Wrote almost directly: I didn't know what to do, for various reasons.

 
Heroix:

Strange, but somehow the code works on MT4. In the loop there, yes, j<=36 is in the original, this is here "drawn" 35.

Thank you, the matter was indeed the array's value declaration. I declare arrays this way once every 100 years, figuratively... don't judge it too harshly.

Okay.

You have on the last lines, speculation, nothing more. Wrote almost directly: I didn't know what to do, for various reasons.

All right, all right. Let's just say I'm having this... Full moon, yeah. It's all the rage these days.

;)

 
papaklass:

Who knows if the MC's position has changed on:

1. Introduction of exception handling (try {} catch() {}) . Was "strongly opposed".

No

2. Introduction of foreach operator () {}.

? Well, that's a bit of a load of nonsense. I don't know what to ask for. The operator is specifically for containers, the concept of which does not exist in MQL at all.

There are only arrays, for which it is perfectly implemented by a regular fork.

 
papaklass:

Who knows if the MC's position has changed on:

1. Introduction of exception handling (try {} catch() {}) . Was "strongly opposed".

2. Introduction of foreach operator () {} .

PS: It's not clear why the operator stood out?

It's highlighted because there's a reserved word for, and it's referenced.
 

I'm working too hard...

the script:

#property script_show_inputs
//--- input parameters
input string   Symb0="EURUSD";
input double   Vol0=0.2;
input string   Symb1="GBPUSD";
input double   Vol1=0.3;
input string   Symb2="CADCHF";
input double   Vol2=0.4;

input bool     buy = true;

MqlTradeRequest TradeRequest[3];
MqlTradeResult  TradeResult[3];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
  if(buy)
  {
  _OrderSend(TradeRequest[0],TradeResult[0],Symb0,ORDER_TYPE_BUY,Vol0,0,0.0,0.0,"EURUSD",0);
  _OrderSend(TradeRequest[1],TradeResult[1],Symb1,ORDER_TYPE_BUY,Vol1,0,0.0,0.0,"GBPUSD",0);
  _OrderSend(TradeRequest[2],TradeResult[2],Symb2,ORDER_TYPE_BUY,Vol2,0,0.0,0.0,"CADCHF",0);
  Comment(PositionsTotal());
  }
  //Sleep(5000);
  else
  {
  
  _OrderSend(TradeRequest[0],TradeResult[0],Symb0,ORDER_TYPE_SELL,Vol0,0,0.0,0.0,"EURUSD",0);
  _OrderSend(TradeRequest[1],TradeResult[1],Symb1,ORDER_TYPE_SELL,Vol1,0,0.0,0.0,"GBPUSD",0);
  _OrderSend(TradeRequest[2],TradeResult[2],Symb2,ORDER_TYPE_SELL,Vol2,0,0.0,0.0,"CADCHF",0);
  }
  
  Sleep(1000);
  _CloseAllPositions();
  }
//+------------------------------------------------------------------+

void _OrderSend(MqlTradeRequest &tradeRequest,
                MqlTradeResult  &tradeResult,
                string          symbol,
                ENUM_ORDER_TYPE type,
                double          volume,
                ulong           deviation,
                double          sl,
                double          tp,
                string          comment,
                int             magic)
{
  MqlTick price; SymbolInfoTick(symbol, price);
  
  tradeRequest.action   = TRADE_ACTION_DEAL;
  tradeRequest.symbol   = symbol;
  tradeRequest.type     = type;
  tradeRequest.volume   = volume;
  
  if(type==ORDER_TYPE_BUY)
    tradeRequest.price    = price.ask;
  if(type==ORDER_TYPE_SELL)
    tradeRequest.price    = price.bid;

  tradeRequest.deviation= deviation;
  tradeRequest.sl       = sl;
  tradeRequest.tp       = tp;
  tradeRequest.comment  = comment;
  tradeRequest.magic    = magic;
  
  OrderSendAsync(tradeRequest,tradeResult);
}


void _CloseAllPositions()
{
  Print("пробую закрытся");
  MqlTradeRequest tradeRequest;
  MqlTradeResult  tradeResult;
  MqlTick price;
  
  if(PositionsTotal()>0)
  {
    
    string symb="";
    
    for(int i=0;i<PositionsTotal();i++)
    {
      symb=PositionGetSymbol(i);
      PositionSelect(symb);
      SymbolInfoTick(symb, price);
      
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
      {
        tradeRequest.type =ORDER_TYPE_SELL;
        tradeRequest.price=price.bid;
      }
      else
      {
        tradeRequest.type =ORDER_TYPE_BUY;
        tradeRequest.price=price.ask;
      }
        tradeRequest.action   =TRADE_ACTION_DEAL;
        tradeRequest.symbol   = symb;
        tradeRequest.volume   = PositionGetDouble(POSITION_VOLUME);
        tradeRequest.deviation= 0;
        tradeRequest.sl       = 0.0;
        tradeRequest.tp       = 0.0;
        tradeRequest.comment  = "";
        tradeRequest.magic    = 0;
        
        OrderSend(tradeRequest,tradeResult);
    }
  }
}

I'm getting errors:

2013.08.23 10:28:54 Trades '1421016': failed instant sell 1.60 CADCHF at 0.87721 [Invalid request]
2013.08.23 10:28:54 Trades '1421016': failed instant sell 1.20 GBPUSD at 1.55836 [Invalid request]
2013.08.23 10:28:54 Trades '1421016': failed instant sell 0.80 EURUSD at 1.33455 [Invalid request]


What is the problem?

 

I have everything open... But it won't close CADCHF. (Server is MetaQuotes Demo)

Changed the direction of the for loop, now everything is fine, everything opens and everything closes.

 
i_logic:

I have everything open... But it won't close CADCHF. (Server - MetaQuotes Demo)

Changed the direction of the for loop, now everything is fine, everything opens and everything closes.

changed to:

for(int i=PositionsTotal()-1;i>=0;i--)

So the closure doesn't work either.

Reason: