文章 "创建一个在若干工具上交易的 EA 交易程序" - 页 3

 

6.Seems to be missing:

TradePerformer(4, Symb4, Trade4, StLoss4, TkProfit4, Lots4, Slippage4, UpSignal, DnSignal, UpStop, DnStop);

在 Exp_TEMA.mq5 中 ?

 
ias:

6.似乎缺失

Exp_TEMA.mq5?

是的!我一定是工作得太辛苦了,在如此不正常的高温下过热!
 
Renat:

请制作一个可重复的示例。也就是说,你需要现成的代码,你可以编译,扔到图表上并得到结果。

没有这个,很少有人会明白我们在说什么。

我想我还是少说两句,免得让大家白跑一趟。

下面是完整版:

#property indicator_separate_window    // 指示器在单独窗口中绘制
#property indicator_buffers 1



#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1  Aqua

input string InstrumentName = "EURJPY";

//-- 指标数组
double ScreenBuffer[]; 

//-- 动态缓冲区 --
double ArrayBuffer[];

int OnInit()                          // 特殊 init() 函数
{
//--------------------------------------------------------------------

   IndicatorSetString(INDICATOR_SHORTNAME,InstrumentName);
   SetIndexBuffer(0,ScreenBuffer,INDICATOR_DATA);
   return 0;                          // 退出
}
//--------------------------------------------------------------------
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[])
{
int Counted_bars;   // 运行的条数 
int copied;

//--------------------------------------------------------------------
   //1 input rates_total = 9667 / prev_calculated = 0 / Bars = 9667
   //-- then rates_total = 9667 / prev_calculated = 9667 / Bars = 9667
   //-- in process then rates_total = 9668 / prev_calculated = 9667 / Bars = 9668
   //Print("rates_total: " + (string)rates_total);
   if (rates_total == prev_calculated) return (rates_total);//-- 还是那个酒吧 所以我们不玩了

   //-- 获取未处理条数(第一次输入时为全部,然后为 1)
   //-- 输出条数指的是图表本身,但我们将输出另一个工具
   //--条数可能不同,因此我们首先将所有数据转储到缓冲区 --
   Counted_bars = rates_total-prev_calculated;
   
   // Print("Counted_bars: " + Counted_bars);
   Print("rates_total: " + rates_total + "   /   prev_calculated: " + prev_calculated + "   /   Bars: " + Bars(Symbol(),0));
   //-- 按照主乐器的小节数分配内存 ----
   if (ArrayResize(ArrayBuffer, Counted_bars,0) == -1) return (rates_total);//-- 内存分配错误 --
   //--- 使用 EMPTY_VALUE 值初始化数组元素 ----
   ArrayInitialize(ArrayBuffer,EMPTY_VALUE);
         
   //-- 获取该仪器实际有多少小节 --
   copied = (int)SeriesInfoInteger(InstrumentName,0,SERIES_BARS_COUNT);
   
   if (copied > 0){
      copied=CopyClose(InstrumentName,0,0,copied,ArrayBuffer);//-- 将数据写入内存缓冲区 --
      if (copied <= 0) return (rates_total);//-- 错误
   } 
   else{

      return (rates_total);//-- 错误 
   }
    
   if (Counted_bars > copied) Counted_bars = copied;//-- 取较低值 --

   Counted_bars--;//-- 从 0 开始计数 --
   //-- 数据已载入内存缓冲区,现在从右向左将其写入屏幕缓冲区。
   for (int i = Counted_bars; i > 0; i--){
      ScreenBuffer[i] = ArrayBuffer[i];
   }   
   
//--------------------------------------------------------------------
   return(rates_total);
}


void OnDeinit(const int reason)
{
   ObjectsDeleteAll(0,0,-1);             // 图表中的所有对象都会被删除。
}
 

我做错了什么?为什么我不能正常显示另一个工具的图表?

在 MQL4 中一切正常,而在这里只有在同一工具上显示时才能正常,而且不会出错。

[删除]  
gisip:

我做错了什么?为什么我不能正常显示另一个工具的图表?

在 MQL4 中一切正常,而在这里只有在同一工具上显示时才能正常,而且不会出错。


我不确定实现和算法总体上是否正确,但根据代码和我能用它做的事情,我认为是这样的:

字符串

// Print("Counted_bars: " + Counted_bars);
Print("rates_total: " + rates_total + "   /   prev_calculated: " + prev_calculated + "   /   Bars: " + Bars(Symbol(),0));

应该是这样的

// Print("Counted_bars: " + Counted_bars);
Print("rates_total: " + rates_total + "   /   prev_calculated: " + prev_calculated + "   /   Bars: " + Bars(InstrumentName,Period()));


也许把所有地方的句点 "0 "改为PERIOD_CURRENT 会更正确。

至少在这样改动之后,我的一切工作都正常了.....。

PS

也许这无关紧要,但这样编译器就不那么重要了

Print("rates_total: ",rates_total," / prev_calculated: ",prev_calculated," / Bars: ",Bars(InstrumentName, PERIOD_CURRENT));
 
Interesting:

我不确定正确的实现方式和算法,但根据代码和我能做的事情,我可以这么认为:

字符串

应该是这样的

PS

也许把所有地方的句点都改为 "0",改为 PERIOD_CURRENT 会更正确。

至少在这样改动之后,我的一切工作都正常了....。

改了,还是不行,图表与实际不符。
 

在我的屏幕上看起来是这样的:


显然是错误的。
[删除]  

我的结果是这样的

但由于我没有深入研究诱导器的逻辑及其实现,因此我无法判断结果的正确性。


PS

我还是会去掉参数中的符号,用当前符号和 TF 来表示,然后在 Expert Advisor 或其他工具中使用通常的 iCustom()。

此外,我并不真正了解缓冲区(我指的是计算器尾部等)的工作逻辑。在我看来,还有很多工作要做....。

附加的文件:
proba.mq5  4 kb
 
Interesting:

这就是我的收获

但由于我没有深入研究诱导器的逻辑及其实现,因此我无法判断结果的正确性。


PS

我还是会去掉参数中的符号,根据当前符号和 TF 制作,然后在 Expert Advisor 或其他工具中使用通常的 iCustom()。


谢谢您的建议,我会试试的。
[删除]  

Interesting:

此外,我也不太了解缓冲区的工作逻辑(我指的是计算器的尾部等)。在我看来,还有很多工作要做....。


如果我理解正确,一个缓冲区就足够了(只需正确计算并绘制在图表上)。

PS

对于当前的变体,我的印象是诱导器显示的是 "左 "数据(历史的开端),而不是 "右 "数据(当前)....。

或者说我完全不理解这个指标的逻辑....。