回测时结果为空白
Blank Results while backtesting
我是 MQL4
代码世界的新手。
我来自 C++
背景,我正在努力学习 MQL4
语言和惯例。
我正在编写一个简单的 Expert Advisor(我的第一个)。
它可以编译,但是当我尝试测试它时,它没有结果。我附上代码以更好地说明我正在尝试做什么:
//+------------------------------------------------------------------+
//| MyFirstExpert.mq4 |
//| Leonardo |
//| http://investinmarkets.altervista.org |
//+------------------------------------------------------------------+
#property copyright "Leonardo "
#property link "http://investinmarkets.altervista.org"
#property version "1.00"
#property strict
input int BarCount = 3;
int Ticket = 0;
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick() {
int BarCountTemp = BarCount + 1;
double bars[];
ArrayResize( bars, BarCountTemp );
for ( int i = 0; i < BarCountTemp; i++ ) {
bars[i] = Close[i + 1];
}
int i = 0;
bool is_p;
do
{
if ( bars[i] > bars[i+1] && i < BarCountTemp ) is_p = true;
else is_p = false;
i++;
}
while ( is_p );
if ( is_p == true && Ticket == 0 ) {
Ticket = OrderSend(_Symbol,OP_SELL,0.1,Bid,0,0,0,"Sell Order Custom",110);
Alert("Sell order opened to match found.");
Comment("Sell order opened #"+Ticket+".");
}
if ( Ticket != 0 ) {
bool select = OrderSelect(Ticket,SELECT_BY_TICKET);
if ( Close[1] > Close[2] ) {
bool close = OrderClose(Ticket,OrderLots(),Ask,0,clrGreen);
Alert("Sell order closed.");
Comment("Sell order closed #"+Ticket+".");
Ticket = 0;
}
}
}
//+------------------------------------------------------------------+
我想简单地计算柱数(由用户输入)然后执行检查:如果例如3 个柱都是正的,然后打开一个卖单(目前只是这种情况)。如果打开,则检查下一根柱线是否仍然为正,如果不是则关闭交易。
我总是得到空白结果。
提前致谢!
欢迎来到 MQL4
世界,莱昂纳多
让我们回顾一下语法:
for ( int i = 0; i < BarCountTemp; i++ ) {
bars[i] = Close[i + 1];
}
int i = 0;
bool is_p;
do
{
if ( bars[i] > bars[i+1] && i < BarCountTemp ) is_p = true;
else is_p = false;
i++;
}
while ( is_p );
可以合并/简化为一个loop/break结构:
bool is_p = True; // FYI: FALSE if not initialised
// WARNING: "New"-MQL4 has changed variable visibility-scope to be limited just to the innermost syntax-construct and variables easily "cease" exist outside that syntax-construct boundary ... for(){bool is_p ...visible...} ...invisible...
for ( int i = 0; // .SET
i < BarCountTemp; // .TEST: [**]
i++ ) { // .INC
if ( Close[i+1] > Close[i+2] // avoid TimeSeries' replica(s)
// && i < BarCountTemp // ALWAYS TRUE [^**]
) continue; // ---------------------------- LOOP-^
else {
is_p = False;
break; // ---------------------------- EXIT-v
}
下一个:图表顶部至少有一个 Comment() 评论 window?
int Ticket = EMPTY; // Rather initialise as = EMPTY;
if ( is_p == True
&& Ticket == EMPTY // un-ambiguous meaning
) {
Ticket = OrderSend( _Symbol, // .SYM
OP_SELL, // .OP
0.1, // .LOTs check sizing, MarketInfo()
Bid, // .PRICE
0, // .SLIPPAGE
0, // .SL
0, // .TP
"Sell Order Custom",// .COMMENT
110 // .MAGNUM
);
if ( Ticket == EMPTY ){ // EXC. HANDLER
...
}
else {
Alert( "Sell order opened to match found." ); // .NOP if isTesting()
Comment( "Sell order opened #" + Ticket + "." ); // .GUI is visible????
}
}
最后:包括可能出现错误的情况的异常处理程序
if ( Ticket != EMPTY // TEST 1st,
&& Close[1] > Close[2] // TEST 2nd, prevent dbPool-ops, if not True
) {
bool select = OrderSelect( Ticket, SELECT_BY_TICKET );
if (!select ){ // EXC. HANDLER
...
}
bool close = OrderClose( Ticket,
OrderLots(),
Ask,
0,
clrGreen
);
if (!close ){ // EXC. HANDLER
...
}
Alert( "Sell order closed." );
Comment( "Sell order closed #" + Ticket + "." );
Ticket = EMPTY; // .SET EMPTY
}
}
我是 MQL4
代码世界的新手。
我来自 C++
背景,我正在努力学习 MQL4
语言和惯例。
我正在编写一个简单的 Expert Advisor(我的第一个)。
它可以编译,但是当我尝试测试它时,它没有结果。我附上代码以更好地说明我正在尝试做什么:
//+------------------------------------------------------------------+
//| MyFirstExpert.mq4 |
//| Leonardo |
//| http://investinmarkets.altervista.org |
//+------------------------------------------------------------------+
#property copyright "Leonardo "
#property link "http://investinmarkets.altervista.org"
#property version "1.00"
#property strict
input int BarCount = 3;
int Ticket = 0;
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick() {
int BarCountTemp = BarCount + 1;
double bars[];
ArrayResize( bars, BarCountTemp );
for ( int i = 0; i < BarCountTemp; i++ ) {
bars[i] = Close[i + 1];
}
int i = 0;
bool is_p;
do
{
if ( bars[i] > bars[i+1] && i < BarCountTemp ) is_p = true;
else is_p = false;
i++;
}
while ( is_p );
if ( is_p == true && Ticket == 0 ) {
Ticket = OrderSend(_Symbol,OP_SELL,0.1,Bid,0,0,0,"Sell Order Custom",110);
Alert("Sell order opened to match found.");
Comment("Sell order opened #"+Ticket+".");
}
if ( Ticket != 0 ) {
bool select = OrderSelect(Ticket,SELECT_BY_TICKET);
if ( Close[1] > Close[2] ) {
bool close = OrderClose(Ticket,OrderLots(),Ask,0,clrGreen);
Alert("Sell order closed.");
Comment("Sell order closed #"+Ticket+".");
Ticket = 0;
}
}
}
//+------------------------------------------------------------------+
我想简单地计算柱数(由用户输入)然后执行检查:如果例如3 个柱都是正的,然后打开一个卖单(目前只是这种情况)。如果打开,则检查下一根柱线是否仍然为正,如果不是则关闭交易。
我总是得到空白结果。
提前致谢!
欢迎来到 MQL4
世界,莱昂纳多
让我们回顾一下语法:
for ( int i = 0; i < BarCountTemp; i++ ) {
bars[i] = Close[i + 1];
}
int i = 0;
bool is_p;
do
{
if ( bars[i] > bars[i+1] && i < BarCountTemp ) is_p = true;
else is_p = false;
i++;
}
while ( is_p );
可以合并/简化为一个loop/break结构:
bool is_p = True; // FYI: FALSE if not initialised
// WARNING: "New"-MQL4 has changed variable visibility-scope to be limited just to the innermost syntax-construct and variables easily "cease" exist outside that syntax-construct boundary ... for(){bool is_p ...visible...} ...invisible...
for ( int i = 0; // .SET
i < BarCountTemp; // .TEST: [**]
i++ ) { // .INC
if ( Close[i+1] > Close[i+2] // avoid TimeSeries' replica(s)
// && i < BarCountTemp // ALWAYS TRUE [^**]
) continue; // ---------------------------- LOOP-^
else {
is_p = False;
break; // ---------------------------- EXIT-v
}
下一个:图表顶部至少有一个 Comment() 评论 window?
int Ticket = EMPTY; // Rather initialise as = EMPTY;
if ( is_p == True
&& Ticket == EMPTY // un-ambiguous meaning
) {
Ticket = OrderSend( _Symbol, // .SYM
OP_SELL, // .OP
0.1, // .LOTs check sizing, MarketInfo()
Bid, // .PRICE
0, // .SLIPPAGE
0, // .SL
0, // .TP
"Sell Order Custom",// .COMMENT
110 // .MAGNUM
);
if ( Ticket == EMPTY ){ // EXC. HANDLER
...
}
else {
Alert( "Sell order opened to match found." ); // .NOP if isTesting()
Comment( "Sell order opened #" + Ticket + "." ); // .GUI is visible????
}
}
最后:包括可能出现错误的情况的异常处理程序
if ( Ticket != EMPTY // TEST 1st,
&& Close[1] > Close[2] // TEST 2nd, prevent dbPool-ops, if not True
) {
bool select = OrderSelect( Ticket, SELECT_BY_TICKET );
if (!select ){ // EXC. HANDLER
...
}
bool close = OrderClose( Ticket,
OrderLots(),
Ask,
0,
clrGreen
);
if (!close ){ // EXC. HANDLER
...
}
Alert( "Sell order closed." );
Comment( "Sell order closed #" + Ticket + "." );
Ticket = EMPTY; // .SET EMPTY
}
}