Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
/*
//------------------------------------------------------------------------------
Program Overview
This program classifies price action into the following states based upon rules
StateNo1 - Up Trend
StateNo2 - Nat Rally
StateNo3 - Sec Rally
StateNo4 - Dn Trend
StateNo5 - Nat React
StateNo6 - Sec React
//------------------------------------------------------------------------------
*/
if(i==0)
{ //Initialization
//var:
StateNo[i]=1;
InUpTrend[i]=True;
InDnTrend[i]=False;
NatRallyReset[i]=True;
NatReactReset[i]=True;
UpTrendPP[i]=C[0];
NatRallyPP[i]=C[0];
NatReactPP[i]=C[0];
DnTrendPP[i]=C[0];
} //end;
else //{Main}
{ //begin //{calc current Threshold if required}
StateNo[i]=StateNo[i-1];
InUpTrend[i]=InUpTrend[i-1];
InDnTrend[i]=InDnTrend[i-1];
UpTrend[i] = UpTrend[i-1];
NatRally[i] = NatRally[i-1];
SecRally[i] = SecRally[i-1];
SecReact[i] = SecReact[i-1];
NatReact[i] = NatReact[i-1];
DnTrend[i] = DnTrend[i-1];
NatRallyReset[i]=NatRallyReset[i-1];
NatReactReset[i]=NatReactReset[i-1];
UpTrendPP[i]=UpTrendPP[i-1];
NatRallyPP[i]=NatRallyPP[i-1];
NatReactPP[i]=NatReactPP[i-1];
DnTrendPP[i]=DnTrendPP[i-1];
ThresholdPct[i]=ThresholdPercentValue[i]/100;
//------------------------------------------------------------------------------
//111111111111111111111111111111111111111111111111111111111111111111111111111111
//------------------------------------------------------------------------------
//State No 1: In Up Trend Column
if(StateNo[i-1]==1)//
{//UpTrend Routine
if(C[i]>=C[i-1])
{//Price Move Up
if(C[i]>UpTrend[i])
{
StateNo[i]=1;//Remain in UpTrend -
1111111111111111111111111111111
InUpTrend[i]=True;
InDnTrend[i]=False;
UpTrend[i]=C[i];
}
}//End of Price Move Up
else
{//Price Move Dn
if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR //PivotPoint Check
(InUpTrend[i] AND C[i]< UpTrend[i]/(1+2*ThresholdPct[i])) )
{//Drop to DnTrend
StateNo[i]=6;//Dn Trend -
6666666666666666666666666666666666666666
InDnTrend[i]=True;
InUpTrend[i]=False;
DnTrend[i]=C[i];
UpTrendPP[i]=UpTrend[i];
}// End of Drop to DnTrend
else
{
if(C[i]<(UpTrend[i]/(1+ThresholdPct[i])))
{//Drop Below Current State React
if(NatReactReset[i] OR C[i] < NatReact[i])
{//First Time or Below NatReact
StateNo[i]=5;//Nat React -
55555555555555555555555555555555
NatReactReset[i]=False;
NatReact[i]=C[i];
UpTrendPP[i]=UpTrend[i];
}//End of First Time or Below NatReact
else
{//Drop to SecReact
StateNo[i]=4;//SecReact -
444444444444444444444444444444444
SecReact[i]=C[i];
UpTrendPP[i]=UpTrend[i];
}//End of Drop to SecReact
}
}//End of Drop Below Current Price React
}//End of Price Move Dn
}//End of UpTrend Routine
//------------------------------------------------------------------------------
//222222222222222222222222222222222222222222222222222222222222222222222222222222
//------------------------------------------------------------------------------
//State No 2: In Nat Rally Column
else if(StateNo[i-1]==2)//
{//NatRally Routine
//NatRallyReset=False;
if(C[i]>C[i-1])
{//Price Move Up
if( (InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
(InDnTrend[i] AND C[i]> DnTrend[i]*(1+2*ThresholdPct[i])) )
{//Price move to UpTrend -
1111111111111111111111111111111111111111111
StateNo[i]=1;
InUpTrend[i]=True;
InDnTrend[i]=False;
UpTrend[i]=C[i];
}//End of Price Move to UpTrend
else
{
if(C[i]>NatRally[i])
{//Price Continue to move to higher NatRally
StateNo[i]=2;//Remain in NatRally -
222222222222222222222222222
NatRally[i]=C[i];
NatRallyReset[i]=False;
}//End of Price Continue to move to higher NatRally
}
}//End of Price Move Up
else //of(C[i]>C[i-1])
{//Price Move Dn
if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR
(InUpTrend[i] AND C[i]< UpTrend[i]/(1+2*ThresholdPct[i])) )
{//Drop to DnTrend
StateNo[i]=6;//Dn Trend -
6666666666666666666666666666666666666666
InDnTrend[i]=True;
InUpTrend[i]=False;
DnTrend[i]=C[i];
NatRallyPP[i]=NatRally[i];
}// End of Drop to DnTrend
else
{
if(C[i]<(NatRally[i]/(1+ThresholdPct[i])))
{//Drop Below Current State React
if(NatReactReset[i] OR C[i] < NatReact[i])
{//First Time or Below NatReact
StateNo[i]=5;//Nat React -
55555555555555555555555555555555
NatReactReset[i]=False;
NatReact[i]=C[i];
NatRallyPP[i]=NatRally[i];
}//End of First Time or Below NatReact
else
{//Drop to SecReact
StateNo[i]=4;//SecReact -
444444444444444444444444444444444
SecReact[i]=C[i];
NatRallyPP[i]=NatRally[i];
}//End of Drop to SecReact
}
}//End of Drop Below Current Price React
}//End of Price Move Dn
}//End of NatRally Routine
//------------------------------------------------------------------------------
//333333333333333333333333333333333333333333333333333333333333333333333333333333
//------------------------------------------------------------------------------
//State No 3: In Sec Rally Column
else if(StateNo[i-1]==3) //
{//SecRally Routine
if(C[i]>C[i-1])
{//Price Move Up
if( (InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
(InDnTrend[i] AND C[i]> DnTrend[i]*(1+2*ThresholdPct[i])) )
{//Price move to UpTrend -
1111111111111111111111111111111111111111111
StateNo[i]=1;
InUpTrend[i]=True;
InDnTrend[i]=False;
UpTrend[i]=C[i];
}//End of Price Move to UpTrend
else
{
if(C[i]>NatRally[i])
{//Price Continue to move to higher NatRally
StateNo[i]=2;//Remain in NatRally -
222222222222222222222222222
NatRally[i]=C[i];
NatRallyReset[i]=False;
if(C[i]>C[i-1])
{//Price Move Up
if( (InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
(InDnTrend[i] AND C[i]> DnTrend[i]*(1+2*ThresholdPct[i])) )
{//Price move to UpTrend -
1111111111111111111111111111111111111111111
StateNo[i]=1;
InUpTrend[i]=True;
InDnTrend[i]=False;
UpTrend[i]=C[i];
}//End of Price Move to UpTrend
else
{
if(C[i]>(SecReact[i]*(1+ThresholdPct[i])))
{//Raise Above Current State React
if(C[i]>NatRally[i])
{
StateNo[i]=2;//Move to NatRally -
2222222222222222222222
NatRally[i]=C[i];
NatRallyReset[i]=False;
}
else
{//Raise to SeconaryRally
StateNo[i]=3;//Raise to SecRally -
333333333333333333333
SecRally[i]=C[i];
}//End of Raise to SecRally
}// End of Raise Above Current State React
}
}//End of Price Move Up
else //of(C[i]>C[i-1])
{//Price Move Dn
if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR
(InUpTrend[i] AND C[i]< UpTrend[i]/(1+2*ThresholdPct[i])) )
{//Drop to DnTrend
StateNo[i]=6;//Dn Trend -
6666666666666666666666666666666666666666
InDnTrend[i]=True;
InUpTrend[i]=False;
DnTrend[i]=C[i];
}// End of Drop to DnTrend
else
{
if(C[i]<NatReact[i])
{//Raise Above NatReact
StateNo[i]=5;//NatReact -
5555555555555555555555555555555555555
NatReact[i]=C[i];
}//Raise Above NatReact
else
{//Remain at SecReact
if(C[i]<SecReact[i])
{//Lower SecReact
SecReact[i]=C[i];
}//End of Lower SecReact
}//End of Remain at SecReact
}
}//End of Price Move Dn
}//End of Sec React Routine
//------------------------------------------------------------------------------
//555555555555555555555555555555555555555555555555555555555555555555555555555555
//------------------------------------------------------------------------------
//State No 5: In Nat React Column
else if(StateNo[i-1]==5)//
{//NatReact Routine
//NatReactReset=False;
if(C[i]>C[i-1])
{//Price Move Up
if( (InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
(InDnTrend[i] AND C[i]> DnTrend[i]*(1+2*ThresholdPct[i])) )
{//Price move to UpTrend -
1111111111111111111111111111111111111111111
StateNo[i]=1;
InUpTrend[i]=True;
InDnTrend[i]=False;
UpTrend[i]=C[i];
NatReactPP[i]=NatReact[i];
}//End of Price Move to UpTrend
else
{
if(C[i]>(NatReact[i]*(1+ThresholdPct[i])))
{//Raise Above Current State React
if(NatRallyReset[i] OR C[i]>NatRally[i])
{
StateNo[i]=2;//Move to NatRally -
2222222222222222222222
NatRallyReset[i]=False;
NatRally[i]=C[i];
NatReactPP[i]=NatReact[i];
}
else
{//Raise to SeconaryRally
StateNo[i]=3;//Raise to SecRally -
333333333333333333333
SecRally[i]=C[i];
NatReactPP[i]=NatReact[i];
}//End of Raise to SecRally
}// End of Raise Above Current State React
}
}//End of Price Move Up
else //of(C[i]>C[i-1]) - Common with State 1
{//Price Move Dn
if((InDnTrend[i] AND C[i]<DnTrendPP[i]) OR
(InUpTrend[i] AND C[i]< UpTrend[i]/(1+2*ThresholdPct[i])) )
{//Drop to DnTrend
StateNo[i]=6;//Dn Trend -
6666666666666666666666666666666666666666
InDnTrend[i]=True;
InUpTrend[i]=False;
DnTrend[i]=C[i];
}// End of Drop to DnTrend
else
{
if(C[i]<NatReact[i])
{//Raise Above NatReact
StateNo[i]=5;//NatReact -
5555555555555555555555555555555555555
NatReact[i]=C[i];
}//Raise Above NatReact
}
}//End of Price Move Dn
}//End of NatReact Routine
//------------------------------------------------------------------------------
//666666666666666666666666666666666666666666666666666666666666666666666666666666
//------------------------------------------------------------------------------
//State No 6: In Dn Trend Column
else if(StateNo[i-1]==6)//
// Must be in State No 6
{//DnTrend Routine
if(C[i]>C[i-1])
{//Price Move Up
if( (InUpTrend[i] AND C[i]>UpTrendPP[i]) OR
(InDnTrend[i] AND C[i]> DnTrend[i]*(1+2*ThresholdPct[i])) )
{//Price move to UpTrend -
1111111111111111111111111111111111111111111
StateNo[i]=1;
InUpTrend[i]=True;
InDnTrend[i]=False;
UpTrend[i]=C[i];
DnTrendPP[i]=DnTrend[i];
}//End of Price Move to UpTrend
else
{
if(C[i]>(DnTrend[i]*(1+ThresholdPct[i])))
{//Raise Above Current State React
if(NatRallyReset[i] OR C[i]>NatRally[i])
{
StateNo[i]=2;//Move to NatRally -
2222222222222222222222
NatRallyReset[i]=False;
NatRally[i]=C[i];
DnTrendPP[i]=DnTrend[i];
}
else
{//Raise to SeconaryRally
StateNo[i]=3;//Raise to SecRally -
333333333333333333333
SecRally[i]=C[i];
DnTrendPP[i]=DnTrend[i];
}//End of Raise to SecRally
}// End of Raise Above Current State React
}
}//End of Price Move Up
else //of(C[i]>C[i-1]) - Common with State 1
{//Price Move Dn
if(C[i]<DnTrend[i])
{//Price move futher Dn
StateNo[i]=6;//Dn Trend -
6666666666666666666666666666666666666666
InDnTrend[i]=True;
InUpTrend[i]=False;
DnTrend[i]=C[i];
}//End of Price move Futher Dn
}//End of Price Move Dn
}//End of DnTrend Routine
//------------------------------------------------------------------------------
// React Values become Obseleted Price moved to high up. Reset them.
if(InUpTrend[i] AND NatReact[i] < UpTrend[i]/(1+2*ThresholdPct[i]) )
{
NatReactReset[i]=True;
}
// Rally Values become Obaseleted as Price move to low Dn. Reset them
if(InDnTrend[i] AND NatRally[i] > DnTrend[i]*(1+2*ThresholdPct[i]) )
{
NatRallyReset[i]=True;
}
} //end; //{main}
} //End of For i Loop!
//InUpTrend
WeightNo= IIf(StateNo==1,5, // UpTrend
IIf(InUpTrend AND StateNo==5,1, // and NatReact
IIf(InUpTrend AND StateNo==2,4, // and NatRally
IIf(InUpTrend AND StateNo==4,2, // and SecReact
IIf(InUpTrend AND StateNo==3,3, // and SecRally
IIf(StateNo==6,-5, // DownTrend
IIf(InDnTrend AND StateNo==2,-1, // and NatRally
IIf(InDnTrend AND StateNo==5,-4, // and NatReact
IIf(InDnTrend AND StateNo==3,-2, // and SecRally
-3 // and SecReact
)))))))));