Hi Peter

To format to 2 decimal places use:

Prec(MyROC[i], 2) 

Ian




--- In [email protected], Peter Dyke 
<[EMAIL PROTECTED]> wrote:
>
> Hi Ian,
> Thank you, thank you, thank you for helping.
> This problem has been taking up so much of my time it has been 
affecting
> my ability to trade.
> I am not strong on logic but by trial and error have come this 
far.
> 
> The WriteVal is only used to format the value to 2 decimal 
places.
> The ROC calc seems to work whether it is placed outside the 
loop or
> inside. I could not find any guidance on this in the 
documentation so
> followed the lead from AB Support's code. If I remember 
correctly I needed
> to initialise the variable to zero outside the loop (as in 
period=0;)then
> let the loop calculate the value of "period". The output can 
then by used
> in Plot Text, Title or an Exploration as period[i]. 
> 
> After altering my code as you suggested the value of MyRoc[i] 
now gives me
> a value when each new Buy signal is shown in Plot Text. So part 
of my
> problem has been solved. Thanks again.
> 
> The ASX market is now up and running so I will have a look at 
the debug
> later. I think that the "logic" may be well beyond my tiny 
brain.
> Peter  
> 
> --- Ian Watts <[EMAIL PROTECTED]> wrote:
> 
> > Hi Peter, Just seen your posts.
> > 
> > The following is my take on the problem, you don't need 
WriteVal 
> > in 
> > Plottext. Also taken the ROC calc outside the loop.
> > 
> > The Plottext works OK but you have a logic problem with the 
value 
> > of 
> > period.
> > 
> > I've also included my debug routine which you may find useful 
in 
> > identifiying the problem.  Put it in an include folder, check 
> > your 
> > path as I don't have AB under "Program Files"
> > 
> > To enable the debug routine select DB1 in the parameters box.
> > 
> > Ian
> > 
> > PS Just noticed I haven't corrected the Sell Plottext - I'll 
leave 
> > that to you...
> > 
> > //aProblemLoop.afl
> > #include "C:\AmiBroker\formulas\Include\DB V2.afl"
> > 
> > //Buy/Sell Rules
> > Buy=Cross(MA(C,7),MA(C,15));
> > Sell=0;
> > per=0;
> > Lookback=100;
> > function CheckMACross( per, Lookback )
> > {
> > result = False;
> > Cma = MA( C, per );
> > bar = BarCount -1 - Lookback;
> > if( Close[ bar ] < Cma[ bar ] )
> > {
> > while( bar < BarCount )
> > {
> > if( Close[ bar ] > Cma[ bar ] )
> > {
> > result = True;
> > }
> > 
> > bar++;
> > }
> > }
> > 
> > return result;
> > }
> > period=0;
> > function DCBelowMALine() // To find if Daily Close was below 
MA 
> > line
> > {
> > found = False;
> > 
> > for ( period = 3; period <= 75 AND NOT found; period++)
> > {
> > CurrentMA=MA(Close,period);
> > 
> > PriceBelowMA=Close<CurrentMA;
> > barsbelowMA=Sum(PriceBelowMA,75);
> > if(barsBelowMA[BarCount-1]==0)
> > found = True;//break out of loop
> > }
> > if(found)
> > Plot(CurrentMA,"Red
> > MA=$"+WriteVal(CurrentMA,1.2),colorRed,styleThick|
styleNoLabel);
> > return period;
> > }
> > 
> > db1("Period a ", Period );
> > 
> > //Plot Text
> > dist=4.5*ATR(10);
> > 
> > MyROC = ROC(C, 50);
> > for (i = 0; i < BarCount; i++)
> > {
> >     if(Buy[i]) PlotText("Buy\nCross Up " + "\nRed MA 
> > Period=" + 
> > period[i]
> >     + "\nROC(C,50)=" + MyROC[i] + "\nClose= $"
> >     + C[i], i, L[i] - dist[i], colorGreen);
> >     if(Sell[i]) PlotText("[EMAIL PROTECTED] $" + 
> > WriteVal(C[i],1.2)+" ",i,H[i] + dist[i], colorRed);
> > 
> > db1("Period b ", Period[i] );
> > 
> > }
> > Plot(C,"Close",1,64);
> > Plot(MA(C,7),"MA7",colorYellow);
> > Plot(MA(C,15),"MA20",colorBlue);
> > Title=Name()+" "+Date()+" Period= "+dcbelowmaline();
> > //END
> > 
> > 
> > 
> > /*
> > DB V2.afl
> > 
> > in main prog use:
> >    db3("adj ", adj );
> >    dbt("adj[k] ", adj[k] );
> > */
> > 
> > _N(Debug = ParamList( "Debug", "Off|DB1|DB2|DB3|DB4|DBT" ));
> > 
> > function db1(Description, indicator)
> >    {
> >    if(debug == "DB1")
> >       {
> >       if(StrLeft(Description, 1) == " ")
> >       {
> >       NewLine = "\n";
> >       printf( NewLine );
> >       }
> >    }
> >    printf( WriteIf(debug == "DB1", Description + "   ", 
"") );
> >    if(debug == "DB1")
> >      {
> >      printf( WriteVal(indicator) + "\n" );
> >      if(StrRight(Description, 1) == " ")
> >        {
> >        NewLine = "\n";
> >        printf( NewLine );
> >        }
> >     }
> > }
> > 
> > function db2(Description, indicator)
> > {
> >   if(debug == "DB2")
> >     {
> >       if(StrLeft(Description, 1) == " ")
> >       {
> >       NewLine = "\n";
> >       printf( NewLine );
> >       }
> >     }
> >   printf( WriteIf(debug == "DB2", Description + "   ", "") );
> >   if(debug == "DB2")
> >     {
> >      printf( WriteVal(indicator) + "\n" );
> >      if(StrRight(Description, 1) == " ")
> >       {
> >       NewLine = "\n";
> >       printf( NewLine );
> >       }
> >     }
> > }
> > 
> > function db3(Description, indicator)
> > {
> >   if(debug == "DB3")
> >     {
> >       if(StrLeft(Description, 1) == " ")
> >       {
> >       NewLine = "\n";
> >       printf( NewLine );
> >       }
> >     }
> >   printf( WriteIf(debug == "DB3", Description + "   ", "") );
> >   if(debug == "DB3")
> >     {
> >      printf( WriteVal(indicator) + "\n" );
> >      if(StrRight(Description, 1) == " ")
> >       {
> >       NewLine = "\n";
> >       printf( NewLine );
> >       }
> >     }
> > }
> > 
> > 
> > function db4(Description, indicator)
> > {
> >   if(debug == "DB4")
> >     {
> >       if(StrLeft(Description, 1) == " ")
> >       {
> >       NewLine = "\n";
> >       printf( NewLine );
> >       }
> >     }
> >   printf( WriteIf(debug == "DB4", Description + "   ", "") );
> >   if(debug == "DB4")
> >     {
> >      printf( WriteVal(indicator) + "\n" );
> >      if(StrRight(Description, 1) == " ")
> >       {
> >       NewLine = "\n";
> >       printf( NewLine );
> >       }
> >     }
> > }
> > 
> > function DBT( DBVString, DVBVariable )
> > {
> > //global ibc, IBPosSize;
> > //IBPosSizeStr = NumToStr(IBPosSize,1.0 );
> > 
> === message truncated ===
> 
> 
> 
>  
> 
____________________________________________________________________________________
> Be a PS3 game guru.
> Get your game face on with the latest PS3 news and previews at 
Yahoo! Games.
> http://videogames.yahoo.com/platform?platform=120121
>


Reply via email to