Keeping track of multiple _potential_ orders?

 

Hello!

I am facing an interesting problem that I have not been able to figure out yet. If anyone could nudge me in the right direction I would be super thankful.

Let's say I have a simple indicator that indicates when I should enter a buy trade (illustrated as a yellow line in the picture). When the robot detects this situation, the first bullish candle that closes above that price should be the trade entry point.

The problems I am currently facing:

1) In the picture below there is two confirmations of possible trade entries coming. How would you keep track of them separately (with the time they were detected and the price they were detected at). There might be up to 3-5 of these indicators in a short timespan. Just omitting all old signals and tracking the last one is the simplest solutions, but I want to explore the possibility of keeping track of multiple just for practice sake.

2) I want to optimize the time allowed between an indicator and the trade entry. Pictured below is just 1 5min candle in between, but usually this could be anything between 1 to let's say 20 candles. How can I track this?

3) Right now the robot is simply looking back 50 candles and comparing the closing prices of bearish candles. Any idea how could I set a minimum and a maximum of the allowed distance between two potential bearish candles?

Any pseudo code, or any function calls I should look into would be sufficient at this point I feel. 

 

Illustration 

 

Your query is actually very "vague" and open to greatly diverging possibilities. I suggest you first make your own attempt at the code and then post sections here when you need help with some specific task.

Since, you have not provided any code skeleton, you are basically asking us to write it for you from scratch, which is not very ethical since such a job would normally be a paid one in the "Freelance" section.

You mention a "robot" and ask for help on changing it's functionality. but provide no source of the section in question that you want help on.

Personally, I think that, what you are requesting can turnout to be quite complex and should really be a job for the "Freelance" section and not exactly just a passing query on the forum.

 

Hey and thanks for the reply.

I'm not asking for anyone to write the code for me and  I've edited the main post to reflect that. A nudge in the right direction would be sufficient because right now I have very little idea how to go about implementing the said features. I am asking these questions because I have little idea where to even begin. This is also why I didn't provide source code. The only code I can provide right now is the already working functionality, which in this case would be irrelevant.

 

As I said, your request is too "vague" and without any starting point in code, we cannot help you much. There is a hundred ways to code an idea, so there is obviously no quick reply for your request. Since you have not provided any base code at all, no matter how irrelevant you may think it is (which is in fact very relevant), there is no way to build on something and steer you in a certain direction.

It is obvious that your programing knowledge is very limited, because any reasonable coder would know that keeping track of anything, at its most basic level is about storing that information in some form (such as in structures or arrays). What kind of data and how to organize it, is of obviously more complex and requires one to think about it, but you have to have a basic initial point to start from.

Sorry, but that is just how it is. You either know how to do it or you don't and as another user here on the forums usually says, and I quote from WHRoeder:

You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.

 
ikonii:

1) In the picture below there is two confirmations of possible trade entries coming. How would you keep track of them separately (with the time they were detected and the price they were detected at). There might be up to 3-5 of these indicators in a short timespan. Just omitting all old signals and tracking the last one is the simplest solutions, but I want to explore the possibility of keeping track of multiple just for practice sake.

2) I want to optimize the time allowed between an indicator and the trade entry. Pictured below is just 1 5min candle in between, but usually this could be anything between 1 to let's say 20 candles. How can I track this?

3) Right now the robot is simply looking back 50 candles and comparing the closing prices of bearish candles. Any idea how could I set a minimum and a maximum of the allowed distance between two potential bearish candles?

  1. Remember the time and price detected.
  2. iBarShift will tell you how many candles back. If it's too far back, forget it.
  3. No need to look back. If the last closed candle didn't exceed the price, neither did any others. If it did, remove signal from the array, and open.
Something like
struct coord{ datetime when; double price};
coord levels[];
void remove_level(int i){
    int n = arraySize(levels);
    levels[i] = levels[--n]; ArrayResize(levels, n);
}
void add_level(datetime when, double price){
   int n = ArraySize(levels);
   ArrayResize(levels, n + 1, 16);
   level[n].when = when;   level[n].price = price;
}
void OnTick(){
   static datetime time0=0; datetime p0=time0; time0=Time[0]; bool isNewBar=(p0!=time0);
   if(isNewBar){
      for(int i=ArraySize(levels)-1; i>=0; --i){
         // check old levels
         int iBar = iBarShift(NULL,0, levels[i].when);
         if(iBar > maxHold) remove_level(i);

         // check last bar
         else if(Close[1] > levels[i].price){ process_level(i); remove_level(i); }
      }
      // check for new signals
      if(signal(1)) add_level(Time[1], High[1]);
  } // isNewBar
  :
}
 
WHRoeder:
  1. Remember the time and price detected.
  2. iBarShift will tell you how many candles back. If it's too far back, forget it.
  3. No need to look back. If the last closed candle didn't exceed the price, neither did any others. If it did, remove signal from the array, and open.

Something like

[code] 


Heya!

This is excellent! iBarShift and the use of a struct to store the datetime and price together were exactly what I was after here. 

Thanks a thousand! 

Reason: