[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 113

 
mukata >> :

so what about the question?

It's quicker to store in a variable than to call a function every time.

By the way, it's easy to check in the tester.

 
StatBars >> :
Where'd you hide your code? I just wanted to tweak it, and it's already...


//+------------------------------------------------------------------+
//| Copyright © 2009, ::: -- SAMER -- ::: |
//| E-MAIL: camep@inbox.ru icq: 422372555 |
//+------------------------------------------------------------------+

extern double TakeProfit = 500;
extern double Lots = 0.1;
extern double Stoploss = 30;
extern double TrailingStop = 30;
extern int iWPRperiod1 = 50;
extern int iWPRperiod2 = 60;
extern int iWPRperiod3 = 60;
extern int iWPRperiod4 = 50;
extern int slowing = 3;
extern int period = 3;
extern int period2 = 5;

int start()
{
double a;
int b;
int total;
int ticket;
int cnt;
int iWPRperiod1;
int iWPRperiod2;
int iWPRperiod3;
int iWPRperiod4;
int slowing;
int period;
int period2;

if(Bars<100)
{
Print("bars less than 100");
return(0);
}

if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return(0);
}

total=OrdersTotal();
if(total<1)
{

if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if((iWPR(NULL,0,iWPRperiod1,0)>iWPR(NULL,0, iWPRperiod2,0)) < iStochastic(NULL,0,period2,period,slowing,0,0,0,0) )

{
ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-Stoploss*Point, Ask+TakeProfit*Point,"comment",16384,0,Green);

if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
{
else Print("Error opening BUY order : ",GetLastError());
return(0);
}

if((iWPR(NULL,0,iWPRperiod1,0)>iWPR(NULL,0, iWPRperiod2,0)) > iStochastic(NULL,0,period2,period,slowing,0,0,0,0) )
{
ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+Stoploss*Point,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}

for(cnt=0; cnt < total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol())

{
if(OrderType()==OP_BUY)
{
if(iWPR(NULL,0,iWPRperiod1,0)>iWPR(NULL,0, iWPRperiod2,0))
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet)
return(0);
}

if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if(iWPR(NULL,0,iWPRperiod3,0)<iWPR(NULL,0, iWPRperiod4,0))
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
return(0);
}
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}

 
TheXpert >> :

It's quicker to store in a variable than to call a function every time.

By the way, it may be easily checked in the tester.

Thanks, that's what I thought too.

But how much code I've read on this forum - no one does that, everyone calls the function every time. I am in the same place.

I understand with the function, but what about the array?

P.S. recently here...

 
//+------------------------------------------------------------------+
//| Copyright © 2009, ::: -- SAMER -- ::: |
//| E-MAIL: camep@inbox.ru icq: 422372555 |
//+------------------------------------------------------------------+

extern double TakeProfit = 500;
extern double Lots = 0.1;
extern double Stoploss = 30;
extern double TrailingStop = 30;
extern int iWPRperiod1 = 50;
extern int iWPRperiod2 = 60;
extern int iWPRperiod3 = 60;
extern int iWPRperiod4 = 50;
extern int slowing = 3;
extern int period = 3;
extern int period2 = 5;

int start()
{
   double a;
   int b;
   int total;
   int ticket;
   int cnt;
   int iWPRperiod1;
   int iWPRperiod2;
   int iWPRperiod3;
   int iWPRperiod4;
   int slowing;
   int period;
   int period2;

   if(Bars<100)
   {
      Print("bars less than 100");
      return(0);
   }

   if( TakeProfit<10)
   {
      Print("TakeProfit less than 10");
      return(0);
   }

   total=OrdersTotal();
   if( total<1)
   {

      if(AccountFreeMargin()<(1000* Lots))
      {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);
      }

      if((iWPR(NULL,0, iWPRperiod1,0)>iWPR(NULL,0, iWPRperiod2,0)) < iStochastic(NULL,0, period2, period, slowing,0,0,0,0) )
      {
         ticket = OrderSend(Symbol(),OP_BUY, Lots,Ask,3,Ask- Stoploss*Point, Ask+ TakeProfit*Point,"comment",16384,0,Green);

         if( ticket>0)
         {
            if(OrderSelect( ticket, SELECT_BY_TICKET, MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
            else Print("Error opening BUY order : ",GetLastError());
            return(0);
         }
      }
      if((iWPR(NULL,0, iWPRperiod1,0)>iWPR(NULL,0, iWPRperiod2,0)) > iStochastic(NULL,0, period2, period, slowing,0,0,0,0) )
      {
         ticket = OrderSend(Symbol(),OP_SELL, Lots,Bid,3,Bid+ Stoploss*Point,Bid- TakeProfit*Point,"macd sample",16384,0,Red);
         if( ticket>0 && OrderSelect( ticket, SELECT_BY_TICKET, MODE_TRADES))Print("SELL order opened : ",OrderOpenPrice());
         else 
         {
            Print("Error opening SELL order : ",GetLastError());
            return(0);
         }
      }
      return(0);
   }  

   for( cnt=0; cnt < total; cnt++)
   {
      OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) 
      {
         if(OrderType()==OP_BUY)
         {
            if(iWPR(NULL,0, iWPRperiod1,0)>iWPR(NULL,0, iWPRperiod2,0))
            {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet);
               return(0); 
            }
            if( TrailingStop>0)
            {
               if(Bid-OrderOpenPrice()>Point* TrailingStop)
               {
                  if(OrderStopLoss()<Bid-Point* TrailingStop)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point* TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                  }
               }
            }
         }
         else
         {
            if(iWPR(NULL,0, iWPRperiod3,0)<iWPR(NULL,0, iWPRperiod4,0))
            {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
               return(0);
            }
            if( TrailingStop>0)
            {
               if((OrderOpenPrice()-Ask)>(Point* TrailingStop))
               {
                  if((OrderStopLoss()>(Ask+Point* TrailingStop)) || (OrderStopLoss()==0))
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point* TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                  }
               }
            }
         }
      }
   }
return(0);
}

The easiest syntax errors I've fixed, you're left with the "easy" ones - the logical ones. :)

 
if((iWPR(NULL,0, iWPRperiod1,0)>iWPR(NULL,0, iWPRperiod2,0)) < iStochastic(NULL,0, period2, period, slowing,0,0,0,0) )
if((iWPR(NULL,0, iWPRperiod1,0)>iWPR(NULL,0, iWPRperiod2,0)) > iStochastic(NULL,0, period2, period, slowing,0,0,0,0) )
It's an odd design.
 
StatBars >> :

how to copy it all to me ^^

when copied into a program, it's all one line.

 
FOREXMASTER писал(а) >>

how to copy it all to me ^^

copying it into a program makes it all one line.

Files:
 
StatBars >> :

>> thank you!)

 
TheXpert >> :

It's quicker to store in a variable than to call a function every time.

By the way, it's easy to check in the tester.

I understand the function, but what about the array?

I have to rewrite a lot to run it in the tester, too.

It's faster to store a variable than to call a function every time, and is it as fast to read an array element as a simple variable?

Or longer - is it an array where you need to look up the index, or the same as for a variable?

>> I don't quite understand these subtleties.

 
mukata >> :

The function is clear, but what about the array?

I don't really understand these things.

It's better to show by code example.


There are ambiguities with an array.


I believe that an EA should not contain arrays related to data interpretation. They belong in indicators.

Many people here think differently. And they try to cram everything into the Expert Advisor.