[IntrabarOrderGeneration = True];
inputs:
// TS inputs
TargetPoints(10),
stopPoints(20),
RR(0),
// end TS input
Price( Close ),
RetraceType( 1 ), // 1 points , 2 percent
RetracePct( 0 ),
RetracePnts( 12 ),
LineColor( Yellow ),
LineWidth( 1 ),
ZigZagLineColorDN( yellow ),
ZigZagLineColorUP( cyan ),
Time_MorningStart_at ( 0800 ),
Time_MorningStop_at ( 1930 ), // set this higher if you do not need 2 window of the session but just once
Time_AfternoonStart_at ( 1530 ),
Time_AfternoonStop_at ( 1730),
Time_CLOSE_SESSION (2120), // close every open contract at this time
VertOffset1 ( 8 ); // offset for display zigzag swings
variables:
NewSwingPrice( 0 ), // SwingHigh/Low zig
SwingPrice( Price ),
ZigZagCount(0),
SwingDate( Date ),
SwingTime( Time ),
PeakTextRef(0), // testo per plottare valore swing
PeakStr(""),
ShowEnterAt(0),
isTheRightTime (false),
canEntry(false),
printDebug (true),
TLDir( 0 ),
var5( 1 + RetracePct * .01 ), // percent retrace up
var6( 1 - RetracePct * .01 ), // percent retrace down
RetracePriceLevel(0), // retracement value for ptns and %
SaveSwing( false ),
AddTL( false ),
UpdateTL( false ),
var10( 0 ),
//----------------
intrabarpersist zigEnabled (false),
intrabarpersist canPrint (false),
//---------------
z1(0),
z2(0),
z3(0),
X(0),
Y(0),
Z(0);
arrays:
ZigZagArray[10,4](0); // Save here the latest swings
//Time frame of the day where entries are allowed
isTheRightTime = ( time >= Time_MorningStart_at and time <= Time_MorningStop_at) or ( time >= Time_AfternoonStart_at and time <= Time_AfternoonStop_at);
//Selezione caso rintracciamento percentuale o a punti
Switch(TLDir)
Begin
Case <= 0:
Switch(RetraceType)
Begin
Case 1: RetracePriceLevel=SwingPrice+RetracePnts;
Case 2: RetracePriceLevel=SwingPrice*var5;
End;
Case >= 0:
Switch(RetraceType)
Begin
Case 1: RetracePriceLevel=SwingPrice-RetracePnts;
Case 2: RetracePriceLevel=SwingPrice*var6;
End;
End;
NewSwingPrice = SwingHigh( 1, Close, 1, 2 ) ; // Picco UP, se al posto di Price metto H usa i massimi altrimenti i close per i vertici
if NewSwingPrice <> -1 then
begin
condition1 = TLDir <= 0 and NewSwingPrice>= RetracePriceLevel ; // var1 * var5 rappresenta RetracePriceLevel
if condition1 then // mi preparo ad aggiungere una trend line UP
begin
SaveSwing= true ;
AddTL= true ;
TLDir= 1 ;
//Alert("Swing Up");
end
else
begin // preparo un upgrade alla trend line UP precedente
condition1 = TLDir= 1 and NewSwingPrice>= SwingPrice;
if condition1 then
begin
SaveSwing= true ;
UpdateTL = true ;
//Alert("Swing Up");
end ;
end;
end
else
begin
NewSwingPrice= SwingLow( 1, Price, 1, 2 ) ; // Picco DOWN
if NewSwingPrice<> -1 then
begin
condition1 = TLDir>= 0 and NewSwingPrice<= RetracePriceLevel ;
if condition1 then
begin
SaveSwing= true ;
AddTL= true ;
TLDir= -1 ;
//Alert("Swing Down");
end
else
begin // preparo un upgrade alla trend line DOWN precedente
condition1 = TLDir= -1 and NewSwingPrice<= SwingPrice;
if condition1 then
begin
SaveSwing= true;
UpdateTL= true ;
//Alert("Swing Down");
end ;
end;
end ;
end ;
if SaveSwing then
begin
SwingPrice= NewSwingPrice;
SwingDate= Date[1] ;
SwingTime= Time[1] ;
SaveSwing= false ;
canEntry= true; // variabile per evitare entrate multiple, cos in teoria puo' farlo solo una volta dopo ogni swing confermato
end ;
if AddTL then
begin
var10 = TL_New( SwingDate, SwingTime, SwingPrice, SwingDate[1], SwingTime[1],
SwingPrice[1] ) ;
TL_SetExtLeft( var10, false ) ;
TL_SetExtRight( var10, false ) ;
TL_SetSize( var10, LineWidth ) ;
PeakTextRef=Text_New(Date,Time,Close," "); // Inizializzo
If(TLDir=-1)Then TL_SetColor(var10,ZigZagLineColorDN)
Else TL_SetColor(var10,ZigZagLineColorUp);
ZigZagCount=ZigZagCount+1;
//Scalo di un posto indietro i valori degli swing prima di inserire il nuovo al posto 0
For Y=9 DownTo 0
Begin
For Z=1 to 4
Begin
ZigZagArray[Y+1,Z]=ZigZagArray[Y,Z];
End;
End;
//Inserisco i nuovi dati dello swing nella prima riga ovvero la zero
ZigZagArray[0,1]=SwingPrice; {Current Swing Price}
ZigZagArray[0,2]=BarNumber; {BarNumber}
ZigZagArray[0,3]=TimetoMinutes(SwingTime); {SwingTime Variable}
ZigZagArray[0,4]=ZigZagCount; {Current ZZ Count}
//print(" zigzag " , NumToStr(ZigZagArray[1,1],2), " ZZ number: " , NumToStr(ZigZagCount,0));
//Plot valore swing
PeakStr=NumToStr(SwingPrice,2);
Text_SetString(PeakTextRef,PeakStr);
Text_SetStyle(PeakTextRef,2,2);
If(TLDir=-1)Then Text_SetColor(PeakTextRef,ZigZagLineColorDN)
Else Text_SetColor(PeakTextRef,ZigZagLineColorUp);
If(TLDir=-1)Then Text_SetLocation(PeakTextRef,SwingDate,SwingTime,SwingPrice - VertOffset1)
else Text_SetLocation(PeakTextRef,SwingDate,SwingTime,SwingPrice + VertOffset1);
AddTL = false ;
canEntry = false;
end
else if UpdateTL then
begin
TL_SetEnd( var10, SwingDate, SwingTime, SwingPrice) ;
ZigZagArray[0,1]=SwingPrice; {Current Swing Price}
ZigZagArray[0,2]=BarNumber; {BarNumber}
ZigZagArray[0,3]=TimetoMinutes(SwingTime); {SwingTime Variable}
//Plot valore swing
PeakStr=NumToStr(SwingPrice,2);
Text_SetString(PeakTextRef,PeakStr);
Text_SetStyle(PeakTextRef,2,2);
If(TLDir=-1)Then Text_SetColor(PeakTextRef,ZigZagLineColorDN)
Else Text_SetColor(PeakTextRef,ZigZagLineColorUp);
If(TLDir=-1)Then Text_SetLocation(PeakTextRef,SwingDate,SwingTime,SwingPrice - VertOffset1)
else Text_SetLocation(PeakTextRef,SwingDate,SwingTime,SwingPrice + VertOffset1);
UpdateTL= false ;
end ;
CommentaryCL ("PeakStr: ",PeakStr,NewLine);
//--------------------------------- STRATEGY START HERE ---------------------------------------
// lo swing attuale (quello che sarebbe z0) e' la variabile SwingPrice
z1 = ZigZagArray[1,1];
z2 = ZigZagArray[2,1];
z3 = ZigZagArray[3,1];
//print("il valore delllo zig 1,1 alle ore ", time," e' ", NumToStr(z1,2), NewLine, NewLine, "mentre lo zig 2,1 e' ", NumToStr(z2,0), NewLine, NewLine,"mentre lo zig 3,1 e' ", NumToStr(z3,0));
if marketposition = 0 then // and isTheRightTime then
begin
//if z2 < z3 and z2 < z1 and z1 < z3 and // condizione massimi decrescenti
if z1 < z2 and z1 < SwingPrice and SwingPrice < z2 and // condizione massimi decrescenti
L < z1 // mi assicuro che una volta passato z1 ovvero il punto 2 l'ordine rimanga a mercato
then begin
//if printDebug and barstatus = 2 then print(NewLine," Punto 3 = SwingPrice alle ore ", time," e' ", NumToStr(swingPrice,2), NewLine, NewLine, " punto 2 = z[1,1] e' ",
//NumToStr(z1,2), NewLine, NewLine,"punto 1 = z[2,1] e' ", NumToStr(z2,2));
//if printDebug then print(NewLine," --Data ",FormatDate("dd-MM-yyyy", ELDateToDateTime(Date))," --Time ",NumToStr(time,0),"-------> SHORT at ", NumToStr(entryprice,2),NewLine);
//ShowEnterAt = Text_New(Date,Time,Close," Zig Short ");
//Text_SetLocation(ShowEnterAt ,barnumber,time,H + VertOffset1);
sellshort ("Short Entry") 1 contract next bar at z1 - 1 * ticksize + RR * ticksize limit;
//canEntry = false;
end;
//if z2 > z3 and z2 > z1 and z1 > z3 and // condizione minimi crescenti
if z1 > z2 and z1 > SwingPrice and SwingPrice > z2 and // condizione minimi crescenti
H > z1 // mi assicuro che una volta passato z1 ovvero il punto 2 l'ordine rimanga a mercato
then begin
//if printDebug and barstatus = 2 then print(NewLine," Punto 3 = SwingPrice alle ore ", time," e' ", NumToStr(swingPrice,2), NewLine, NewLine, " punto 2 = z[1,1] e' ",
// NumToStr(z1,2), NewLine, NewLine,"punto 1 = z[2,1] e' ", NumToStr(z2,2));
//if printDebug then print(NewLine," --Data ",FormatDate("dd-MM-yyyy", ELDateToDateTime(Date))," --Time ",NumToStr(time,0),"-------> LONG at ", NumToStr(entryprice,2),NewLine);
ShowEnterAt = Text_New(Date,Time,Close," Zig Long ");
Text_SetLocation(ShowEnterAt ,date,time,L - VertOffset1);
buy ("Long Entry") 1 contract next bar at z1 + 1 * ticksize - RR * ticksize limit;//
canPrint = true;
end;
end;
setstoploss( stopPoints * bigpointvalue);
setprofittarget( targetPoints * bigpointvalue );
if marketposition = 1 then begin
//Sell("TargetLong") 1 contract Next Bar at (entryprice + TargetPoints) limit;
//Sell("StopLong") 1 contract Next Bar at (entryprice - stopPoints) stop;
if printDebug and canPrint and barstatus = 2 then print(NewLine," Punto 3 = SwingPrice alle ore ", time," e' ", NumToStr(swingPrice,2), NewLine, NewLine, " punto 2 = z[1,1] e' ",
NumToStr(z1,2), NewLine, NewLine,"punto 1 = z[2,1] e' ", NumToStr(z2,2));
if time = Time_CLOSE_SESSION then sell("LE CLOSE SESSION") 1 contract next bar at market;
canprint = false;
end;
if marketposition = -1 then begin
//buytocover("TargetShort") 1 contract Next Bar at (entryprice - TargetPoints) limit;
//buytocover("StopShort") 1 contract Next Bar at (entryprice + stopPoints) stop;
if time = Time_CLOSE_SESSION then buytocover("SE CLOSE SESSION") 1 contract next bar at market;
end;
|