Issues With Assigning 2D Array Elements

thread: Issues With Assigning 2D Array Elements

  1. #1
    Senior Member Juana.pkmixxar's Avatar
    133

    Issues With Assigning 2D Array Elements

    Attached is a part of a Expert Advisor I have been working on to examine out a trading egy, but I'm having some difficulty with the limitations of MQL4 when dealing with arrays. What I want to so is use an array to store information regarding the situations that that I have open and additionally to redefine the elements' values. What I want to implement is a series of 3 functions that reconstructs the collection of open orders. This could be done after closing or every position opening. The next function is supposed to sort the open orders according to their respective opening prices. The sequential function would be to reevaluate the stop loss and take profit values. The values to the prevent losses and make profit values are to be based upon the introductory price of the order. I desired the EA to execute the stop loss and take profit values. I am aware there are risks to establishing an EA this way and with doing so, that I wish to proceed.





    Double OrderStack[7][9]; // Order information array


    if((OrderStack[TotalOrders 1][1] lt; Bid) (TotalOrders lt; 2)) // Opens new Sell position at more favorable price
    //3
    TicketNum = OrderSend(Symbol(),OP_SELL,LotSize2,Bid,3,0,0,Comm entString,0,0,Red); //Open this order.
    If(TicketNumlt;0)
    //4
    Print(Error Opening Trade: Error Code = ,GetLastError(),, Lotsize: ,Lots);
    //3
    else
    //4
    if(OrderSelect(TicketNum,SELECT_BY_TICKET))
    //5
    Print(Sell Order Opened at Price: ,OrderOpenPrice());
    OrderFlagS = 1; // Used by primary EA function for remarks
    Terminal(); // Call to function that produces open order data array
    //4
    //3
    //2
    } //1
    } //0

    //--------------------------------------------------------------------
    // Terminal.mqh
    //------------------------------------------------------------------------------ 1 --
    // Order accounting function
    // Global variables:
    // OrderStack[7][9]
    // The latest known orders array
    // 1st index = order number
    // [][0] not defined
    // [][1] order open price (abs. Price value)
    // [][2] StopLoss of this order (stomach) Price value)
    // [][3] TakeProfit of this order (stomach) Price value)
    // [][4] order number
    // [][5] order volume in lots (abs. Price value)
    // [][6] order form 0=B,1=S,2=BL,3=SL,4=BS,5=SS
    // [][7] order magic number
    // [][8] 0/1 remark accessibility
    // Mas_Tip[6]
    // Array of the number of orders of all sorts
    // [] order form: 0=B,1=S,2=BL,3=SL,4=BS,5=SS
    //------------------------------------------------------------------------------ 2 --
    double Deck()
    //1
    int Mas_Tip[6];
    int Qnt = 0;
    int I;

    // Orders counter
    //------------------------------------------------------------------------------ 3 --

    ArrayInitialize(OrderStack, 0.0); // Zeroize the selection
    ArrayInitialize(Mas_Tip, 0); // Zeroize the array
    //------------------------------------------------------------------------------ 4 --
    for(I = 0; I lt; OrdersTotal(); I ) // For market and pending orders
    //2
    if((OrderSelect(I,SELECT_BY_POS) == true) (OrderSymbol() == Symbol()))
    //When there is the subsequent one. . And our currency pair
    //3
    //--------------------------------------------------------------------- 5 --
    Qnt ; // Amount of orders
    OrderStack[Qnt][1] = OrderOpenPrice(); // Order open price
    OrderStack[Qnt][2] = OrderStopLoss(); // SL price
    OrderStack[Qnt][3] = OrderTakeProfit(); // TP price
    OrderStack[Qnt][4] = OrderTicket(); // Order number
    OrderStack[Qnt][5] = OrderLots(); // Amount of lots
    Mas_Tip[OrderType()] ; // Amount of orders of the type
    OrderStack[Qnt][6] = OrderType(); // Order type
    OrderStack[Qnt][7] = OrderMagicNumber(); // Magic number
    if (OrderComment()==)
    //4
    OrderStack[Qnt][8] = 0; // If there's absolutely no comment
    //3
    else
    //4
    OrderStack[Qnt][8] = 1; // If there is a comment
    //3
    //2
    //--------------------------------------------------------------------- 6 --

    OrderStack[0][0] = Qnt; // Amount of orders

    //------------------------------------------------------------------------------ 7 --

    FillStack(OrderStack, Trend_Up); // Call to function that sorts open trade data based on trend direction and initial trade price
    return(0);
    //1

    //0
    //------------------------------------------------------------------------------ 8 --




    //
    // Existing Orders Sorting Function
    //

    double SortStack(double OrderStack[7][9], bool Trend_Up) // Function to sort the reconstructed order array in
    // order based on initial order open price
    //1
    int I, TotalOrders;
    TotalOrders = OrderStack[0][0];

    if(Trend_Up == true)
    //2
    ArraySort(OrderStack[TotalOrders][1], TotalOrders,1,MODE_DECEND);
    //1
    if(Trend_Up == false)
    //2
    ArraySort(OrderStack[TotalOrders][1], TotalOrders,1,MODE_ASCEND);
    //1
    FillStack(OrderStack, Trend_Up); // Call to function that defines trade parameters for adverse
    // market trades into order array
    return(0);
    //0

    //
    // Record Adverse Market Trade Parameters Function
    //

    double FillStack(double OrderStack[7][9], bool Trend_Up) // Defines Adverse Market Trade Parameters
    // based on initial order from Bollinger band piercing

    //1

    double PriceIn;

    PriceIn = OrderStack[1][1];
    //2
    if(Trend_Up == true)
    //3
    OrderStack[1][2] = PriceIn - StopLossVal; // Column 2, Stop Loss Entry Column
    OrderStack[1][3] = PriceIn 0.0030; // Column 3, Take Profit Entry Column
    OrderStack[2][1] = PriceIn - 0.0010; // Column 1, Average Down Market Order Buy Price
    OrderStack[2][3] = PriceIn - 0.0005; // Column 3, Take Profit for Avg Down Market Entry
    //2
    if(Trend_Up == false)
    //3
    OrderStack[1][2] = PriceIn StopLossVal; // Column 2, Stop Loss Entry Column
    OrderStack[1][3] = PriceIn - 0.0030; // Column 3, Take Profit Entry Column
    OrderStack[2][1] = PriceIn 0.0010; // Column 1, Average Down Market Order Buy Price
    OrderStack[2][3] = PriceIn 0.0005; // Column 3, Take Profit for Avg Down Market Entry
    //2
    //1
    return(0);
    //0




    The problem I am having with implementing this EA is that the compiler gives me error messages about ”array item cannot be assigned” for the code in my FillStack() function. What is perplexing is that it look like that is precisely what's being done from the Terminal() function above my FillStack() function. I'm hoping that one of those programmers that are experienced can give me a cure for this bug.
    Its hard to believe that with all of the similarities which MQL4 has C that the capability to assign values to array elements like C wouldn't exist in MQL4 also. Thank you.

  2. #2
    Junior Member Ale21tt's Avatar
    16
    OrderStack[0][0] = Qnt; // Number of orders

    TotalOrders = OrderStack[0][0];
    hello,

    just a note that reserving area for nine doubles for advice that can be held in 1 integer, as revealed in your quoted text is bad distance adminiion.

    Research and find out the variety functions from the MetaEditor help file (Navigator) and always keep in mind that the more info floating around the lower your code/computer executes.

  3. #3
    This error indies that a write to a read only array. Since this post is old I am assuming that you didn't post followup and discovered a solution or found an alternative solution.

    Inserted Code dual OrderStack#91;7#93;#91;9#93; void function (dual array#91;#93;#91;#93;-RRB- Alert (range size , ArraySize(range)); range#91;0#93;#91;0#93; = EURUSD; // error not allowed to write The key to read/write arrays passed to serve is in the statement. The code block won't through a mistake.

    Inserted Code double OrderStack#91;7#93;#91;9#93; void function (#91;color=Purple#93;dual#91;/colour#93;#91;b#93;#

  •