需要帮助创建一个非常简单的EA - 页 3

 

//+------------------------------------------------------------------+
//| Stepper.mq4 |
//| doshur |
//| www.doshur.com |
//+------------------------------------------------------------------+
#property copyright "doshur"
#property link "www.doshur.com"

extern int TakeProfit = 5;
extern int Range = 20;
extern int Risk = 2;

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

int deinit()
{
return(0);
}

int start()
{
//----
static bool ToTrade = false;
static bool FirstTrade = true;

double PrevLow = iLow(Symbol(), 0, 1);
double PrevHigh = iHigh(Symbol(), 0, 1);
double PrevRange = (PrevHigh - PrevLow) / Point;

if(NewBar())
{
if(FirstTrade == false)
{
if(PrevRange >= Range)
ToTrade = true;
else
ToTrade = false;
}
else
{
FirstTrade = false;
}
}

if(ToTrade)
{
if(COT(1) < 1)
{
if(Ask > PrevHigh)
OrderSend(Symbol(), OP_BUY, MM(PrevRange, Risk), Ask, 3, PrevLow, Ask + TakeProfit * Point, "Stepper - BUY", 57390, 0, Blue);
}

if(COT(2) < 1)
{
if(Bid < PrevLow)
OrderSend(Symbol(), OP_SELL, MM(PrevRange, Risk), Bid, 3, PrevHigh, Bid - TakeProfit * Point, "Stepper - SELL", 57391, 0, Red);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+

//---- Check Is New Bar
bool NewBar()
{
static datetime PrevBar;

if(PrevBar < Time[0])
{
PrevBar = Time[0];
return(true);
}
else
{
return(false);
}

return(false);
}

//---- Check Open Trades
int COT(int BS)
{
int Buys = 0, Sells = 0;

for(int cnt_COT = 0; cnt_COT < OrdersTotal(); cnt_COT++)
{
OrderSelect(cnt_COT, SELECT_BY_POS, MODE_TRADES);

if(OrderType() == OP_BUY && OrderSymbol() == Symbol()) Buys++;
if(OrderType() == OP_SELL && OrderSymbol() == Symbol()) Sells++;
}

if(BS == 1) return(Buys);
if(BS == 2) return(Sells);
}

//---- Money Management
double MM(int SL, int RK)
{
double rLots = NormalizeDouble(AccountBalance() / 1000 * RK / SL, 1); // Risk ?% of balance

if(rLots < 0.1) rLots = 0.1;

return(rLots);
}


已经实施了第一次运行以克服这个问题和其他一些问题

还没有测试代码

请测试并列出其他修正案

 

is there away where we can modify the stop loss to so 15 or 20 instead of the other end of the candle?

 

crazfoto 2008.12.02 08:27是否有离开,我们可以修改止损到15或20,而不是蜡烛的另一端?


是的。这是有可能的。

 

这个是2小时平均线的吗?还是30分钟的另一个版本?


如果是2小时平均线,它昨天没有执行任何交易。

 
crazfoto:

这是为2小时平均数准备的吗? 还是30分钟的另一个版本?


如果是2小时平均线,它昨天没有执行任何交易。

你是说我的代码?

它按照你的要求实施了30分钟。

 

哦,我的错。我现在要测试一下。


非常感谢你对我的帮助。我在4小时图上玩了一下。我想如果我在4小时图上将止损点改为15或20点,结果会很好,也是我所习惯的。

 
我看到很多人在离线图表上使用EA的时候都有问题。
 
它只在1小时图上工作
 
好的。它在30分钟的图表上工作,但每当有一个订单支付出去,它就会不断地输入一个订单。所以它没有等待30分钟的蜡烛形成后再输入新的订单。
 

oops.

我忘了在它进入后禁用。

让我修改一下代码