[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Little help Flagging date a stock is purchased on the chart


  • To: imresident2001 <amibroker@xxxxxxxxxxxxxxx>
  • Subject: Re: [amibroker] Re: Little help Flagging date a stock is purchased on the chart
  • From: Herman <psytek@xxxxxxxx>
  • Date: Sun, 21 Jan 2007 19:18:33 -0500

PureBytes Links

Trading Reference Links

Hello imresident2001,

Sunday, January 21, 2007, 6:55:59 PM, you wrote:

> Hey Herman could you please explain how to use the code you posted in
> more detail please. I posted your code at the end of the discretionary
> equity code, but the info still didnt save. I dont understand the
> saving numbers part of it. thanks

1) Functions should be located at the very top of your code, once you
know they work i suggest you place the in an #Include file.
2) You need to create a directory named "PersistentVariables" in the
AmiBroker folder. This is where the variables will be saved.
3) Each variable is a small file, if you have lots of them there are
better ways of doing this. But this will get you started.
4) The VarName is should be unique for each variable you use so that you
can read the back.
5) You use them exactly like you do Static Variables, except they are
named differently.

Here is an example of how to use them, I added two functions for
numbers...:

PersistentPath = "C:\\Program Files\\AmiBroker\\PersistentVariables\\";
 
 function PersistentVarSetText( VarName, String )
         {
         global PersistentPath;
         fh = fopen( PersistentPath+VarName+".pva","w" );
         if( fh )
                 {
                 fputs( String, fh );
                 fclose( fh );
                 }
         return fh;
         }
 
 function PersistentVarGetText( VarName )
         {
         global PersistentPath;
         fh = fopen( PersistentPath+VarName+".pva","r" );
         if( fh )
                 {
                 String = fgets( fh );
                 fclose( fh );
                 }
         else string = "";
         return String;
         }

 function PersistentVarSet( VarName, Number )
         {
         global PersistentPath;
                        String = NumToStr(Number);
         fh = fopen( PersistentPath+VarName+".pva","w" );
         if( fh )
                 {
                 fputs( String, fh );
                 fclose( fh );
                 }
         return fh;
         }
 
 function PersistentVarGet( VarName )
         {
         global PersistentPath;
         fh = fopen( PersistentPath+VarName+".pva","r" );
         if( fh )
                 {
                 String = fgets( fh );
                 fclose( fh );
                 }
         else string = "";
                        Number = StrToNum(String);
         return Number;
         }

Number1 = Param("Select Number",10,0,1000,1);
PersistentVarSet( "TestNumber", Number1 );
String1 = ParamStr("Enter Test String","TestString");
persistentvarsettext("MyPersistentStringVariable", String1);

Number2 = PersistentVarGet("TestNumber");
String2 = PersistentVarGetText("MyPersistentStringVariable");
Title = "\n"+
"Number2 Read from file: "+NumToStr(Number2,1.4)+"\n"+
" String read from file: "+String2;



> --- In amibroker@xxxxxxxxxxxxxxx, Herman <psytek@xxx> wrote:
>>
>> Hello imresident2001,
>> 
>> Sunday, January 21, 2007, 5:55:54 PM, you wrote:
>> 
>> > Thankyou for sharing that code Terry. Thats so much better than what i
>> > had in mind. The only negative is all the trades are lost when you
>> > close amibroker. Can some one pleas figure out a way to save the
>> > trades please. 
>> 
>> You can create/use PersistentVariables as shown below, they will save
>> data indefinitely until deleted. To save numbers you convert them to a
>> string first and pass the string to the function,
>> for example: String = numtostr(Number,1.2);
>> 
>> 
>> PersistentPath = "C:\\Program Files\\AmiBroker\\PersistentVariables\\";
>> 
>> function PersistentVarSetText( VarName, String )
>>         {
>>         global PersistentPath;
>>         fh = fopen( PersistentPath+VarName+".pva","w" );
>>         if( fh )
>>                 {
>>                 fputs( String, fh );
>>                 fclose( fh );
>>                 }
>>         return fh;
>>         }
>> 
>> function PersistentVarGetText( VarName )
>>         {
>>         global PersistentPath;
>>         fh = fopen( PersistentPath+VarName+".pva","r" );
>>         if( fh )
>>                 {
>>                 String = fgets( fh );
>>                 fclose( fh );
>>                 }
>>         else string = "";
>>         return String;
>>         }
>>




> Please note that this group is for discussion between users only.

> To get support from AmiBroker please send an e-mail directly to 
> SUPPORT {at} amibroker.com

> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> http://www.amibroker.com/devlog/

> For other support material please check also:
> http://www.amibroker.com/support.html
>  
> Yahoo! Groups Links





-- 
Best regards,
 Herman                            mailto:psytek@xxxxxxxx


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.3/642 - Release Date: 1/20/2007 10:31 PM