A newbie programmer need some help.

 

I just wrote my grid program, took two weeks and the result is a program that that only open order at the first level and fails to open on the subsequent levels. i wanted it to open on the levels as ask price goes above the grid levels but its not doing this. The program is attached , will appreciate some guidance .Thanks to everyone for being here.

Files:
mygrid2.mq4  6 kb
 
        while (true)  // <-- 1. issue
            {
              if ( n==OrdersTotal())//---------------+check open orders   // <-- 2. issue
               {

1. The code will not leave the while loop.
2. n is initialized with 0. You do never adjust it in your code. 

Suggestion: Remove the while loop and do something with n (start with giving it a meaningful name). 

I dont really understant what you are trying here, I am afraid... 

                  if (Ask>Buy_price&& OrderSelect(n,SELECT_BY_POS)==false)// ask greater than order price at level and no existing open order at level
                  BuyTrade=true;//------------------------------------------condition to open buy
                  if (Bid<Sell_price&& OrderSelect(n,SELECT_BY_POS)==false)
                  SellTrade=true;//-----------------------------------------condition to open sell
 
okanski:

I just wrote my grid program, took two weeks and the result is a program that that only open order at the first level and fails to open on the subsequent levels. 

It will only open an Order when . . .

if (Ask > Buy_price && OrderSelect(n,SELECT_BY_POS) == false)  // ask greater than order price at level and no existing open order at level

When this order is opened another order won't be opened until Ask has moved far enough to make this condition valid for the next level.  If you want to open multiple orders at once use pending orders,  but make sure you check to see how many you open or you will have more than you expected.

 
kronin:

1. The code will not leave the while loop.
2. n is initialized with 0. You do never adjust it in your code. 

Suggestion: Remove the while loop and do something with n (start with giving it a meaningful name). 

I dont really understant what you are trying here, I am afraid... 

 

Kronin, thanks for the response. i think i get what you mean with the n and while , will adjust it and update you on how it performs. i appreciate your help.
 
okanski:
Kronin, thanks for the response. i think i get what you mean with the n and while , will adjust it and update you on how it performs. i appreciate your help. I see now the Orderselect part is  not needed as the piont of preventing multiple open orders at the same level is already taken care of by the Buytrade changing to true after ordersend returns ticket>0.
 
RaptorUK:

It will only open an Order when . . .

When this order is opened another order won't be opened until Ask has moved far enough to make this condition valid for the next level.  If you want to open multiple orders at once use pending orders,  but make sure you check to see how many you open or you will have more than you expected.

 

Thanks a lot, will look at using pending orders too.
Reason: