Formula 123 High

Da traderpedia.
Jump to navigation Jump to search

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:

  • Account
    capitale iniziale utilizzabile default (10000)
  • MaxPercRisk
    definisce in percentuale il capitale rischiato in caso di stop loss. Lo stop-loss è due volte questo parametro, di default (2)
  • MaxPercLoss
    definisce in percentuale il massimo rischio accettabile tra prezzo di entry e prezzo di stop. Quando il rischio calcolato è maggiore, il sistema non genera ordini. Di default (5)
  • Note
    il sistema non gestische entrate multiple, ovvero quando è sul mercato non genera altri ordini.


Release: 123 High 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(Magenta), {Colore 1a Barra}
Color2(Red), {"" "" 2a "" ""}
Color3(Magenta), {"" "" 3a "" ""}
History(True), {Cancella old 123High}
NrDelPrev(5); {Se History=False Nr di 123High da cancellare}
Input:Account(10000),MaxPercRisk(2),MaxPercLoss(5),LowRisk(True);
{****************************************************************************}
var: BarHigh1(0), {contatore High 1a barra}
BarLow2Low(0), { "" "" Low 2a "" }
BarLow2High(0), { "" "" High "" "" }
BarHigh3High(0), { "" "" "" 3a "" }
BarHigh3Low(0), { "" "" Low "" "" }
One(False), {True/False 1a Barra}
Two(False), { "" "" 2a "" ""}
Three(False), { "" "" 3a "" ""}
Low2high(False), {Setup High 2a barra}
Low2Low(False), { "" Low "" "" }
High3High(False), { "" High 3a "" }
High3Low(False), { "" Low "" "" }
OffSet(0), {Offset Up/Down Testo}
OldHigh1(0), {Precedente valore del High1 x Nullify Bar}
ValueOne(-1), {ID testo 1a barra}
ValueTwo(-1), {"" "" 2a "" ""}
ValueThree(-1), {"" "" 3a "" ""}
ValueBrk(0), {}
BarTwoTxt(0), {Posizione testo 2a barra}
BarThreeTxt(0), { "" "" "" 3a "" }
CompleteLow(False), {Setup 123High Low }
CompleteHigh(False),{Setup 123High High }
BarBrkout(0), {Posizione breakout 123H }
idx(0), {contatore generico }
Complete(False); {Abilita incremento oldHigh1}
Var:TradeAccount(-1),PosSize(0),TrailBars(10),cCurrentEntries(0),cAvgEntryPrice(0),cEntryPrice(0);
Var:BuyStop(-1),LExitStop(-1),SellStop(-1),SExitStop(-1),HighLimit(-1),XAverage90(0),Eq(0),T1(0);

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

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

{Incrementa contatori}
if complete then OldHigh1=OldHigh1+1;
if complete then BarBrkOut=BarBrkOut+1;
If One Then BarHigh1=BarHigh1+1;
If Low2High then begin
BarLow2High=BarLow2High+1;
BarTwoTxt=BarTwoTxt+1;
end;
If Two And High3High then begin
BarHigh3High=BarHigh3High+1;
BarThreeTxt=BarThreeTxt+1;
end;
If Low2Low then BarLow2Low=BarLow2Low+1;
If High3Low then BarHigh3Low=BarHigh3Low+1;
{Fine incremento contatori}

{inizio setup}
{Se il massimo e' superiore al massimo del High1 allora l' UpTrend continua
annulla il Setup }
if High >= High[BarHigh1] and One then begin
One=False;
Two=False;
Three=False;
Low2High=False;
Low2Low=False;
High3High=False;
High3Low=False;
BarHigh1=0;
BarLow2Low=0;
BarLow2High=0;
BarHigh3high=0;
BarHigh3Low=0;
BarTwoTxt=0;
BarThreeTxt=0;
CompleteLow=False;
CompleteHigh=False;
end;

{Ricerca la prima barra alla fine di un Uptrend }
{Swing High}
if One=False And High[1] >=Highest(High[2],BarsBackTrend) and High < High[1] then begin
BarHigh1=1;
One=True;
Two=False;
Three=False;
Low2High=True;
BarLow2High=0;
Complete=False;
High3High=False;
High3Low=False;
CompleteLow=False;
if Low < Low[1] then begin
Low2Low=True;
BarLow2Low=0;
Two=True;
BarTwoTxt=0;
end;
If Low[1] < Low[2] then begin
Low2Low=True;
BarLow2Low=1;
Two=True;
BarTwoTxt=1;
end;
end;

{Ricerca della 2 barra del 123High}
{Se fine uptrend trovato e non e' stata ancora trovati il minimo < minimo 1a barra}
If One And Two=False and Low < Low[1] and condition1 then begin
Low2Low=True; {trovato massimo superiore aggiorna contatore}
Two=True; {Trovata 2a barra}
Three=False; {cerca 3a barra}
High3High=False;
High3Low=False;
BarLow2Low=0;
BarTwoTxt=0;
end;

{Se setup 1 e 2 barre dell'123High sono passati cerca la 3 barra ritracciata}
If One And Two And Three=False then begin
if High3High=False And High > High[BarLow2High] or High > High[1] and condition1 then begin
High3High=True;
BarHigh3High=0;
BarThreeTxt=0;
end;
if High3Low=False And Low > Low[BarLow2Low] or Low > Low[1] and condition1 then begin
High3Low=True;
BarHigh3Low=0;
end;
if High3High And High3Low then begin
Three=True;
value1=Low[BarHigh1];
BarTwoTxt=BarHigh1;
for idx = BarHigh1 downto 0 begin
if Low[idx] < value1 then begin
value1=Low[idx];
BarTwoTxt=idx;
end;
end;
value1=High[BarTwoTxt];
for idx = BarTwoTxt downto 1 begin
if High[idx] > value1 then begin
value1=High[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 BarHigh1 > MaxBtwBar*3 or MaxList(BarLow2Low,BarLow2High) > MaxBtwBar*2 or MaxList(BarHigh3High,BarHigh3Low) > MaxBtwBar then begin
One=False;
Two=False;
Three=False;
Low2High=False;
Low2Low=False;
High3High=False;
High3Low=False;
BarHigh1=0;
BarLow2Low=0;
BarLow2High=0;
BarHigh3high=0;
BarHigh3Low=0;
BarTwoTxt=0;
end;

{Completamento 123High }
{Ricerca primo ritracciamento completo dell'123High}
If One And Two And Three then begin
If CompleteLow Then BarBrkOut=barBrkOut+1;
If CompleteLow=False And Low < Low[1] then begin
CompleteLow=True;
BarBrkOut=0;
end;
if CompleteHigh=False And High< High[1] then CompleteHigh=True;
If CompleteHigh=False Or CompleteLow=False And High >= High[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[BarHigh1],Time[BarHigh1],High[BarHigh1]+Offset,"1");{Testo della prima barra}
ValueTwo=Text_new(Date[BarTwoTxt],time[barTwoTxt],Low[BarTwoTxt]-Offset,"2");{testo seconda barra }
ValueThree=Text_new(Date[barThreeTxt],time[BarThreeTxt],High[BarThreeTxt]+Offset,"3");
Value1=Text_SetColor(ValueOne,Color1);
Value2=Text_SetColor(ValueTwo,Color2);
Value3=Text_SetColor(ValueThree,Color3);
OldHigh1=BarHigh1;
Complete=True;
end;
One=False;
Two=False;
Three=False;
Low2High=False;
Low2Low=False;
High3High=False;
High3Low=False;
CompleteLow=False;
CompleteHigh=False;
end;
end;

{Setup x RH e display 123H}
If Complete then begin
if DisplayRH then begin
ValueBrk=Text_new(Date[barbrkout],time[barbrkout],Low[barbrkout]-offset*2,"RH------");
Value1=Text_SetColor(ValueBrk,Color2);
end;
Alert("Sell Short < "+NumToStr(Low[BarHigh3Low],3)+" / Stop > "+NumToStr(High[BarHigh3High],3));
{Complete=False;}
end;

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

{ Strategy }
XAverage90=XAverage(Close,89)[1];
if Complete then begin
value9=AbsValue(High[BarThreeTxt]-Low[BarTwoTxt])/Close*100;
if value9<=MaxPercLoss and cCurrentEntries=0 then begin
TradeAccount=Account-(CurrentContracts*AvgEntryPrice)+NetProfit;
if Close>XAverage90 and (LowRisk=false or (High[BarThreeTxt]>XAverage90[BarThreeTxt] and Low[BarTwoTxt]>XAverage90[BarTwoTxt])) then begin
BuyStop=TicksRound(High[BarThreeTxt]+TicksMTS(High[BarThreeTxt]));
LExitStop=TicksRound(Low[BarTwoTxt]-TicksMTS(Low[BarTwoTxt]));
SellStop=-1;
SExitStop=-1;
HighLimit=-1;
end
else if Close<=XAverage90 and (LowRisk=false or (Low[BarTwoTxt]<=XAverage90[BarTwoTxt] and High[BarThreeTxt]<=XAverage90[BarThreeTxt])) then begin
SellStop=TicksRound(Low[BarTwoTxt]-TicksMTS(Low[BarTwoTxt]));
SExitStop=TicksRound(High[BarThreeTxt]+TicksMTS(High[BarThreeTxt]));
HighLimit=TicksRound(High[BarHigh1]+TicksMTS(High[BarHigh1]));
BuyStop=-1;
LExitStop=-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;
HighLimit=-1;
SellStop=-1;
SExitStop=-1;
end;
end;
{print("Complete0 ",date[BarHigh1]," ",date[BarTwoTxt]," ",date[BarThreeTxt]," ",date);
print("Complete1 ",date[BarLow2Low]," ",date[BarLow2High]," ",date[BarHigh3Low]," ",date[Barhigh3High]);}
Complete=False;
end;

if MarketPosition=0 then begin
if BuyStop<>-1 then begin
if Low>LExitStop and Close>XAverage90 then
Buy ("RHL") PosSize shares next bar at BuyStop stop
else begin
BuyStop=-1;
LExitStop=-1;
HighLimit=-1;
end;
end
else if SellStop<>-1 then begin
if High<HighLimit 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;
HighLimit=-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: