전역 초기화 실패!!!!!!! - 페이지 4

 
deysmacro :

객체가 이미 존재하는지 여부를 확인하기 위해 객체 찾기 기능 을 넣지 않습니다. 거기에서 그에 따라 개체를 만듭니다.


나는 지금 당신을 돕고 있습니다.


이제 OnInit()를 정리하는 좋은 힌트입니다. 감사합니다.

위의 문제를 실제로 해결하는 것은 아닙니다.

레이블이 여전히 제자리에 고정되지 않습니다.

내가 한 모든 일을 한 후에는 더 나아졌지만 여전히 완벽하지는 않습니다.

나는 문제가 훨씬 더 심오하고 데이터가 정리되지 않는 것과 관련이 있다고 생각합니다.

마치 MT4가 청소되지 않은 레지스터에서 오래된 데이터를 검색한 것처럼.

 

코딩의 궁극은 실제로 코딩을 하는 분이기 때문에 힌트만 드리자면 죄송합니다.

불행히도 많은 사람들이 주어진 힌트를 이해하지 못하거나 선택하지 않습니다.

 
qjol :



1. 레이블이 XDISTANCE 및 YDISTANCE를 준수하지 않은 것처럼 라인에서 벗어납니다.

그들은 Tf를 앞뒤로 전환한 후에만 인라인으로 돌아갑니다.

차트 창을 전환하거나 매개변수 입력을 변경하면 라인이 벗어납니다.

즉, 코드에서 수정할 수 있습니다.

나는 많은 일을 했지만 아무 것도 도움이 되지 않는다.

그것은 나아지지만 여전히, 즉. X,Y가 아닌 매개변수에서 smth를 변경한 후 레이블이 잘못되었습니다!

 //+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30 ;
extern double RiskPercent = 3 ;
extern int Corner = 3 ;
extern int Font_Size = 13 ;
extern string Font_Type = "Berlin Sans FB" ;
extern color Font_Color = clrSnow ;
extern color Warning_Color = clrRed ;
extern int XDistance = 9 ;
extern int YDistance = 27 ;
string   comment;
int X,Y;


int OnInit ()   {   
 X = XDistance;
 Y = YDistance;
if ( ObjectFind ( "Lot_Size_Label" )== 0 )
 {
 ObjectDelete ( "Lot_Size_Label" );
 }
ObjectCreate ( "Lot_Size_Label" , OBJ_LABEL , 0 , 0 , 0 ); return ( 0 ); 
  }

//-------------------------------------------------------------+
  
int OnDeinit ( int reason) 
  {
   ObjectDelete ( "Lot_Size_Label" ); 
   return ( 0 ); 
  }

//-------------------------------------------------------------+
int start()  
{
       string AcctCurrency = AccountCurrency ();
       
       if (AcctCurrency == "" )
           return ( 0 );
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo ( Symbol (), MODE_TICKVALUE ); 
   if ( Digits == 3 || Digits == 5 ) pipValue *= 10 ;
   double step     = MarketInfo ( Symbol (), MODE_LOTSTEP );
       int norm     = 0 ;
             if (step== 1 )    norm = 0 ;
             if (step== 0.1 )  norm = 1 ;
             if (step== 0.01 ) norm = 2 ;
   double minLot = MarketInfo ( Symbol (), MODE_MINLOT );
   double maxLot = MarketInfo ( Symbol (), MODE_MAXLOT );
   if (pipValue!= 0 )
    {
   double lots   = AccountBalance ()*(RiskPercent/ 100.0 )/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble (lots,norm);
          
         comment = "SL(" + DoubleToStr (RiskPercent, 2 )+ "%): " + DoubleToStr (StopLoss, 0 )+ " Pts  Vol: " + DoubleToStr (lots,norm)+ " Lot" ;
          
           double actualRisk,maxRiskSL; 
           if (lots<minLot)
            {
               actualRisk = ( 100 *minLot*StopLoss*pipValue)/ AccountBalance ();
               if (RiskPercent<= 0 ) RiskPercent= 1 ;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL(" + DoubleToStr (actualRisk, 2 )+ "%): " + DoubleToStr (StopLoss, 0 )+ " Pts  Vol: " + DoubleToStr (minLot,norm)+ " Lot" + "  SL(" + IntegerToString (RiskPercent, 0 )+ "%): " + IntegerToString (maxRiskSL, 0 )+ " Pts" ;
               Font_Color=Warning_Color;
            }
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_CORNER ,Corner);

   ObjectSet     ( "Lot_Size_Label" , OBJPROP_XDISTANCE ,X);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_YDISTANCE ,Y);
   ObjectSetText ( "Lot_Size_Label" ,comment,Font_Size,Font_Type,Font_Color);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_SELECTABLE , false ); 
 
   return ( 0 );
}

코드에 문제가 있습니까?



 
Dadas :


코드에 문제가 있습니까?


당신은 이미 들었습니다, 잊어

 int start()  

새로운 방법을 사용하기 시작

 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[])
  {

이미 위에 작성된 daymacro

나는 ObjectFind()가 보이지 않는다

 if ( ObjectFind (....) == xxx, or != yyy ...)
   {
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_CORNER ,Corner);
   
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_XDISTANCE ,X);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_YDISTANCE ,Y);
   ObjectSetText ( "Lot_Size_Label" ,comment,Font_Size,Font_Type,Font_Color);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_SELECTABLE , false ); 
   }
else
   {
   do something maybe GetLastError() ??
   }
 
qjol :

당신은 이미 들었습니다, 잊어

새로운 방법을 사용하기 시작

이미 위에 작성된 daymacro

나는 ObjectFind()가 보이지 않는다



그래서 저는 다음과 같이 했습니다.

 //+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30 ;
extern double RiskPercent = 3 ;
extern int Corner = 3 ;
extern int Font_Size = 13 ;
extern string Font_Type = "Berlin Sans FB" ;
extern color Font_Color = clrSnow ;
extern color Warning_Color = clrRed ;
extern int XDistance = 9 ;
extern int YDistance = 27 ;
string   comment;
int X,Y;
//
//
//
//
//

int OnInit ()   {   
 X = XDistance;
 Y = YDistance;
if ( ObjectFind ( "Lot_Size_Label" )== 0 )
 {
 ObjectDelete ( "Lot_Size_Label" );
 }
ObjectCreate ( "Lot_Size_Label" , OBJ_LABEL , 0 , 0 , 0 ); 

   return ( INIT_SUCCEEDED ); 
  }
  
void OnDeinit ( const int reason) 
  {
   ObjectDelete ( "Lot_Size_Label" ); 
  }

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[])
 {                
       string AcctCurrency = AccountCurrency ();
       
       if (AcctCurrency == "" )
           return (rates_total);
          
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo ( Symbol (), MODE_TICKVALUE ); 
   if ( Digits == 3 || Digits == 5 ) pipValue *= 10 ;
   double step     = MarketInfo ( Symbol (), MODE_LOTSTEP );
       int norm     = 0 ;
             if (step== 1 )    norm = 0 ;
             if (step== 0.1 )  norm = 1 ;
             if (step== 0.01 ) norm = 2 ;
   double minLot = MarketInfo ( Symbol (), MODE_MINLOT );
   double maxLot = MarketInfo ( Symbol (), MODE_MAXLOT );
   if (pipValue!= 0 )
    {
   double lots   = AccountBalance ()*(RiskPercent/ 100.0 )/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble (lots,norm);
          
           //
           //
           //
           //
           //
          comment = "SL(" + DoubleToStr (RiskPercent, 2 )+ "%): " + DoubleToStr (StopLoss, 0 )+ " Pts  Vol: " + DoubleToStr (lots,norm)+ " Lot" ;
          
           double actualRisk,maxRiskSL; 
           if (lots<minLot)
            {
               actualRisk = ( 100 *minLot*StopLoss*pipValue)/ AccountBalance ();
               if (RiskPercent<= 0 ) RiskPercent= 1 ;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL(" + DoubleToStr (actualRisk, 2 )+ "%): " + DoubleToStr (StopLoss, 0 )+ " Pts  Vol: " + DoubleToStr (minLot,norm)+ " Lot" + "  SL(" + IntegerToString (RiskPercent, 0 )+ "%): " + IntegerToString (maxRiskSL, 0 )+ " Pts" ;
               Font_Color=Warning_Color;
            }
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_CORNER ,Corner);

   ObjectSet     ( "Lot_Size_Label" , OBJPROP_XDISTANCE ,X);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_YDISTANCE ,Y);
   ObjectSetText ( "Lot_Size_Label" ,comment,Font_Size,Font_Type,Font_Color);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_SELECTABLE , false );  
   return (rates_total);
}

그래도 같은 효과. 이것은 라벨 위치에 관한 한 아무 것도 변경하지 않았습니다.

ObjectFind()는 OnInit()에 개체가 있는지 확인하고 개체가 있으면 삭제합니다.

indi 초기화에 대한 레이블은 원래 있어야 하는 위치에 있습니다.

일부 매개변수를 변경하면 오른쪽으로 사라집니다.

Tf 이동 후에만 제자리로 다시 점프합니다.

 
실제로 처음 로드할 때 첫 번째 개체 세트와 로드 후 두 번째 개체 세트(먼지가 가라앉음)와 같은 것이 필요합니다. 나는 또한 내가 말한대로 문제를 해결하는 것과 같은 문제를 겪었습니다. 해결 방법과 비슷하지만 모두 나에게 충분합니다.
 
deysmacro :
실제로 처음 로드할 때 첫 번째 개체 세트와 로드 후 두 번째 개체 세트(먼지가 가라앉음)와 같은 것이 필요합니다. 나는 또한 내가 말한대로 문제를 해결하는 것과 같은 문제를 겪었습니다. 해결 방법과 비슷하지만 모두 나에게 충분합니다.

그래서 X,Y 좌표를 다시 확인하여 좌표가 다른 경우 레이블을 다시 설정합니다.

주스도 없고, 아무 것도 바뀌지 않으며, 위와 같이 동작합니다.

 //+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

extern double StopLoss    = 30 ;
extern double RiskPercent = 3 ;
extern int Corner = 3 ;
extern int Font_Size = 13 ;
extern string Font_Type = "Berlin Sans FB" ;
extern color Font_Color = clrSnow ;
extern color Warning_Color = clrRed ;
extern int XDistance = 9 ;
extern int YDistance = 27 ;
string   comment;
int X,Y;
//
//
//
//
//

int OnInit ()   {   
 X = XDistance;
 Y = YDistance;
if ( ObjectFind ( "Lot_Size_Label" )== 0 )
 {
 ObjectDelete ( "Lot_Size_Label" );
 }
   ObjectCreate ( "Lot_Size_Label" , OBJ_LABEL , 0 , 0 , 0 ); 
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_CORNER ,Corner);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_XDISTANCE ,X);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_YDISTANCE ,Y);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_SELECTABLE , false );    
  
   return ( INIT_SUCCEEDED ); 
  }
  
void OnDeinit ( const int reason) 
  {
   ObjectDelete ( "Lot_Size_Label" ); 
  }

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[])
 {                
       string AcctCurrency = AccountCurrency ();
       
       if (AcctCurrency == "" )
           return (rates_total);
          
 X = XDistance;
 Y = YDistance;
           
   double pipValue = MarketInfo ( Symbol (), MODE_TICKVALUE ); 
   if ( Digits == 3 || Digits == 5 ) pipValue *= 10 ;
   double step     = MarketInfo ( Symbol (), MODE_LOTSTEP );
       int norm     = 0 ;
             if (step== 1 )    norm = 0 ;
             if (step== 0.1 )  norm = 1 ;
             if (step== 0.01 ) norm = 2 ;
   double minLot = MarketInfo ( Symbol (), MODE_MINLOT );
   double maxLot = MarketInfo ( Symbol (), MODE_MAXLOT );
   if (pipValue!= 0 )
    {
   double lots   = AccountBalance ()*(RiskPercent/ 100.0 )/(StopLoss*pipValue);
    }
         lots   = NormalizeDouble (lots,norm);
          
           //
           //
           //
           //
           //
          comment = "SL(" + DoubleToStr (RiskPercent, 2 )+ "%): " + DoubleToStr (StopLoss, 0 )+ " Pts  Vol: " + DoubleToStr (lots,norm)+ " Lot" ;
          
           double actualRisk,maxRiskSL; 
           if (lots<minLot)
            {
               actualRisk = ( 100 *minLot*StopLoss*pipValue)/ AccountBalance ();
               if (RiskPercent<= 0 ) RiskPercent= 1 ;
               maxRiskSL = StopLoss/(actualRisk/RiskPercent);
               comment = "SL(" + DoubleToStr (actualRisk, 2 )+ "%): " + DoubleToStr (StopLoss, 0 )+ " Pts  Vol: " + DoubleToStr (minLot,norm)+ " Lot" + "  SL(" + IntegerToString (RiskPercent, 0 )+ "%): " + IntegerToString (maxRiskSL, 0 )+ " Pts" ;
               Font_Color=Warning_Color;
            }
            
   if ( ObjectFind ( "Lot_Size_Label" )== 0 )
   {         
   int x_check= ObjectGet ( "Lot_Size_Label" , OBJPROP_XDISTANCE );
   int y_check= ObjectGet ( "Lot_Size_Label" , OBJPROP_YDISTANCE );  
   }  

   if (X!=x_check||Y!=y_check)
   {            
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_CORNER ,Corner);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_XDISTANCE ,X);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_YDISTANCE ,Y);
   ObjectSetText ( "Lot_Size_Label" ,comment,Font_Size,Font_Type,Font_Color);
   ObjectSet     ( "Lot_Size_Label" , OBJPROP_SELECTABLE , false );  
   }
   return (rates_total);
}
PS. this didn't happen in B625, only started with B646 update.

	          
 
그래서, 아직 완료 되었습니까?
 

그리고 재미있는 점은 Comment() 를 사용 하면 레이블이 올바른 경우에도 좌표가 변경되지 않는다는 것입니다.

따라서 문제가 남아 있으며 완료되지 않았습니다.

 
Comment()는 대부분 차트에 영향을 미치지 않습니다.