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

 
Eugen8519:

I have made this feature, thank you for your support and for your help.


You're welcome)
 
Mihail Matkovskij:

It depends on how you are going to calculate stop and take based on statistics... It is not very clear what the "statistics by candlestick" is, how you calculate it.

The answer is like the whistle of a cancer and the strange thing is that it always answers my question.

 
darirunu1:

The answer is like the whistling of a crayfish, and oddly enough, it's always the answer to my question.

How can you answer a question where you don't know what it is...? :)

In order to understand how to calculate the stop and take, in your case, you need to know how you calculate the statistics by candlestick? Because "candlestick stats" is a very broad term...

Also, what kind of stop and take ratio do you want...? There's a whole trading system to come up with for you here, as you don't even know the task at hand...
 
Mihail Matkovskij:

How can you answer a question where it's not clear what it's about...? :)

In order to understand how to calculate stop and take, in your case, you need to know how you calculate candlestick stats? Since "candlestick stats" is a very flexible term...

Also, what stop and take ratio do you want...? There's a whole trading system to come up with for you here, as you don't even know the task at hand...

int cnt,ticket,total=0;

st = "general hours Mon-Fri Wed-Wed Thu-Fri \n";

double cHeight, gHeight, max;

int sat, sun, mon, thu, wen, ths, fri; //, NN;

int H = TimeHour(TimeCurrent()); // determine the current hour

double NN = H + N*24; // define offset

if (NN>Bars) NN=Bars;

for (int t=0; t<24; t++)

{

int HeightZ = 0; int z=0;

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

{

HeightZ = MathAbs(High[i]-Low[i])/Point ;

z++;

}

What options do you suggest?
 
darirunu1:

What options do you suggest?
int cnt,ticket,total=0;

st = "часы общ. пон. вт. ср. чт. пт. \n";

double cHeight, gHeight, Max;

int sat, sun, mon, thu, wen, ths, fri; //, NN;

int H = TimeHour(TimeCurrent()); // определим текущий час

double NN = H + N*24; // определим смещение

if (NN>Bars) NN=Bars;

for (int t=0; t<24; t++)

{

  int HeightZ = 0; int z=0;

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

  {

    HeightZ = (High[i]-Low[i])/Point;

    z++;
  }

}

As far as I understand, your motion is calculated as bar height(MathAbs were not needed).

и

double NN = H + N*24;

here you are trying to calculate the number of bars... But it's better to set it as just a positive number, for starters.

You can calculate the average bar movement like this:

double avBarMove(int _period) {
  double cmMove = 0;
  for (int i = 0; i < _period; i++)
    cmMove += High[i]-Low[i];
  return cmMove / _period;
} 

Now, you can try to calculate the stop and take based on the result of the function.

 



Help me to position the function correctly

SendNotification ("текст");




Inserted it for the position entry message here

void OPENORDER(string ord)

  {
  
  double priceL=m_symbol.Ask();
   if(ord=="Sell")      
    SendNotification ("текст");

        //--- check for free money
            if(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_BUY,my_lot,priceL)<0.0)
               printf("We have no money. Free Margin = %f",m_account.FreeMargin());
            else
      if(!m_trade.Sell(my_lot,Symbol(),m_symbol.Bid(),my_SL,my_TP,""))
         Print("BUY_STOP -> false. Result Retcode: ",m_trade.ResultRetcode(),
               ", description of Retcode: ",m_trade.ResultRetcodeDescription(),
               ", ticket of order: ",m_trade.ResultOrder());                     // Если sell, то не открываемся
     double priceS=m_symbol.Bid();
   if(ord=="Buy")
    SendNotification ("текст");
 //--- check for free money
            if(m_account.FreeMarginCheck(Symbol(),ORDER_TYPE_SELL,my_lot,priceS)<0.0)
               printf("We have no money. Free Margin = %f",m_account.FreeMargin());
            else
      if(!m_trade.Buy(my_lot,Symbol(),m_symbol.Ask(),my_SL,my_TP,""))
 
         Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
               ", description of result: ",m_trade.ResultRetcodeDescription(),
               ", ticket of deal: ",m_trade.ResultDeal());
   return;
 }

And I'm already successfully getting notifications on my smartphone.




But how and where to insert

SendNotification

To get a message when I reach stop loss ortake profit?

 
Eugen8519:


Help to position the function correctly


Inserted it for the position entry message here

And I'm already successfully getting notifications on my smartphone.


But how and where to insert

To get a message when I reach Stop Loss orTake Profit?

See OnTradeTransaction

 

Eugen8519:

But how and where to insert

To send a message when Stop Loss orTake Profit is reached?

First, you need to create a function to control the closing of orders.

 
MakarFX:

First, we need to create a function to control the closing of orders.

OnTradeTransaction will be triggered when any stop order on the server is triggered.

 
MakarFX:

First, we have to create a function to control the closing of orders.

How about through?

DEAL_REASON_SL
DEAL_REASON_TP
Reason: