allora ragazzi...il poco tempo a disposizione non mi fa procedere speditamente nello sviluppo del TS in amibroker. questo è il listato allo stato attuale.
in pratica vengono calcolati e plottati su grafico i livelli di pivot; vengono calcolati gli entry points (long e short) e per ciascuno di essi, con l'istruzione valuewhen, viene stabilito il livello target a cui vorrei impostare l'uscita dal trade.
ora l'istruzione
Buy = Cl_1 OR Cl_2 OR Cl_3 OR Cl_4 OR Cl_5;
identifica tutti gli entry points long.
il problema è il seguente: Non so come definire l'istruzione Sell
in modo tale che in corrispondenza ad ogni entry level il programma esca se e quando il target relativo è stato raggiunto.
ogni suggerimento è come sempre molto ben accetto.
_SECTION_BEGIN("Pivot Points");
yh = TimeFrameGetPrice( "H", inDaily, -1 );
yl = TimeFrameGetPrice( "L", inDaily, -1 );
yc = TimeFrameGetPrice( "C", inDaily, -1 );
//---------------------------------------------------------------------------
// To calculate the Pivot Levels
//---------------------------------------------------------------------------
pivot = (yh + yl + yc) / 3;
range = yh - yl;
r1 = (2 * pivot) - yl ;
s1 = (2 * pivot) - yh ;
r2 = pivot - s1 + r1;
s2 = pivot - (r1 - s1) ;
r3 = 2 * (pivot - yl) + yh ;
s3 = yl - (2 * (yh - pivot));
//---------------------------------------------------------------------------
// To Plot Pivot Levels in the screen
//---------------------------------------------------------------------------
Plot(pivot, "\n Pivot - ",colorGreen,1);
Plot(r1, "Resistance 1 - ",colorDarkRed,1);
Plot(r2, "Resistance 2 - ",colorDarkRed,1);
Plot(r3, "Resistance 3 - ",colorDarkRed,1);
Plot(s3, "Support 2 - ",colorDarkGreen,1);
Plot(s2, "Support 2 - ",colorDarkGreen,1);
Plot(s1, "Support 1 - ",colorDarkGreen,1);
_SECTION_END();
SetBacktestMode( backtestRegular );
SetOption("InitialEquity", 20000 );
PosQty = 4; // You can define here how many open positions you want
SetOption("MaxOpenPositions", PosQty );
PositionSize = -100/PosQty; // invest 100% of portfolio equity divided by max. position count
// condizioni long
Cl_1 = L<r2 AND Ref(L,-1)>r2;
Cl_2 = L<r1 AND Ref(L,-1)>r1;
Cl_3 = L<Pivot AND Ref(L,-1)>Pivot;
Cl_4 = L<s1 AND Ref(L,-1)>s1;
Cl_5 = L<s2 AND Ref(L,-1)>s2;
// condizioni sell short
Cs_1 = H>r2 AND Ref(H,-1)<r2;
Cs_2 = H>r1 AND Ref(H,-1)<r1;
Cs_3 = H>Pivot AND Ref(H,-1)<Pivot;
Cs_4 = H>s1 AND Ref(H,-1)<s1;
Cs_5 = H>s2 AND Ref(H,-1)<s2;
// condizioni exit (livelli target di uscita da posizioni long e short)
tgt_l1 = ValueWhen (Cl_1, r3, 1);
tgt_l2 = ValueWhen (Cl_2, r2, 1);
tgt_l3 = ValueWhen (Cl_3, r1, 1);
tgt_l4 = ValueWhen (Cl_4, Pivot, 1);
tgt_l5 = ValueWhen (Cl_5, s1, 1);
tgt_s1 = ValueWhen (Cs_1, r1, 1);
tgt_s2 = ValueWhen (Cs_2, Pivot, 1);
tgt_s3 = ValueWhen (Cs_3, s1, 1);
tgt_s4 = ValueWhen (Cs_4, s2, 1);
tgt_s5 = ValueWhen (Cs_5, s3, 1);
Buy = Cl_1 OR Cl_2 OR Cl_3 OR Cl_4 OR Cl_5;
Short = Cs_1 OR Cs_2 OR Cs_3 OR Cs_4 OR Cs_5;