Internal loop: PositionClose

 
David Diez:

Hi there community,

I was using this internal loop for a long time to close a position by a reversal one:

Now I've been working into a new advisor which can open more than one position in the same direction, so I wrote another filter with the hope to let all those trades running until the reversal signal comes:

I don't actually know if I explained properly, but essentially this is the way I've tried to make reversal close when buying or selling more than one position, and the problem is basically that I got same results. Could it be that the issue is being around the PositionOpen rules (opening no more than 1), but I don't actually think so.

Could someone give a review into this lines to let me know if I'm doing properly?

I'm not sure I fully understand your issue, but apparently your code has nothing to do with the issue. It may be better to solve the problem with a few  functions and easier logics.

 
David Diez :


What is a "reversal signal" for you? The signal always goes BEFORE the OPEN position. You call something else a signal. Can you explain in more detail?

 
Vladimir Karputov:

What is a "reversal signal" for you? The signal always goes BEFORE the OPEN position. You call something else a signal. Can you explain in more detail?

Reversal signal means opposite i.e: RSI overbought - RSI oversold, they are opposite signals.

I first open the opposite and then close olders, that's why I use if(PosCount>1){Close--;}.

Now they could be more than just one position in the current direction i.e. RSI H1 (overbought), then RSI H4 (overbought) = 2 short positions.

I need to close those 2 short positions just when the first long is opened.

 
Salih Yasar:

I'm not sure I fully understand your issue, but apparently your code has nothing to do with the issue. It may be better to solve the problem with a few  functions and easier logics.

I'm not very skilled. Just using, maybe not easier, but simple logics to make this work.

There is a more clear explanation into the Vladimir comment.

 
David Diez :

Reversal signal means opposite i.e: RSI overbought - RSI oversold, they are opposite signals.

I first open the opposite and then close olders , that's why I use if(PosCount>1){Close--;} .

Now they could be more than just one position in the current direction i.e. RSI H1 (overbought), then RSI H4 (overbought) = 2 short positions.

I need to close those 2 short positions just when the first long is opened.

Why do that? It is necessary to do the opposite: if there is an opposite signal, then first close the opposite positions, and then open the position.

 
Vladimir Karputov:

Why do that? It is necessary to do the opposite: if there is an opposite signal, then first close the opposite positions, and then open the position.

I consider that having an opposite deal would be a proper condition to close olders, just need to fit this idea.

 

Ok, I've been checking this loop into another codes and it seems to be working fine.

Then the problem besides on entry conditions, sorry for this.

Reason: