in another example the result is right,what's the reason?
//+------------------------------------------------------------------+
//| testTrigger.mq4 |
//| qiuyg |
//| |
//+------------------------------------------------------------------+
#property copyright "qiuyg"
#property link ""
int curTrend = 3;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
Print("curTrend: ",curTrend);
curTrend = 2;
//----
return(0);
}
//+------------------------------------------------------------------+
a part of log:
17:44:41 myFuctions EURUSD,M15: removed 17:44:41 testTrigger EURUSD,M15: loaded successfully 17:44:41 testTrigger started for testing 17:44:41 1999.11.02 01:00 testTrigger EURUSD,M15: curTrend: 3 17:44:41 1999.11.02 01:01 testTrigger EURUSD,M15: curTrend: 2 17:44:41 1999.11.02 01:02 testTrigger EURUSD,M15: curTrend: 2 17:44:41 1999.11.02 01:14 testTrigger EURUSD,M15: curTrend: 2 17:44:41 1999.11.02 01:15 testTrigger EURUSD,M15: curTrend: 2
external variables cannot be changed within expert - there are external parameters and should be changed from property page
the variable "curTrend" is not external
int curTrend=5;
not
extern int curTrend=5;
variable "curTrend" be changed to 1 in start() fucntion,but be reset to 5 before start() be trigged next time.
parameter "curTrend" value be reset to 5,how can i to avoid this? thx!
...
int curTrend=5;
...
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
...
else
{
Print("33 curTrend: ",curTrend);
int curTrend = getTrend(longestPeriod,longTrendKeepPeriod,longTrendKeepRange*Point,1);
if (curTrend == TRENDBULL)
{
if ((isUpCross(shortestPeriod,longestPeriod,1) || isUpCross(shorterPeriod,longestPeriod,1) || isUpCross(longerPeriod,longestPeriod,1))
&& (isAbove(shortestPeriod,longestPeriod,1) && isAbove(shorterPeriod,longestPeriod,1) && isAbove(longerPeriod,longestPeriod,1)))
{
Print("**** begin bull trend ****");
Print("44 curTrend: ",curTrend);
return (0);
}
else
{
Print("55 curTrend: ",curTrend);
curTrend = TRENDNO;
}
}
}
}
return(0);
}
//+------------------------------------------------------------------+
int curTrend=5;
...
{
Print("33 curTrend: ",curTrend);
int curTrend = getTrend(longestPeriod,longTrendKeepPeriod,longTrendKeepRange*Point,1);
do not mix variables with same name but different scopes - global and local
int curTrend=5;
...
{
Print("33 curTrend: ",curTrend);
int curTrend = getTrend(longestPeriod,longTrendKeepPeriod,longTrendKeepRange*Point,1);
do not mix variables with same name but different scopes - global and local
o...,it's my stupid mistake
thank you every much Slawa
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
//+------------------------------------------------------------------+ //| FOLLOWTREND.mq4 | //| Copyright ?2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "qiuyg fx." #property link "" #include <stdlib.mqh> #import "myFuctions.ex4" //---- messages int getTrend(int maPeriod,int keepPeriod,double keepRange,int shiftBars); /** *shiftBars周期前maPeriod的均线上拐 */ bool isTurningPointUp(int maPeriod,int shiftBars); /** *shiftBars周期前maPeriod的均线下拐 */ bool isTurningPointDown(int maPeriod,int shiftBars); /** *判断shiftBars周期前maPeriod的均线已经连续保持keepPeriod周期转牛,并且累计幅度达到keepRange,否则为无明显趋势 *keepRange可为负数,表示跌势趋缓 */ bool beBuller(int maPeriod,int keepPeriod,double keepRange,int shiftBars); /** *判断shiftBars周期前maPeriod的均线已经连续保持keepPeriod周期转熊,并且累计幅度达到keepRange,否则为无明显趋势 *keepRange可为正数,表示涨势趋缓 */ bool beBearer(int maPeriod,int keepPeriod,double keepRange,int shiftBars); /** *shiftBars周期前period1的均线上穿period2的均线 */ bool isUpCross(int period1,int period2,int shiftBars); /** *shiftBars周期前period1的均线在period2的均线上方 */ bool isAbove(int period1,int period2,int shiftBars); #import //---- input parameters extern double defaultTakeProfit = 80; extern double defaultTrailingStop = 40; extern double shortestPeriod = 3; extern double shorterPeriod = 21; extern double longerPeriod = 84; extern double longestPeriod =336; extern int beginCaculateTime = 197001; extern int endCaculateTime = 200812; extern int backPoint_Buy = 5,backPoint_Sell = 5; //真正的下跌反抽总是特别小 extern int distanceFromMa = 50; //回调至均线可介入的范围 extern int slippage = 0; extern bool tradeAllTime = false; extern bool buySwitch = true; extern bool sellSwitch = true; double lastDealBars = 0,lastTradeBars; int longTrendKeepPeriod = 8; //长期趋势保持最短时间 double longTrendKeepRange = 0.5; //长期趋势保持最小幅度 bool isBeyondCaculateTime = false; //是否超过了统计计算的时间 bool isBarsCountEnough = false; //是否够已经多的计算周期 bool isActiveTime = false; color dealTypeColor; color UPCOLOR = Blue,DOWNCOLOR = Red; color manualCloseColor = Black,modifyColor = Yellow; double dealPrice,stopPrice,profitPrice; //委托价格 int ticket,errId; int curTrend=5; int MyLots = 1; int lastTradeType; int expirationSec = 1800; //越界秒数 //定义表示趋势常量 int TRENDBULL = 1; //牛市 int TRENDBEAR = -1; //熊市 int TRENDNO = 0; //盘整 //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- TODO: Add your code here. //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: Add your code here. //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- TODO: Add your code here. //---- double MacdCurrent=0, MacdPrevious=0, SignalCurrent=0; double SignalPrevious=0, MaCurrent=0, MaPrevious=0; int cnt=0, total; //每个周期只是处理一次 if(lastDealBars == Bars ) return(0); lastDealBars = Bars; Print("11 curTrend: ",curTrend); //是否够已经多的计算周期 if (!isBarsCountEnough){ if(Bars<(longestPeriod+longTrendKeepPeriod)) return(0); else isBarsCountEnough = true; } if (OrdersTotal()<1) { Print("22 curTrend: ",curTrend); if(curTrend == TRENDBULL) { if(isAbove(shortestPeriod,longestPeriod,1) && isAbove(shorterPeriod,longestPeriod,1) && isAbove(longerPeriod,longestPeriod,1)) { Print(" 牛市继续 "); return (0); } else { Print(" 牛市结束 "); curTrend = TRENDNO; } } else { Print("33 curTrend: ",curTrend); int curTrend = getTrend(longestPeriod,longTrendKeepPeriod,longTrendKeepRange*Point,1); //牛市 if (curTrend == TRENDBULL) { //至少有一条均线向上穿越,并且所以均线均处于上方 if ((isUpCross(shortestPeriod,longestPeriod,1) || isUpCross(shorterPeriod,longestPeriod,1) || isUpCross(longerPeriod,longestPeriod,1)) && (isAbove(shortestPeriod,longestPeriod,1) && isAbove(shorterPeriod,longestPeriod,1) && isAbove(longerPeriod,longestPeriod,1))) { Print("**** begin bull trend ****"); Print("44 curTrend: ",curTrend); return (0); } else { Print("55 curTrend: ",curTrend); curTrend = TRENDNO; } } } } return(0); } //+------------------------------------------------------------------+a part of log: