Edit Your Comment
Modifying zigzag code in Swing Trading strategy
May 02, 2012 zamanından beri üye
15 iletiler
Jun 10, 2014 at 12:28
May 02, 2012 zamanından beri üye
15 iletiler
I'm wondering if there's anyone who is able to guide me of another obstacles to modify the below coding to suit my need. The below listed code will BUY when the swing crosses above zigzag & SELL when swing crosses below zigzag.
However, I don't wished to use the zigzag to enter the trade. What I would like is :-
1). BUY when price > last appeared DOWNBAR high,
a). close when price < LAST UPBAR low,
b). then immediately place a SELL order and will close order when price > last DOWNBAR high
2). SELL when price < last appeared UPBAR low,
a). close when price > LAST DOWNBAR high,
b). then immediately place a BUY order and will close order when price > last UPBAR low
Thanks and best regards.
//+------------------------------------------------------------------+
//| expert Detect if we have swing cross and back function
//+------------------------------------------------------------------+
bool DetectSwingCross(string symbol, int timeframe, int type)
{
double Ask_Price = MarketInfo(symbol, MODE_ASK);
double Bid_Price = MarketInfo(symbol, MODE_BID);
if (type == OP_SELL)
{
if ((iLow(symbol, timeframe, 1) < GetSwingHigh(symbol, timeframe)
&& Ask_Price > GetSwingHigh(symbol, timeframe)))
return(true);
}
if (type == OP_BUY)
{
if ((iHigh(symbol, timeframe, 1) > GetSwingLow(symbol, timeframe)
&& Bid_Price < GetSwingLow(symbol, timeframe)))
return(true);
}
return(0);
}
double GetSwingHigh(string symbol, int period)
{
int kg = 0;
double z1 = 0;
double z2 = 0;
double z3 = 0;
datetime t1, t2, t3;
double SwingHigh, SwingLow;
double val, highest, lowest;
highest = -1000000;
lowest = 1000000;
while (true)
{
if (kg == iBars(symbol, period))
break;
double zz = iCustom(symbol, period, "Zigzag", 12, 5, 3, 0, kg);
if (zz != 0)
{
z1 = z2; z2 = z3; z3 = zz;
t1 = t2; t2 = t3; t3 = iTime(symbol, period, kg);
val = iHigh(symbol, period, kg);
if (val > highest)
highest = val;
val = iLow(symbol, period, kg);
if (val < lowest)
lowest = val;
}
if (z1 > 0)
break;
kg++;
}
if (z2 < z3)
{
SwingLow = z2;
SwingHigh = z3;
}
if (z2 > z3)
{
SwingLow = z3;
SwingHigh = z2;
}
return(SwingHigh);
}
double GetSwingLow(string symbol, int period)
{
int kge = 0;
double z1 = 0;
double z2 = 0;
double z3 = 0;
datetime t1, t2, t3;
double SwingHigh, SwingLow;
double val, highest, lowest;
highest = -1000000;
lowest = 1000000;
while (true)
{
if (kge == iBars(symbol, period))
break;
double zz = iCustom(symbol, period, "Zigzag", 4, 5, 3, 0, kge);
if (zz != 0)
{
z1 = z2; z2 = z3; z3 = zz;
t1 = t2; t2 = t3; t3 = iTime(symbol, period, kge);
val = iHigh(symbol, period, kge);
if (val > highest)
highest = val;
val = iLow(symbol, period, kge);
if (val < lowest)
lowest = val;
}
if (z1 > 0)
break;
kge++;
}
if (z2 < z3)
{
SwingLow = z2;
SwingHigh = z3;
}
if (z2 > z3)
{
SwingLow = z3;
SwingHigh = z2;
}
return(SwingLow);
}
However, I don't wished to use the zigzag to enter the trade. What I would like is :-
1). BUY when price > last appeared DOWNBAR high,
a). close when price < LAST UPBAR low,
b). then immediately place a SELL order and will close order when price > last DOWNBAR high
2). SELL when price < last appeared UPBAR low,
a). close when price > LAST DOWNBAR high,
b). then immediately place a BUY order and will close order when price > last UPBAR low
Thanks and best regards.
//+------------------------------------------------------------------+
//| expert Detect if we have swing cross and back function
//+------------------------------------------------------------------+
bool DetectSwingCross(string symbol, int timeframe, int type)
{
double Ask_Price = MarketInfo(symbol, MODE_ASK);
double Bid_Price = MarketInfo(symbol, MODE_BID);
if (type == OP_SELL)
{
if ((iLow(symbol, timeframe, 1) < GetSwingHigh(symbol, timeframe)
&& Ask_Price > GetSwingHigh(symbol, timeframe)))
return(true);
}
if (type == OP_BUY)
{
if ((iHigh(symbol, timeframe, 1) > GetSwingLow(symbol, timeframe)
&& Bid_Price < GetSwingLow(symbol, timeframe)))
return(true);
}
return(0);
}
double GetSwingHigh(string symbol, int period)
{
int kg = 0;
double z1 = 0;
double z2 = 0;
double z3 = 0;
datetime t1, t2, t3;
double SwingHigh, SwingLow;
double val, highest, lowest;
highest = -1000000;
lowest = 1000000;
while (true)
{
if (kg == iBars(symbol, period))
break;
double zz = iCustom(symbol, period, "Zigzag", 12, 5, 3, 0, kg);
if (zz != 0)
{
z1 = z2; z2 = z3; z3 = zz;
t1 = t2; t2 = t3; t3 = iTime(symbol, period, kg);
val = iHigh(symbol, period, kg);
if (val > highest)
highest = val;
val = iLow(symbol, period, kg);
if (val < lowest)
lowest = val;
}
if (z1 > 0)
break;
kg++;
}
if (z2 < z3)
{
SwingLow = z2;
SwingHigh = z3;
}
if (z2 > z3)
{
SwingLow = z3;
SwingHigh = z2;
}
return(SwingHigh);
}
double GetSwingLow(string symbol, int period)
{
int kge = 0;
double z1 = 0;
double z2 = 0;
double z3 = 0;
datetime t1, t2, t3;
double SwingHigh, SwingLow;
double val, highest, lowest;
highest = -1000000;
lowest = 1000000;
while (true)
{
if (kge == iBars(symbol, period))
break;
double zz = iCustom(symbol, period, "Zigzag", 4, 5, 3, 0, kge);
if (zz != 0)
{
z1 = z2; z2 = z3; z3 = zz;
t1 = t2; t2 = t3; t3 = iTime(symbol, period, kge);
val = iHigh(symbol, period, kge);
if (val > highest)
highest = val;
val = iLow(symbol, period, kge);
if (val < lowest)
lowest = val;
}
if (z1 > 0)
break;
kge++;
}
if (z2 < z3)
{
SwingLow = z2;
SwingHigh = z3;
}
if (z2 > z3)
{
SwingLow = z3;
SwingHigh = z2;
}
return(SwingLow);
}
Sep 24, 2012 zamanından beri üye
155 iletiler
Jun 10, 2014 at 14:54
Sep 24, 2012 zamanından beri üye
155 iletiler
how result after use this logic sir?
May 02, 2012 zamanından beri üye
15 iletiler
Jun 10, 2014 at 15:05
May 02, 2012 zamanından beri üye
15 iletiler
myfacefx99 posted:
how result after use this logic sir?
I'm hoping someone who could modify the code above based on my request in order for me to back test before I can tell you the result.

forex_trader_28881
Feb 07, 2011 zamanından beri üye
691 iletiler
Jun 10, 2014 at 22:42
Feb 07, 2011 zamanından beri üye
691 iletiler
Results will be terrible. ZigZag not a particularly good way of getting levels.
Been there, got that T shirt...
Been there, got that T shirt...
Jun 09, 2011 zamanından beri üye
183 iletiler
Jun 23, 2014 at 04:39
Jun 09, 2011 zamanından beri üye
183 iletiler
try here man
http://www.mql5.com/en/job
http://www.mql5.com/en/job
http://www.freeforexrebates .info
Jun 03, 2010 zamanından beri üye
675 iletiler
Jun 26, 2014 at 18:08
Jun 03, 2010 zamanından beri üye
675 iletiler
Indeed, ZigZag is very bad to get levels :) Better stay away to make decisions mainly on ZigZag.
PAMM MANAGER // Professional Fund Manager

*Ticari kullanım ve istenmeyen e-postalara müsamaha gösterilmez ve hesabın feshedilmesine neden olabilir.
İpucu: Bir resim/youtube urlsi yayınlamak, onu otomatik olarak gönderinize gömer!
İpucu: Bu tartışmaya katılan bir kullanıcı adını otomatik olarak tamamlamak için @ işaretini yazın.