Questions from Beginners MQL5 MT5 MetaTrader 5 - page 225

 

Good evening!

I've been using the system with comments for a long time to distinguish if I modified a position earlier or not...

How can I distinguish correctly, for example, the fact that after I placed a buy order, I changed SL and TP in the position? Are there any position-specific fields or functions?

 
websafe25:

Good evening!

I've been using the system with comments for a long time to distinguish if I modified a position earlier or not...

How can I distinguish correctly, for example, the fact that after I placed a buy order, I changed SL and TP in the position? Are there any position-specific fields or functions?

It is unlikely.

In my opinion, we should not rely on the current state of the position or orders. It is much more reliable when after the restart the system forms the state which must be in the current market situation. And after that it will adjust the position and order placement.

 
pronych:

This is unlikely.

In my opinion, we should not rely on the current state of a position or orders. It is much more reliable when the system forms the state which it should have in the current market situation after the restart. And then it will adjust the position and the order chart.

Thank you for your reply.

I will now describe my own situation.

When the position reaches let's say a 10 pips profit, I want to transfer it to a no-loss one, i.e. I move my stops to the opening price + 3 pips, for example.

The following situation is happening right now.

if(AccountInfo.OrderProfitCheck(_Symbol,ORDER_TYPE_SELL,Lot,PositionInfo.PriceOpen(),NormalizeDouble(PositionInfo.PriceOpen()-ModifyPips*_Point,_Digits)) <= PositionInfo.Profit())
        {
        if(Trade.PositionModify(_Symbol,NormalizeDouble(PositionInfo.PriceOpen()-ModifySLPips*_Point,_Digits),NormalizeDouble(PositionInfo.PriceOpen()-TP*_Point,_Digits)))
          {

If profit on a trade is more or equal to 10 pips, I change stops.Profit increases, and modification happens over and over again, constantly. I need to move a trade to no-loss once, and then skip it by .....

How do I get rid of it? Or it would be better to write not <= but =? Is it possible that while EA will reach this operation and starts comparing profit on a trade, it will not be equal to 10 pips, and the profit will be more, then it will not close without loss?

P.S.> I think when getting a position just watch at what level from the price is SL, if above the price then already modified...

I decided it this way:

if(PositionInfo.Select(_Symbol))
{
   if(PositionInfo.PositionType()==POSITION_TYPE_BUY)
     {
     if(PositionInfo.StopLoss() > PositionInfo.PriceOpen())
       {
         if(AccountInfo.OrderProfitCheck(_Symbol,ORDER_TYPE_BUY,Lot,PositionInfo.PriceOpen(),NormalizeDouble(SymbolInfo.Ask()+ModifyPips*_Point,_Digits)) >= PositionInfo.Profit())
          {
             Trade.PositionModify(_Symbol,NormalizeDouble(PositionInfo.PriceOpen()+ModifySLPips*_Point,_Digits),NormalizeDouble(PositionInfo.PriceOpen()+TP*_Point,_Digits));
          }
       }
     }
   if(PositionInfo.PositionType()==POSITION_TYPE_SELL)
     {
     if(PositionInfo.StopLoss() < PositionInfo.PriceOpen())
       {
      if(AccountInfo.OrderProfitCheck(_Symbol,ORDER_TYPE_SELL,Lot,PositionInfo.PriceOpen(),NormalizeDouble(PositionInfo.PriceOpen()-ModifyPips*_Point,_Digits)) <= PositionInfo.Profit())
        {
        Trade.PositionModify(_Symbol,NormalizeDouble(PositionInfo.PriceOpen()-ModifySLPips*_Point,_Digits),NormalizeDouble(PositionInfo.PriceOpen()-TP*_Point,_Digits));
        }
       }
     }
}
 
websafe25:

P.S> I think when getting a position just look at which level from the price is SL, if above the price then already modified...

Decided it this way:

What you have written after P.S. is quite obvious. (if you need it very precisely, up to finding the level of high/low bars since the last measurement.)) but this is unlikely))

Only it would be desirable to detach ourselves from the concept of 'profit' and turn to the concept of 'point'.

And it would be more beautiful to consider not the price of last deal(Last) (and generally forget about this type of price), but ask/bid in the advantageous variant;))

 

Good evening!

Unfortunately I couldn't find any specific instructions on how to use a signal module for example RSI. That is, there is a record of how it is initialized, parameters are set, but how to simply check the condition to buy from my EA - no. What next? How do I check if there is a buy/sell condition?

/--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(-2);
     }
//---
   ExtExpert.InitSignal(signal);
   signal.ThresholdOpen(100);
   signal.ThresholdClose(100);
   signal.PriceLevel(0.0);
   signal.StopLevel(SL);
   signal.TakeLevel(TP);
//--- Creating filter CSignalRSI
   CSignalRSI *filter0=new CSignalRSI;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(-3);
     }
   signal.AddFilter(filter0);
//--- Set filter parameters
   filter0.PeriodRSI(PeriodRSI);
   filter0.Applied(PRICE_CLOSE);
   filter0.Weight(0.8);
 
websafe25:

Good evening!

Unfortunately I couldn't find any specific instructions on how to use a signal module for example RSI. That is, there is a record of how it is initialized, parameters are set, but how to simply check the condition to buy from my EA - no. What next? How do I check if there is a condition to buy/sell?

The Signals Module is connected to your Expert Advisor at the design stage. Each module of signals organizes voting...

In general, this article is a must-read:

Create a trading robot in 6 steps!

And finally

Generator of Custom Indicator Trading Signals

 

By the way - am I the only one who thinks it is incorrect to take the arithmetic average of the signals in the voting module?

double CExpertSignal::Direction(void)
  {
   long   mask;
   double direction;
   double result=m_weight*(LongCondition()-ShortCondition());
   int    number=(result==0.0)? 0 : 1;      // number of "voted"
//---
   int    total=m_filters.Total();
//--- loop by filters
   for(int i=0;i<total;i++)
     {
      //--- mask for bit maps
      mask=((long)1)<<i;
      //--- check of the flag of ignoring the signal of filter
      if((m_ignore&mask)!=0)
         continue;
      CExpertSignal *filter=m_filters.At(i);
      //--- check pointer
      if(filter==NULL)
         continue;
      direction=filter.Direction();
      //--- the "prohibition" signal
      if(direction==EMPTY_VALUE)
         return(EMPTY_VALUE);
      //--- check of flag of inverting the signal of filter
      if((m_invert&mask)!=0)
         result-=direction;
      else
         result+=direction;
// Вот тут бы       number+=filter.Weight();

      number++;
      }
//--- normalization
   if(number!=0)
      result/=number; // Вот туточки???
//--- return the result
   return(result);
  }
 
YAndrey:

By the way - am I the only one who thinks it is incorrect to take the arithmetic average of the signals in the voting module?

Everything is logical.

Read more articleMQL5 Wizard: The New Version and here is a piece of picture from the article:

normalisation

 
barabashkakvn:

It all makes sense.

Read more articleMQL5 Wizard: The New Version and here is a piece of drawing from the article:

Is it really logical? If weights are 1, then yes, it's logical.

Let's imagine that I have 2 filter-signals. One is good, fat one that I trust and set weight 1 for it. The other one is small, auxiliary for fun, therefore its weight = 0.1.

The thick signal gives a buy signal equal to 100, and the small one gives a buy signal equal to 10. What will be the total signal? 50.5??? Isn't it strange that the small one underestimates the situation?

 
YAndrey:

Does it make sense? If the weights are 1 each, then yes, it makes sense.

Let's imagine I have 2 signal filters. One is good, thick, which I trust and set weight 1 for it. Another one is small, auxiliary for fun, so its weight = 0.1.

The thick signal gives a buy signal equal to 100, and the small one gives a buy signal equal to 10. What will be the total signal? 50.5??? Isn't it strange that the small one underestimates the situation so much???

1. The total number of votes. Its main characteristic is the direction. The second characteristic is the final value.
2. If your strategy triggers two signals: one with strength equal to 100*1, and the second with strength equal to 10*0.1, then you should review your strategy in terms of signal selection.
Reason: