找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 25|回复: 0

移动的左价签,好玩的实验

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-27 13:24:00 | 显示全部楼层 |阅读模式
#property strict
#property script_show_inputs
input string            InpName="LeftPrice";
input int               InpDate=100;         
input int               InpPrice=10;         
input color             InpColor=clrRed;
input ENUM_LINE_STYLE   InpStyle=STYLE_SOLID;
input int               InpWidth=2;           
input bool              InpBack=false;      
input bool              InpSelection=true;
input bool              InpHidden=true;   
input long              InpZOrder=0;        
bool ArrowLeftPriceCreate(const long            chart_ID=0,   
                          const string          name="LeftPrice",  
                          const int             sub_window=0,      
                          datetime              time=0,            
                          double                price=0,           
                          const color           clr=clrRed,     
                          const ENUM_LINE_STYLE style=STYLE_SOLID,
                          const int             width=1,           
                          const bool            back=false,     
                          const bool            selection=true,
                          const bool            hidden=true,   
                          const long            z_order=0)      
  {

   ChangeArrowEmptyPoint(time,price);

   ResetLastError();

   if(!ObjectCreate(chart_ID,name,OBJ_ARROW_LEFT_PRICE,sub_window,time,price))
     {
      Print(__FUNCTION__,
            ": failed to create the left price label! Error code = ",GetLastError());
      return(false);
     }

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);

   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

   return(true);
  }
bool ArrowLeftPriceMove(const long   chart_ID=0,
                        const string name="LeftPrice",
                        datetime     time=0,           
                        double       price=0)         
  {

   if(!time)
      time=TimeCurrent();
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);

   ResetLastError();

   if(!ObjectMove(chart_ID,name,0,time,price))
     {
      Print(__FUNCTION__,
            ": failed to move the anchor point! Error code = ",GetLastError());
      return(false);
     }

   return(true);
  }
bool ArrowLeftPriceDelete(const long   chart_ID=0,
                          const string name="LeftPrice")
  {

   ResetLastError();

   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": failed to delete the left price label! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }
void ChangeArrowEmptyPoint(datetime &time,double &price)
  {

   if(!time)
      time=TimeCurrent();

   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  }
void OnStart()
  {

   if(InpDate<0 || InpDate>100 || InpPrice<0 || InpPrice>100)
     {
      Print("Error! Incorrect values of input parameters!");
      return;
     }

   int bars=(int)ChartGetInteger(0,CHART_VISIBLE_BARS);

   int accuracy=1000;
   datetime date[];
   double   price[];

   ArrayResize(date,bars);
   ArrayResize(price,accuracy);

   ResetLastError();
   if(CopyTime(Symbol(),Period(),0,bars,date)==-1)
     {
      Print("Failed to copy time values! Error code = ",GetLastError());
      return;
     }
   double max_price=ChartGetDouble(0,CHART_PRICE_MAX);
   double min_price=ChartGetDouble(0,CHART_PRICE_MIN);

   double step=(max_price-min_price)/accuracy;
   for(int i=0;i<accuracy;i++)
      price=min_price+i*step;

   int d=InpDate*(bars-1)/100;
   int p=InpPrice*(accuracy-1)/100;

   if(!ArrowLeftPriceCreate(0,InpName,0,date[d],price[p],InpColor,
      InpStyle,InpWidth,InpBack,InpSelection,InpHidden,InpZOrder))
     {
      return;
     }

   ChartRedraw();
   Sleep(1000);


   int v_steps=accuracy*4/5;

   for(int i=0;i<v_steps;i++)
     {

      if(p<accuracy-1)
         p+=1;

      if(!ArrowLeftPriceMove(0,InpName,date[d],price[p]))
         return;

      if(IsStopped())
         return;

      ChartRedraw();
     }

   Sleep(1000);

   ArrowLeftPriceDelete(0,InpName);
   ChartRedraw();

   Sleep(1000);

  }


复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-10 14:11 , Processed in 0.098781 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表