kO\aNtK
均线交叉513源码,求教 如何把慢线13设置成简单平均线(SMA)? nz]+G2h
|P]>[}mD
513源码: F\;G'dm
//+----------------------------------------------------------------------------------------+ WY%'ps_]<
//| EMA Cross | mMvt#+O
//| Clay - Copyright 2006 | w+~s}ta2^
//| v 1.1 fixed emas | .5zqpm
//+----------------------------------------------------------------------------------------+ N?h=Zl|
y-93 >Y
/K"koV;
@<tkwu
//---- input parameters MGd 7Ont
extern double StopLoss = 30; ^6 F-H(
extern double TakeProfit = 1000; ;5A
extern double Lots = 0.1; 8M;VX3X
extern double TrailingStop = 200; {(i>$RG_
WUSkN;idVG
extern int ShortEma = 5; NuKktQd
extern int LongEma = 13; n5X0Gi9
-ckk2D?
Q<.847 )
//+------------------------------------------------------------------+ BD+V{x}P
//| expert initialization function | >L F
y:a
//+------------------------------------------------------------------+ p.kJNPO\@
int init() 8{aS$V"
{ =l?F_
//---- 4vi P lO
dYdZt<6W<(
//---- 4<b=;8
return(0); =~M%zdIXv
} $xRZU9+
//+------------------------------------------------------------------+ YY~BNQn6d
//| expert deinitialization function | d4OWnPHv&}
//+------------------------------------------------------------------+ FV>j
!>Y
int deinit() P70\ |M0~y
{ KUs\7Sb
//---- kkfwICBI
gG;d+s1
//---- Z]-C,8MM
return(0); uMW5F-~-+
} mQ#E{{:H+
Of|e]GR
//+------------------------------------------------------------------+ XAN{uD^3\%
//| expert start function + 0:K4,
//| This is where we initialize internal variables for program use + 6*@\Qsp615
//+------------------------------------------------------------------+ w3j51v` 0'
int start() VKa-
{ ~i)O^CKq
//---- D}Jhg`9
*|c*/7]<
//LotCalc Declarations >-0b@ +j
int cnt, ticket, total; 5[WhjTo
//MAs &JoMrcEZ
double FEMAnow,FEMAprevious,FEMA2previous,SEMAnow,SEMAprevious,SEMA2previous; amI$0
1m-"v:fT5D
!=#230Y
if(Bars<100) [P*3ld,,G%
{ NEQcEUd?
Print("bars less than 100"); ~Z5?\a2Ld
return(0); 3mn0
} N}\Da:_
if(TakeProfit<10) ,eRl
Z3T
{ )61CrQiY
Print("TakeProfit less than 10");
1W;3pN
return(0); // check TakeProfit ^ j@Q2>&?
} h~elF1dG
vnz.81OR
//MA and Filter Variable Definition 8{Y
?;~G
FEMAnow = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0); p'k stiB
FEMAprevious = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,1); uYL6g:]+ZC
FEMA2previous = iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,2); L5yxaF{]
SEMAnow = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_OPEN,0); ,-CDF)~G=3
SEMAprevious = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_OPEN,1); =
k3O4gE7
SEMA2previous = iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_OPEN,2); V-=$:J"J'\
o9wg<LP
int isCrossed = 0; pw>AQ
`8FC&%X_
if (FEMAnow > SEMAnow && FEMAprevious > SEMAprevious && FEMA2previous < SEMAprevious) [=U7V;5($
{isCrossed = 1; tEN]0`
} Ysr{1! K
tB_ V%qH
if (FEMAnow < SEMAnow && FEMAprevious < SEMAprevious && FEMAprevious > SEMAprevious) 0[v :^H
{isCrossed = 2; {t=Nnc15K
} e-e{-pB6
y5Pw*?kn
tjd"05"@:
//We check the trading terminal to see if it is empty rqF PUp
total = OrdersTotal(); %eV`};9
if(total < 1) //If trading terminal is empty... ^m+W
{ l?R_wu,Q
if(isCrossed == 1) //if cross indicates LONG swing... ky~ x4_y5
U3V<ITZI8t
<Z__Q
{ K%gFD?{^q
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,2,Ask-StopLoss*Point,Ask+TakeProfit*Point,"EMa cross",12345,0,Yellow); q@sH@-z4]
if(ticket>0) \1MDCP9:
{ [T%blaSX
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); C\; 8l}t
} 64vSJx>u
else Print("Error opening BUY order : ",GetLastError()); KCT8Q!\
return(0); :A'!u r=\
} o{he)r6)_
if(isCrossed == 2) //if cross indicates SHORT swing... aOHCr>po,
oB\Xl)A<
{ TUaK:*x*
t0>{0 5
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,2,Bid+StopLoss*Point,Bid-TakeProfit*Point,"EMA cross",12345,0,Red); ' XF`&3i
if(ticket>0) wuzz%9;@B
{ !Ia"pNDf
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); )sf~l6
} 8zC k9&
else Print("Error opening SELL order : ",GetLastError()); mx9/K+:
return(0); `t1$Ew<
} Qs9 U&*L
return(0); pq3 A%|
} F2$bUY
s[q4K
//Position exit function... E`fssd~
for(cnt=0;cnt<total;cnt++) aNC,ccm
{ 3DAGW"F
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); *ZR@z80i
OrderPrint(); Om2X>/V%C
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) bmVgTm&
{ 1m`tqlFU9
if(OrderType()==OP_BUY) // long position is opened A>t!/_"
{ H='9zqYZ<W
// Check if we have a SHORT cross condition... ,(0XsBL
if(isCrossed == 2) '<D `:srV
{ mu6xL QdA
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position gLaO#cQ%
return(0); // exit S`c]Fc
} (C l`+ V
// Check our trailing stop to see if it needs to be adjusted ]PzTl {]
if(TrailingStop>0) )YnI!v2T
{ K_&c5(-(_
if(Bid-OrderOpenPrice()>Point*TrailingStop) 38U5^`
{ [)H,zpl
if(OrderStopLoss()<Bid-Point*TrailingStop) y/@;c)1b9
{ r%TLv
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); AU\xNF3
return(0); ~Q_)>|R2
} )]/i
} ^J#?hHz
} A;fB6
} jU]]:S4xD/
else // go to short position @tr&R==([
{ 4i_spF-3
// Check if we have a LONG cross condition... }g>dn
if(isCrossed == 1) Bmx(qE
{ !dfS|BA]
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position g(-;_j!=
return(0); // exit =oo[ Eyr
} &u+yM
D
// Check our trailing stop to see if it needs to be adjuste E|HSwTHe
if(TrailingStop>0) 8O~0RYk
{ zWy
,Om8P
if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) lbQ6
a
{ 8 ne/=N|,
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) S-isL4D.Z
{ LMAmpVo
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); qOW#Q:T
return(0); uc 'p]WhQ
} 24//21m
} *~cqr
} G@9u:\[l
} xZX`%f-
} @|BD|{k
} ?{eY\I
S`=n&'
return(0); |=O1Hn
} J_PH7Z*=,
//+------------------------------------------------------------------+