[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 917

 
_SS_:
How do I create a function and call it?
Read a textbook... :)
 

artemida70, put together my first EA using S. Kovalev's tutorial. It turned out that its criterion function worked with losses. Wrote my criterion function. Checked it for errors and then compiled the Expert Advisor. As a result of the work, I got:

- on criteria function: O - errors, 1 warning;

-for compilation of Expert Advisor: О - errors, О - warnings.

But the work in the Strategy Tester did not go, put test ALERTS in functions int init, int start, int deinit. I see in the responses that control is passed from Terminal to the int init function and control is not passed to the int start function - no response ALERT. When the EA is unloaded, there is a response from the int deinit function.

Please, your advice on this situation. Very much need advice from an experienced professional.

THANK YOU

artmedia70:
Read a tutorial... :)
 
artmedia70:
Here you have a strange structure. You are doing the standard loop of orders of the terminal. From zero to OrdersTotal() -1. And then you check the complete absence of orders in the terminal in the loop. Why don't you check the ticket for orders? Or a magik? And your flag =0 for some reason. And why not false? However, you are the boss. Your logic, you must understand it... :)

Thanks for the tip))) Exactly at this point:. From zero to OrdersTotal() -1... That's the reason why the tester didn't continue placing orders))))

I use this scheme because I learned it from someone else's classes. If you could describe a more rational method, I'd be very grateful))))

 

I've been screwed, I haven't gotten out of mql4 for almost a month, I think I'm going crazy or what?

i have no idea what i am trying to do with it.

I'm putting it out there, at least give me a hint, what's wrong? Gurus, help the dummies!

I'm not seeing any errors in the log.
 
extern double StopLoss=50.0;
extern double TakeProfit=50.0;
extern double Lots=1;
extern int total;

int start()
{
double Price_1, Price_2, min, max;
RefreshRates();
Price_1=Bid;
Price_2=Ask;

min=iLow(NULL,0,2);
max=iHigh(NULL,0,2);
total=OrdersTotal();
if(total<1)
{

if(Price_1>max)
OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Bid-StopLoss*Point,Ask+TakeProfit*Point, "My order#",16384,0,Green);

if(Price_2<min)
OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Ask+StopLoss*Point,Bid-TakeProfit*Point, "My order#",16384,0,Green);
}
}
return(0);
 
boris.45:

artemida70, put together my first EA using S. Kovalev's tutorial. It turned out that its criterion function worked with losses. Wrote my criterion function. Checked it for errors and then compiled the Expert Advisor. As a result of the work, I got:

- on criteria function: O - errors, 1 warning;

-for compilation of Expert Advisor: О - errors, О - warnings.

But the work in the Strategy Tester did not go, put test ALERTS in functions int init, int start, int deinit. I see in the responses that control is passed from Terminal to the int init function and control is not passed to the int start function - no response ALERT. When the EA is unloaded, there is a response from the int deinit function.

Please, your advice on this situation. Very much need advice from an experienced professional.

THANK YOU


I'd like to see what you've done there... :)
I don't understand what it means - IC's criteria function works with losses. After all, any function, if it tracks the opening criteria, may either work correctly or incorrectly, and therefore it may have errors. But the strategy itself - it can be losing or profitable... The criteria function only tracks the criteria set by the strategy and sends signals to the trading function.
 
ViktorF:

Thanks for the tip))) Exactly at this point:. From zero to OrdersTotal() -1... That's the reason why the tester didn't continue placing orders))))

I use this scheme because I learned it from someone else's classes. If you could describe a more rational method, I'd be very grateful)))).

There are many ways. All depends on what you want to find.

In any case, you can start looping through the orders

for (int i =0; i<OrdersTotal(); i++)

then check exactly what you want to find in the loop.

if (OrderSelect(i, SELECT_BY_POS) // If the order is selected (here, I omitted the MODE_TRADES function parameter since it is selected by default)

and then - you already check the parameters of the order that you need, for example, magik

if (OrderMagicNumber()==Magic) // if the order has the given magic number, then... then this is the order we need...

Well... Or its type...

if (OrderType()==OP_BUY || OrderType()==OP_SELL) // if the order type is Buy or Sell...

etc..

Although, we can do it completely differently... It all depends on your habits, and on the code's requirements...

 
gheka:

should work. is the smiley face smiling?
 

Hi all! I have the following code in my Expert Advisor (see below). As I understand it, the signal to open a position is taken from the indicators of two indices. How can we make the orders open based on only one indicator, e.g. CCI? Thank you very much.

int getSignal() {
   int Momentum = checkMomentum();
   int CCI = checkCCI();
   if (Momentum != CCI) return (0);
   return (Momentum);
}
int checkCCI() {
   double CCI = iCCI(NULL, 0, 60, PRICE_TYPICAL, 1);
   Print("CCI: ", CCI);
   if (CCI > 0.0) return (1);
   if (CCI < 0.0) return (-1);
   return (0);
}

int checkMomentum() {
   double Momentum = iMomentum(NULL, 0, 60, PRICE_TYPICAL, 1);
   Print("Momentum ", Momentum);
   if (Momentum > 100 && Momentum < 101) return (1);
   if (Momentum < 100 && Momentum > 99) return (-1);
   return (0);
}
 

Help, advisor does not close all orders when reaching a profit

void CloseAllOrders()
{
  for (int i = 0; i < OrdersTotal(); i++)
  {
    if (OrderSelect(i, SELECT_BY_POS))
    {
      if (OrdersTotal() > 1 && OrderSymbol() == Symbol() && AccountProfit() >= AccountBalance()*AllProfit/100)
      {
        if((OrderType()==OP_BUY || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)) OrderClose(OrderTicket(), OrderLots(),Bid,0);
        if((OrderType()==OP_SELL || OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT)) OrderClose(OrderTicket(), OrderLots(),Ask,0);
        if(UseSound == true)
        {
        PlaySound(SuccesSound);
        }        
      }
    }
  }
}
Reason: