[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 197

 
CLAIN:

Comrades, help please... I wrote a simple code, but when compiling it says that the brackets are out of balance, but I've already counted them 300 times - everything is in place

The idea is simple - if MACD has been above (or below) 0 for 7 minutes or less, the position opens


Check this function

void AnalyzeSignal(int signal) 
{ 
  if(signal == 100) 
  { 
    ticket = OrderSend(Symbol(),OP_BUY,lots,Ask,slip,Bid-TS*Point,Bid+TP*Point,"покупаем",Magic,0,Green); 
    if(ticket>0) 
    { 
      OrderSelect(ticket,SELECT_BY_TICKET); 
      Print("открылись на покупку по цене:" OrderOpenPrice()); 
    } 
    else 
    { 
      Print("открыться не удалось по причине:" GetLastError()); 
      return(0); 
    } 
  } 
  if(signal == -100) 
  { 
    ticket = OrderSend(Symbol(),OP_SELL,lots,Bid,slip,Ask+TS*Point,Ask-TP*Point,"Продаем",Magic,0,Green); 
    if(ticket>0) 
    { 
      OrderSelect(ticket,SELECT_BY_TICKET); 
      Print("открылись на продажу по цене:" OrderOpenPrice()); 
    } 
    else 
    { 
      Print("открыться не удалось по причине:" GetLastError()); 
      return(0); 
    } 
  } 
} 

//---- 
return(0); 
} 
 
CLAIN:
p.s. how do you draw a script as nicely as you do?

There's an SRC button when you write your answer.

As for brackets, I'm in the habit of specifying what the close bracket refers to

}//for

}// (signal...

 
splxgf:

And as for the brackets, I have a habit of specifying what the closing refers to

}//for

}// (signal...


"to taste and colour..." - but I must admit that this approach overloads the code with unnecessary information + takes time to write extra lines of code + does not solve the problem of deep nesting (numbering levels?)

Better structure the code - as in the example above

 

Good afternoon, could you please tell me how to write a condition so that after opening one order, the second cannot open on the same candle. I am writing the following:

if (... && CountOrder<2 && (BarLast>1 || BarLast==-1))
{
OrderSend(Symbol(),OP_BUY,MinLot,Ask,0,VStopLossLong,0, "BUY: ",MagicL,0,Green);

}

where

// count the number of open orders for a security
int CountOrder=0;
for (int j=0; j<OrdersTotal(); j++)
if (OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
if (OrderSymbol()==Symbol()) CountOrder++;

// bar number of last closed position or -1, if it hasn't been opened yet
int BarLast=BarLastClosePose();


и

// bar number of the last closed position
int BarLastClosePose()
{
datetime t;
int i;

for (i=0; i<OrdersHistoryTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
//if (OrderMagicNumber()!=Magic) continue;
if (OrderSymbol()!=Symbol()) continue;
if (OrderType()>1) continue;
if (t<OrderCloseTime()) t=OrderCloseTime();
}
}

return (iBarShift(Symbol(),Period(),t,true));
}

 
Thank you Roger
 
datetime LastTradeBar;

bool CanTrade = True;

int Start()

{ 

if (LastTradeBar==Time[0] ) CanTrade=False; else CanTrade=True; 

if (... && CountOrder<2 && (BarLast>1 || BarLast==-1))
{
if (CanTrade)

{

OrderSend(Symbol(),OP_BUY,MinLot,Ask,0,VStopLossLong,0,"BUY: ",MagicL,0,Green);

LastTradeBar=Time[0];

} 

}
In fact, the logical variable is superfluous here.
 
Vinin:


Check this function


Vinin, verified, everything is fine in this function... return(0) refers to the start function, and if you don't count the brackets attached to return'y, you get 14 brackets... 7 each way
 
CLAIN:

Vinin, verified, everything is fine in this function... return(0) refers to the start function, and if you don't count the brackets that are attached to return'y, you get 14 brackets... 7 each way.

Copying each function into a separate file and verifying compilation helps.

If the brackets are correct, then indicate where the start ends and the MACD signal begins.

int start() 
{ 
//---- 

int total,ticket; //объявил тотал и тикет 
int signal = signal_MACD(); //сигнал МАКД передает значение в сигнал
AnalyzeSignal(signal); //аналайз сигнал анализирует сигнал
int MACD[8] = {0,1,2,3,4,5,6,7}; //создал одномерный массив МАКД
MACD[0] = iMACD(Symbol(),1,5,34,5,PRICE_CLOSE,MODE_MAIN,7); 
///Бла-бла-бла
MACD[7] = iMACD(Symbol(),1,5,34,5,PRICE_CLOSE,MODE_MAIN,0); 

total = OrdersTotal(); //тотал считает ордера
///Тут большая жирная закрывающая скобка, если конечно следующая строчка это функция
int signal_MACD()
 
splxgf:

Copying each function into a separate file and verifying compilation helps.

If the brackets are correct, indicate where the start ends and the MACD signal begins.


hmm... int signal_MACD() is indeed a function... but why does it have to be behind the start function? i honestly don't understand why some functions are written outside the start and some inside... what is the difference?
 
To be honest, I don't know if it is possible to describe one function within another, I've never come across such a thing.
Reason: