Lot size - page 2

William Roeder
25088
William Roeder  
SteeveNi25: So it should be like this?
(TimeSeconds(TimeCurrent()) < 60)

That will always be true.

Soconia UG
233
Werner Klehr  

Hi there,

i have changed the function for you and now it saves the date of the last update into the file:

double GetInitAccount()
{
        int FileHandle;
        string FileName = "MyAccountBalance.dat";
        double InitAccount = 0.0;
        double TmpValue = 0.0;
        int LastMonth = 0;

        FileHandle = FileOpen(FileName, FILE_READ | FILE_BIN); 
        if (FileHandle != INVALID_HANDLE)
        {
                TmpValue    = FileReadDouble(FileHandle, DOUBLE_VALUE);
                InitAccount = FileReadDouble(FileHandle, DOUBLE_VALUE);
                FileClose(FileHandle);

                LastMonth = TimeMonth((datetime) TmpValue);
        }

        if ((LastMonth != TimeMonth(TimeCurrent())) || (LastMonth == 0))
        {
                FileHandle = FileOpen(FileName, FILE_WRITE | FILE_BIN); 
                if (FileHandle == INVALID_HANDLE)
                {
                        Print("FileOpen failed / FileName: " + FileName + " / Error: " + IntegerToString(GetLastError()));
                        return(-1.0);
                }

                InitAccount = AccountBalance();

                FileWriteDouble(FileHandle, (double) TimeCurrent());    
                FileWriteDouble(FileHandle, InitAccount);
                FileClose(FileHandle);
        }

        return(InitAccount);
}

I hope, this one works better for you.

Best regards,

Tan Chee Ho
229
Tan Chee Ho  
what if make use of the monthly candle opening. every time new monthly candle created, then take the balance of that point. Will that works?
SteeveNi25
62
SteeveNi25  
Werner Klehr:

Hi there,

i have changed the function for you and now it saves the date of the last update into the file:

I hope, this one works better for you.

Best regards,

William Roeder:

That will always be true

I have changed it but it does not work :-(  it should Alert the new balance when the month change
int FileHandle;
        string FileName = "MyAccountBalance.dat";
        double InitAccount = 0.0;
        double TmpValue = 0.0;
        int LastMonth = 0;

        FileHandle = FileOpen(FileName, FILE_READ | FILE_BIN | FILE_ANSI); 
        if (FileHandle != INVALID_HANDLE)
        {
                TmpValue    = FileReadDouble(FileHandle, DOUBLE_VALUE);
                InitAccount = FileReadDouble(FileHandle, DOUBLE_VALUE);
                FileClose(FileHandle);

                LastMonth = TimeMonth((datetime) TmpValue);

                 if ((LastMonth != TimeMonth(TimeCurrent())) || (LastMonth == 0))
                 {
                         FileHandle = FileOpen(FileName, FILE_WRITE | FILE_BIN | FILE_ANSI); 
         
                         InitAccount = AccountBalance();
         
                         FileWriteDouble(FileHandle, (double) TimeCurrent());    
                         FileWriteDouble(FileHandle, InitAccount);
                         FileClose(FileHandle);
                 }
                 else
                 {
                         FileHandle = FileOpen(FileName, FILE_READ | FILE_BIN | FILE_ANSI); 
                         double str=FileReadDouble(FileHandle, InitAccount);
                         FileClose(FileHandle);
                         Alert("Initial balance:",str);   //initial balance 0
                 }
                 return(InitAccount);
        }
        else{
                 Print("FileOpen failed / FileName: " + FileName + " / Error: " + IntegerToString(GetLastError()));
                 return(-1.0);
             }
SteeveNi25
62
SteeveNi25  
I have tried an another code and it works well but the problem is,when the weekend is at
TimeDay(TimeCurrent()) == 1
, the new balance does not appear
int FileHandle;
        string FileName = "MyAccountBalance.dat";
        double InitAccount = 0.0;

        if ((TimeDay(TimeCurrent()) == 1))
        {
                FileHandle = FileOpen(FileName, FILE_WRITE | FILE_BIN | FILE_ANSI); 
                if (FileHandle == INVALID_HANDLE)
                {
                        Print("FileOpen failed / FileName: " + FileName + " / Error: " + IntegerToString(GetLastError()));
                        return(-1.0);
                }

                InitAccount = AccountBalance();
        
                FileWriteDouble(FileHandle, InitAccount);
                FileClose(FileHandle);
        }
        else
        {
                FileHandle = FileOpen(FileName, FILE_READ | FILE_BIN | FILE_ANSI); 
                if (FileHandle == INVALID_HANDLE)
                {
                        Print("FileOpen failed / FileName: " + FileName + " / Error: " + IntegerToString(GetLastError()));
                        return(-1.0);
                }
                double str=FileReadDouble(FileHandle, InitAccount);
                FileClose(FileHandle);
                Alert("Initial balance:",str);   //initial balance ok
        }
        return(InitAccount);
SteeveNi25
62
SteeveNi25  
Tan Chee Ho:
what if make use of the monthly candle opening. every time new monthly candle created, then take the balance of that point. Will that works?
yes, I do not think so, I will try that
SteeveNi25
62
SteeveNi25  
Tan Chee Ho:
what if make use of the monthly candle opening. every time new monthly candle created, then take the balance of that point. Will that works?
it does not work
SteeveNi25
62
SteeveNi25  
SteeveNi25:
I have tried an another code and it works well but the problem is,when the weekend is at , the new balance does not appear
William Roeder:

That will always be true.

I think it is good to specify the weekend however I do not know how to do that

for eg: if TimeDay(TimeCurrent()) == 1 is in weekEnd, choose TimeDay(TimeCurrent()) == 2

          if TimeDay(TimeCurrent()) == 2 is in weekend, choose TimeDay(TimeCurrent()) == 3

          ... and soon as


but we should specify the number of day in one month(31 days for january,28 or 29 days for february... and soon as)

SteeveNi25
62
SteeveNi25  
SteeveNi25:

I think it is good to specify the weekend however I do not know how to do that

for eg: if TimeDay(TimeCurrent()) == 1 is in weekEnd, choose TimeDay(TimeCurrent()) == 2

          if TimeDay(TimeCurrent()) == 2 is in weekend, choose TimeDay(TimeCurrent()) == 3

          ... and soon as


but we should specify the number of day in one month(31 days for january,28 or 29 days for february... and soon as)

It does not work :-(
int FileHandle;
        string FileName = "MyAccountBalance.dat";
        double InitAccount = 0.0;
        int TC=TimeCurrent();
        if( TimeDayOfWeek(TC)==0){bool Sunday=true;}
        if( TimeDayOfWeek(TC)==6){bool Saturday=true;}
        if(Sunday || Saturday){
                 if(TimeDay(TimeCurrent()) == 1){
                    Injection = 2;
                 }
                 if(TimeDay(TimeCurrent()) == 2){
                    Injection = 3;
                 }
                 if(TimeDay(TimeCurrent()) == 3){
                    Injection = 4;
                 }
                 if(TimeDay(TimeCurrent()) == 4){
                    Injection = 5;
                 }
                 if(TimeDay(TimeCurrent()) == 5){
                    Injection = 6;
                 }
                 if(TimeDay(TimeCurrent()) == 6){
                    Injection = 7;
                 }
                 if(TimeDay(TimeCurrent()) == 7){
                    Injection = 8;
                 }
                 if(TimeDay(TimeCurrent()) == 8){
                    Injection = 9;
                 }
                 if(TimeDay(TimeCurrent()) == 9){
                    Injection = 10;
                 }
                 if(TimeDay(TimeCurrent()) == 10){
                    Injection = 11;
                 }
                 if(TimeDay(TimeCurrent()) == 11){
                    Injection = 12;
                 }
                 if(TimeDay(TimeCurrent()) == 12){
                    Injection = 13;
                 }
                 if(TimeDay(TimeCurrent()) == 13){
                    Injection = 14;
                 }
                 if(TimeDay(TimeCurrent()) == 14){
                    Injection = 15;
                 }
                 if(TimeDay(TimeCurrent()) == 15){
                    Injection = 16;
                 }
        }

        if ((TimeDay(TimeCurrent()) == Injection))
        {
                FileHandle = FileOpen(FileName, FILE_WRITE | FILE_BIN | FILE_ANSI); 
                if (FileHandle == INVALID_HANDLE)
                {
                        Print("FileOpen failed / FileName: " + FileName + " / Error: " + IntegerToString(GetLastError()));
                        return(-1.0);
                }

                InitAccount = AccountBalance();
        
                FileWriteDouble(FileHandle, InitAccount);
                FileClose(FileHandle);
        }
        else
        {
                FileHandle = FileOpen(FileName, FILE_READ | FILE_BIN | FILE_ANSI); 
                if (FileHandle == INVALID_HANDLE)
                {
                        Print("FileOpen failed / FileName: " + FileName + " / Error: " + IntegerToString(GetLastError()));
                        return(-1.0);
                }
                double str=FileReadDouble(FileHandle, InitAccount);
                FileClose(FileHandle);
                Alert("Initial balance:",str);   
// WHEN THE date is in weekEnd,it does not give a value 
        }
        return(InitAccount);
SteeveNi25
62
SteeveNi25  
Werner Klehr:

Hi,

i'm sorry, but i think i forgot a little thing: you must use the FILE_BIN Option in the FileOpen statement - the
correct code should look like this:


Best regards,

William Roeder:

What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart.

Hello, plz help me

@William Roeder: I do not understand exactly what I mean

I have updated the code but the problem now is it gets the balance 2 times in one month, however it shoud get the value of TP once per month

The code does not get the value of the account balance before write and read a file

 
        int FileHandle;
        string FileName = "MyAccountBalance.dat";
        double InitAccount = 0.0;
        int time=TimeDayOfWeek(datetime(TimeYear(TimeCurrent())+"."+TimeMonth(TimeCurrent())+".1"))+1;
        Alert("Current time:",time);    
                     
               if(time==1 && DayOfWeek()==1){
                 if(TimeDay(TimeCurrent()) == 1)
                 {
                  Injection=1;
                  }
                 if(TimeDay(TimeCurrent()) == 2)
                 {
                  Injection=2;
                  }
                 if(TimeDay(TimeCurrent()) == 3)
                 {
                  Injection=3;
                  }}
                          
               if(time==2 && DayOfWeek()==2){
                 if(TimeDay(TimeCurrent()) == 1)
                 {
                  Injection=1;
                  }
                 if(TimeDay(TimeCurrent()) == 2)
                 {
                  Injection=2;
                  }
                 if(TimeDay(TimeCurrent()) == 3)
                 {
                  Injection=3;
                  }}
                          
               if(time==3 && DayOfWeek()==3){
                 if(TimeDay(TimeCurrent()) == 1)
                 {
                  Injection=1;
                  }
                 if(TimeDay(TimeCurrent()) == 2)
                 {
                  Injection=2;
                  }
                 if(TimeDay(TimeCurrent()) == 3)
                 {
                  Injection=3;
                  }}
                          
               if(time==4 && DayOfWeek()==4){
                 if(TimeDay(TimeCurrent()) == 1)
                 {
                  Injection=1;
                  }
                 if(TimeDay(TimeCurrent()) == 2)
                 {
                  Injection=2;
                  }
                 if(TimeDay(TimeCurrent()) == 3)
                 {
                  Injection=3;
                  }}
                          
               if(time==5 && DayOfWeek()==5){
                 if(TimeDay(TimeCurrent()) == 1)
                 {
                  Injection=1;
                  }
                 if(TimeDay(TimeCurrent()) == 2)
                 {
                  Injection=2;
                  }
                 if(TimeDay(TimeCurrent()) == 3)
                 {
                  Injection=3;
                  }}
        
        if ((TimeDay(TimeCurrent()) == Injection) && (TimeHour(TimeCurrent()) == 3) && (TimeMinute(TimeCurrent()) == 0) && (TimeSeconds(TimeCurrent()) < 5))
        {
                FileHandle = FileOpen(FileName, FILE_WRITE | FILE_BIN | FILE_ANSI); 
                if (FileHandle == INVALID_HANDLE)
                {
                        Print("FileOpen failed / FileName: " + FileName + " / Error: " + IntegerToString(GetLastError()));
                        return(-1.0);
                }

                InitAccount = AccountBalance();
        
                FileWriteDouble(FileHandle, InitAccount);
                FileClose(FileHandle);
        }
        else
        {
                FileHandle = FileOpen(FileName, FILE_READ | FILE_BIN | FILE_ANSI); 
                if (FileHandle == INVALID_HANDLE)
                {
                        Print("FileOpen failed / FileName: " + FileName + " / Error: " + IntegerToString(GetLastError()));
                        return(-1.0);
                }
                double str=FileReadDouble(FileHandle, InitAccount);
                FileClose(FileHandle);
                Alert("Initial balance:",str);   //initial balance 0
        }
        return(InitAccount);