Frequency analysis of Array in EasyLanguage

post your indicators here

Moderator: moderators

casamba
rank: <50 posts
rank: <50 posts
Posts: 3
Joined: Fri Jul 14, 2006 7:03 pm
Reputation: 0
Gender: Male

Frequency analysis of Array in EasyLanguage

Postby casamba » Wed Aug 09, 2006 11:40 pm

I have a 2D Array aMktStates[2500,6](0); which contains approximately 250 different Market States spread over 2,500 bars. These are different combinations of three moving averages, their slopes, and crossovers.
(I'm using Adaptive Moving Average and John Ehler's Instant TrendLine which show great promise in truly differentiating between trending and range-bound market cycles in Forex)
For each bar I have the date, the MktState ID, and the price change, up or down, for the next x bars.
I want to count the frequency of occurrences of each MktState, the total value of PriceChange Up and Price Change Down, and the average for each.
Then I want to add a column to the Array that attaches the running Average to date for the particular Market State of that particular day.

I have easily done this in Excel using a FREQUENCY Array and a AVLOOKUPS formula sequence (courtesy the good people at FastExcel!).

Is it possible to code this in EasyLanguage? Below is a PrintLog snippet. I would be grateful for any advice or guidance.

[code]
Jul 12 06 MktStateID 137004 PriceChgCCup 0.0000 PriceChgCCdn -0.0160
Jul 13 06 MktStateID 110702 PriceChgCCup 0.0029 PriceChgCCdn 0.0000
Jul 14 06 MktStateID 120706 PriceChgCCup 0.0000 PriceChgCCdn -0.0083
Jul 17 06 MktStateID 130706 PriceChgCCup 0.0000 PriceChgCCdn -0.0165
Jul 18 06 MktStateID 130704 PriceChgCCup 0.0000 PriceChgCCdn -0.0174
Jul 19 06 MktStateID 130706 PriceChgCCup 0.0039 PriceChgCCdn 0.0000
Jul 20 06 MktStateID 140506 PriceChgCCup 0.0301 PriceChgCCdn 0.0000

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

obx
rank: <50 posts
rank: <50 posts
Posts: 41
Joined: Fri May 26, 2006 12:35 pm
Reputation: 0
Gender: Male

Postby obx » Wed Aug 16, 2006 2:54 pm

casamba,

for the freq of occurrences, you could add more elements to your array and
do a for loop through the MktState values and when
currentMktState = arrElementMktState then increment
one of the new elements of your array for arrElementMktState by one -> each MktState value would be then accompanied by it’s count

re: “total value of PriceChange Up and Price Change Down, and the average for each” –
This also is do-able – but thought of several ways you could be meaning this, so please clarify

hth

z

casamba
rank: <50 posts
rank: <50 posts
Posts: 3
Joined: Fri Jul 14, 2006 7:03 pm
Reputation: 0
Gender: Male

Postby casamba » Mon Aug 21, 2006 1:25 am

Thanks OBX - I will try your suggestion - in the meantime here is the code that works so far, with the coding lacuna highlighted by asterisk.

Code: Select all

if Barnumber=1 then ClearPrintLog;
Inputs:   
{SlowMA Values}      iPrice(Close),iLength(13),
{FastMA Slope Vals} iFastMASlopeLen(2),
{vAMA Values}       iEffRatioLength(10), iFastAvgLength(2), iSlowAvgLength(30),
{vAMA Slope Values} iAMASlopeLen(2),iSlope(10),
{TrendBrackets}      iNoTrend(0),iUpTrend(10),iDnTrend(-10),
{MarketState Vals}   iDaysFwd(3);

Vars:   
{vSlowMA Values}   vSlowMA(0),vFastMA(0),vFastMASlope(0),
{vAMA Values}      vAMA(0),vAMASlope(0),
{MarketStateID's}   vAMAvsFastMAiD(0),vFastMAiD(0),vAMASlopeID(0),vXOFastMAiD(0),vMktStateID(0),
{MktStateIDVal's}   vPriceChgCC(0),vCountChgCC(0),vPriceChgCCup(0),vCntChgCCup(0),vPriceChgCCdn(0),vCntChgCCdn(0);            ;

//VARIABLE ASSIGNMENTS
{vSlowMA Formula}   vSlowMA = AverageFC(iPrice, iLength);
               vFastMA = 2*vSlowMA - vSlowMA[2];
               vFastMASlope = LinearRegSlopeFC(vFastMA, iFastMASlopeLen)*10000;

{vAMA Formula}      vAMA    = AdaptiveMovAvg(iPrice,iEffRatioLength,iFastAvgLength,iSlowAvgLength);
               vAMASlope =LinearRegSlopeFC(vAMA, iAMASlopeLen)*10000;

{MarketStateID's}   //For each Bar I want to know the current relationship of the three MA's
               // Is the AMA above or below the FastMA? Assign 6 digit ID of 100,000 or 200,000
               If vAMA>=vFastMA then vAMAvsFastMAiD = 100000 Else vAMAvsFastMAiD = 200000;
               //Assign 5 digit ID to intensity of FastMA slope: Strong Up, Weak Up, Weak Down or Strong Down
               If vFastMASlope>=iUpTrend then vFastMAiD = 10000
                  Else If vFastMASlope>iNoTrend then vFastMAiD = 20000
                     Else If vFastMASlope>iDnTrend then vFastMAiD = 30000 Else vFastMAiD = 40000;
               //Assign one of 4 digit ID's to Bins of AMA Slope if positive
               If vAMASlope>=30 then vAMASlopeID = 1000 Else If vAMASlope>=25 then vAMASlopeID = 2000
                  Else If vAMASlope>=20 then vAMASlopeID = 3000 Else If vAMASlope>=15 then vAMASlopeID = 4000
                     Else If vAMASlope>=10 then vAMASlopeID = 5000 Else If vAMASlope>=5 then vAMASlopeID = 6000
                        Else If vAMASlope>=0 then vAMASlopeID = 7000;
               //Assign one of 3 digit ID's to Bins of AMA Slope if negative
               If vAMASlope<-30 then vAMASlopeID = 100 Else If vAMASlope<-25 then vAMASlopeID = 200
                  Else If vAMASlope<-20 then vAMASlopeID = 300 Else If vAMASlope<-15 then vAMASlopeID = 400
                     Else If vAMASlope<-10 then vAMASlopeID = 500 Else If vAMASlope<-5 then vAMASlopeID = 600
                        Else If vAMASlope<0 then vAMASlopeID = 700;
               //Assign one of 1 digit code to FastMA/SlowMA Crossover, or CrossUnder, or neither
               If vFastMA[1]<vSlowMA[1] and vFastMA > vSlowMA then vXOFastMAiD = 2
                  Else If vFastMA[1]>vSlowMA[1] and vFastMA < vSlowMA then vXOFastMAiD = 4
                     Else vXOFastMAiD = 6;
               //Summation of all 5 ID's for 384 different possible combinations
               vMktStateID = vAMAvsFastMAiD+vFastMAiD+vAMASlopeID+vXOFastMAiD;
               
               //Calculate Price Change (Close to Close) for each bar iDaysFwd into the future,
               //identify net Ups vs Dns, and count them
                  
               vPriceChgCC=Close-Close[iDaysFwd];
               If vPriceChgCC>0 then
                       vPriceChgCCup=vPriceChgCC else vPriceChgCCup=0;
                  If    vPriceChgCCup>0 then  vCntChgCCup=vCntChgCCup+1 else vCntChgCCup=vCntChgCCup;
                If vPriceChgCC<0 then
                  vPriceChgCCdn=vPriceChgCC else vPriceChgCCdn=0;
                  If    vPriceChgCCdn<0 then vCntChgCCdn=vCntChgCCdn+1 else vCntChgCCdn=vCntChgCCdn;
                  
// ************* THIS IS WHERE I NEED CODING TO SUM THE FREQUENCY, OUTCOME AND VALUE OF EACH vMktStateID ********                  
               
{Arrays}            
                  Array: aMktStates[3000,7](0);
                  Var: BarCounter(0);
//This is my attempt to code a count of how often each daily MktStateID has occurred in the past.  it does not work.
                  Value1 = countif(vMktStateID=vMktStateID[10],10);
//Once I have Value1, I want Value2 to Sum how often the daily MktStateID has resulted in a PriceChgUp, and Value3, PriceChgDn
                  //Value2 =                      
                   //Value3 =
//I then want Value4 to Sum the total value of points attributable to Value2
                  //Value4 =
//And Value5 to Sum the total value of points attributable to Value3
                  //Value5 =                   
                     aMktStates[BarCounter,1] = vMktStateID;
                     aMktStates[BarCounter,2] = vMktStateID[iDaysFwd];
                     aMktStates[BarCounter,3] = Value1;
                     {Insert Value2 to Value5 once code established}
                     aMktStates[BarCounter,4] = vPriceChgCCup;
                     aMktStates[BarCounter,5] = vCntChgCCup;
                     aMktStates[BarCounter,6] = vPriceChgCCdn;
                     aMktStates[BarCounter,7] = vCntChgCCdn;
                     
                                          
               

            
               If BarNumber > 1 then begin
               Print((FormatDate("MMM dd yy",ELDateToDateTime(Date)))," ",
               "BarCntr"," ",BarNumber:4:0," ",
               "CurrMktState"," ",aMktStates[BarCounter,1]:6:0," ",
               "MktStateID"," ",aMktStates[BarCounter,2]:6:0," ",
               "CountMktStateID"," ",aMktStates[BarCounter,3]:4:0," ",
               {Insert Value2 to Value5 once code established}
               "PriceChgCCup"," ",aMktStates[BarCounter,4]:7:4," ",
               "CntChgUp"," ",aMktStates[BarCounter,5]:4:0," ",   
               "PriceChgCCdn"," ",aMktStates[BarCounter,6]:7:4," ",
               "CntChgDn"," ",aMktStates[BarCounter,7]:4:0);
               End;   


                  
                  
               
                  
{Plots}   If vAMASlope>iNoTrend and vAMASlope>iUpTrend Then SetPlotColor(1,Green)
       Else If vAMASlope<iUpTrend and vAMASlope > iNoTrend Then SetPlotColor(1,Yellow);
      If vAMASlope< iNoTrend and vAMASlope < iDnTrend Then SetPlotColor(1,Red);
      If vAMASlope< iNoTrend and vAMASlope > iDnTrend Then SetPlotColor(1,Yellow);
                  
      If vFastMASlope>vFastMASlope[1] Then SetPlotColor(5,Green);

      If vFastMASlope< vFastMASlope[1] Then SetPlotColor(5,Red);

               
         Plot1( vAMASlope, "vAMASlope" );
         Plot2(iNoTrend,"NoTrend");
         Plot3(iUpTrend,"UpTrend");
         Plot4(iDnTrend,"DnTrend");
         Plot5( vFastMASlope, "vFastMASlp" ) ;


casamba
rank: <50 posts
rank: <50 posts
Posts: 3
Joined: Fri Jul 14, 2006 7:03 pm
Reputation: 0
Gender: Male

Postby casamba » Thu Aug 31, 2006 9:13 pm

After some 3 weeks I have finally arrived at the solution with the assistance of an EL Engineer.
The final working code can be seen at
[url=https://www.tradestation.com/Discussions/Topic.aspx?Topic_ID=54813]

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.


Return to “Tradestation indicators”