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

 
Ekburg:

then i'm no help) need to go through the entire advisor.

I've changed everything to double, it's working fine now, I need to test the rest of the points =) If I make the EA make a good profit, I can post it if necessary =)

I would have forgotten what the problem was because I don't understand why it didn't work properly and I'm glad I didn't!)

 
SpikeOne:

I've changed everything to double, it's working fine now, I need to test the rest of the points =) If I make the EA make a good profit, I can post it if necessary =)

I would have liked to forget it otherwise, I don't know why it didn't work out as I should have done =) I'm glad I didn't forget it.)


You can, why not)

You're welcome).

The road will walk, I, too, at first had such moments, headache, but when you solve the problem, there is a kind of satisfaction, and that feeling is priceless))

 
The time after signal 1 must be recorded and not changed until signal 2 arrives, with signal 1 repeatedly occurring while waiting for signal 2, but the time must remain unchanged since signal 1 was first received.
 
Forexman77:
The time after signal 1 must be recorded and not changed until signal 2 arrives, with signal 1 repeatedly occurring while waiting for signal 2, but the time must remain unchanged since signal 1 was first received.

int sm;
datetime data;
if(sm==0) if(сигнал1==true) data=TimeLocal(); sm=1;
if(sm==1) if(сигнал2==true) data=TimeLocal();
 
extern bool test=false;  // откл объектов при тесте
extern int prof=4;     // уровень профита
extern int chag=3;     // шаг между ордерами
extern int risk=0;         //уровень риска
extern double lot = 0.01; // начальный лот
extern double k_lot=2; // увеличение объема
extern double lot_max=100; // максимальный лот
//=====================================================//
int kn=20;  // величина вертикальной шкалы
int magic = 37649; 
extern double  BeginHour =3;
bool result;
bool fail=false; 
double gg=0;
int k,c,b_ind,s_ind,objtot,er;
double buy_prs,sel_prs,buy_ind,sel_ind,or_bu,or_sl,prf_b,prf_s,b_pr,s_pr,b2_cls,s2_cls;
string nh;
//нннннннннннннннннннннннннннн//
int init()
  {
//----
 
if(Digits==2) k=1;
if(Digits==3) k=10;
if(Digits==4) k=1;
if(Digits==5) k=10;
nh=StringSubstr(Symbol(),2,2);
 
 if(!IsTesting()){
    buy_prs=GlobalVariableGet(nh+"_buy_prs"); buy_ind=GlobalVariableGet(nh+"_buy_ind");
    sel_prs=GlobalVariableGet(nh+"_sel_prs"); sel_ind=GlobalVariableGet(nh+"_sel_ind");}
 
c=0;
chag=chag*k;
prof=prof*k;
//нннннннннннннннннннннннннннн//
   return(0);
  }
//============================================//
int start()
  {
//----
int i,y,tick_s,tick_b,tick_slm,tick_blm;
double prov,price_b,price_s,prof_b,prof_s,lot_b,lot_s,b_cls,s_cls,abc;
bool mod_b=false,mod_s=false;
 
//=================//
   if(Bars-c>1) c=0;
   i=Bars-c; c=Bars;
//==================================//   
 if(!IsTesting()){for(y=0;y<OrdersTotal();y++)
   {OrderSelect(y,0,0); if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=magic||(OrderType()!=0&&OrderType()!=1)) continue;
      prov=prov+OrderProfit()+OrderSwap()+OrderCommission();}
   if(prov<0&&prov<GlobalVariableGet(nh+"_max_prov"))GlobalVariableSet(nh+"_max_prov",prov);}
 
//=================================================//
    for (y=0;y<OrdersTotal();y++){OrderSelect(y,0);
      if(Symbol()!=OrderSymbol()||OrderMagicNumber()!=magic) continue; 
      if (OrderType() == 0 || OrderType() == 1) abc=abc + OrderProfit() + OrderSwap() + OrderCommission();
     
      if(OrderType()==0){if(prf_b!=OrderTakeProfit() && prf_b!=0) mod_b=true; prf_b=OrderTakeProfit();}
      if(OrderType()==OP_BUY && tick_b<OrderTicket()) {
       tick_b=OrderTicket();
       price_b=OrderOpenPrice();
       lot_b=OrderLots();
       prof_b=OrderTakeProfit();}
 
      if(OrderType()==1){if(prf_s!=OrderTakeProfit() && prf_s!=0) mod_s=true; prf_s=OrderTakeProfit();}      
      if(OrderType()==OP_SELL && tick_s<OrderTicket()) {
       tick_s=OrderTicket();
       price_s=OrderOpenPrice();
       lot_s=OrderLots();
       prof_s=OrderTakeProfit();} 
 
      if (OrderType()==OP_BUYLIMIT)  tick_blm = OrderTicket();
      if (OrderType()==OP_SELLLIMIT) tick_slm = OrderTicket();}
//=====================================================//
   if(Ask>buy_prs && or_bu<=0) {buy_prs=Ask; buy_ind=Ask;}
   if((Ask<buy_prs && Ask<buy_ind) || buy_ind==0) buy_ind=Ask;
   b_cls=buy_ind+MathFloor(prof+chag/2)*Point;
   or_bu=MathFloor((buy_prs-buy_ind)/Point/chag); 
   if(Bid>=b_cls && or_bu>0){buy_prs=Ask; buy_ind=Ask; or_bu=0;}
   if(tick_b==0 && b_ind>0){buy_prs=Ask; buy_ind=Ask; or_bu=0;}
 
   if((Bid<sel_prs||sel_prs==0) && or_sl<=0) {sel_prs=Bid; sel_ind=Bid;}
   if(Bid>sel_prs && Bid>sel_ind) sel_ind=Bid;
   s_cls=sel_ind-MathFloor(prof+chag/2)*Point;
   or_sl=MathFloor((sel_ind-sel_prs)/Point/chag);
   if(Ask<=s_cls && or_sl>0){sel_prs=Bid; sel_ind=Bid; or_sl=0;}
   if(tick_s==0 && s_ind>0) {sel_prs=Bid; sel_ind=Bid; or_sl=0;}
 
 if(!IsTesting()){
   GlobalVariableSet(nh+"_buy_prs",buy_prs); GlobalVariableSet(nh+"_buy_ind",buy_ind);
   GlobalVariableSet(nh+"_sel_prs",sel_prs); GlobalVariableSet(nh+"_sel_ind",sel_ind);} 
//===============================
   if(tick_b==0 && tick_blm!=0) OrderDelete(tick_blm);
   if(tick_s==0 && tick_slm!=0) OrderDelete(tick_slm);
   if (AccountBalance()>gg)
   {
    gg= AccountBalance();
   }
   if(Hour() >= BeginHour )
{
if ( AccountEquity()>=gg)
   {
 //if(AccountEquity()>=740)
  // {
 
   for(int zx=OrdersTotal(); zx+1>=0; zx--)
      {
      if(OrderSelect(zx,SELECT_BY_POS,MODE_TRADES)==true)
      OrderDelete(OrderTicket());
      }
   while (OrdersTotal()>0)
      {
      if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
         {
         if(OrderType()==OP_BUY) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS)),3,CLR_NONE);
         if(OrderType()==OP_SELL) result=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),3,CLR_NONE);
         if (OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
         OrderDelete(OrderTicket());
         if(result!=TRUE)
            {
            er=GetLastError();
            Print("LastError = ",er, " ",Symbol());
            }
         else er=0;
         }
      else Print( "Error when order select ", GetLastError());
      }
   if(OrdersTotal()==0) fail=true;
   }
}
if(fail==true) return(0);
 
   if(or_bu==risk && tick_b==0) open(0);
   if(or_sl==risk && tick_s==0) open(1);

Here is the code in general, it is inserted at the beginning and the whole part up to the place I have given below, here is the Expert Advisor itself in which you should insert the beginning https://www.mql5.com/ru/code

You start the night at about 00:00 and it trades till a certain time, after that it closes the trades and the EA.

if(or_bu==risk && tick_b==0) open(0);
if(or_sl==risk && tick_s==0) open(1);
 
Ekburg:


It needs to be a little more complicated. A variable depends on signal 1, so as long as there is no signal 2, the data used by signal 1 will be updated, changing the variable, but I need the variable to change once. Subsequent changes to the variable only after signal 2. In short, switch 1 is triggered, triggers one and nothing else changes until switch 2 is triggered. But, as switch 1 uses certain data to switch on, it will process it again, and you only need to do it once.

 
SpikeOne:

Here is the code in general, it is inserted at the beginning and the whole part up to the place I have given below, here is the Expert Advisor itself in which you should insert the beginning https://www.mql5.com/ru/code

You start the night at about 00:00 and it trades till a certain time, after that it closes the trades and the EA.


So?! Does it work?)
 
Forexman77:

It needs to be a little more complicated. A variable depends on signal 1, so as long as there is no signal 2, the data used by signal 1 will be updated, changing the variable, but I need the variable to change once. Subsequent changes to the variable only after signal 2. In short, switch 1 is triggered, triggers one and nothing else changes until switch 2 is triggered. But, as switch 1 uses certain data to switch on, it will process it again, and you only need to do it once.


I've given you the basics, go ahead and do it yourself! Why are you so lazy... as you described it, so I wrote it, without even saying thank you;)
 
Ekburg:

I gave you the basics, go ahead and do it yourself! Why are you so lazy... I wrote as you described it, and you didn't even say thank you;)
Thanks! To be honest I know the basics myself)
 
Ekburg:

So what?! Does it work?:)


well, yeah. You can check it yourself=) set the amount above 700 dollars and test it=) 5 minute interval

You could also modify it and make it start every night by itself =)

Reason: