MQL4 및 MQL5에 대한 초보자 질문, 알고리즘 및 코드에 대한 도움말 및 토론 - 페이지 1614

 
Fast235 # :

유일한 질문은 이 줄입니다

-50 추가 및 어레이

"0" 위/아래로 그리는 것입니다.

하지만 그것 없이는 가능합니다. 핸들 사용법의 본질이 필요합니다.

 
Vladimir Simakov # :

강력 추천:

그렇지 않으면 작동합니다)))

또한, 전체 리드 바로 직전 분할 후 올바르게. 그렇지 않으면, 이진 미적분은 많은 일을 할 수 있습니다)))

 
MakarFX # :

"0" 위/아래로 그리는 것입니다.

하지만 그것 없이는 가능합니다. 핸들 사용법의 본질이 필요합니다.

핸들은 일반적으로 OnInit()에서 생성되는 표시기 파일에 대한 포인터입니다.

   Handle= iCustom ( Symbol (), PERIOD_H1 , "_iTrend" , 10 );
//--- Если не удалось получить хендл индикатора
   if (Handle== INVALID_HANDLE )
     {
       PrintFormat ( "Failed to create handle of the iAO indicator for the symbol %s/%s, error code %d" ,
                   Symbol (),
                   EnumToString ( Period ()),
                   GetLastError ());
       //---
       return ( INIT_FAILED );
     }

코드를 더 아래로

     if ( CopyBuffer (Handle, 0 , 1 , 1 ,Buffer1) <= 0 проверка на ошибку
---
в Buffer1[ 1111 ] получаем значение
 
Fast235 # :

핸들은 일반적으로 OnInit()에서 생성되는 표시기 파일에 대한 포인터입니다.

코드를 더 아래로

감사합니다만 참고용으로 보이는데 아쉽게도 이해가 안되네요(

그래서 내가 직접 작업의 논리를 분석하기 위해 내 코드를 mql5로 번역하도록 요청했습니다.

나는 지금 이것을하고있다

 //+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
   IndicatorSetInteger ( INDICATOR_DIGITS , _Digits );
   prd = _Period > TimeFrame ? _Period : TimeFrame;
   atrHandle = iATR ( _Symbol , prd, Per_Count);
   if (atrHandle == INVALID_HANDLE )
     {
       Print ( "Can't load indicator." ); return INIT_FAILED ;
     }
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,Label1Buffer, INDICATOR_DATA );
   SetIndexBuffer ( 1 ,Label2Buffer, INDICATOR_DATA );
   
   ArraySetAsSeries (Label1Buffer, true );
   ArraySetAsSeries (Label2Buffer, true );
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[])
  {
//---
   int limit,i;
   int barPlus= iBarShift ( _Symbol , _Period , iTime ( _Symbol , PERIOD_W1 ,WeekCount), false );
   limit=rates_total-prev_calculated- 3 ;
   if (WeekCount!= 0 )limit=barPlus- 1 ;
   if (limit< 1 ) return ( 0 );
   for (i=limit;i>= 0 ;i--)
     {
       TimeToStruct (time[i],inTime);
      index01= iBarShift ( _Symbol , PERIOD_D1 ,time[i], false );
       if (inTime.hour== 0 &&inTime.min== 0 )
        {
         Label1Buffer[i]=GetIndicator(atrHandle, index01+ 1 );
        }
     }
   
//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+
double GetIndicator( const int handle, const int i)
  {
   double res[ 1 ];
   if ( CopyBuffer (handle, 0 , i, 1 , res) <= 0 ) return 0 ;
   return res[ 0 ];
  }
//+------------------------------------------------------------------+

그러나 뭔가 잘못되었다는 느낌과 iMAOnArray는 도움말에서 전혀 발견되지 않았습니다.

 

좋은 오후에요.

마틴의 루핑 문제를 해결할 수 없습니다.

실행 후 꺼짐: (n>=OrdersClose) - 수익성 있는 거래가 발생할 때까지 마틴이 켜지지 않습니다.

실행 후 다음이 필요합니다. (n>=OrdersClose) - 반환 (dLots)이 발생하고 다음 거래가 다시 수익성이 없으면 마틴이 다시 시작됩니다.

정리하는 방법을 알려주세요?

 double LOT()
{
   int n= 0 ;
   double OL=dLots;
   for ( int j = OrdersHistoryTotal()- 1 ; j >= 0 ; j--)
   {
       if ( OrderSelect (j, SELECT_BY_POS,MODE_HISTORY))
      {
         if (OrderSymbol() == Symbol () && OrderMagicNumber() == iMagic)
         {
             if (OrderProfit()< 0 ) 
            {
               if (n== 0 ) OL= NormalizeDouble (OrderLots()*K_Martin,DigitsLot);
               n++;
               if (n>=OrdersClose) { return (dLots);}
            }
             else
            {
               if (n== 0 ) { return (dLots);}
               else { return (OL);}
            }
         }
      }
   }
   return (OL);
}
 

모두에게 좋은 하루!!!

알려주세요, 그리드 어드바이저의 코드에서 차트에 평균 가격 표시를 등록했습니다. 모든 것이 괜찮지만 그리드가 닫힌 후 라인이 올바르게 삭제되지 않습니다. 즉, 수요일에 가격이 없습니다. 내가 뭘 잘못했는지 말해주세요. 다음은 코드와 그림입니다.

//+----------------------------------------------- ------------------------------+
//| 단체주문 수정 |
//+----------------------------------------------- ------------------------------+
무효 ModifyOrders(int otype)
{
이중 avg_price, AveragePriceBuy, AveragePriceSell, order_lots = 0;
가격 = 0;

for(int i = OrdersTotal()-1; i>=0; i--)
{
if(주문선택(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
{
가격 += OrderOpenPrice() * OrderLots();
order_lots += OrderLots() ;
}
}
}
avg_price = NormalizeDouble(price / order_lots, Digits);
AveragePriceBuy = NormalizeDouble(avg_price + 스프레드, 자릿수);
AveragePriceSell = NormalizeDouble(avg_price - 스프레드, 자릿수);
{
ObjectDelete(0, "AveragePriceLine");
ObjectCreate("AveragePriceLine",OBJ_HLINE, 0, 0,AveragePriceBuy);
ObjectCreate("AveragePriceLine" ,OBJ_HLINE, 0, 0 ,AveragePriceSell);
ObjectSet("AveragePriceLine",OBJPROP_COLOR,파란색);
}
if ((otype == OP_BUY) && (Drawdown <= DrawdownClosingTakeprofitZero))
tp = NormalizeDouble(AveragePriceBuy + TakeProfitGroupOrder*포인트, 자릿수);
if ((otype == OP_SELL) && (Drawdown <= DrawdownClosingTakeprofitZero))
tp = NormalizeDouble(AveragePriceSell - TakeProfitGroupOrder*포인트, 자릿수);
if ((otype == OP_BUY) && (Drawdown > DrawdownClosingTakeprofitZero))
tp = NormalizeDouble(AveragePriceBuy, 자릿수);
if ((otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero))
tp = NormalizeDouble(AveragePriceSell, 자릿수);

for(int i = OrdersTotal()-1; i>=0; i--)
{
if(주문선택(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
{
if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0))
Print("주문이 성공적으로 수정되었습니다!");
else Print("주문 수정 오류!");
}
}
}
}


 
EVGENII SHELIPOV # :

모두에게 좋은 하루!!!

알려주세요, 그리드 어드바이저의 코드에서 차트에 평균 가격 표시를 등록했습니다. 모든 것이 괜찮지만 그리드가 닫힌 후 라인이 올바르게 삭제되지 않습니다. 즉, 수요일에 가격이 없습니다. 내가 뭘 잘못했는지 말해주세요. 다음은 코드와 그림입니다.

이 시도

 //+----------------------------------------------------------------------------+
//| Модификация групповых ордеров                                              |
//+----------------------------------------------------------------------------+
void ModifyOrders( int otype)
{
     double avg_price, AveragePriceBuy, AveragePriceSell, order_lots = 0 ;
    price = 0 ;
   
     for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--)
    {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
       {
         if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic && OrderType() == otype)
         {
            price += OrderOpenPrice() * OrderLots();
            order_lots += OrderLots() ;
         }
       }
    }
    avg_price = NormalizeDouble (price / order_lots, Digits );
    AveragePriceBuy = NormalizeDouble (avg_price + Spread, Digits );
    AveragePriceSell = NormalizeDouble (avg_price - Spread, Digits );
     if ( ObjectFind ( 0 , "AveragePriceLineBuy" )== 0 )
     {
     ObjectDelete ( 0 , "AveragePriceLineBuy" );
     ObjectCreate ( 0 , "AveragePriceLineBuy" , OBJ_HLINE , 0 , 0 ,AveragePriceBuy);
     ObjectSetInteger ( 0 , "AveragePriceLine" , OBJPROP_COLOR ,Blue);
     }
     else
     {
     ObjectCreate ( 0 , "AveragePriceLineBuy" , OBJ_HLINE , 0 , 0 ,AveragePriceBuy);
     ObjectSetInteger ( 0 , "AveragePriceLine" , OBJPROP_COLOR ,Blue);
     }
     if ( ObjectFind ( 0 , "AveragePriceLineSell" )== 0 )
     {
     ObjectDelete ( 0 , "AveragePriceLineSell" );
     ObjectCreate ( 0 , "AveragePriceLineSell" , OBJ_HLINE , 0 , 0 ,AveragePriceSell);
     ObjectSetInteger ( 0 , "AveragePriceLine" , OBJPROP_COLOR ,Blue);
     }
     else
     {
     ObjectCreate ( 0 , "AveragePriceLineSell" , OBJ_HLINE , 0 , 0 ,AveragePriceSell);
     ObjectSetInteger ( 0 , "AveragePriceLine" , OBJPROP_COLOR ,Blue);
     }
     if ((otype == OP_BUY) && (Drawdown <= DrawdownClosingTakeprofitZero)) 
    tp = NormalizeDouble (AveragePriceBuy + TakeProfitGroupOrder* Point , Digits );
     if ((otype == OP_SELL) && (Drawdown <= DrawdownClosingTakeprofitZero))
    tp = NormalizeDouble (AveragePriceSell - TakeProfitGroupOrder* Point , Digits );
     if ((otype == OP_BUY) && (Drawdown > DrawdownClosingTakeprofitZero)) 
    tp = NormalizeDouble (AveragePriceBuy, Digits );
     if ((otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero))
    tp = NormalizeDouble (AveragePriceSell, Digits );
    
     for ( int i = OrdersTotal ()- 1 ; i>= 0 ; i--) 
    {
       if ( OrderSelect (i, SELECT_BY_POS, MODE_TRADES))
       {
           if (OrderSymbol() == Symbol () && OrderMagicNumber() == Magic && OrderType() == otype)
           {
               if (OrderModify(OrderTicket(), OrderOpenPrice(), 0 , tp, 0 ))
                   Print ( "Ордера успешно модифицированы!" );
                 else Print ( "Ошибка модификации ордеров!" );
           }
       }
    }
}   

쓰는게 낫다

미결 판매 주문이 없으면 판매 라인을 삭제합니다...

베이와 유사

 
좋은 저녁입니다. 클릭했을 때 그래픽 버튼의 상태를 재설정하여 다시 클릭할 때까지 항상 눌려지지 않도록 하는 방법은 무엇입니까?
 
Nerd Trader # :
좋은 저녁입니다. 클릭했을 때 그래픽 버튼의 상태를 재설정하여 다시 클릭할 때까지 항상 눌려지지 않도록 하는 방법은 무엇입니까?
 ObjectSetInteger ( 0 ,name, OBJPROP_STATE , false );
 
MakarFX # :
아니, 당신이 잘못 이해했습니다. 클릭을 놓은 후 일반 버튼처럼 상태를 재설정해야 합니다. mql4에 마우스 버튼 상태 이벤트가 없는 경우 이를 구현하는 방법: press/release.