Multicurrency advisor question - page 13

 

Good morning!

Please advise. This is how positions are opened for each pair in the multi-currency EA.

//ЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮ
//-------------------------Изначальная позиция ----------
if ( Trade && pb==0 && (iBarShift("EURCHF_FX", timeFr, OpenTime1)!= 0) 
//если нет открытых дл. позиций и не было на этом баре
   && Bid_< Lbid+ Delta* Point_){
if ( iMA("EURCHF_FX",0, period_MA,0,MODE_SMMA,PRICE_MEDIAN,0)< iClose("EURCHF_FX", period_TF,0)
// || !Filter_DT)  { //если фильтр разрешает  
   SL=0; TP=0;
if( StopLoss>0)   SL= Ask_- Point_* StopLoss;
if( TakeProfit>0) TP= Ask_+ Point_* TakeProfit;   
ticket= WHCOrderSend("EURCHF_FX",OP_BUY, Lots, Ask_,3, SL, TP,"_001", Magic,0,Blue);
if( ticket < 0) { Print("Ошибка открытия ордера BUY EURCHF_FX  #", GetLastError()); 
               Sleep(10000);   return (0); }
 initorders();               
OpenTime1 = iTime("EURCHF_FX", timeFr,0);
   }}
//жжжжжжжжж Дополнительная позиции жжжжжжжжжжжжжжжжж 
if ( NumberOfPositions("EURCHF_FX",OP_BUY, Magic)==1 && 
NumberOfPositions("EURCHF_FX",OP_BUY, Magic_2)<1) {
//если открыта начальная позици
 if ( GetProfitOpenPosInPoint("EURCHF_FX",OP_BUY, Magic)<= LEVEL_1
  && iBarShift("EURCHF_FX", timeFr, OpenTime1)!= 0) {
//и если убыток начальн. позиции больше заданного значения
 SL=0; TP=0;
if( StopLoss>0)   SL= Ask_- Point_* StopLoss;
if( TakeProfit>0) TP= Ask_+ Point_* TakeProfit;   
ticket= WHCOrderSend("EURCHF_FX",OP_BUY, Lots+ dL2, Ask_,50, SL, TP,"002", Magic_2,0,Blue);
if( ticket < 0) { Print("Ошибка открытия ордера BUY EURCHF_FX #", GetLastError()); 
               Sleep(10000);   return (0); }
            
OpenTime1 = iTime("EURCHF_FX", timeFr,0);
   } } 
//ЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮЮ

Please advise. How can I write a separate function instead of this block.

So I don't have to rewrite this block for every pair ?

(The block uses I.Kim's fi and Market Watch's opening fi).

 
Rita писал(а) >>

Good morning!

Please advise. This is how positions are opened for each pair in the multi-currency EA.

Please advise. How can I write a separate function instead of this block.

So I don't have to rewrite this block for every pair ?

(I used I.Kim's fi and Market Watch opening fi in conditions of market order execution).

void FUN(string _Symbol){

// Your code, but using _Symbol instead of a symbol

}

 

Thank you. What about bids, asks, Delta, Lots and bool TRADE (this is input permission) for each pair?

Would this be correct? -

void FUN(string _Symbol, bool TRADE, double _BID, double _AZK,
         double _Delta,  double _LOTS){

Also. I seem to have heard in passing that it's incorrect to use (call) one custom function inside another.

And I'm using a function in a block to open positions in market order execution Market Watch

int WHCOrderSend(string symbol,   int cmd,   double volume, 
                 double price,int slippage,double stoploss, 
                 double takeprofit,string comment, nt magic, 
                 datetime expiration,   color arrow_color)
{  int ticket = OrderSend( symbol, cmd, volume, price, slippage, 0, 0, comment,
magic, expiration, arrow_color);                              int check = -1;
if ( ticket > 0 && ( stoploss != 0                      || takeprofit != 0)) {
if(!OrderModify( ticket, price, stoploss, takeprofit, expiration, arrow_color)) {
check = GetLastError();                         if ( check != ERR_NO_ERROR) {
Print("OrderModify error: ", ErrorDescription( check)); }   }   }      else {
check = GetLastError();                          if ( check != ERR_NO_ERROR){
Print("OrderSend error: ", ErrorDescription( check));   }}   return ( ticket);}
Won't there be problems and malfunctions?
 
Rita писал(а) >>

Thank you. What about bids, asks, Delta, Lots and bool TRADE (this is input permission) for each pair?

Would this be correct? -

Also. I seem to have heard in passing that it's incorrect to use (call) one custom function inside another.

And I use in my block the function for opening of positions in conditions of market orders execution Market Watch

Won't there be any problems and malfunctions ?

double _Bid=MarketInfo(_Symbol, MODE_BID);

double _Ask=MarketInfo(_Symbol, MODE_ASK);

....................................................................

The call function can be in any place. There will be no problems.

 
Okay. Thank you.
 

Good afternoon!

I use a trawl in a multi-currency truck. It's like this:

void TrailPositions() // функция трейлинг стоп
{
  int Orders = OrdersTotal();
  for (int i=0; i< Orders; i++) {
    if (!(OrderSelect( i, SELECT_BY_POS, MODE_TRADES))) continue;
    if (OrderSymbol() != Symbol()) continue;
     if (OrderMagicNumber() == Magic ){ 
//--------------------------------------   
     if (OrderType() == OP_BUY )  {
      if (Bid-OrderOpenPrice() > MinProfit*Point) {
        if (OrderStopLoss() < Bid-( TrailingStop+ TrailingStep-1)*Point) {
          OrderModify(OrderTicket(), OrderOpenPrice(), Bid- TrailingStop*Point,
                                                     OrderTakeProfit(), 0, Blue);
        }}}
//-----------------------------------------
     if (OrderType() == OP_SELL)  {
      if (OrderOpenPrice()-Ask > MinProfit*Point) {
        if (OrderStopLoss() > Ask+( TrailingStop+ TrailingStep-1)*Point 
                                                       || OrderStopLoss() == 0) {
          OrderModify(OrderTicket(), OrderOpenPrice(), Ask+ TrailingStop*Point,
                                                      OrderTakeProfit(), 0, Blue);
        }}} 
//---------------------------------------------  
 }   }  }

In order to engage the trawl for all pairs of multicurrency, I reworked it like this.

(Bids-asking-points are called via MarketInfo(Symbol_1,MODE_ASK);

void TrailPositions(string _Symbol,
                    double _BID,
                    double _AZK,
                    double _Point,
                    int MAGIC,
                    int MinProfit,
                    int TrailingStop,
                    int TrailingStep) 
{  int Orders = OrdersTotal();  for (int i=0; i< Orders; i++) {
    if (!(OrderSelect( i, SELECT_BY_POS, MODE_TRADES))) continue;
    if (OrderSymbol() != _Symbol) continue;
     if (OrderMagicNumber() == MAGIC){ 
//----------------------------------------------------   
     if (OrderType() == OP_BUY )  {
      if (_BID-OrderOpenPrice() > MinProfit*_Point) {
        if (OrderStopLoss() < _BID-( TrailingStop+ TrailingStep-1)*_Point) {
          OrderModify(OrderTicket(), OrderOpenPrice(), _BID- TrailingStop*_Point,
                                                     OrderTakeProfit(), 0, Blue);
        }      }    }
//-------------------------------------------------------
    if (OrderType() == OP_SELL)  {
      if (OrderOpenPrice()- _AZK > MinProfit*_Point) {
        if (OrderStopLoss() > _AZK+( TrailingStop+ TrailingStep-1)*_Point 
                                                       || OrderStopLoss() == 0) {
          OrderModify(OrderTicket(), OrderOpenPrice(), _AZK+ TrailingStop*_Point,
                                                      OrderTakeProfit(), 0, Blue);
        }   }   } 
//--------------------------------------------------------------
   }   }  }

The Expert Advisor works by opening prices.

The trawl is called like this:

if ( UseTrailing_1) {//выключатель трейлинг стопа 1 пары
if(iTime( Symbol_1, TimeFR_1,0)== prevtime) return(0);//ждём появления нового бара
    prevtime = iTime( Symbol_1, TimeFR_1,0);//если появился новый бар , включаемся 
TrailPositions( Symbol_1, Bid1, Ask1, Point1, Magic_1, MinProfit_1,
                                      TrailingStop_1, TrailingStep_1);}
//-------------------------------------------------------------------------------  
 
if ( UseTrailing_2){//выключатель трейлинг стопа 2 пары
if(iTime( Symbol_2, TimeFR_2,0)== prevtime) return(0);//ждём появления нового бара
    prevtime = iTime( Symbol_2, TimeFR_2,0);//если появился новый бар , включаемся 
TrailPositions( Symbol_2, Bid2, Ask2, Point2, Magic_2, MinProfit_2,
                                      TrailingStop_2, TrailingStep_2);}

However. The trawl does not work with this setting.

If I remove the trawl of one symbol, the trawl of another pair starts working.

If both trail pair calls are present in code, none of them works.

Please advise. Where may it be an error?

 

You have to use a different prevtime for each instrument and timeframe.

 

Thank you Vinin !

I was just about to write my own trawl for each pair....

 

Help with the multi-currency advisor.

I have written an EA. It simultaneously opens/closes orders for two pairs EURUSD <-> GBPUSD. I link it to EURUSD. Reads quotes for both pairs (iOpen). The commands below are executed

Ask_EUR = MarketInfo("EURUSD", MODE_ASK);

Bid_EUR = MarketInfo("EURUSD", MODE_BID);

And these commands are not executed

Ask_GBP = MarketInfo("GBPUSD", MODE_ASK);

Bid_GBP = MarketInfo("GBPUSD", MODE_BID);

Values ask = bid = 0

Can you tell me what is the matter?

 
Is there a second pair present in the MARKET OVERVIEW window?
Reason: