Formula 123 Low

Seguici su Facebook
Da Traderpedia.

Ci sono alcune modifiche minori per gestire alcuni casi non previsti nella rilevazione dei pattern 123, sia high che low. Per quanto riguarda le strategy ho fatto alcune verifiche sperimentali sulle prestazioni dei pattern 123H e 123L, come primo risultato ho riscontrato che il 123H, che in teoria andrebbe usato per entrare short su sfondamento del low di 2, spesso dà ottimi risultati entrando long sù rottura dell'high di 3. Lo stesso vale per il 123L, dove anzichè entrare long sù rottura dell'high di 2, si può anche entrare short su sfondamento del low di 3.

Alla luce di queste verifiche è stato introdotto un filtro per stabilire in che direzione entrare in presenza di un pattern,  "the trend is your friend" e quindi è stata inserita una media mobile esponenziale a 90 periodi come filtro indicatore del trend primario. Aggiunto anche l' Expert Commentary


Descrizione di alcune variabili di Input:


Release: 123 Low  Version 0.0.6 15.10.2005

Categoria: Strategia
Formula per Tradestation™:

INIZIO FORMULA

input: BarsBackTrend(15), {Bars Back ricerca del trend}
MaxBtwBar(4), {Max barre tra successive sequenze}
DisplayRH(True), {Abilita/Disabilita visualizzazione RH}
chkRange(True), {Abilita/Disabilita controllo Range > 0}
Color1(Cyan), {Colore 1a Barra}
Color2(Red), {"" "" 2a "" ""}
Color3(Cyan), {"" "" 3a "" ""}
History(True), {Cancella old 123Low}
NrDelPrev(5); {Se History=False Nr di 123Low da cancellare}
Input:Account(10000),MaxPercRisk(2),MaxPercLoss(5),LowRisk(True);
{****************************************************************************}
var: BarLow1(0), {contatore Low 1a barra}
BarHigh2Low(0), { "" "" Low 2a "" ""}
BarHigh2High(0), { "" "" High "" "" ""}
BarLow3High(0), { "" "" High 3a "" ""}
BarLow3Low(0), { "" "" Low "" "" ""}
One(False), {True/False 1a Barra}
Two(False), { "" "" 2a "" ""}
Three(False), { "" "" 3a "" ""}
High2High(False), {Setup High 2a Barra}
High2Low(False), { "" Low "" "" }
Low3High(False), { "" High 3a "" }
Low3Low(False), { "" Low "" "" }
OffSet(0), {Offset Up/Down Testo}
OldLow1(0), {Precedente valore del High1 x Nullify Bar}
ValueOne(0), {ID testo 1a barra}
ValueTwo(0), {"" "" 2a "" ""}
ValueThree(0), {"" "" 3a "" ""}
ValueBrk(0), {}
BarTwoTxt(0), {Posizione testo 2a barra}
BarThreeTxt(0), {"" "" "" 3a "" }
CompleteLow(False), {Setup 123Low Low }
CompleteHigh(False),{Setup 123Low High }
BarBrkout(0), {Posizione Breakout 123Low}
idx(0), {Contatore generico }
Complete(False); {Setup 123Low }
Var:TradeAccount(-1),PosSize(0),TrailBars(10),cCurrentEntries(0),cAvgEntryPrice(0),cEntryPrice(0);
Var:BuyStop(-1),LExitStop(-1),SellStop(-1),SExitStop(-1),LowLimit(-1),XAverage90(0),Eq(0),T1(0);

{****************************************************************************}

condition1=True;
if chkRange then condition1=Range > 0 ;

{Incrementa contatori}
if complete then OldLow1=OldLow1+1;
if complete then BarBrkOut=BarBrkOut+1;
If One Then BarLow1=BarLow1+1;
If High2High then BarHigh2High=BarHigh2High+1;
if Two then BarTwoTxt=BarTwoTxt+1;
If High2Low then BarHigh2Low=BarHigh2Low+1;
If Two And Low3High then begin
BarLow3High=BarLow3High+1;
BarThreeTxt=BarThreeTxt+1;
end;
If Low3Low then BarLow3Low=BarLow3Low+1;
{fine incremento contatori}

{Inizio Setup}
{Se il minimo e' inferiore al minimo del Low1 allora l' DownTrend continua
annulla il Setup }
if Low <= Low[BarLow1] and One then begin
One=False;
Two=False;
Three=False;
High2High=False;
High2Low=False;
Low3High=False;
Low3Low=False;
BarLow1=0;
BarHigh2Low=0;
BarHigh2High=0;
BarLow3High=0;
BarLow3Low=0;
BarTwoTxt=0;
BarThreeTxt=0;
CompleteLow=False;
CompleteHigh=False;
end;

{Ricerca la prima barra alla fine di un Downtrend }
{Swing Low}
if One=False And Low[1] <= Lowest(Low[2],BarsBackTrend) and Low > Low[1] then begin
BarLow1=1;
One=True;
Two=False;
Three=False;
Low3High=False;
Low3Low=False;
CompleteHigh=False;
CompleteLow=False;
if Low > Low[1] then begin
High2Low=True;
BarHigh2Low=0;
Two=True;
BarTwoTxt=0;
end;
If Low[1] > Low[2] then begin
High2Low=True;
BarHigh2Low=1;
Two=True;
BarTwoTxt=1;
end;
end;

{Ricerca della 2 barra del 123Low}
{Se fine downtrend trovato e non e' stata ancora trovato il massimo > massimo 1a barra}
If One And Two = False and High > High[1] and condition1 then begin
High2High=True;
Two=True;
Three=False;
Low3High=False;
Low3Low=False;
BarHigh2High=0;
BarTwoTxt=0;
end;

{Se setup 1 e 2 barre dell'123Low sono passati cerca la 3 barra ritracciata}
If One And Two And Three = False then begin
if Low3High=False And High < High[BarHigh2High] or High < High[1] and Condition1 then begin
Low3High=True;
BarLow3High=0;
end;
if Low3Low=False And Low < Low[BarHigh2Low] or Low < Low[1] and condition1 then begin
Low3Low=True;
BarLow3Low=0;
BarThreeTxt=0;
end;
if Low3High And Low3Low then begin
Three=True;
value1=High[BarLow1];
BarTwoTxt=BarLow1;
for idx = BarLow1 downto 0 begin
if High[idx] > value1 then begin
value1=High[idx];
BarTwoTxt=idx;
end;
end;
value1=Low[BarTwoTxt];
for idx = BarTwoTxt downto 1 begin
if Low[idx] < value1 then begin
value1=Low[idx];
BarThreeTxt=idx;
end;
end;
End;
CompleteLow=False;
CompleteHigh=False;
end;

{Controllo che la combinazioni non superi il numero massimo delle barre}
{Ross consiglia max 3 barre 1 ,2, e 3 }
if BarLow1 > MaxBtwBar*3 or MaxList(BarHigh2Low,BarHigh2High) > MaxBtwBar*2 or MaxList(BarLow3High,BarLow3Low) > MaxBtwBar then begin
One=False;
Two=False;
Three=False;
High2High=False;
High2Low=False;
Low3High=False;
Low3Low=False;
BarLow1=0;
BarHigh2Low=0;
BarHigh2High=0;
BarLow3High=0;
BarLow3Low=0;
BarTwoTxt=0;
end;

{Completamento 123Low }
{ricerca primo ritracciamneto completo dell'123Low}
If One And Two And Three then begin
If CompleteLow=False And Low > Low[1] then CompleteLow=True;
if completeHigh then BarBrkOut=BarBrkOut+1;
if CompleteHigh=False And High > High[1] then begin
CompleteHigh=True;
BarBrkout=0;
end;
If CompleteHigh=False Or CompleteLow=False And Low <= Low[barThreeTxt] then BarThreeTxt=0;
If CompleteLow And CompleteHigh then begin
if date[BarTwoTxt] <= date[BarThreeTxt] then begin
Offset=Average(Range,15)*0.5; {Offset x testo}
{Trova il minimo e il massimo tra la 1a e la 3a dell-123Low}
ValueOne=TEXT_new(Date[BarLow1],Time[BarLow1],Low[BarLow1]-Offset,"1");{Testo della prima barra}
ValueTwo=Text_new(Date[BarTwoTxt],time[barTwoTxt],High[BarTwoTxt]+Offset,"2");{testo seconda barra }
ValueThree=Text_new(Date[barThreeTxt],time[BarThreeTxt],Low[BarThreeTxt]-Offset,"3");
Value1=Text_SetColor(ValueOne,Color1);
Value2=Text_SetColor(ValueTwo,Color2);
Value3=Text_SetColor(ValueThree,Color3);
OldLow1=BarLow1;
Complete=True;
end;
One=False;
Two=False;
Three=False;
High2High=False;
High2Low=False;
Low3High=False;
Low3Low=False;
CompleteLow=False;
CompleteHigh=False;
end;
end;

{Set x RH e display 123L}
if Complete then begin
if DisplayRH then begin
ValueBrk=Text_new(Date[barbrkout],time[barbrkout],High[barbrkout]+offset*2,"RH------");
Value1=Text_SetColor(ValueBrk,Color2);
end;
Alert("Buy Long > "+NumToStr(High[BarLow3High],3)+" / Stop < "+NumToStr(Low[BarLow3Low],3));
{complete=False;}
end;

{Se True cancella vecchie barre}
if History=False and ValueOne > NrDelPrev then value1=Text_Delete(Text_Getfirst(1));

{ if false then Plot1(0,""); Not in Signal }

{ Strategy }
XAverage90=XAverage(Close,89)[1];
if Complete then begin
value9=AbsValue(High[BarTwoTxt]-Low[BarThreeTxt])/Close*100;
if value9<=MaxPercLoss and cCurrentEntries=0 then begin
TradeAccount=Account-(CurrentContracts*AvgEntryPrice)+NetProfit;
{print(Close," ",XAverage90," ",date);
print(High[BarTwoTxt]," ",XAverage90[BarTwoTxt]," ",Low[BarThreeTxt]," ",XAverage90[BarThreeTxt]);
print(Low[BarThreeTxt]," ",XAverage90[BarThreeTxt]," ",High[BarTwoTxt]," ",XAverage90[BarTwoTxt]);}
if Close>XAverage90 and (LowRisk=false or (High[BarTwoTxt]>XAverage90[BarTwoTxt] and Low[BarThreeTxt]>XAverage90[BarThreeTxt])) then begin
BuyStop=TicksRound(High[BarTwoTxt]+TicksMTS(High[BarTwoTxt]));
LExitStop=TicksRound(Low[BarThreeTxt]-TicksMTS(Low[BarThreeTxt]));
LowLimit=TicksRound(Low[BarLow1]-TicksMTS(Low[BarLow1]));
SellStop=-1;
SExitStop=-1;
end
else if Close<=XAverage90 and (LowRisk=false or (Low[BarThreeTxt]<=XAverage90[BarThreeTxt] and High[BarTwoTxt]<=XAverage90[BarTwoTxt])) then begin
SellStop=TicksRound(Low[BarThreeTxt]-TicksMTS(Low[BarThreeTxt]));
SExitStop=TicksRound(High[BarTwoTxt]+TicksMTS(High[BarTwoTxt]));
BuyStop=-1;
LExitStop=-1;
LowLimit=-1;
end;
if MaxList(BuyStop,SellStop)<>-1 and TradeAccount>2*MaxList(BuyStop,SellStop) then
PosSize=PositionMoneyMng(TradeAccount,MaxPercRisk,MaxList(BuyStop,SellStop),MaxList(BuyStop,SExitStop)-MaxList(LExitStop,SellStop))
else begin
BuyStop=-1;
LExitStop=-1;
LowLimit=-1;
SellStop=-1;
SExitStop=-1;
end;
end;
Complete=False;
{print("Complete0 ",date[BarLow1]," ",date[BarTwoTxt]," ",date[BarThreeTxt]);
print("Complete1 ",date[BarHigh2Low]," ",date[BarHigh2High]," ",date[BarLow3Low]," ",date[BarLow3High]);}
end;

if MarketPosition=0 then begin
if BuyStop<>-1 then begin
if Low>LowLimit and Close>XAverage90 then
Buy ("RHL") PosSize shares next bar at BuyStop stop
else begin
BuyStop=-1;
LExitStop=-1;
LowLimit=-1;
end;
end
else if SellStop<>-1 then begin
if High<SExitStop and Close<=XAverage90 then
Sell ("RHS") PosSize shares next bar at SellStop stop
else begin
SellStop=-1;
SExitStop=-1;
end;
end;
end;

cCurrentEntries=CurrentEntries;
cAvgEntryPrice=AvgEntryPrice;
if (cCurrentEntries>cCurrentEntries[1]) then begin
cEntryPrice=(CurrentContracts*AvgEntryPrice-(CurrentContracts-PosSize)*cAvgEntryPrice[1])/PosSize;
BuyStop=-1;
LowLimit=-1;
SellStop=-1;
end;
if (cCurrentEntries=0 and cCurrentEntries[1]<>0) then begin
LExitStop=-1;
SExitStop=-1;
end;

{ Gestione Exit Stop & Trailing }
if MarketPosition=1 then begin
{if Low>cEntryPrice and cEntryPrice>LExitStop then
LExitStop=cEntryPrice;} {Peggiora performance}
ExitLong ("LES") next bar at LExitStop stop;
if BarsSinceEntry>TrailBars then
ExitLong ("LET") next bar at TicksRound(Lowest(Low,TrailBars)) stop;
end
else if MarketPosition=-1 then begin
{if High<cEntryPrice and cEntryPrice<SExitStop then
SExitStop=cEntryPrice;} {Peggiora performance}
ExitShort ("SES") next bar at SExitStop stop;
if BarsSinceEntry>TrailBars then
ExitShort ("SET") next bar at TicksRound(Highest(High,TrailBars)) stop;
end;

{ Expert Commentary Report }
If AtCommentaryBar then begin
Eq=Account-(CurrentContracts*AvgEntryPrice)+NetProfit;
Vars:Str("");
Str=Str+"*************** System inputs **************************"+NewLine;
Str=Str+"Starting Capital : "+NumToStr(Account,2)+NewLine;
Str=Str+"Percentage of Equity to risk : "+NumToStr(MaxPercRisk,2)+" % "+NewLine;
Str=Str+"*************** Current statistics ************************"+NewLine;
Str=Str+"Market position : "+NumToStr(MarketPosition,0)+NewLine;
Str=Str+"Current Shares held : "+NumToStr(CurrentContracts,0)+NewLine;
Str=Str+"Current Equity : "+NumToStr(Eq,2)+NewLine;
if BuyStop<>-1 or SellStop<>-1 then
Str=Str+"Percentage of current Equity to risk : "+NumToStr(MaxPercRisk,2)+" % equals "+NumToStr(-Eq*MaxPercRisk/100,2)+" dollars "+NewLine;
If BuyStop<>-1 then begin
Str=Str+"Entry Long : "+NumToStr(BuyStop,4)+NewLine;
Str=Str+"Exit Long : " +NumToStr(LExitStop,4)+NewLine;
Str=Str+"Difference between Entry Long and Exit Long in Dollars : "+NumToStr(BuyStop-LExitStop,4)+NewLine;
Str=Str+"Number of shares to buy to risk "+NumToStr(MaxPercRisk,2)+" % of capital : "+NumToStr(PosSize,0)+NewLine;
end
else If MarketPosition=1 then begin
Eq=Account+NetProfit;
T1=-CurrentContracts*(cAvgEntryPrice-LExitStop);
Str=Str+"Percentage of current Equity to risk : "+NumToStr(AbsValue(100*T1/Eq),2)+" % equals "+NumToStr(T1,2)+" dollars "+NewLine;
Str=Str+"Entry Long : "+NumToStr(cEntryPrice,4)+NewLine;
Str=Str+"Exit Long : " +NumToStr(LExitStop,4)+NewLine;
Str=Str+"Difference between Entry Long and Exit Long in Dollars : "+NumToStr(cEntryPrice-LExitStop,4)+NewLine;
Str=Str+"Open Position Profit in Dollars : "+NumToStr(OpenPositionProfit,2)+NewLine;
end;
If SellStop<>-1 then begin
Str=Str+"Entry Short : "+NumToStr(SellStop,4)+NewLine;
Str=Str+"Exit Short : " +NumToStr(SExitStop,4)+NewLine;
Str=Str+"Difference between Entry Short and Exit Short in Dollars : "+NumToStr(SExitStop-cEntryPrice,4)+NewLine;
Str=Str+"Number of shares to Sell to risk "+NumToStr(MaxPercRisk,2)+" % of capital : "+NumToStr(PosSize,0)+NewLine;
end
else If MarketPosition=-1 then begin
Eq=Account+NetProfit;
T1=-CurrentContracts*(SExitStop-cAvgEntryPrice);
Str=Str+"Percentage of current Equity to risk : "+NumToStr(AbsValue(100*T1/Eq),2)+" % equals "+NumToStr(T1,2)+" dollars "+NewLine;
Str=Str+"Entry Short : "+NumToStr(cEntryPrice,4)+NewLine;
Str=Str+"Exit Short : " +NumToStr(SExitStop,4)+NewLine;
Str=Str+"Difference between Entry Short and Exit Short in Dollars : "+NumToStr(SExitStop-cEntryPrice,4)+NewLine;
Str=Str+"Open Position Profit in Dollars : "+NumToStr(OpenPositionProfit,2)+NewLine;
end;
Commentary(Str);
end;

FINE FORMULA

Vedi anche:

Strumenti personali
Varianti
Azioni




Navigazione
Categorie Principali
Altre Categorie
Traderpedia Store