Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 221

 
artmedia70:
Just on that page, the link to which you posted in your post. Read it there more carefully.

Yes, I was stupid. I just need to start(); start additionally via init(){}...

int init(){start();}

...

void start(){...}

Thanks, I figured it out.

 
Yikes... I'm so stupid)))) Don't you get it, don't touch init(), deinit() and start() functions in the vain. Only in the way the great metaquotes tell you to))))
 
How do I redeem my bonuses for money?
 
Alexs65:
How do I redeem my bonuses for money?

Whose bonuses?
 

I have the following code:

extern datetime start = D'2013.10.17 23:59';

int start()

{

int b1=iBarShift(Symbol(),0,start,0);

double hb=iHigh(Symbol(),0,b1); //bar

double hb2=iHigh(Symbol(),0,b1-1); //bar of tomorrow from specified date

Could you please tell me how to put yesterday's day from specified date, because double hb3=iHigh(Symbol(),0,b1+1); doesn't work...

 

Hi all!!! I have an EA opening orders against the movement, how to change or advise where to change???

string GLOB_START;

int init()
{
GLOB_START = "@" + DoubleToStr(ID,0) + "@" + "_start";
if !GlobalVariableCheck( GLOB_START )GlobalVariableSet(GLOB_START,TimeCurrent());
return(0);
}

int deinit()
{
switch( UninitializeReason() )
{
case REASON_REMOVE: delete_glob ("@" + DoubleToStr(ID,0) + "@" );
}
if ( IsTesting() )delete_glob ("@" + DoubleToStr(ID,0) + "@" );
return(0);
}

void delete_glob ( string c )
{
int i;
for ( i = GlobalVariablesTotal()-1; i>= 0 ; i-- )if ( StringFind(GlobalVariableName(i),c) >= 0 )GlobalVariableDel(GlobalVariableName(i))
}

int start()
{
Comment(Info());
int KOL_BUY = order_total(0);
int KOL_SELL = order_total(1);
double l;

if ( order_total() == 0 )
{
open(0,Lot,0,TP);
open(1,Lot,0,TP);
}

if ( KOL_BUY == 0 && KOL_SELL != 0 )
{
open(0,Lot,0,TP);
l = last_trade(1);
open(1,l,0,0);
modify_orders(1);
}

if ( KOL_BUY != 0 && KOL_SELL == 0 )
{
open(1,Lot,0,TP);
l = last_trade(0);
open(0,l,0,0);
modify_orders(0);
}

return(0);
}

string Info()
{
int i;
double buff_1 = 0, buff_2 = 0, buff_3 = 0;
string res = "\n";

for( i = OrdersHistoryTotal() - 1; i >= 0; i-- )
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if( OrderMagicNumber() == ID )
{
if ( OrderOpenTime() >= iTime(NULL,PERIOD_D1,0) )buff_1 += OrderProfit();
if ( OrderOpenTime() >= iTime(NULL,PERIOD_D1,1) && OrderOpenTime() < iTime(NULL,PERIOD_D1,0) )buff_2 += OrderProfit();
if ( OrderOpenTime() >= GlobalVariableGet(GLOB_START) )buff_3 += OrderProfit();
}
}

res = res + "Profit in the deposit currency for " + TimeToStr(iTime(NULL,PERIOD_D1,0)) + ": " + DoubleToStr(buff_1,0) + "\n" + "\n";
res = res + "Profit in deposit currency for " + TimeToStr(iTime(NULL,PERIOD_D1,1)) + ": " + DoubleToStr(buff_2,0) + "\n" + "\n";
res = res + "Profit in the deposit currency total:" + DoubleToStr(buff_3,0) + "\n";
return(res);
}

void modify_orders( int type )
{
int i;
datetime time_last = 0, time_first = TimeCurrent();
double SPREAD = MarketInfo(Symbol(),MODE_SPREAD)*MarketInfo(Symbol(),MODE_POINT), op_pr_last, op_pr_first, level;

for( i = OrdersTotal() - 1; i >= 0; i-- )
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if( OrderMagicNumber() == ID && OrderType() == type )
{
if ( OrderOpenTime() > time_last )
{
op_pr_last = OrderOpenPrice();
time_last = OrderOpenTime();
}
if ( OrderOpenTime() < time_first )
{
op_pr_first = OrderOpenPrice();
time_first = OrderOpenTime();
}
}
}


if ( type == 0 )level = op_pr_last + MathAbs(op_pr_last-op_pr_first) * (SL/100);
if ( type == 1 )level = op_pr_last - MathAbs(op_pr_last-op_pr_first) * (SL/100);

for( i = OrdersTotal() - 1; i >= 0; i -- )
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if( OrderMagicNumber() == ID && OrderType() == type && NormalizeDouble(OrderTakeProfit(),Digits) != NormalizeDouble(level,Digits) )OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),level,0)
}
}

double last_trade( int t )
{
int i;
double res = -1;
datetime time=0;

for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderOpenTime()>time && OrderMagicNumber()==ID && OrderType() == t)
{
res = OrderLots();
time = OrderOpenTime();
}
}
if ( multiplier )return(res * Lot_koeff);
if ( !multiplier )return(res + Lot_koeff);
}
int open(int type, double l, double sl=0, double tp=0, string comm = "")
{
int isOpened = 0, try = 0;
double s,t;
while ( IsTradeContextBusy() ){Sleep(500);}
RefreshRates();
if ( sl != 0 && sl < MarketInfo(Symbol(),MODE_STOPLEVEL) )sl = MarketInfo(Symbol(),MODE_STOPLEVEL);
if ( tp != 0 && tp < MarketInfo(Symbol(),MODE_STOPLEVEL) )tp = MarketInfo(Symbol(),MODE_STOPLEVEL);
if ( type == 0 )
{
if ( tp == 0 )t = 0;
if ( tp != 0 )t = Ask + tp * Point;
if ( sl == 0 )s = 0;
if ( sl != 0 )s = Bid - sl * Point;
}
if ( type == 1 )
{
if ( tp == 0 )t = 0;
if ( tp != 0 )t = Bid - tp * Point;
if ( sl == 0 )s = 0;
if ( sl != 0 )s = Ask + sl * Point;
}
s = NormalizeDouble(s,Digits);
t = NormalizeDouble(t,Digits);
if(type==0)isOpened = OrderSend(Symbol(),type,check_lot(l),NormalizeDouble(Ask,Digits),10,s,t,comm,ID);
if(type==1)isOpened = OrderSend(Symbol(),type,check_lot(l),NormalizeDouble(Bid,Digits),10,s,t,comm,ID);
Sleep(500);
while(isOpened<0)
{
while ( IsTradeContextBusy() ){Sleep(500);}
RefreshRates();
if ( type == 0 )
{
if ( tp == 0 )t = 0;
if ( tp != 0 )t = Bid + tp * Point;
if ( sl == 0 )s = 0;
if ( sl != 0 )s = Bid - sl * Point;
}
if ( type == 1 )
{
if ( tp == 0 )t = 0;
if ( tp != 0 )t = Ask - tp * Point;
if ( sl == 0 )s = 0;
if ( sl != 0 )s = Ask + sl * Point;
}
s = NormalizeDouble(s,Digits);
t = NormalizeDouble(t,Digits);
try++;
if(type==0)isOpened = OrderSend(Symbol(),type,check_lot(l),NormalizeDouble(Ask,Digits),10,s,t,comm,ID);
if(type==1)isOpened = OrderSend(Symbol(),type,check_lot(l),NormalizeDouble(Bid,Digits),10,s,t,comm,ID);
if(try > 5) break;
if(isOpened>=0)break;
Sleep(500);
}
if(isOpened<0) Alert("Order not opened, error :", GetLastError());
return(isOpened);
}

int order_total( int type_1 = -1, int type_2 = -1 )
{
int i;
int kol=0;
for(i=OrdersTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==ID && (OrderType() == type_1 || OrderType() == type_2) )kol++;
if(OrderMagicNumber()==ID && type_1 == -1 && type_2 == -1 )kol++;
}
return(kol);
}

double check_lot(double &lo)
{
double l = MarketInfo(Symbol(),MODE_LOTSTEP);
int ok = 0;
while ( l < 1 ){l*=10;ok++;}
if( lo < MarketInfo(Symbol(),MODE_MINLOT) )lo = MarketInfo(Symbol(),MODE_MINLOT);
if( lo > MarketInfo(Symbol(),MODE_MAXLOT) )lo = MarketInfo(Symbol(),MODE_MAXLOT);
return(NormalizeDouble(lo,ok));

 
Good day to all. Gentlemen, I have a question, please enlighten me, if I work with Alpari and Master_Forex I test an Expert Advisor on the stories I download from my work terminal, nothing from outside, no left stories, like from Dukas, no auxiliary programs like Tick Data Suite, just 90% modelling from the terminal of my DS specifically Alpari or Master_Forex, method ........ I test half year on different conditions and parameters, choose the best, then back test and the next half year, so 2-5 years then everything in the pile and the owl is ready. Can this be a reliable prepper or does it still need 99% and everything attached to it.
Thank you!!! ........
 

How do I make a trawl for "Funds:" (AccountEquity())?

Parameters

extern double TrailingStart = 10000; // Trailing level
extern double TrailingStop = 100; // Trailing size
extern double TrailingStep = 10; // Trailing step

 

How do I find two top/bottom fractals in a row? The picture below.

I tried to write an indicator, but I didn't think it through.

//+------------------------------------------------------------------+
//|                                           Dvigubas fraktalas.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_color1 Red
#property indicator_width1 2
#property indicator_buffers 1

double FRACTAL[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,119);
   SetIndexBuffer(0,FRACTAL);
   SetIndexLabel(0,"Fractal");
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int limit;
   
   
   
//---- последний посчитанный бар будет пересчитан
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;
//---- основной цикл
   for(int i = limit; i > 0; i--)
     {           
         int f1 = GetFractal("", 0, 0);
         int f2 = GetFractal("", 0, 1);
         
        if( f1 == 1 && f2 == 1) FRACTAL[i] = High[i]+100*Point;
        else 
         if( f1 == 0 && f2 == 0) FRACTAL[i] = Low[i]- 100*Point;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
        |
//+----------------------------------------------------------------------------+
int GetFractal(string sy="0", int tf=0, int nf=0) 
{
  if (sy=="" || sy=="0") sy=Symbol();
  int f=-1;
  int    i, k=iBars(sy, tf), kf;
  for (i=3; i<k; i++) 
  {
    if(iFractals(sy, tf, MODE_UPPER, i)>0)f=1;
    else
      if(iFractals(sy, tf, MODE_LOWER, i)>0)f=0;
    kf++;
    if (kf>nf) return(f);    
  }
  
}

Maybe someone has seen such an indicator ready?

 
Syntax is mastered, but logic is a bit hard to come by.