如何编码? - 页 62

 
Dan7974:
我如何编写这个代码?

如果市场触及(X.XX50或X.XX00)

则买入。如何识别最后两个数字?

谢谢。

这应该是可以的。

if ( Point == 0.01 ) {xPrice = Close - MathMod(Close,0.50) ; }

else { xPrice = Close - ( MathMod(100*Close,0.50)*0.01 ) ; }

P1Buffer = xPrice + Point*50;

P2Buffer = xPrice ;

P3Buffer = xPrice - Point*50;

[/CODE]

When MathMod(Close,0.50) = 0 then the price ends in 00 or 50.

Here's my indicator to identify 00 lines:

[CODE]

//+------------------------------------------------------------------+

//| _TRO_00_Lines |

//| |

//| |

//+------------------------------------------------------------------+

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 LightGray

#property indicator_color2 LightGray

#property indicator_color3 LightGray

// indicators parameters

//---- buffers

double P1Buffer[];

double P2Buffer[];

double P3Buffer[];

double xPrice ;

int myStyle = 2 ;

int myWingDing = 250 ;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

SetIndexBuffer(0, P1Buffer);

SetIndexBuffer(1, P2Buffer);

SetIndexBuffer(2, P3Buffer);

SetIndexArrow(0, myWingDing);

SetIndexArrow(1, myWingDing);

SetIndexArrow(2, myWingDing);

SetIndexStyle(0, DRAW_ARROW, myStyle, 1);

SetIndexStyle(1, DRAW_ARROW, myStyle, 1);

SetIndexStyle(2, DRAW_ARROW, myStyle, 1);

SetIndexEmptyValue(0,0);

SetIndexEmptyValue(1,0);

SetIndexEmptyValue(2,0);

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int i, dayi, counted_bars = IndicatorCounted();

//---- check for possible errors

if(counted_bars < 0)

return(-1);

//---- last counted bar will be recounted

if(counted_bars > 0)

counted_bars--;

int limit = Bars - counted_bars;

//----

for(i = limit - 1; i >= 0; i--)

{

if ( Point == 0.01 ) {xPrice = Close - MathMod(Close,1.00) ; }

else { xPrice = Close - ( MathMod(100*Close,1.00)*0.01 ) ; }

P1Buffer = xPrice + Point*100;

P2Buffer = xPrice ;

P3Buffer = xPrice - Point*100;

} // for

return(0);

} // start
 

不过我需要它来做一个EA!

 

编码员请帮助

如何修改代码以使蜡烛图中的上下点位更多?

附加的文件:
diagram.gif  18 kb
 

如果你贴出代码,有人可能真的会帮助你。

卢克斯

 

以下是该指标

指标,你可以改变代码,使之成为上下移动的圆点

附加的文件:
 

正确使用Time[]

我是一个普通的程序员,但对mql4是新手。 我正在做一个箱体交易(又称突破交易)专家顾问。 从本质上讲,它应该找到一个特定时间框架的最高值和最低值,当蜡烛收盘时,在该箱体之外,我就会进行交易。

基本上有三种状态,我可以启动我的EA

1)在前一天收盘后,在箱体开始时间之前。

2)在箱体开始后但在箱体结束前。

3)箱体结束后。

我发现令人困惑的是Time[]数组,因为索引一直在变化。 假设我在状态2进入。 在init函数 中,我打算设置一个全局变量,给出盒子开始的位置。 当引号进入时,我的start函数被不断调用,一旦到达盒子的结束时间,我就会得到开始和结束的位置。 当然,情况并非如此,因为时间数组上的索引不断向前滚动。

充其量我可以不断地增加盒子的起始索引的位置,但这似乎不是一个非常干净的方法。

如果你有什么建议,我应该如何改变我的思维,从传统的c/c++到mql4,我很想听听。

另外,当我完成后,我显然会从一个更资深的程序员的代码审查中获益匪浅。 有谁愿意做这个志愿者吗?

谢谢你的时间。

马库斯

 
mweltin:
我是一个合格的程序员,但对mql4是个新手。 我正在做一个箱体交易(又称突破交易)专家顾问。 从本质上讲,它应该找到特定时间段的最高值和最低值,当蜡烛收盘时,在该箱体之外,我将进行交易。

基本上有三种状态,我可以启动我的EA

1)在前一天收盘后,在箱体开始时间前。

2)盒子开始后,但在盒子结束前。

3)箱体结束后。

我发现令人困惑的是Time[]数组,因为索引一直在变化。 假设我在状态2进入。 在init函数中,我打算设置一个全局变量,给出盒子开始的位置。 当引号进入时,我的start函数被不断调用,一旦到达盒子的结束时间,我就会得到开始和结束的位置。 当然,情况并非如此,因为时间数组上的索引不断向前滚动。

充其量我可以不断地增加盒子的起始索引的位置,但这似乎不是一个非常干净的方法。

如果你有什么建议,我应该如何改变我的思维,从传统的c/c++到mql4,我很想听听。

另外,当我完成后,我显然会从一个更资深的程序员的代码审查中获益匪浅。 有谁愿意做这个志愿者吗?

谢谢你的时间。

马库斯

你好,Time[]函数 不会一直变化--只有在当前图表条的末端才会变化。 另一方面,TimeCurrent()返回一个持续变化的值(尽管,分辨率为1秒)。

你也可以使用iTime()来获得任何条形和时间框架的确切时间。 有相当多的方法可以去做...

 

在同一时间打开两个订单(问题...)。

嗨,我不知道为什么在某些机会下,脚本会在同一时间打开两个订单。

谁能帮助我解决这个问题,请

if(UseStopLoss)

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,EAName, MagicNo, 0,Green)。

否则

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,EAName,MagicNo,0,Green) 。

如果(ticket>0)

{

如果(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))Print("BUY订单打开:",OrderOpenPrice())。

}

否则 Print("打开BUY订单错误。",GetLastError())。

谢谢

 

对代码的帮助

大家好。

我想编写一个指标来计算收盘值,以创造一个像HMA这样的指标的反转。为此,我需要创建一个函数来计算HMA的一个值,并有一个收盘值选项卡,我在其中修改当前值的二分法循环,以找到创造反转的值。

有谁能帮助我的ComputeHull函数?

这里是我的代码,没有二分法的研究,它只是一个简单的HMA指标,带有computeHull功能,指标被显示出来,但它被向下移动了。

注意事项

//#属性 indicator_separate_window

#属性indicator_chart_window

#属性 indicator_buffers 3

#属性 indicator_color1 Blue

//---- 输入参数

extern int HullAntPeriod=12;

//---- 缓冲区

double TempBuf1[];

double TempBuf2[];

double HullAntBuf[];

//变量

int HalfHullAntPeriod;

int SqrtHullAntPeriod;

//+------------------------------------------------------------------+

//| 具体功能

//+------------------------------------------------------------------+

double ComputeHull(int ActualBar)

{

double CloseTemp[];

双倍Temp[]。

双重Temp1, Temp2;

双重结果 = -1;

int i;

//复制关闭值到CloseTemp

ArrayResize(CloseTemp, HullAntPeriod+SqrtHullAntPeriod)。

ArrayCopy(CloseTemp, Close, 0, ActualBar, HullAntPeriod+SqrtHullAntPeriod);

ArraySetAsSeries(CloseTemp, true)。

ArrayResize(Temp, SqrtHullAntPeriod)。

//HMA值的计算

for(i=0; i<SqrtHullAntPeriod; i++)

{

Temp1 = iMAOnArray(CloseTemp, 0, HalfHullAntPeriod, 0, MODE_LWMA, i)。

Temp2 = iMAOnArray(CloseTemp, 0, HullAntPeriod, 0, MODE_LWMA, i);

Temp = 2*Temp1-Temp2。

}

ArraySetAsSeries(Temp, true)。

result = iMAOnArray(Temp, 0, SqrtHullAntPeriod, 0, MODE_LWMA, 0);

//---- 完成

return(result)。

}

//+------------------------------------------------------------------+

//|自定义指标初始化函数|

//+------------------------------------------------------------------+

int init()

{

//---- 1个额外的缓冲区被用于临时数据。

IndicatorBuffers(3)。

//---- 绘图设置

SetIndexStyle(0,DRAW_LINE);

SetIndexStyle(1,DRAW_NONE);

//---- 2个指标缓冲区 的映射

SetIndexBuffer(0,HullAntBuf);

SetIndexBuffer(1,TempBuf1);

SetIndexBuffer(2,TempBuf2);

//---- DataWindow和指标子窗口标签的名称

IndicatorShortName("HULL ANTICIP("+HullAntPeriod+")")。

SetIndexLabel(0, "HULL ANTICIPATION")。

SetIndexLabel(1,NULL);

SetIndexLabel(2,NULL);

//---- 特定指标的初始化

HalfHullAntPeriod = MathFloor(HullAntPeriod/2);

SqrtHullAntPeriod = MathFloor(MathSqrt(HullAntPeriod))。

//---- 初始化完成

返回(0)。

}

//+------------------------------------------------------------------+

//|自定义指标去初始化函数

//+------------------------------------------------------------------+

int deinit()

{

//----

//----

return(0);

}

//+------------------------------------------------------------------+

//|自定义指标迭代函数|

//+------------------------------------------------------------------+

int start()

{

int bar, limit, i;

int counted_bars=IndicatorCounted()。

if(counted_bars<0) return(-1);

如果(counted_bars>0) counted_bars--。

limit=Bars-counted_bars。

for(i=0; i<limit; i++)

HullAntBuf=ComputeHull(i)。

//----

返回(0)。

}

//+------------------------------------------------------------------+

 

为什么这不起作用?

int Highest;

double Place;

int Start()

{

Highest=iHighest(Symbol(),0,MODE_HIGH,1,0);Place=iHigh(Symbol(),0,Highest);

if(Gate==0){

if(iClose(Symbol(),0,0)>=Place){

OrderModify(ticket3,Ask,Ask-TrailingStop*Point-Spread,0,0,Green);

Gate=1;}

return(0);

}

我得到了错误。我不能做一个简单的尾随止损!!!!!!!。