如何编码? - 页 115

 
matrixebiz:
我这样做不是在做同样的事情吗?

如果(Hour() 17) TradeHour = false。

意思是,如果小时在12和17之间,TradeHour=true ,正确吗?

(在我的买入/卖出语句中添加&&TradeHour)

否定了下面的语句。

if(Hour()>=12 && Hour()<17)

TradingEnabled=true;

[/CODE]

is

[CODE]

if(Hour()=17)

TradingEnabled=false;

 

还有一件事 ,我如何在代码中添加一个重新进入的延迟,这样,如果一个交易刚刚打开并关闭,要等待60分钟,然后再次检查 是否仍然满足交易条件。

谢谢你

 
matrixebiz:
还有一件事 ,我如何在代码中添加一个重新进入的延迟,这样如果一个交易刚刚打开并关闭,要等待60分钟,然后再次检查交易条件是否仍然满足。谢谢你

我不清楚你的要求是什么。

你想在一次交易条件检查和 下一次检查之间等待60分钟吗?

如果这是你的要求,可能这应该是可行的。

// Global variable

bool TradingEnabled = true; // flag to enable/disabled trading logic

bool TradingCheckDone = false; // flag to know if a a check was just done

datetime LastCheckTime = 0; // Time when the last check was done

.... somewhere in EA start() function ....

if( !TradingCheckDone )

{

// Default: We assume that trading logic must run ...

TradingEnabled = true;

// ... but only between 12:00:00 and 16:59:59

if(Hour()=17)

TradingEnabled=false;

// We must remember a check was just done

TradingCheckDone = true;

// We must even know when it was done

LastCheckTime = TimeCurrent();

} else

{

// if a hour has passed since the last check, it's time to retry

if( TimeCurrent() - LastCheckTime >= 3600 )

{

TradingCheckDone = false;

}

}

 
gorgoroth:
我不清楚你的要求是什么。

你想在一次交易条件检查和下一次检查之间等待60分钟吗?

如果这是你的要求,可能这应该是可行的。

// Global variable

bool TradingEnabled = true; // flag to enable/disabled trading logic

bool TradingCheckDone = false; // flag to know if a a check was just done

datetime LastCheckTime = 0; // Time when the last check was done

.... somewhere in EA start() function ....

if( !TradingCheckDone )

{

// Default: We assume that trading logic must run ...

TradingEnabled = true;

// ... but only between 12:00:00 and 16:59:59

if(Hour()=17)

TradingEnabled=false;

// We must remember a check was just done

TradingCheckDone = true;

// We must even know when it was done

LastCheckTime = TimeCurrent();

} else

{

// if a hour has passed since the last check, it's time to retry

if( TimeCurrent() - LastCheckTime >= 3600 )

{

TradingCheckDone = false;

}

}

不,只有当一个交易刚刚发生并关闭时,我希望EA等待一个小时,然后检查 交易条件是否仍然符合,如果是,那么好,再次交易,但如果不是,那就这样。那么这段代码能达到我想要的效果吗?由于有TimeCurrent的检查,这在测试器中能行吗?

编辑:不是每小时都做检查,只是在交易结束后,等待一个小时的条件检查,就是这样。然后,如果在一天内产生并关闭了另一个交易,那么再等待一个小时,如果没有信号,那么就这样了,不再等待检查,直到下一个交易打开和关闭。

谢谢你

附上一个小的EA,如果你能用我提到的正确设置来修改它。谢谢

附加的文件:
ozfx_method.mq4  11 kb
 

买入限价单和买入止损单

限价单和止损单 的区别是什么?

谢谢

 
gorgoroth:
大家好。

我已经开发了一组函数来管理EA的配置设置。

这些函数是由一个C++ DLL导出的,每个导出的函数都有__stdcall调用的信念,要求我的MQL4。

当一个函数需要返回一个字符串给EA时,我的问题就出现了。

当然,这个函数不能。

- 返回一个指向本地变量的指针(变量会超出范围)

- 返回一个指向dll全局变量的指针(并发访问的问题)。

- 返回一个指向堆分配的字符串的指针(需要释放内存的函数来从EA中调用:我不喜欢这种方法)

所以我决定从EA中传递一个字符串和字符串大小。Es:

string buffer;

GetString( buffer, 30 );

[/CODE]

and from the c++ dll, something like this

void __stdcall GetString( LPTSTR buffer, int BufSize )

{

// Read a string from a some source

....

// -1 to take into account the terminating null character

StringCchCopy( buffer, BufSize-1, ReadStringFromASource );

}

[/CODE]

Here starts the weird behaviour of MQL managing strings returned from a DLL.

using the following code:

string buffer;

GetString( buffer, 30 );

the first time buffer contains the right string. A first question arises: buffer is not initialized but after calling GetString it contains the string returned. I have to suppose that MQL allocates space for a string variable when it's declared.

Next time GetString() is called the string returned seems to be truncated to the length-1 of the previous string length and not resetted as expected because of the 'string buffer;' statement.

Tried even:

[CODE]

string buffer = " "; // 'allocate' 30 blank characters

GetString( buffer, StringLen(buffer) );

but after the first time, when the execution returns to this code, the assignment of buffer does not work any more and buffer still contains the previous read string, and it seems it can only contains the number of characters of his content.

At first I have thought that the null character is not handled very well by MQL and modified the c++ code like this ...

[CODE]

CopyMemory( buffer, ReadStringFromASource, min(BufferSize,ReadStringFromASourceLength) );

并且不添加结尾的空字符。

但是,当从MQL调用时,根本就没有字符串返回。

有谁能回答?

没有人遇到过从DLLs返回字符串的问题吗?

 

我需要帮助。

谁能告诉我一个代码吗?

每个信号一个订单...因为有时我有3个信号,因为不同的TF...我希望所有的信号都打开...

或者有一个代码,可以在每个条形图上接受一个订单,但每个时间段都附加在一个EA上,我不想打开很多图表。

 

我的BuyStop有什么问题?

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);

 
matrixebiz:
我的BuyStop有什么问题?

ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);

你的止损和止盈...

在添加之前,你还应该在你的距离上添加*点。

或者

Bid-((Distance-StopLoss)*Point), Ask+((Distance+TakeProfit)*Point)