Pb Entries consecutive trendline SwingGann  [SOLVED]

Questions about MultiCharts and user contributed studies.
maubonvi
Posts: 16
Joined: 26 Sep 2014

Pb Entries consecutive trendline SwingGann

Postby maubonvi » 13 Apr 2015

I need help, (sorry for my English writing).
I would like to understand why revenue consecutive occur after the breakout of the trendline.
My idea is to do only one entry, long or short, the breakout of the trendline created between two points of swing with the original rules of Gann
Below, I attach the code of system based on the trendline breakout of Gann Swing, please can someone tell me why there are consecutive revenue?.
Also in the following images, you will also find the settings of the properties of the strategy.

Thanks .

Regards

Mauro
Attachments
PbDoubleEntry.JPG
(43.32 KiB) Downloaded 485 times

maubonvi
Posts: 16
Joined: 26 Sep 2014

Re: Pb Entries consecutive trendline SwingGann

Postby maubonvi » 13 Apr 2015

Setting
Attachments
StratProp_Properties.JPG
(62.97 KiB) Downloaded 469 times

maubonvi
Posts: 16
Joined: 26 Sep 2014

Re: Pb Entries consecutive trendline SwingGann

Postby maubonvi » 13 Apr 2015

Strategy Properties BackTesting
Attachments
StratProp_BackTesting.JPG
(68.09 KiB) Downloaded 455 times

maubonvi
Posts: 16
Joined: 26 Sep 2014

Re: Pb Entries consecutive trendline SwingGann

Postby maubonvi » 13 Apr 2015

... oops... the code .
[+] the code

Code: Select all

//+------------------------------------------------------------------+
//| BM_EA_SwingGann_v1_01_StdBars |
//| Copyright MauroBonvini, Mar15 |
//+------------------------------------------------------------------+

//+---------------------------------------------+
//| Declare Inputs |
//+---------------------------------------------+
Input: Label("--- Parameters for Swing Gann ---"),
SwGannPeriod(2),

Label2("--- Parameters for TrendLine ---"),
TlUpGap(0),
TlLoGap(0),
TlUp_Color(Blue),
TlLo_Color(Red),
TlUp_Style(tool_dotted),
TlLo_Style(tool_dotted),

Label3(" ----- Stategy for Size Contract and Entry ------- "),
NContractEntry (1),

Label4(" ----- Stategy for Exit ------- "),
ProfitTargetAmt(100),

Label8(" -------Parameters for BreakEvent ---------- "),
UseBE(true),
BreakEventAmt(50),

Label9(" -------Parameters for StopLoss ---------- "),
StopLossSecurityAmt (100),

Label11(" Parameters for Time Filter "),
StartTime1 (0800),
EndTime1 (2300);

//+---------------------------------------------+
//| Declare Variables |
//+---------------------------------------------+
Vars: Hi (0),
Hi1(0),
Lo (0),
Lo1(0),
Cl (0),
Cl1(0),
Op (0),
Op1(0),
SwingGann(0),
MaxSwingGann(0),
MinSwingGann(0),
AvgVal(0),
min1 (0),
min2 (0),
max1 (0),
max2 (0),
date1L (0),
date2L (0),
date1H (0),
date2H (0),
time1L (0),
time2L (0),
time1H (0),
time2H (0),
TlUp (-1),
TlLo (-1),
TlUpGetVal(-1),
TlLoGetVal(-1);

//+---------------------------------------------+
//| Declare Arrays |
//+---------------------------------------------+
Arrays: DateL[1](0),
TimeL[1](0),
SwGannL[1](0),
DateH[1](0),
TimeH[1](0),
SwGannH[1](0);

//+---------------------------------------------+
//| Calculate to Condition |
//+---------------------------------------------+

// {}

// Calculated SwingGann ---------------------+
//Calculated according to the original formula of Swing anChart W.Gann:
// 1_ Gann Swing Chart = the value of High bar in formation when both the maximum that the minimum, maximum and higher minimum earlier.
// 2_ Gann Swing Chart = the value of Low bar in formation when it is the minimum that the most, compared to the minimum and maximum of the previous.
// 3_ Gann Swing Chart remain 'unchanged if a bar inside.
// 4_ Swing Chart Gann = the value of High in the case of a bar outside (engulfing),
// if Close bar in formation will be 'in the upper part of the range and the contrary.

Hi = HIgh;
Hi1 = High[1];
Lo = Low;
Lo1 = Low[1];
Cl = Close;
Cl1 = Close[1];
Op = Open;
Op1 = Open[1];

if ( (Hi>Hi1) and (Lo>Lo1)) then
SwingGann = Hi;

if ( (Hi<Hi1) and (Lo<Lo1)) then
SwingGann = Lo;

if ( (Hi<Hi1) and (Lo>Lo1)) then // inside
SwingGann = SwingGann[1];

if ( (Hi>Hi1) and (Lo<Lo1)) then begin //engulfing
if( Cl>(Low+(Range*0.5)) ) then begin
SwingGann = Hi;
end
else SwingGann = Lo;
end;

// Identification reversal point------------------------+

AvgVal= Average(Close,3);

MaxSwingGann = highest(SwingGann,SwGannPeriod);
MinSwingGann = Lowest(SwingGann,SwGannPeriod);

condition1 = SwingGann[1] = MaxSwingGann;
condition2 = SwingGann < SwingGann[1];
condition3 = SwingGann[2] <= SwingGann[1];
condition4 = SwingGann[3] < SwingGann[2];
condition5 = SwingGann[1] = MinSwingGann;
condition6 = SwingGann > SwingGann[1];
condition7 = SwingGann[2] >= SwingGann[1];
condition8 = SwingGann[3] > SwingGann[2];
condition9= SwingGann<>0;

condition10= (condition1 and condition2 and condition3 and condition4 and condition9) ;
condition11= (condition5 and condition6 and condition7 and condition8 and condition9) ;

if(SwingGann[1]<AvgVal[1]) then begin
if condition11 then begin
date1L = date[1];
time1L = time[1];
min1 = SwingGann[1];

DateL[1]= date1L ;
TimeL[1]= time1L ;
SwGannL[1]= min1-TlLoGap;

date2L = DateL[1][2];
time2L = TimeL[1][2];
min2 = SwGannL[1][2];

if(SwGannL[1]>min2) then begin
TlLo = tl_new(DateL[1],TimeL[1],SwGannL[1],date2L,time2L,min2 );
tl_setcolor(TlLo ,TlLo_Color);
tl_Setstyle(TlLo ,TlLo_Style);
end
else TlLo = -1;
end;
end
else begin
if condition10 then begin
date1H = date[1];
time1H = time[1];
max1 = SwingGann[1];
DateH[1]= date1H ;
TimeH[1]= time1H ;
SwGannH[1]= max1+TlUpGap;

date2H = DateH[1][2];
time2H = TimeH[1][2];
max2 = SwGannH[1][2];

if(SwGannH[1]<max2) then begin
TlUp = tl_new(DateH[1],TimeH[1],SwGannH[1],date2H,time2H,max2);
tl_setcolor(TlUp ,TlUp_Color);
tl_Setstyle(TlUp ,TlUp_Style);
end
else TlUP = -1;
end;
end;
//--- end tl LOWER
TlLoGetVal=tl_getvalue(TlLo,d,t);

if (TlLo<>-1) and (Close<TlLoGetVal) then
tl_setend(TlLo,d,t,TlLoGetVal);

//--- end tl UPPER
TlUpGetVal=tl_getvalue(TlUp ,d,t);

if (TlUp<>-1) and (Close>TlUpGetVal) then
tl_setend(TlUp,d,t,TlUpGetVal);


//Strategy ORDER -------------------------------------------+

//Entry LONG: // if Ask cross over trenline lower

//Entry SHORT:// if Bid cross over trendline upper

if (Time>StartTime1) and (Time<EndTime1) then begin
if (TlUp<>-1) and (MarketPosition(1)<> 1) then
BUY("EntryLONG") NContractEntry contracts next bar at TlUpGetVal stop;

if (TlLo<>-1) and (MarketPosition(1)<> -1) then
SELLSHORT("EntrySHORT") NContractEntry contracts next bar at TlLoGetVal stop;
end;

// Set a BREAKEVENT (standard version) ---------------------------------------------------+
if (UseBE) then begin
SetStopPosition;
setbreakeven(BreakEventAmt);
end;

// Set a PROFIT TARGET ------------------------------------------------------------+

SetStopPosition;
setprofittarget(130);

// Set a safety STOP LOSS -----------------------------------------------------+

SetStopPosition;
setstoploss(100);
//----------------------------------------------------------+
// Chiude per sicurezza dei gap di apertura giorno, tutte eventuali posizioni aperte all'ultima barra della sessione aperta di mercato.
SetExitOnClose

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Pb Entries consecutive trendline SwingGann

Postby TJ » 14 Apr 2015

See post #2, point #3
viewtopic.php?f=16&t=10811

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Pb Entries consecutive trendline SwingGann  [SOLVED]

Postby TJ » 14 Apr 2015

You have SetExitOnClose.
Your exit is counted on the same bar as the original entry.


Return to “MultiCharts”