전문 고문 - 기타 질문 - 페이지 9

 

아래 코드는 잘 작동하는 것처럼 보이고 이미 bool ' stoploss_use & takeprofit_use '를 시도 했지만 제대로 작동하지 않아 의심되는 코드 가 있으면 알려주세요. (필요한 경우 - 해당 테스트 EA의 코드를 모두 게시할 수 있습니다.)

void OnChartEvent ( const int      id     ,
                   const long &   lparam ,
                   const double & dparam ,
                   const string & sparam
                  )
{
     // Sell
     if ( sparam == sellbutton )
    {
         ObjectSetInteger ( 0 , sparam, OBJPROP_STATE , false );
         // stoploss
         if ( stoploss_use == true )
        { sl = Bid + points_to_change( stoploss );}
         // takeprofit
         if ( takeprofit_use == true )
        { tp = Bid - points_to_change( takeprofit );}
         if ( ! OrderSend ( Symbol (), OP_SELL , lot, Bid , slippage, sl, tp, NULL , magic, 0 , CLR_NONE ) )
             Print ( " | OrderSend SELL: " , GetLastError () );
         return ;
    }
     // Buy
     if ( sparam == buybutton )
    {
         ObjectSetInteger ( 0 , sparam, OBJPROP_STATE , false );
         // stoploss
         if ( stoploss_use == true )
        { sl = Ask - points_to_change( stoploss ); }
         // takeprofit
         if ( takeprofit_use == true )
        { tp = Ask + points_to_change( takeprofit ); }
         if ( ! OrderSend ( Symbol (), OP_BUY , lot, Ask , slippage, sl, tp, NULL , magic, 0 , CLR_NONE ) )
             Print ( " | OrderSend SELL: " , GetLastError () );

         return ;
    }
}

따라서 위의 코드가 라고 말하면 잘 작동합니다. 그런 다음 코드 조합이 최적 인지 묻고 싶습니다. 그래서 저는 최적의 코드 조합 을 얻으려고 노력하고 있습니다. 즉, 코드가 완벽하게 작동해야 합니다.

저를 도와주시거나 좋은 조언을 부탁드립니다.
모두 제일 좋다.

 

실패하면 오류가 발생하고 설명서에서 오류 코드 를 찾을 수 있습니다.

때때로 주문 보내기가 미끄러지거나 인용 부호가 떨어져 실패하므로 항상 코딩 문제일 필요는 없습니다.

정류장을 시장 가격에 너무 가깝게 배치하면 코딩 문제가 됩니다.

또한 주문을 위해 별도의 함수를 작성하고 단순히 onchart 이벤트 내부에서 호출합니다.

그러나 결과는 동일해야 합니다.

 
Marco vd Heijden :

또한 주문을 위해 별도의 함수를 작성하고 단순히 onchart 이벤트 내부에서 호출합니다.

좋은 의견, 이미 분리하기 시작했습니다. 감사합니다.
 

아래 코드 조합이 좋은가요?

// Sell
if ( sparam == sellbutton )
{
     ObjectSetInteger ( 0 , sparam, OBJPROP_STATE , false );
    ordersellfnc();
     return ;
}
void ordersellfnc()
{    
     if ( stoploss_use   == true ) { sl = Bid + points_to_change( stoploss   ); }
     if ( takeprofit_use == true ) { tp = Bid - points_to_change( takeprofit ); }
     if ( ! OrderSend ( Symbol (), OP_SELL , lot, Ask , slippage, sl, tp, NULL , magic, 0 , clrRed ) )
           Print ( " | OrderSend SELL: " , GetLastError () );
     return ;
}

미리 감사드립니다.

 
Ordersend는 티켓 번호를 반환하거나 함수 가 실패하면 -1을 반환합니다.
 
Marco vd Heijden :
Ordersend는 티켓 번호를 반환하거나 함수 가 실패하면 -1을 반환합니다.
아 왜 최근 댓글만 이해가 안가는지 모르겠는데 그게 문제인가요? 그렇다면 어떻게 해결할 수 있습니까?
 

#확인 표시 - 열기

나에게 잘 맞는 'Stop Loss Default' 값에 대해 아래 코드를 사용할 수 있습니다.
그러나 나는 이미 ' 체크 표시 ' 사용 ' 켜기 / 끄기 ' 를 위해 몇 시간을 보냈지만 불행히도 좋은 결과는 아닙니다. 그냥 ' Bitmap Label ' 개체가 있어서 따로 사용하면 잘 되지만 이렇게 사용하려고 하면 ON 이면 'Stop Loss'를 적용할 수 있고 OFF 이면 'Stop Loss'를 적용할 수 없습니다.

이 함수에 대한 코드를 작성하기 시작했을 때, 나는 단지 몇 분 안에 작성할 수 있다고 생각했습니다. 그러나 불행히도 이미 몇 시간이 걸렸습니다. 도와주세요. 제 삶의 시간이 걸리고 있습니다.

(내 걱정이 어리석은 것처럼 보였다면 나를 비난하지 마십시오. 단지 이유가 소진 된 것입니다)

if ( stoploss == stoplossresetvalue )
{   ObjectSetInteger ( 0 , stoplossbmp, OBJPROP_STATE , false ); } else
{   ObjectSetInteger ( 0 , stoplossbmp, OBJPROP_STATE , true   ); }

     ObjectSetString ( 0 , stoplossedit, OBJPROP_TEXT , IntegerToString ( stoploss ) );

미리 감사드립니다.

 

비트맵 레이블은 버튼 개체와 약간 다르게 작동합니다.

두 개의 비트맵을 하나는 켜짐 상태용으로 사용하고 다른 하나는 꺼짐 상태용으로 사용합니다.

#property strict
//--- description
#property description "Script creates \"Bitmap Label\" object."
//--- display window of the input parameters during the script's launch
#property script_show_inputs
//--- input parameters of the script
input string             InpName= "BmpLabel" ;               // Label name
input string             InpFileOn= "\\Images\\dollar.bmp" ; // File name for On mode
input string             InpFileOff= "\\Images\\euro.bmp" ;   // File name for Off mode

input bool               InpState= false ;                   // Label pressed/released
input ENUM_BASE_CORNER   InpCorner= CORNER_LEFT_UPPER ;       // Chart corner for anchoring
input ENUM_ANCHOR_POINT InpAnchor= ANCHOR_CENTER ;           // Anchor type
input color              InpColor= clrRed ;                   // Border color when highlighted
input ENUM_LINE_STYLE    InpStyle= STYLE_SOLID ;             // Line style when highlighted
input int                InpPointWidth= 1 ;                   // Point size to move
input bool               InpBack= false ;                     // Background object
input bool               InpSelection= false ;               // Highlight to move
input bool               InpHidden= true ;                   // Hidden in the object list
input long               InpZOrder= 0 ;                       // Priority for mouse click
//+------------------------------------------------------------------+
//| Create Bitmap Label object                                       |
//+------------------------------------------------------------------+
bool BitmapLabelCreate( const long               chart_ID= 0 ,               // chart's ID
                       const string             name= "BmpLabel" ,           // label name
                       const int                sub_window= 0 ,             // subwindow index
                       const int                x= 0 ,                       // X coordinate
                       const int                y= 0 ,                       // Y coordinate
                       const string             file_on= "" ,               // image in On mode
                       const string             file_off= "" ,               // image in Off mode
                       const int                width= 0 ,                   // visibility scope X coordinate
                       const int                height= 0 ,                 // visibility scope Y coordinate
                       const int                x_offset= 10 ,               // visibility scope shift by X axis
                       const int                y_offset= 10 ,               // visibility scope shift by Y axis
                       const bool               state= false ,               // pressed/released
                       const ENUM_BASE_CORNER   corner= CORNER_LEFT_UPPER , // chart corner for anchoring
                       const ENUM_ANCHOR_POINT anchor= ANCHOR_LEFT_UPPER , // anchor type
                       const color              clr= clrRed ,               // border color when highlighted
                       const ENUM_LINE_STYLE    style= STYLE_SOLID ,         // line style when highlighted
                       const int                point_width= 1 ,             // move point size
                       const bool               back= false ,               // in the background
                       const bool               selection= false ,           // highlight to move
                       const bool               hidden= true ,               // hidden in the object list
                       const long               z_order= 0 )                 // priority for mouse click
  {
//--- reset the error value
   ResetLastError ();
//--- create a bitmap label
   if (! ObjectCreate (chart_ID,name, OBJ_BITMAP_LABEL ,sub_window, 0 , 0 ))
     {
       Print ( __FUNCTION__ ,
             ": failed to create \"Bitmap Label\" object! Error code = " , GetLastError ());
       return ( false );
     }
//--- set the images for On and Off modes
   if (! ObjectSetString (chart_ID,name, OBJPROP_BMPFILE , 0 ,file_on))
     {
       Print ( __FUNCTION__ ,
             ": failed to load the image for On mode! Error code = " , GetLastError ());
       return ( false );
     }
   if (! ObjectSetString (chart_ID,name, OBJPROP_BMPFILE , 1 ,file_off))
     {
       Print ( __FUNCTION__ ,
             ": failed to load the image for Off mode! Error code = " , GetLastError ());
       return ( false );
     }

//--- set label coordinates
   ObjectSetInteger (chart_ID,name, OBJPROP_XDISTANCE ,x);
   ObjectSetInteger (chart_ID,name, OBJPROP_YDISTANCE ,y);
//--- set visibility scope for the image; if width or height values
//--- exceed the width and height (respectively) of a source image,
//--- it is not drawn; in the opposite case,
//--- only the part corresponding to these values is drawn
   ObjectSetInteger (chart_ID,name, OBJPROP_XSIZE ,width);
   ObjectSetInteger (chart_ID,name, OBJPROP_YSIZE ,height);
//--- set the part of an image that is to be displayed in the visibility scope
//--- the default part is the upper left area of an image; the values allow
//--- performing a shift from this area displaying another part of the image
   ObjectSetInteger (chart_ID,name, OBJPROP_XOFFSET ,x_offset);
   ObjectSetInteger (chart_ID,name, OBJPROP_YOFFSET ,y_offset);
//--- define the label's status (pressed or released)
   ObjectSetInteger (chart_ID,name, OBJPROP_STATE ,state);

//--- set the chart's corner, relative to which point coordinates are defined
   ObjectSetInteger (chart_ID,name, OBJPROP_CORNER ,corner);
//--- set anchor type
   ObjectSetInteger (chart_ID,name, OBJPROP_ANCHOR ,anchor);
//--- set the border color when object highlighting mode is enabled
   ObjectSetInteger (chart_ID,name, OBJPROP_COLOR ,clr);
//--- set the border line style when object highlighting mode is enabled
   ObjectSetInteger (chart_ID,name, OBJPROP_STYLE ,style);
//--- set a size of the anchor point for moving an object
   ObjectSetInteger (chart_ID,name, OBJPROP_WIDTH ,point_width);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger (chart_ID,name, OBJPROP_BACK ,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse
   ObjectSetInteger (chart_ID,name, OBJPROP_SELECTABLE ,selection);
   ObjectSetInteger (chart_ID,name, OBJPROP_SELECTED ,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger (chart_ID,name, OBJPROP_HIDDEN ,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger (chart_ID,name, OBJPROP_ZORDER ,z_order);
//--- successful execution
   return ( true );
  }
//+------------------------------------------------------------------+
//| Set a new image for Bitmap label object                          |
//+------------------------------------------------------------------+
bool BitmapLabelSetImage( const long    chart_ID= 0 ,       // chart's ID
                         const string name= "BmpLabel" , // label name
                         const int     on_off= 0 ,         // modifier (On or Off)
                         const string file= "" )         // path to the file
  {
//--- reset the error value
   ResetLastError ();
//--- set the path to the image file
   if (! ObjectSetString (chart_ID,name, OBJPROP_BMPFILE ,on_off,file))
     {
       Print ( __FUNCTION__ ,
             ": failed to load the image! Error code = " , GetLastError ());
       return ( false );
     }
//--- successful execution
   return ( true );
  }
//+------------------------------------------------------------------+
//| Move Bitmap Label object                                         |
//+------------------------------------------------------------------+
bool BitmapLabelMove( const long    chart_ID= 0 ,       // chart's ID
                     const string name= "BmpLabel" , // label name
                     const int     x= 0 ,             // X coordinate
                     const int     y= 0 )             // Y coordinate
  {
//--- reset the error value
   ResetLastError ();
//--- move the object
   if (! ObjectSetInteger (chart_ID,name, OBJPROP_XDISTANCE ,x))
     {
       Print ( __FUNCTION__ ,
             ": failed to move X coordinate of the object! Error code = " , GetLastError ());
       return ( false );
     }
   if (! ObjectSetInteger (chart_ID,name, OBJPROP_YDISTANCE ,y))
     {
       Print ( __FUNCTION__ ,
             ": failed to move Y coordinate of the object! Error code = " , GetLastError ());
       return ( false );
     }
//--- successful execution
   return ( true );
  }
//+------------------------------------------------------------------+
//| Change visibility scope (object) size                            |
//+------------------------------------------------------------------+
bool BitmapLabelChangeSize( const long    chart_ID= 0 ,       // chart's ID
                           const string name= "BmpLabel" , // label name
                           const int     width= 0 ,         // label width
                           const int     height= 0 )         // label height
  {
//--- reset the error value
   ResetLastError ();
//--- change the object size
   if (! ObjectSetInteger (chart_ID,name, OBJPROP_XSIZE ,width))
     {
       Print ( __FUNCTION__ ,
             ": failed to change the object width! Error code = " , GetLastError ());
       return ( false );
     }
   if (! ObjectSetInteger (chart_ID,name, OBJPROP_YSIZE ,height))
     {
       Print ( __FUNCTION__ ,
             ": failed to change the object height! Error code = " , GetLastError ());
       return ( false );
     }
//--- successful execution
   return ( true );
  }
//+--------------------------------------------------------------------+
//| Change coordinate of the upper left corner of the visibility scope |
//+--------------------------------------------------------------------+
bool BitmapLabelMoveVisibleArea( const long    chart_ID= 0 ,       // chart's ID
                                 const string name= "BmpLabel" , // label name
                                 const int     x_offset= 0 ,       // visibility scope X coordinate
                                 const int     y_offset= 0 )       // visibility scope Y coordinate
  {
//--- reset the error value
   ResetLastError ();
//--- change the object's visibility scope coordinates
   if (! ObjectSetInteger (chart_ID,name, OBJPROP_XOFFSET ,x_offset))
     {
       Print ( __FUNCTION__ ,
             ": failed to change X coordinate of the visibility scope! Error code = " , GetLastError ());
       return ( false );
     }
   if (! ObjectSetInteger (chart_ID,name, OBJPROP_YOFFSET ,y_offset))
     {
       Print ( __FUNCTION__ ,
             ": failed to change Y coordinate of the visibility scope! Error code = " , GetLastError ());
       return ( false );
     }
//--- successful execution
   return ( true );
  }
//+------------------------------------------------------------------+
//| Delete "Bitmap label" object                                     |
//+------------------------------------------------------------------+
bool BitmapLabelDelete( const long    chart_ID= 0 ,       // chart's ID
                       const string name= "BmpLabel" ) // label name
  {
//--- reset the error value
   ResetLastError ();
//--- delete the label
   if (! ObjectDelete (chart_ID,name))
     {
       Print ( __FUNCTION__ ,
             ": failed to delete \"Bitmap label\" object! Error code = " , GetLastError ());
       return ( false );
     }
//--- successful execution
   return ( true );
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart ()
  {
//--- chart window size
   long x_distance;
   long y_distance;
//--- set window size
   if (! ChartGetInteger ( 0 , CHART_WIDTH_IN_PIXELS , 0 ,x_distance))
     {
       Print ( "Failed to get the chart width! Error code = " , GetLastError ());
       return ;
     }
   if (! ChartGetInteger ( 0 , CHART_HEIGHT_IN_PIXELS , 0 ,y_distance))
     {
       Print ( "Failed to get the chart height! Error code = " , GetLastError ());
       return ;
     }
//--- define bitmap label coordinates
   int x=( int )x_distance/ 2 ;
   int y=( int )y_distance/ 2 ;
//--- set label size and visibility scope coordinates
   int width= 32 ;
   int height= 32 ;
   int x_offset= 0 ;
   int y_offset= 0 ;
//--- place bitmap label at the center of the window
   if (!BitmapLabelCreate( 0 ,InpName, 0 ,x,y,InpFileOn,InpFileOff,width,height,x_offset,y_offset,InpState,
      InpCorner,InpAnchor,InpColor,InpStyle,InpPointWidth,InpBack,InpSelection,InpHidden,InpZOrder))
     {
       return ;
     }
//--- redraw the chart and wait one second
   ChartRedraw ();
   Sleep ( 1000 );
//--- change label's visibility scope size in the loop
   for ( int i= 0 ;i< 6 ;i++)
     {
       //--- change visibility scope size
      width--;
      height--;
       if (!BitmapLabelChangeSize( 0 ,InpName,width,height))
         return ;
       //--- check if the script's operation has been forcefully disabled
       if ( IsStopped ())
         return ;
       //--- redraw the chart
       ChartRedraw ();
       // 0.3 seconds of delay
       Sleep ( 300 );
     }
//--- 1 second of delay
   Sleep ( 1000 );
//--- change label's visibility scope coordinates in the loop
   for ( int i= 0 ;i< 2 ;i++)
     {
       //--- change visibility scope coordinates
      x_offset++;
      y_offset++;
       if (!BitmapLabelMoveVisibleArea( 0 ,InpName,x_offset,y_offset))
         return ;
       //--- check if the script's operation has been forcefully disabled
       if ( IsStopped ())
         return ;
       //--- redraw the chart
       ChartRedraw ();
       // 0.3 seconds of delay
       Sleep ( 300 );
     }
//--- 1 second of delay
   Sleep ( 1000 );
//--- delete the label
   BitmapLabelDelete( 0 ,InpName);
   ChartRedraw ();
//--- 1 second of delay
   Sleep ( 1000 );
//---
  }

예를 들어 동일한 bmp의 컬러 버전과 그레이스케일 버전을 사용하여 켜짐 및 꺼짐 상태를 표시할 수 있습니다.

참조:

https://docs.mql4.com/constants/objectconstants/enum_object/obj_bitmap_label

두 개의 이미지를 사용한 경우 상태를 설정하는 위치에 코드를 더 게시하세요. 클릭할 수 있게 하시겠습니까? 목표는 무엇입니까?
OBJ_BITMAP_LABEL - Object Types - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
OBJ_BITMAP_LABEL - Object Types - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
OBJ_BITMAP_LABEL - Object Types - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
 
Max Enrik :
아 왜 최근 댓글만 이해가 안가는지 모르겠는데 그게 문제인가요? 그렇다면 어떻게 해결할 수 있습니까?

나는 OrderSend() 함수 가 부울이 아닌 정수를 반환한다는 점을 지적하고 싶었습니다.

티켓 번호 또는 함수가 실패하는 경우 -1은 true 또는 false와 매우 다릅니다.

 

Marco vd Heijden :  

두 개의 이미지를 사용한 경우 상태를 설정하는 위치에 코드를 더 게시하세요. 클릭할 수 있게 하시겠습니까? 목표는 무엇입니까?

우선 좋은 의견 감사합니다. 감사합니다. 내 관심사가 설명되지 않았을 수도 있지만 하나 더 쓰려고 노력할 것입니다.

그래서 저는 항상 'test.mq4'에 코드를 작성하려고 합니다. 그리고 이미 내가 원하는 이미지 2개를 사용하고 있습니다. 그리고 다음과 같은 기능을 가져오고 싶습니다.

  1. State = true(이미지에 ' On '이 표시됨) - 이 함수에 대한 코드를 작성하려는 경우 - 'Stop Loss'가 내 주문에 적용될 수 있습니다.
  2. State = false(이미지에 ' Off '가 표시됨) - 이 함수에 대한 코드를 작성하고 싶은 경우 - 'Stop Loss'를 내 주문에 적용할 수 없습니다.
다른 기능에 이미 ' Bitmap Label Object'를 사용하고 있어도 이 기능을 수행할 수 없으며 다른 기능은 내가 원하는 기능이 완벽하게 작동합니다. 도와주세요.

당신에게 최선을 다합니다.

(내가 .zip 파일을 만들었으므로 내 테스트 .mq4 파일과 2x .bmp 파일 형식을 찾을 수 있습니다. 내 문제를 이해하는 데 도움이 되길 바랍니다.)

파일:
사유: