(Help) Problem with my Arrays and For Loop

 

Hi forum,

Can somebody please review my code. Im currently trying to developing a lot martingale strategy for expert advisor. And stuck at the problem now. As you can see in my piece of code its a not working one. I'm not sure how to use the Array and For Loop for my code problem ( Yes, im a noob in MQL4). The main rule of this code is : 

extern int    MaxLot        = 99;
extern int    Lot1          = 1;
extern int    Lot2          = 2;
extern int    Lot3          = 4;
extern int    Lot4          = 6;
extern int    Lot5          = 8; 
extern int    Lot6          = 9;
extern int    Lot7          = 9;
extern int    Lot8          = 10;
extern int    Lot9          = 11;
extern int    Lot10         = 11;

int init()
{

/////////////////////////////////////


   int nxtlot[10];
   nxtlot[0] = Lot1;
   nxtlot[1] = Lot2;
   nxtlot[2] = Lot3;
   nxtlot[3] = Lot4;
   nxtlot[4] = Lot5;
   nxtlot[5] = Lot6;
   nxtlot[6] = Lot7;
   nxtlot[7] = Lot8;
   nxtlot[8] = Lot9;
   nxtlot[9] = Lot10;

 return (0);
}

 int start()
{

 int totalopen = OrdersTotal();

 int start()
   {
   
   if (totalopen > 1 && totalopen <= MaxLot)
   {
      for (int s = totalopen ; s<=11; s++)
      {
         .....................ArrayResize(nxtlot[s])) OPnow = TRUE;
         .....................ArrayResize(nxtlot[s])) OPnow = TRUE;
      }
   }
  1. When total opened orders is >1 and < than the MaxLot, the Loop will start and take Array index and value to open next position with Lot that has been input in extern parameters

if (totalopen > 1 && totalopen <= MaxLot) 

      2. I want to limit until the total opened Orders  =  11 orders, so i put a limit in the Loop

for (int s = totalopen ; s<=11; s++)

 Your help will really relief me! Happy green pips :)

 

It may be just that Im very tired, but it looks like OrdersTotal() happens to be the index of the next lotsize, so a loop to find the next lotsize is unnecessary.

int nxtlot[] = {Lot1,Lot2,Lot3,Lot4,Lot5,Lot6,Lot7,Lot8,Lot9,Lot10};

if(logic to open a new trade){
        lotsize  = nxtlot[OrdersTotal()]
        int res = OrderOpen(.....)
[handle res appropriately]
}

assuming that your ea only works on one symbol at a time, otherwise youd have to count the orders that are open on the relevant symbol.


As an aside; martingale looks like it works right up to the moment it doesnt.

 

Does your code compile?

You declare

int nxtlot[10];

in Init(). That means that it is locally declared and cannot be accessed from any other function.

 int start()
{

 int totalopen = OrdersTotal();

 int start()

You can't have 2 functions called start and you cannot declare a function inside another function.

Rethink your code and post code that compiles and somebody may be able to help you.


In future please post in the correct section

I will move your topic to the MQL4 and Metatrader 4 section.