OBJ_VLINE

 

여보세요,

지표에서 그래픽 개체를 사용한 것은 이번이 처음입니다. 매일 "22:00"에 수직선 을 그려야 하는데, 해결 방법을 알려주실 수 있나요?

감사해요

 
desert :

여보세요,

지표에서 그래픽 개체를 사용한 것은 이번이 처음입니다. 매일 "22:00"에 수직선을 그려야 하는데, 해결 방법을 알려주실 수 있나요?

감사해요

VLine 대신 Cycles를 사용하십시오.

안부, 루크

 
for (int shift22=0; shift22<Bars && TimeHour(Time[shift22])!=22; shift22++){}
VLine("2200", Time[shift22] %3600, Red); // %3600 needed for M30 and lower
===================================
void vLine(string name, datetime T0, color clr){        #define WINDOW_MAIN 0
    if (!Show.Objects)  return;
    /**/ if (ObjectMove( name, 0, T0, 0 )){}
    else if(!ObjectCreate( name, OBJ_VLINE, WINDOW_MAIN, T0, 0 ))
        Alert("ObjectCreate(",name,",VLINE) failed: ", GetLastError() );
    if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [1] failed: ", GetLastError() );
    if (!ObjectSetText(name, TimeToStr(T0, TIME_MINUTES), 10))
        Alert("ObjectSetText(",name,") [1] failed: ", GetLastError());
}
 

안녕하세요 여러분,

다른 코드로 문제를 해결할 수 있지만(사실 위에 제공된 솔루션을 적용할 수 없음) 전혀 그렇지 않았습니다.

이제 이전의 모든 22:00 양초에 대한 수직선 을 얻었지만 가격(미래)의 오른쪽에 오는 22:00 양초의 선이 필요합니다. 어떻게 얻을 수 있습니까?

이것은 코드입니다:

...

(shift=NumBars;shift>=0;shift--)

{
if (TimeHour(Time[shift])== 오프셋 && TimeMinute(Time[shift])==0)
{
if(ObjectFind("오프셋"+shift) != 0)
{
ObjectCreate("오프셋"+shift, OBJ_VLINE, 0, 시간[shift], 0);
ObjectSet("오프셋"+shift, OBJPROP_STYLE, STYLE_DASHDOTDOT);
ObjectSet("오프셋"+shift, OBJPROP_COLOR, 흰색);
}
}

}

돕다!

감사해요 :)

 

이것을 사용하여 코드를 게시하십시오. . . 읽기 쉽게 만듭니다.

 
desert :
이제 이전의 모든 22:00 양초에 대한 수직선을 얻었지만 가격(미래)의 오른쪽에 오는 22:00 양초의 선이 필요합니다. 어떻게 얻을 수 있습니까?
  1. 다음에는 원래 질문으로 더 정확합니다.
  2.  datetime now = Time[ 0 ],
             bod = now - now % 86400 ,   // Beginning of the day
             Hr22= bod + 22 * 3600 ;     // 2200
    VLine( "2200" , Hr22, Red );
 
WHRoeder :
  1. 다음에는 원래 질문으로 더 정확합니다.
매우 감사합니다!
 

날짜만 알고 차트 오른쪽에 세로선을 현재 가격에서 멀어지게 그릴 수 있습니까?

예를 들어 현재 시간 이 2019.05.17 00:00이라고 가정하고 날짜 정보만 사용하여 미래의 2019.06.04 16:00에 수직선을 그리고 싶습니다.

 

네.

Use ObjectCreate ( and OBJ_VLINE

또는 예를 들어 이 기능 을 사용하십시오.

 //+------------------------------------------------------------------+ 
//| Create the vertical line                                         | 
//+------------------------------------------------------------------+ 
bool VLineCreate( const long             chart_ID= 0 ,         // chart's ID 
                 const string           name= "VLine" ,       // line name 
                 const int              sub_window= 0 ,       // subwindow index 
                 datetime               time= 0 ,             // line time 
                 const color            clr= clrRed ,         // line color 
                 const ENUM_LINE_STYLE style= STYLE_SOLID , // line style 
                 const int              width= 1 ,           // line width 
                 const bool             back= false ,         // in the background 
                 const bool             selection= true ,     // highlight to move 
                 const bool             ray= true ,           // line's continuation down 
                 const bool             hidden= true ,       // hidden in the object list 
                 const long             z_order= 0 )         // priority for mouse click 
  { 
//--- if the line time is not set, draw it via the last bar 
   if (!time) 
      time= TimeCurrent (); 
//--- reset the error value 
   ResetLastError (); 
//--- create a vertical line 
   if (! ObjectCreate (chart_ID,name, OBJ_VLINE ,sub_window,time, 0 )) 
     { 
       Print ( __FUNCTION__ , 
             ": failed to create a vertical line! Error code = " , GetLastError ()); 
       return ( false ); 
     } 
//--- set line color 
   ObjectSetInteger (chart_ID,name, OBJPROP_COLOR ,clr); 
//--- set line display style 
   ObjectSetInteger (chart_ID,name, OBJPROP_STYLE ,style); 
//--- set line width 
   ObjectSetInteger (chart_ID,name, OBJPROP_WIDTH ,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 line by mouse 
//--- when creating a graphical object using ObjectCreate function, the object cannot be 
//--- highlighted and moved by default. Inside this method, selection parameter 
//--- is true by default making it possible to highlight and move the object 
   ObjectSetInteger (chart_ID,name, OBJPROP_SELECTABLE ,selection); 
   ObjectSetInteger (chart_ID,name, OBJPROP_SELECTED ,selection); 
//--- enable (true) or disable (false) the mode of displaying the line in the chart subwindows 
   ObjectSetInteger (chart_ID,name, OBJPROP_RAY ,ray); 
//--- 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 ); 
  } 
//+------------------------------------------------------------------+ 
 
Marco vd Heijden :

네.

또는 예를 들어 이 기능 을 사용하십시오.

Marco에게 감사합니다. 작동하지 않았습니다. 전체 코드를 게시하겠습니다. 경고에 올바른 날짜가 있지만 해당 날짜에 행을 만들 수 없다는 경고가 표시됩니다.

내가 달성하려는 것은 시장이 닫히고 브로커와 연결되지 않은 VPS에서 MT4가 열릴 때 정보가 손실되는 경우와 같이 차트에 있는 정보를 저장하는 것입니다.
그래서 주말 전에 차트의 미래 섹션(맨 오른쪽)에 있는 선을 유지하고 싶습니다. 차트에 기호를 만들고 해당 기호의 날짜를 저장한 다음 해당 날짜를 사용하여 선을 다시 만듭니다. .. 선을 다시 만드는 부분을 제외하고는 모두 좋은데 누군가가 그것을 도울 수 있는지 궁금합니다.

 //+------------------------------------------------------------------+
//|                                                    TestLines.mq4 |
//|                                             Copyright 2019, Alfa |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, Alpha"
#property version    "1.00"
#property strict


datetime PreTradeDOT, Symb_Chart_Dates, Exit_SymDOT;
string    Exit_SymSymbol = "Exit_Sym" , ExitLine = "Exit" ;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
{
//---
     OnTick ();
//---
     return ( INIT_SUCCEEDED );
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick ()
{
//---Object creation
     ObjectCreate ( 0 , Exit_SymSymbol, OBJ_ARROW_DOWN , 0 , Time[ 0 ] + Period () * 60 * 40 , High[ 0 ]);
    ObjectSet(Exit_SymSymbol, OBJPROP_COLOR , Red);
    ObjectSet(Exit_SymSymbol, OBJPROP_STYLE , STYLE_SOLID );
    ObjectSet(Exit_SymSymbol, OBJPROP_WIDTH , 3 );
    ObjectSet(Exit_SymSymbol, OBJPROP_RAY , false );
    ObjectSet(Exit_SymSymbol, OBJPROP_BACK , True);
    ObjectSet(Exit_SymSymbol, OBJPROP_NAME , True);
    ObjectSet(Exit_SymSymbol, OBJPROP_TEXT , True);
    ObjectSetText(Exit_SymSymbol, "Exit_SymSymbol" , 1 );


     datetime TimeExit_SymSymbol = ( datetime ) ObjectGetInteger ( 0 , Exit_SymSymbol, OBJPROP_TIME1);
     string    TxtExit_SymSymbol  = TimeToStr(TimeExit_SymSymbol, TIME_DATE | TIME_SECONDS );

//---
     if ( ObjectFind ( 0 , Exit_SymSymbol) == 0 ) // Object is found on main screen when its ==0
    {
        Exit_SymDOT = ( datetime ) ObjectGetInteger ( 0 , Exit_SymSymbol, 0 , 0 );
         //Alert(Exit_SymDOT );
        SaveDates();
    }
     if ( ObjectFind ( 0 , ExitLine) != 0 )
    {
        ReadDates();

         datetime Symb_Dates = StringToTime ( StringSubstr (Symb_Chart_Dates, 0 , 16 )); // OK
   



         Alert (Symb_Dates);

        VLineCreate( 0 , "VLine" , 0 , Symb_Dates, clrRed , STYLE_SOLID , 1 , false , true , true , true , 0 );


/*
       // ObjectCreate(0,ExitLine, OBJ_VLINE, 0, StringToTime(Symb_Dates), Low[0]);
        ObjectCreate(ExitLine, OBJ_VLINE, 0, StringToTime( Symb_Dates), Low[0]);

       // ObjectCreate(vLine, OBJ_VLINE, 0, Time[0] + (Symb_Dates-TimeCurrent()) , Low[0]);
        //ObjectCreate( ExitLine, OBJ_VLINE, 0, Symb_Dates, 0 );
        ObjectSet(ExitLine, OBJPROP_COLOR, Orange);
        ObjectSet(ExitLine, OBJPROP_STYLE, STYLE_SOLID);
        ObjectSet(ExitLine, OBJPROP_WIDTH, 3);
        ObjectSet(ExitLine, OBJPROP_RAY, false);
        ObjectSet(ExitLine, OBJPROP_BACK, True);

 */
    }
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//-- Function:  ReadSpread
//+------------------------------------------------------------------+
void ReadDates()
{
     string fileName = getFileName( 1 );
     int     file     = FileOpen (fileName, FILE_CSV | FILE_READ );
//--- This is a protection to avoid low spread and also for the expert
//--- if the file has not been created then create a new file

    Symb_Chart_Dates    = ( datetime ) ObjectGetInteger ( 0 , Exit_SymSymbol, OBJPROP_TIME1, 0 );
   
     int ShiftEntryBar = 10 , TradeExit_SymBar = 30 ;
     if (file <= - 1 )
    {
        Exit_SymDOT = Time[ 0 ] + Period () * 60 * TradeExit_SymBar;

        SaveDates();
    }
//--- If there is a file then save the spreads
     if (file > 0 )
    {
        Symb_Chart_Dates    = FileReadNumber (file);
         FileClose (file);
    }
}


//
//+------------------------------------------------------------------+
//-- Function:  saveSpread
//+------------------------------------------------------------------+
void SaveDates()
{
     string fileName = getFileName( 1 );
     int     file     = FileOpen (fileName, FILE_CSV | FILE_WRITE );
     if (file > 0 )
    {
         FileWrite (file, PreTradeDOT, Symb_Chart_Dates, Exit_SymDOT);
         FileClose (file);
    }
}



//+--------------------------------------------------------------------------------------------------+
//--                                   Function:  getFileName
//+--------------------------------------------------------------------------------------------------+
string getFileName( int FileNo)
{
     string filename;
//--- The spread file will be used for all time frames
     if (FileNo == 1 )
        filename = " # " + "Lines" + ".txt" ;   // spread file

     return (filename);
}





//+------------------------------------------------------------------+
//| Create the vertical line                                         |
//+------------------------------------------------------------------+
bool VLineCreate( const long chart_ID = 0 ,                   // chart's ID
                 const string name = "VLine" ,               // line name
                 const int sub_window = 0 ,                   // subwindow index
                 datetime time = 0 ,                         // line time
                 const color clr = clrRed ,                   // line color
                 const ENUM_LINE_STYLE style = STYLE_SOLID , // line style
                 const int width = 1 ,                       // line width
                 const bool back = false ,                   // in the background
                 const bool selection = true ,               // highlight to move
                 const bool ray = true ,                     // line's continuation down
                 const bool hidden = true ,                   // hidden in the object list
                 const long z_order = 0 )                     // priority for mouse click
{
//--- if the line time is not set, draw it via the last bar
     if (!time)
        time = TimeCurrent ();
//--- reset the error value
     ResetLastError ();
//--- create a vertical line
     if (! ObjectCreate (chart_ID, name, OBJ_VLINE , sub_window, time, 0 ))
    {
         Print ( __FUNCTION__ ,
               ": failed to create a vertical line! Error code = " , GetLastError ());
         return ( false );
    }
//--- set line color
     ObjectSetInteger (chart_ID, name, OBJPROP_COLOR , clr);
//--- set line display style
     ObjectSetInteger (chart_ID, name, OBJPROP_STYLE , style);
//--- set line width
     ObjectSetInteger (chart_ID, name, OBJPROP_WIDTH , 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 line by mouse
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
     ObjectSetInteger (chart_ID, name, OBJPROP_SELECTABLE , selection);
     ObjectSetInteger (chart_ID, name, OBJPROP_SELECTED , selection);
//--- enable (true) or disable (false) the mode of displaying the line in the chart subwindows
     ObjectSetInteger (chart_ID, name, OBJPROP_RAY , ray);
//--- 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 );
}
//+------------------------------------------------------------------+
 
Alpha Beta :

날짜만 알고 차트 오른쪽에 세로선을 현재 가격에서 멀어지게 그릴 수 있습니까?

예를 들어현재 시간 이 2019.05.17 00:00이라고 가정하고 날짜 정보만 사용하여 미래의 2019.06.04 16:00에 수직선을 그리고 싶습니다.

D' 형식을 사용하여 ObjectCreate() 에서 원하는 시간 설정

 ObjectCreate ( 0 , "v_line" , OBJ_VLINE , 0 , D'2019.06.04 16:00' , 0 );
사유: