Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 197

 
Aleksandr Verkhozin:


I've watched the video on working with external indicator, wrote a little code to see the values of buffers in the tester:

void OnTick()

{

double Buf1=iCustom(NULL,0, "Shved-Supply-and-Demand-e600",0,1);

double Buf2=iCustom(NULL,0, "Shved-Supply-and-Demand-e600",1,1);

double Buf3=iCustom(NULL,0, "Shved-Supply-and-Demand-e600",2,1);

double Buf4=iCustom(NULL,0, "Shved-Supply-and-Demand-e600",3,1);

Comment("Buf1=",Buf1,"\n", "Buf2=",Buf2,"\n","Buf3=",Buf3,"\n","Buf4=",Buf4);

}

The zones appear and disappear in visualization mode. But the value of the buffers is always zero anyway. Is there no way to formalize these zones in the code?

Maybe there is a function, other than iCustom, that would be suitable for such indicators? Maybe, someone has written owls with such indicators?


No way to use indicator buffers, they store fractal values.

In the indicator properties fractals_show = true; you will see them on the chart

Zones, graphical object OBJ_RECTANGLE

You can get the value of those zones using


ObjectGet

Returns the value of a specified object property.

doubleObjectGet(
stringobject_name,// object name
intindex// property identifier
);


You loop through all the objects, find the right one, and find the path.

 int obj_total=ObjectsTotal(); 
  string name; 
  for(int i=0;i<obj_total;i++) 
    { 
     name = ObjectName(i);
     Print(i," - объект ",name); 
    }

Approximately, it looks like this

 
Artyom Trishkin:
You know, right in this thread I posted a template for a trawl that uses the indicator value sent to it in its calculations. Look it up, don't be lazy.

I need a correct trailing stop on open positions. In the end there are 1 or 3 of them and they are linked by Step value, i.e. stop/reverse system. Hence the complexity. Or maybe it is easier to trail on all orders using CalculateProfit() function. Now I cannot figure out how the indicator value in this order handling scheme can be related to trailing the total profit of the open positions.
 
geratdc:

I need exactly the correct trailing stop on the profit of open positions. In the end there are 1 or 3 of them and they are bound by the Step value, i.e. it is a stop and reverse system. Hence the complexity. Or maybe it is easier to trail on all orders using CalculateProfit() function. Now I cannot figure out how the indicator value in this order handling scheme can be related to trailing the total profit of the open positions.

The indicator, its value, can be a value other than, for example, the MAK on the desired bar. The value of the price calculated for moving the total stop of positions can be sent to the trawl.

However, it is not clear what kind of trawl you have on open positions - what and when exactly it trawls.

 
geratdc: I'm looking for the correct trawling for profit

All trails are here. From file TrailingFuncLib.mq4 I take the function TrailingStairs - STANDARD-STANDARD Trailing. Each order is trailed independently.

 
Artyom Trishkin:

The indicator, its value, can be a value other than, for example, the MAK on the desired bar. The value of the price calculated for moving the total stop of positions can be sent to the trawl.

However, it is not clear what kind of trawl you have on open positions - what and when exactly it trawls.


In principle, yes, I was once offered a trawl by average price. Everything seems logical, but what does it mean - average price? Is it (price of 1 order + Step*Point + (price of 2 orders + Step*Point) + price of 3 orders) / 3? So it is a lot of parameters - you have to call up the open positions and the current price of each position. Anyway, this trailing stop bothers me less than the fact that the EA loses value during tests. What will happen in real trading? It can be set, but then again we do not know which turn the currency chart will take in a week or a month, so there is one weakness - if 3 orders are opened and there is a counter-movement in the market, the Expert Advisor will fail due to drawdown. So, we should think about limiting the drawdown and closing positions before the deposit is zeroed out. To make a long story short, it is Fox that interests me the most)))
 

I can't figure it out myself and I haven't found any specific information either(( The idea is to mark price borders in the code, the nearest zones built by the indicator. I started to write code, but I'm confused and don't know if I'm doing it right or not. I do not know if I'm doing it right or wrong.

 int obj_total=ObjectsTotal();       

  string name; 

  for(int i=0;i<obj_total;i++)

  {

  name = ObjectName(i); 

  if(ObjectType(name)==OBJ_RECTANGLE)

  {

    pr1=ObjectGet(name,OBJPROP_PRICE1);// верхняя цена зоны

    pr2=ObjectGet(name,OBJPROP_PRICE2);// нижняя цена зоны

  }  

  }  

And why my code is not inserted here, as in the original, to multicoloured and lines next to each other?
 
-Aleks-:

Figured it out - apparently the terminal didn't have enough memory - closed a couple of charts and it worked.

Thank you - indeed, the calculations take place.

And if variables are not int type, but bool , what to do?


//+------------------------------------------------------------------+
//|                                                       Decode.mq4 |
//|                                            Copyright 2017, Vinin |
//|                                             http://vinin.ucoz.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Vinin"
#property link      "http://vinin.ucoz.ru"
#property version   "1.00"
#property strict
#property script_show_inputs
//--- input parameters
input int N=162;  //0..162
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   for (int n=0;n<N;n++)
   {
      int tmp=n;
      int a=(int) MathMod(tmp,3);
      tmp=(tmp-a)/3;
      int b=(int) MathMod(tmp,3);
      tmp=(tmp-b)/3;
      bool c= (bool) MathMod(tmp,2);
      tmp=(tmp-c)/2;
      int d=tmp;
   
      Print("N=",n,"; A=", 2+2*a, "; B=", b+1,"; C=",c,"; D=", 16+4*d);
   }
  }
//+------------------------------------------------------------------+
 
Victor Nikolaev:

I'm sorry, but is this code different from the last one?
 
-Aleks-:

I'm sorry, but is this code different from the last one?


The differences are minimal. One of the variables is logical.

The output will say true or false

 
Victor Nikolaev:


The differences are minimal. One of the variables is logical.

The output will say true or false

Are you sure you looked at the last code you posted? If so, I need a rest... thank you.
Reason: