在过去36个高点中的最高点上画出H_线

 

你好

我试着在代码中这样写。

当随机指数(80,30,30)的K%线>75时,回看36个柱子(34,shift 2)并从最高点到当前柱子画一条H_line "tomato"。

当随机指数(80,30,30)的K%线<25时,回看36个柱子(34,shift 2),并从最低点到当前柱子画一条H_线 "橄榄"。

int start()
  {

double stoch;
stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);

double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,2);
low_price=Low[low_nr];

/////////////////////////////////////////////////////////////////////////////////
for(high_nr=2;high_nr<36;high_nr++)
{

   if(Bid<high_price && stoch>75)
     {
      ObjectCreate("tomato",OBJ_TREND,0,Time[high_nr],high_price,Time[0],high_price);
      ObjectSet("tomato",OBJPROP_COLOR,Tomato);
      Print ("tomato ON"+high_price);
     }
       
}
///////////////////////////////////////////////////////////////////////////////
for(low_nr=2;low_nr<36;low_nr++)
{
if(Bid>low_price && stoch<25)
   {
   ObjectCreate("olive",OBJ_TREND,0,Time[low_nr],low_price,Time[0],low_price);
   ObjectSet("olive",OBJPROP_COLOR,Olive);
   Print ("olive ON"+low_price);
   }
}   
   
   
//----
   
//----
   return(0);
  }

当我运行这个程序时,我得到了番茄和橄榄的第一个设置,然后即使在日志中我得到了 "番茄开 "不同的价格水平,我也没有在图表上得到新的番茄线。 橄榄的情况也一样。

该EA的想法是利用这些线来进行交易,所以我最终想要的是这样。

当K%>75

绘制 最高的线(过去36条)。

如果线打开,不再画线,直到线被删除。

如果有交易开启,则删除该线

如果没有交易,并且从决定K%>75的那根柱子算起已经过了24根柱子,也要删除这根线。

:)

这是我人生中写的第一个代码,请教我如何看待这个问题。

谢谢你

 

需要不同的名字

      ObjectCreate("tomato " + high_nr,OBJ_TREND,0,Time[high_nr],high_price,Time[0],high_price);
      ObjectSet("tomato " + high_nr,OBJPROP_COLOR,Tomato);
 

之后

   ObjectCreate("olive"+low_nr,OBJ_TREND,0,Time[low_nr],low_price,Time[0],low_price);
   ObjectSet("olive"+low_nr,OBJPROP_COLOR,Olive);

代码放了25行,在相同的价格上,但不是从蜡烛的低点(总是10,无所谓哪个是 stoch <25后的真实数字)开始,而是从蜡烛的35开始。

西红柿也是如此。

:(

 

一旦一个对象被创建,你就不能以相同的名字创建另一个对象。

这就是为什么在第一次创建时可以正常工作,但之后就不行了(在你的原始代码中)。

如果你只想让符合标准的最后一行显示在图表上,在init中创建该行,然后使用ObjectMove 将该对象移动到新的坐标。

如果你想让所有过去的线都显示出来。

ObjectCreate("tomato " + high_nr,OBJ_TREND,0,Time[high_nr],high_price,Time[0],high_price);

由于high_nr是条形转换,它可能会在以后的时间里被复制,所以不会正常工作。在名称中使用日期时间,那么它将是唯一的。

 
具体说明 你要 完成的任务吗?
 
cichichan:

你好

我试着在代码中这样写。

当随机指数(80,30,30)的K%线>75时,回看36个柱子(34,shift 2)并从最高点到当前柱子画一条H_line "tomato"。

当随机指数(80,30,30)的K%线<25时,回看36个柱子(34,shift 2),并从最低点到当前柱子画一条H_线 "橄榄"。

当我运行这个程序时,我得到了番茄和橄榄的第一个设置,然后即使在日志中我得到了 "番茄开 "不同的价格水平,我也没有在图表上得到新的番茄线。 橄榄的情况也一样。

该EA的想法是利用这些线来进行交易,所以我最终想要的是这样。

当K%>75

绘制最高的线(过去36条)。

如果线打开,不再画线,直到线被删除。

如果有交易开启,则删除该线

如果没有交易,并且从决定K%>75的那根柱子算起已经过了24根柱子,也要删除这根线。

:)

这是我人生中写的第一个代码,请教我如何看待这个问题。

谢谢你

我们从头开始.....

double stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);

在小节0处,STOCH可以在小节0处的某处数值>75,并以较低的数值结束。

在这种情况下,它是否要画一条线?还是只针对收盘价随机结束?

double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,2);
low_price=Low[low_nr];

曾经使用过iHighest和/或iLowest吗? 请看如何做iHighestiLowest

if(stoch > 75) high_price = High[iHighest(NULL,0,MODE_HIGH,......

如果(stoch < 25) low_price = Low[iLowest(........)

//-----

for(high_nr=2;high_nr<36;high_nr++)   // why do you repeat this ??
{

   if(Bid<high_price && stoch>75)
     {
      ObjectCreate("tomato",OBJ_TREND,0,Time[high_nr],high_price,Time[0],high_price);
      ObjectSet("tomato",OBJPROP_COLOR,Tomato);
      Print ("tomato ON"+high_price);
     }
       
}

一次创建就足够了 .... 循环只重复{ }中的内容。

所以不需要循环....

然后在你创建之前

  • 检查正在运行的交易
  • 检查名称以 "tomato "开头的对象是否已经存在,如果存在则检查是否必须删除旧的对象。

创建一个名字的时刻,你要让它像

linenamehigh =     "tomato  "+ TimeToStr(Time[0],TIME_DATE|TIME_MINUTES)

检查你的对象是否可以用

//----
   int i, ot=ObjectsTotal()-1;
   string id;
//----
   for(i=ot;i>=0;i--)
    {id=ObjectName(i);
     if(StringSubstr(id,0,7)=="tomato ")
      {
      //check when created 
      if(StringSubstr(id,8,...)< TimeToStr(Time[24],........)){ObjectDelete(id);}
      }  
     if(StringSubstr(id,0,6)=="olive ")
         {
         //.....
         }
    }

点击链接并尝试了解发生了什么

在代码中带有....... 的地方,你可以试着自己填上。

 
qjol:
说明 你要 完成的 任务


最后的想法。

信号1 = 当K%>75,并且bar[1]和当前bar[0]的高点小于过去36个bar的最高点(High_point)时。

在High_point上画番茄线

如果已经画了番茄线,则不再画线,直到该线被删除。

如果使用番茄线的交易已经开始,则删除该线。

如果没有交易,并且从决定 高点 那根柱子开始已经过了96根柱子 ,则删除该线。

现在,我在每个信号1上只得到一条线(Print函数 在每个有效的tick上发送36个 "tomato ON",我猜),所以我必须告诉代码在找到tomato线后停止循环。我去煮一些意大利面条,想想我应该怎么写......在我脑子里这应该是下一步.... 希望我没有错过什么 :)

非常感谢你的帮助和建议,我在正确的轨道上吗?

到现在为止的代码。

//+------------------------------------------------------------------+
//|                                                      1expert.mq4 |
//|                                                              ant |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "ant"
#property link      ""

#property indicator_chart_window

extern int Kperiod = 80;
extern int Dperiod = 30;
extern int Stochshift = 30;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

double stoch;
stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);

double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,2);
low_price=Low[low_nr];
datetime H=Time[high_nr];
datetime L=Time[low_nr];

/////////////////////////////////////////////////////////////////////////////////
for(high_nr=2;high_nr<36;high_nr++)
{

   if(Bid<high_price && High[0]<high_price && High[1]<high_price && stoch>75)
     {
      ObjectCreate("tomato"+H,OBJ_TREND,0,H,high_price,Time[0],high_price);
      ObjectSet("tomato"+H,OBJPROP_COLOR,Tomato);
      Print ("tomato ON"+H);
     }
       
}
///////////////////////////////////////////////////////////////////////////////
for(low_nr=2;low_nr<36;low_nr++)
{
if(Bid>low_price && Low[0]>low_price && Low[1]>low_price && stoch<25)
   {
   ObjectCreate("olive"+L,OBJ_TREND,0,L,low_price,Time[0],low_price);
   ObjectSet("olive"+L,OBJPROP_COLOR,Olive);
   Print ("olive ON"+low_price);
   }
}   
   
   
//----
   
//----
   return(0);
  }
 

我和deVries 的帖子是同时发的。

我去看了:)

 
double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,2);
low_price=Low[low_nr];
datetime H=Time[high_nr];
datetime L=Time[low_nr];

if (stoch > 75 && High[1] < High[high_nr] && High[0] < High[high_nr])
   {
   ObjectCreate("tomato"+H,OBJ_TREND,0,Time[H],high_price,Time[0],High[0]);
   ObjectSet("tomato"+H,OBJPROP_COLOR,Tomato);
   Print ("tomato ON"+H);   
   }

B.T.W.不需要线来做它

 

你所说的cichichan的情况很少会发生,所以你必须使用一个索引,这样你就可以看到你所做的事情。

http://charts.mql5.com/3/799/eurusd-h1-fxpro-financial-services.png

arrow_down不显示,在某处有一个bug....。

//+------------------------------------------------------------------+
//|                                                      lexpert.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "ant"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 8
#property  indicator_color1 YellowGreen  
#property  indicator_color2 Coral


extern int Kperiod = 80;
extern int Dperiod = 30;
extern int Stochshift = 30;

 double arrow_up[];
 double arrow_down[];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   //-------- 
   SetIndexBuffer(0, arrow_up );
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID,2);
   SetIndexArrow(0,233);
   SetIndexEmptyValue(0,0.0);
//-------- 
   SetIndexBuffer(1,arrow_down);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID,2);
   SetIndexArrow(1,234 );
   SetIndexEmptyValue(1,0.0);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

   int    limit;
   int    counted_bars=IndicatorCounted();

   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   //---- macd counted in the 1-st additional buffer
   for(int i=limit; i>=0; i--)
      { 

double stoch_1, stoch_2;
stoch_2=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,i+2);
stoch_1=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,i+1);

double high_price,low_price;
int high_nr,low_nr;
high_nr=iHighest(NULL,0,MODE_HIGH,34,i+2);
high_price=High[high_nr];
low_nr=iLowest(NULL,0,MODE_LOW,34,i+2);
low_price=Low[low_nr];
datetime H=Time[high_nr];
datetime L=Time[low_nr];

/////////////////////////////////////////////////////////////////////////////////


   if(Bid<high_price && High[i]<high_price && High[i+1]<high_price && stoch_2<75 && stoch_1 >75)
     {
     arrow_down[i] =  High[i] + 5*iATR(NULL,0,200,i);
      ObjectCreate("tomato"+H,OBJ_TREND,0,H,high_price,Time[i],high_price);
      ObjectSet("tomato"+H,OBJPROP_RAY_RIGHT, false);
      ObjectSet("tomato"+H,OBJPROP_WIDTH,5 ); 
      ObjectSet("tomato"+H,OBJPROP_COLOR,Tomato);
      Print ("tomato ON"+H);
     }
    else    arrow_down[i] = 0.0;

///////////////////////////////////////////////////////////////////////////////

if(Bid>low_price && Low[i]>low_price && Low[i+1]>low_price &&  stoch_2>25 && stoch_1 < 25)
   {
   arrow_up[i] = Low[i] - 5*iATR(NULL,0,200,i);
   ObjectCreate("olive"+L,OBJ_TREND,0,L,low_price,Time[i],low_price);
   ObjectSet("olive"+L,OBJPROP_COLOR, Yellow );
   ObjectSet("olive"+L,OBJPROP_WIDTH,5 );
   ObjectSet("olive"+L,OBJPROP_RAY_RIGHT, false);
   Print ("olive ON"+low_price);
   }
   else  arrow_up[i] = 0.0;
   
//----
  } 
//----
   return(0);
  }
 
绝接受其N项指示,不接受EA。