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

 
artmedia70:

Hour() and Minute() return the current hour and the current minute of the last server time at program start. And the returned values are of int type. And these are just integers. So you still need to format them. For example, like this:


Thank you !
 
abeiks:
Thank you!

You're welcome. If it's no secret, why do you need a timestamp showing the last time your program was started - the time in it won't change.

Just idle curiosity...

 

Good afternoon!

Please advise how to correctly implement the function of limiting 1 deal to 1 bar (i.e. if a deal has already been opened or closed on a candle, a new deal will not open on that candle)

I have found many variants, but cannot figure out how to correctly write the code of an owl (i.e. what part should be written in global variables, and what part should be written in the deal opening condition)

For example, here is such a variant:

int TekBar = -1; // Current bar.

if (TekBar == Bars)return(0); // Only one trade per bar.
TekBar = Bars; // There is only one trade on one bar.

{...}

which part of this script should be inserted in which area of the owl code?

 
DuKle:

Good afternoon!

Please advise how to correctly implement the function of limiting 1 deal to 1 bar (i.e. if a deal has already been opened or closed on a candle, a new deal will not open on that candle)

I have found many variants, but cannot figure out how to correctly write the code of an owl (i.e. what part should be written in global variables, and what part should be written in the deal opening condition)

For example, here is such a variant:

int TekBar = -1; // Current bar.

if (TekBar == Bars)return(0); // Only one trade per bar.
TekBar = Bars; // There is only one trade on one bar.

{...}

which part of this script should be inserted in which area of the owl code?

You need to find out if the last trade at bar number 0 was opened or closed.

To do this, you need to find the last open trade and the last closed trade.

View the bar of the last open trade and the bar of the last closed trade.

If any of these values (bar of last open trade or bar of last closed trade) is zero, you cannot open new positions.

And, yes: it's not a script, it's just a piece of code. And you don't need to insert anything into the owl: the owl is a nocturnal raptor, and let the bird live.

 

Hello! Please help!

I have an idea, but I don't know how to implement it. And most importantly, I don't know if this problem has a solution.

The essence of it is as follows: We have an indicator that draws some line on the chart on a given number of bars.

Is it possible to change the number of bars on which the line is drawn by dragging the left "end" of the line with the mouse? After dragging, the indicator should remember the new number of bars used for the calculation. Here is an example of an indicator I want to improve

//+------------------------------------------------------------------+
//|                                                      Canal__.mq4 |
//+------------------------------------------------------------------+
//----------------------------------
#property indicator_chart_window
//----------------------------------
extern int Hours=20;
extern color col=Red;
//------------------
double lr,lr0,lrp;
double sx,sy,sxy,sx2,aa,bb;
int p,fs;
ulong sName;
int f,f0,f1;
double dh,dl,dh_1,dl_1,dh_2,dl_2;
int ai_1,ai_2,bi_1,bi_2;
double hai,lai,dhi,dli,dhm,dlm,ha0,hap,la0,lap;
double price_p1,price_p0,price_p2,price_01,price_00,price_02;
int p1,p0,p2,fp;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   p=Hours*60/Period();
   if(fs==0)
     {
      sName=TimeCurrent(); 
      fs=1;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("1"+(string)sName);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i,n;
//----
   if(f==1)
     {
      p1=iBarShift(Symbol(),Period(),(datetime)ObjectGet("1"+(string)sName,OBJPROP_TIME1));
      if(fp==0 && p!=p1) {p=p1; fp=1;}
     }
//----
   sx=0; sy=0; sxy=0; sx2=0;
   for(n=0; n<=p; n++)
     {
      sx+=n; sy+=Close[n]; sxy+=n*Close[n]; sx2+=MathPow(n,2);
     }
   aa=(sx*sy-(p+1)*sxy)/(MathPow(sx,2)-(p+1)*sx2); bb=(sy-aa*sx)/(p+1);
//----
   for(i=0; i<=p; i++)
     {
      lr=bb+aa*i;
      dh=High[i]-lr; dl=Low[i]-lr;
      //----
      if(i<p/2)
        {
         if(i==0)
           {
            dh_1=0.0; dl_1=0.0; ai_1=i; bi_1=i;
           }
         if(dh>=dh_1) {dh_1=dh; ai_1=i;}
         if(dl<=dl_1) {dl_1=dl; bi_1=i;}
        }
      //----
      if(i>=p/2)
        {
         if(i==p/2)
           {
            dh_2=0.0; dl_2=0.0; ai_2=i; bi_2=i;
           }
         if(dh>=dh_2) {dh_2=dh; ai_2=i;}
         if(dl<=dl_2) {dl_2=dl; bi_2=i;}
        }
     }
   lr0=bb; lrp=bb+aa*(i+p);
//===================================================
   if(MathAbs(ai_1-ai_2)>MathAbs(bi_1-bi_2)) f=1;
   if(MathAbs(ai_1-ai_2)<MathAbs(bi_1-bi_2)) f=2;
   if(MathAbs(ai_1-ai_2)==MathAbs(bi_1-bi_2))
     {
      if(MathAbs(dh_1-dh_2)<MathAbs(dl_1-dl_2)) f=1; if(MathAbs(dh_1-dh_2)>=MathAbs(dl_1-dl_2)) f=2;
     }
//=================================================
   if(f==1)
     {
      for(n=0; n<=20; n++)
        {
         f1=0;
         for(i=0; i<=p; i++)
           {
            hai=High[ai_1]*(i-ai_2)/(ai_1-ai_2)+High[ai_2]*(i-ai_1)/(ai_2-ai_1);
            if(i==0 || i==p/2) dhm=0.0;
            if(High[i]-hai>dhm && i<p/2) {ai_1=i; f1=1;}
            if(High[i]-hai>dhm && i>=p/2) {ai_2=i; f1=1;}
           }
         if(f==0) break;
        }
      //----------------------------
      for(i=0; i<=p; i++)
        {
         hai=High[ai_1]*(i-ai_2)/(ai_1-ai_2)+High[ai_2]*(i-ai_1)/(ai_2-ai_1);
         dli=Low[i]-hai;
         if(i==0) dlm=0.0; if(dli<dlm) dlm=dli;
        }
      ha0=High[ai_1]*(0-ai_2)/(ai_1-ai_2)+High[ai_2]*(0-ai_1)/(ai_2-ai_1);
      hap=High[ai_1]*(p-ai_2)/(ai_1-ai_2)+High[ai_2]*(p-ai_1)/(ai_2-ai_1);
      //----------------------------
      price_p1=hap+dlm/2;
      price_01=ha0+dlm/2;
     }
//=================================================
   if(f==2)
     {
      for(n=0; n<=20; n++)
        {
         f1=0;
         for(i=0; i<=p; i++) 
           {
            lai=Low[bi_1]*(i-bi_2)/(bi_1-bi_2)+Low[bi_2]*(i-bi_1)/(bi_2-bi_1);
            if(i==0 || i==p/2) dlm=0.0;
            if(Low[i]-lai<dlm && i<p/2) {bi_1=i; f1=1;}
            if(Low[i]-lai<dlm && i>=p/2) {bi_2=i; f1=1;}
           }
         if(f==0) break;
        }
      //----------------------------
      for(i=0; i<=p; i++)
        {
         lai=Low[bi_1]*(i-bi_2)/(bi_1-bi_2)+Low[bi_2]*(i-bi_1)/(bi_2-bi_1);
         dhi=High[i]-lai;
         if(i==0) dhm=0.0; if(dhi>dhm) dhm=dhi;
        }
      la0=Low[bi_1]*(0-bi_2)/(bi_1-bi_2)+Low[bi_2]*(0-bi_1)/(bi_2-bi_1);
      lap=Low[bi_1]*(p-bi_2)/(bi_1-bi_2)+Low[bi_2]*(p-bi_1)/(bi_2-bi_1);
      //----------------------------------------------------------------
      price_p1=lap+dhm/2;
      price_01=la0+dhm/2;
     }
//=================================================================================== отрисовка линий
   ObjectCreate("1"+(string)sName,2,0,Time[p],price_p1,Time[0],price_01);
//-----------------------------------------------------------------
   ObjectSet("1"+(string)sName,OBJPROP_COLOR,col);
   ObjectSet("1"+(string)sName,OBJPROP_STYLE,STYLE_DASHDOT);
   ObjectSet("1"+(string)sName,OBJPROP_RAY,false);
//---------------------------------------------
   ObjectSet("1"+(string)sName,OBJPROP_TIME1,Time[p]);
   ObjectSet("1"+(string)sName,OBJPROP_PRICE1,price_p1);
   ObjectSet("1"+(string)sName,OBJPROP_TIME2,Time[0]);
   ObjectSet("1"+(string)sName,OBJPROP_PRICE2,price_01);
   f=1; p1=p; p0=p; p2=p; fp=0;
//===================================================================================
   return(0);
  }
//+------------------------------------------------------------------+
 
Night63:

Hello! Please help!

I have an idea, but I don't know how to implement it. And most importantly, I don't know if this problem has a solution.

The essence of it is as follows: We have an indicator that draws some line on the chart on a given number of bars.

Is it possible to change the number of bars on which the line is drawn by dragging the left "end" of the line with the mouse? After dragging, the indicator should remember the new number of bars used for the calculation. Here is an example of an indicator I want to improve

You need to add OnChartEvent() to the indicator and track the event of line size change by its name: CHARTEVENT_OBJECT_CHANGE. Recalculate the new line length in bars, and use its new size as a parameter for the calculation.
 
artmedia70:

You need to find out whether the last trade was opened or closed on bar number 0.

To do this, you need to find the last open trade and the last closed trade.

View the open bar of the last open trade and the close bar of the last closed trade.

If either of these values (the bar of the last open trade or the bar of the last closed trade) is zero, you cannot open new positions.

And, yes: you don't have a script, it's just a part of the code of nepomyshchego. And you don't need to insert anything into the owl: the owl is a nocturnal raptor, and let the bird live.

I understand the principle of detecting the presence of a deal. I don't know how to implement it in the code :-(
 
DuKle:
I understand the principle of determining whether a transaction exists, I do not know how to implement it in code :-(

How sad it all is...

Shall I do it for you?

For a start, and to understand further, read the"Useful functions from KimIV" thread.

The code, of course, is redundant, but it's just right for getting started and learning.

 

Dear mql4/5 programmers !

I am a beginner who learned the basics of the programming language and developed an EA for my diploma!

I have a chapter in my diploma called "Economics".

If I was to develop a program for a company - everything is clear with the economic part.

But how to be in my case? What can I take into account and which paths to follow!

Thank you very much!!!!

___________________________

The road is travelled by those who walk (c)

 
artmedia70:
You need to add to the indicator OnChartEvent() and monitor the event of line size change by its name: CHARTEVENT_OBJECT_CHANGE. Recalculate the new line length in bars, and use its new size as a parameter for the calculation.

Thank you! It all worked out! =))

Only I usedCHARTEVENT_OBJECT_DRAG. It worked better for me.

Reason: