Looking for some ideas/help - page 2

 
rwb181:

If you could show me how to change the existing time frame to a new time frame, I will be forever grateful to you and your kindred.


I am not sure what u mean by this... Do u mean change the time-frame on a chart via code? Or do u mean change the time-frame used for some indicator/calculation...?

 
gordon:

I am not sure what u mean by this... Do u mean change the time-frame on a chart via code? Or do u mean change the time-frame used for some indicator/calculation...?

When the trade is first opened, I can use the function you wrote AddTicket() to add the ticket # and current time frame of the chart. When I want to modify the trailing stop, I can use GetTimeFrame() to determine which time frame that order should use for it's trailing stop calculations. When the right conditions are met, the trailing stop calculations will be taken from the next larger time frame. At that point, I need to change the time frame assigned for that particular order in the array to reflect this change so it will know to use the higher time frame on the next pass for calculating the trailing stop. A function called ChangeTimeFrame(), maybe.


Does that help?

 
rwb181:

When the trade is first opened, I can use the function you wrote AddTicket() to add the ticket # and current time frame of the chart. When I want to modify the trailing stop, I can use GetTimeFrame() to determine which time frame that order should use for it's trailing stop calculations. When the right conditions are met, the trailing stop calculations will be taken from the next larger time frame. At that point, I need to change the time frame assigned for that particular order in the array to reflect this change so it will know to use the higher time frame on the next pass for calculating the trailing stop. A function called ChangeTimeFrame(), maybe.


Does that help?

Here is a function to set time-frame for a particular ticket. Returns true if success of false if fails (if ticket not found in array).

bool SetTimeFrame( int ticket, int timeframe, int& ticket_arr[][] )
   {
   int size = ArrayRange( ticket_arr, 0 );        // get size of the first dimension of the array (number of array 'lines')
   
   for ( int i = 0; i < size; i++ )               // loop on all elements in tickets column and search for ticket
      if ( ticket_arr[i][0] == ticket )
         {           
         ticket_arr[i][1]  = timeframe;           // if ticket found then set timeframe and return true
         return(true);
         }
   
   return(false);                                 // if ticket not found then return false
   }

Assuming we selected the ticket, let's say we want to set it's time-frame to 30, we can call this function like so:

bool result = SetTimeFrame( OrderTicket(), 30, ticket_arr )

If it succeeds then result will be true. You can also combine these utility functions into one if you want less code...

 
WHRoeder:
The problem with this time of implementation is if the terminal is restarted (power failure) then you loose ticket_arr and must have a fall back method.

rwb181, please note that WHRoeder is right of course, and with this kind of solution u should add some kind of persistence layer in case of terminal restart. Alternatively, u can use the magic number of an order to store time-frame information. Magic numbers are kept server side so a terminal restart won't affect them (in theory u can also use the order's comment, but servers sometime change comments, so that won't be reliable...).

 
gordon:

Here is a function to set time-frame for a particular ticket. Returns true if success of false if fails (if ticket not found in array).

Assuming we selected the ticket, let's say we want to set it's time-frame to 30, we can call this function like so:

If it succeeds then result will be true. You can also combine these utility functions into one if you want less code...

Thank you very much gordon. What I had tried was in line with yours and now I can see where I went wrong. If you would be willing to show me how to put these three into one, that would be great! I have these lessons saved for future reference and adding that would make it much more valuable.


If someone shows me how to do it, I can learn. And I can usually find ways to take what I was taught to higher levels. But, for some reason, I seem to have a hard time putting my ideas into code.

 
rwb181:

Thank you very much gordon. What I had tried was in line with yours and now I can see where I went wrong. If you would be willing to show me how to put these three into one, that would be great! I have these lessons saved for future reference and adding that would make it much more valuable.


If someone shows me how to do it, I can learn. And I can usually find ways to take what I was taught to higher levels. But, for some reason, I seem to have a hard time putting my ideas into code.

Here is a one-in-all function:

int TicketArray( int ticket, int timeframe, int& ticket_arr[][], bool add_ticket )
   {
   int size = ArrayRange( ticket_arr, 0 );         // get size of the first dimension of the array (number of array 'lines')
   if ( add_ticket )                               // if we want to add a ticket
      {
      ArrayResize( ticket_arr, size + 1 );         // resize the array to add one more 'line'
      ticket_arr[size][0] = ticket;                // set values of ticket and timeframe in the new created 'line' 
      ticket_arr[size][1] = timeframe;
      return(timeframe);                           // return the timeframe
      }
   
   // if we reached this pooint then we want to set/retrieve timeframe data from array
   for ( int i = 0; i < size; i++ )                // loop on all elements in tickets column and search for ticket
      if ( ticket_arr[i][0] == ticket )            // if ticket found in array...
         if ( timeframe == 0 )
            return(ticket_arr[i][1]);              // if we pass timeframe == 0 then return stored timeframe  
         else
            {                                   
            ticket_arr[i][1] = timeframe;          // else we set stored timeframe to the passed timeframe and return it
            return(timeframe);
            }
   
   return(-1);                                     // if we reached this point then ticket was not found, return fail -1
   }

If u want to add a new ticket we pass add_ticket = true and the function will behave similar to AddTicket(). Otherwise we pass add_ticket = false; if u want to read time-frame of a ticket u pass timeframe = 0 and if the ticket is found the timeframe will be returned, else -1. If u want to set the time frame then just set timeframe to whatever u want and if the ticket is found the timeframe will be set (and returned) else -1 will be returned... Enjoy!

 
gordon:

Here is a one-in-all function:

If u want to add a new ticket we pass add_ticket = true and the function will behave similar to AddTicket(). Otherwise we pass add_ticket = false; if u want to read time-frame of a ticket u pass timeframe = 0 and if the ticket is found the timeframe will be returned, else -1. If u want to set the time frame then just set timeframe to whatever u want and if the ticket is found the timeframe will be set (and returned) else -1 will be returned... Enjoy!


Thank you very much, gordon. These examples will be very useful to me.

Have a great day!!

Reason: