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

 

pro! there is a problem with the line on the angle.

I built aTRENDBYANGLE using coordinates.

ObjectCreate(0,"anglestok",OBJ_TRENDBYANGLE,0,0,0);
ObjectSet("anglestok",OBJPROP_TIME1,X1); ObjectSet("anglestok",OBJPROP_PRICE1,Y1);
ObjectSet("anglestok",OBJPROP_TIME2,X2); ObjectSet("anglestok",OBJPROP_PRICE2,Y2);

- I need an angle.

anglestok= ObjectGetDouble(0,"anglestok",OBJPROP_ANGLE);

help says that the line created by the program - the angle of ZERO is ok.

I ran the same code again at the same coordinates without touching the line - it appears the correct number of degrees, not zero. why, how can I do it right the first time?

or i gave one coordinate - i ask for angle - it says 0. then i give another one - it says angle of the previous coordinates. nonsense

 
For which cases do they put const after the description of the function signature? I can't find any information about this.
void qwe(int abc) const {...}
 
Can't seem to find any real knowledgeable people here, just signed up for nothing =/
 
K_i_r_i_t_o:
I moved this comment to the beginning because no one has answered, but I really need it =/
Is it possible to implement this:if I press any key, one part of the indicator code is turned on (responsible for creating an object with a mouse click), then if an event occurs (the second part of the code, the event may be, creating the same object for example), then the first part of the code is disabled (and if not do this, the object is created by each click), and also runs when you press the key, and so on around the circle)
You can. Add OnChartEvent block. In it, keep track of the necessary presses, measurements and describe the reaction to them according to your idea.
 
SunnYtheDreamer:
You can. Add OnChartEvent block. In it, keep track of the necessary presses, measurements and describe the reaction to them, according to your idea.
To implement disabling of part of code for time period before pressing the key is impossible =/ There is an easier variant, but there is one problem,when pressing the key imustreturn its value to the beginning of the first if statement
#define  VK_D 0x44
void OnChartEvent(const int id,         // идентификатор события   
                  const long& lparam,   // параметр события типа long 
                  const double& dparam, // параметр события типа double 
                  const string& sparam) // параметр события типа string 
{ 
 Comment(__FUNCTION__,": id=",id," lparam=",lparam," dparam=",dparam," sparam=",sparam);

int      y     =(int)dparam;
datetime dt    =0;
double   price =0;  
int      window=0;
int i;
int x=(int)lparam;

if (id==CHARTEVENT_CLICK)
{
ChartXYToTimePrice(0,x,y,window,dt,price);
ObjectCreate("Trend Line"+i,OBJ_TREND,0,dt,price,dt,price);
ObjectSetInteger(0,"Trend Line"+i,OBJPROP_SELECTED,true);

if(id==CHARTEVENT_KEYDOWN) 
{ switch(int(lparam)) 
{ case VK_D:
i=rand();
}}}}
 
K_i_r_i_t_o:
I can't implement disabling part of the code for the period before the keystroke =/ There is an easier way, but there is one problem:i needs toreturn its value to the beginning of the first if statement when the key is pressed.
if (id==CHARTEVENT_CLICK)
{
   ChartXYToTimePrice(0,x,y,window,dt,price);
   ObjectCreate("Trend Line"+i,OBJ_TREND,0,dt,price,dt,price);
   ObjectSetInteger(0,"Trend Line"+i,OBJPROP_SELECTED,true);

   if(id==CHARTEVENT_KEYDOWN) 
   {
      switch(int(lparam)) 
      {
         case VK_D: i=rand();
      }
   }
}
This code will be executed only if the mouse is clicked. In this case, after 3 lines of code, the event of pressing the key is checked. And these 3 lines of code are executed in a few milliseconds, and even if the id during the current call OnChartEvent is able to change, the chance that during the execution of 3 lines of code, the key will be pressed = 0%. Obviously, it's pointless to check id, inside a block that is triggered at a certain id value, and wait there for a different value. First, check the key press, in a separate block, save in a variable the number of the key or just the fact of pressing the desired key. And with this variable, enable or disable the piece of code located in the block for mouse click.
char key = -1; //эта переменная должна быть объявлена за пределами блока OnCharEvent
if(id==CHARTEVENT_KEYDOWN)
key = lparam;

if (id==CHARTEVENT_CLICK && key == 'D')
{
   ChartXYToTimePrice(0,x,y,window,dt,price);
   ObjectCreate("Trend Line"+i,OBJ_TREND,0,dt,price,dt,price);
   ObjectSetInteger(0,"Trend Line"+i,OBJPROP_SELECTED,true);
   i=rand();
   key = -1;
}
 
SunnYtheDreamer:
This code will only execute if the mouse is clicked, with 3 lines of code checking for a keystroke event. And these 3 lines of code are executed in a few milliseconds, and even if id during the current call OnChartEvent is able to change, the chance that during the time, execution of 3 lines of code, the key will be pressed = 0%. Obviously, it's pointless to check id, inside a block that is triggered at a certain id value, and wait there for a different value. First, check the key press, in a separate block, save in a variable the number of the key or just the fact of pressing the desired key. And with this variable, enable or disable the piece of code located in the block for mouse click.

Thank you very much!) This is the line I was looking for if (id==CHARTEVENT_CLICK && key == 'D'), could not connect two events, this did not work if (id==CHARTEVENT_CLICK & id==CHARTEVENT_KEYDOWN) Thanks a lot again)

 

Hello, I have a function that calculates the average size of a candle from the last n candles. sometimes it outputs the following values: "5e-05.0". i don't need them, to my shame i don't know how much they are and how to cut them off. NormalizeDouble() does not help. please tell me how to calculate such numbers programmatically to cut them off

 
pycha:

Hello, I have a function that calculates the average size of a candle from the last n candles. sometimes it outputs the following values: "5e-05.0". i don't need them, to my shame i don't know quantitatively how many and how to cut them off. NormalizeDouble() does not help. please tell me how to calculate such numbers programmatically to cut them off


5e-05 (5*10 to -5th power) = 0.00005.
What to cut off, then:
if(val >= 0.00001)
Such small candles, 5 pips, only at low latitude, in a 5-digit account, on low timeframes may occur. If you do not deal with scalping, but the average is sometimes so small for n candles, then the implementation of the function should be suspicious.
 
Yes, the program works relatively close to scalping, I understand the general premise. I will try to check that it is not less than 0.0001 - I do not care about such differences and if I understand correctly, they will cut off unnecessary values
Reason: