|
初心者ですが複利とトレーリングストップを持ったEAを作りたです。
そこで豊嶋久道さんの書籍を参考に以下のように書きましたが
動作しません。
どう直せばいいでしょうか?
#include <MyLib.mqh>
extern int Leverage = 1;
extern int Slippage = 3;
extern int HLPeriod = 5;
double CalculateLots(double leverage)
{
string symbol = StringSubstr(Symbol(), 0, 3)
+ AccountCurrency();
double conv = iClose(symbol, 0, 0);
if(conv == 0) conv = 1;
double lots = leverage * AccountFreeMargin() / 100000 / conv;
double minlots = MarketInfo(Symbol(), MODE_MINLOT);
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT);
int lots_digits = MathLog(1.0/minlots)/MathLog(10.0);
lots = NormalizeDouble(lots, lots_digits);
if(lots < minlots) lots = minlots;
if(lots > maxlots) lots = maxlots;
return(lots);
}
extern int MomPeriod = 20;
int EntrySignal(int magic)
{
double pos = MyCurrentOrders(MY_OPENPOS, magic);
double mom1 = iMomentum(NULL, 0, MomPeriod, PRICE_CLOSE, 1);
int ret = 0;
if(pos <= 0 && mom1 > 100) ret = 1;
if(pos >= 0 && mom1 < 100) ret = -1;
return(ret);
}
int start()
{
double lots = CalculateLots(Leverage);
double spread = Ask-Bid;
double HH = iCustom(Symbol(), 0, "HLBand", HLPeriod, 1, 1)+spread;
double LL = iCustom(Symbol(), 0, "HLBand", HLPeriod, 2, 1);
if(MyCurrentOrders(OP_BUY, MAGIC) !=0) MyOrderModify(LL, 0, MAGIC);
if(MyCurrentOrders(OP_SELL, MAGIC) !=0) MyOrderModify(HH, 0, MAGIC);
int sig_entry = EntrySignal(MAGIC);
if(sig_entry > 0)
{
MyOrderClose(Slippage, MAGIC);
MyOrderSend(OP_BUY, lots, Ask, Slippage, 0, 0, COMMENT, MAGIC);
}
if(sig_entry < 0)
{
MyOrderClose(Slippage, MAGIC);
MyOrderSend(OP_SELL, lots, Bid, Slippage, 0, 0, COMMENT, MAGIC);
}
return(0);
}
|
|