Help with this code please - page 3

 
Now down to the actual work. There are 15 labels but there could be more than 15 open orders. In February I had 96 open orders on one account. The thing is that at the moment the program could crash by indexing into non-existant label locations. 15 is a reasonable limit, but we must trap the error. How? A decision has to be made. Do we print buy orders until we run out of buy orders and then move on to sell orders; do we do some and some? It can't be programmed until it has been decided.
 
peteshr2st:


There are 2 final small changes I would like to make. These are not a major changes at all just things I would like to get done before I can say it is completed.

First one is to do with the line break. When there are 1 or more open buy and sell orders on screen it looks great but when there is just 1 buy order on its own it is still visible and not needed. This is because the line break code tells it to appear above all buy orders.

The logic I need is to tell the indicator to display the line break only when there are 1 or more open buy and sell orders. When there is just 1 sell order open it doesn't appear and looks great because the line break code was only added to the code applying to buy orders. Any ideas on this?

...

The next small edit I am hoping to figure out is the order display. As you can see below open orders are displayed starting with sell orders then a dashed line break and the buy orders. Is it possible to rearrange these so buys appear on top of the sells? This is not a big deal just something I would like to hear your opinion on because for all I know it might just be a straightforward code edit to do it.


The labels are numbered with 1 at the bottom left corner. By writing the buy orders first they appear at the bottom of the screen.

The line breaks are done within the buy order section. All that is needed is a test to only print them when there is also a sell order, ie ns > 0. It's trivial.

 

This bit is annoying me.

         if(sells_list[i][1] > 0){ 
            res = "Sell " +sellsymbol[i]+  "  Pips +" + DoubleToStr(sells_list[i][2]/10, 1);
            if( show_profit_values )
               res = res + "  Profit +" + DoubleToStr(sells_list[i][1], 2);

            ObjectSetText("lab"+lab, res, font_size, font_name, profit_colour);
         }
         else{
            res = "Sell " +sellsymbol[i]+  "  Pips  " + DoubleToStr(sells_list[i][2]/10, 1);
            if( show_profit_values )
               res = res + "  Profit  " + DoubleToStr(sells_list[i][1], 2);

            ObjectSetText("lab"+lab, res, font_size, font_name, loss_colour);
         }

It is mostly duplicated code. The colour bit is easy to do but also doing the plus sign in the middle is messy. I can't seem to make it elegant in the sense of having a minimal number of tests whilst still being readable. Obviously the first res assignment can come out of the blocks as it is common.

It would probably look better if you said "Profit" when it is in profit and "Loss " when it is in loss, rather than having a negative profit.

 

Your earlier code looked like this ...

               sellsymbol = OrderSymbol();
               sellprice = OrderOpenPrice();
               selllots = OrderLots();
               sellpips = ( OrderProfit() - OrderCommission() ) / OrderLots() / MarketInfo( OrderSymbol(), MODE_TICKVALUE );
               sellprofit = OrderProfit()+OrderCommission()+OrderSwap();

Your new code looks like this

         sellsymbol[ns] = OrderSymbol();
         sells_list[ns][1] = OrderProfit();
         sells_list[ns][2] = ( OrderProfit() - OrderCommission() ) / OrderLots() / MarketInfo( OrderSymbol(), MODE_TICKVALUE );
         sells_profit += sells_list[ns][1];
         sells_volume += sells_list[ns][2];

which is messed up. The Order Volume for example isn't summing OrderLots.

It will be a lot easier to understand if you use 1 dimensional arrays rather than 2. Then you would have a hard job making errors like this :-)

I think you have a bit more work to do than you think.

Reason: