Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 614

 
yan720:

The general idea, of course, is this. And how do you determine the width of the channel (range in your case)? I do it through the size of an average candle plus it's all tied to the length of the channel, because the presence of the channel is not checked on a rigid number of bars, but, for example, on a length of 10 to 30 bars.

What I am interested in is the question of selecting the width from the length...

You can make several external parameters for the channel width in one indicator. And make separate calculations for each parameter.

 

For length, the same is true.

 
Example2:
Hello. The basket Expert Advisor should close all the orders when the condition comes, but it closes the order first, then tries to close it again (the server gives us an error saying "Invalid ticket") and only then it goes further. Here is a sample code and the EA itself.

In your function CloseOrders(), if the order is closed, the while(cnt<=5 ) cycle will once again send the code to close the order, and an error will occur, of course, then exit through if(). break;

                    int cnt=0;
                    while(cnt<=5){
                      Result[0]=OrderClose(OrderTicket(),OrderLots(),MarketInfo("USDCAD",MODE_BID),slip,Blue);
                      if(!Result[0]){
                        Answer=ERRORS(GetLastError());
                        if (Answer==1)continue; cnt++;
                        if (Answer==2)break;
                      }
                    }

In the ProtectionClose() function, you have already added lines with the correct while exit.

 if(Result[0])break;
 }continue;
Try to dig here.
 
pu6ka:

In your function CloseOrders(), if the order is closed, the while(cnt<=5) cycle will once again send the code to close the order, and an error will occur, of course, then exit through if(). break;

In the ProtectionClose() function, you have already added lines with the correctwhile exit

Try to do some digging here.


But in the case I have described, it is the ProtectionClose() function that closes the order. I will correct that error.
 
Example2:

However, it is the ProtectionClose() function that closes orders in the case I have described. I will fix that error.

I haven't dug deep into code, I couldn't run it in tester, there is no indicator.

But, for example, your functions OpenUsdbuy(); OpenSellusd() are consecutive.

OpenSellusd() opens GBPUSD, EURUSD, AUDUSD, NZDUSD, etc. You will be the first to close them in reverse order of NZDUSD, AUDUSD, etc.

Only three pairs in the ProtectionClose() function have a while exit in two variants: USDCAD, USDCHF and USDJPY.

In other currencies, you can exit while() only by an error if(!Result[...]).

 
FOReignEXchange:

It is possible to make several external parameters for the channel width in one indicator. And make separate calculations for each parameter.

The point is that I do not want to set the channel width forcibly - the Expert Advisor/indicator must detect the presence of the channel regardless of the currency pair and/or the current volatility. Accordingly, I set the minimum and the maximum channel length from external parameters, and this only in the process of debugging the algorithm - afterwards these parameters will be sewn into it. At this stage, there are some complaints. Although I can catch the channels in general (the picture was taken from the working code), I would like to see other solutions of this issue.

 
pu6ka:

I haven't dug deep into code, I couldn't run it in tester, there is no indicator.

But, for example, your functions OpenUsdbuy(); OpenSellusd() are consecutive.

OpenSellusd() opens GBPUSD, EURUSD, AUDUSD, NZDUSD, etc. You will be the first to close them in reverse order of NZDUSD, AUDUSD, etc.

Only three pairs in the ProtectionClose() function have a while exit in two variants: USDCAD, USDCHF and USDJPY.

In other currencies you can exit while() only by an error if(!Result[...])


Thanks for the tip, I forgot to leave the loop in this case, it should work now. If you want I can paste the indicator as a thank you.
 
yan720:

The general idea, of course, is this. And how do you determine the width of the channel (range in your case)? I do it through the size of an average candle plus it's all tied to the length of the channel, because the presence of the channel is not checked on a rigid number of bars, but, for example, on a length of 10 to 30 bars.

It is the choice of width from length that interests me...

This length of 10 bars is the fundamental figure. I mean not less than 10... and if it's longer, it's fate. Take it to the outside to be able to experiment. The range may be an average size of the candle, it doesn't matter, but it's better to put it outside too. Maybe you'll want to set the maximal and minimal ranges, so you'll have to set two variables Max_ and Min_. Then on every bar you'll check the average size of a candle in these 10 bars and if it suits you, draw trends above and below the 10 bars. For the next bar, you can already check for 11 bars and if the condition is fulfilled, ObjectSet(...); only OBJPROP_PRICE1 changes for the first coordinate , and OBJPROP_PRICE2 and OBJPROP_TIME2 change for the second oneand so on every bar. Or, you may not recalculate anything and consider the channel already formed and wait for the breakdown of this channel. This is up to your taste.

Well, in my case, I suggested a lighter option from the lantern to assign the channel height and the minimum number of bars as well.


yan720:

The point is that I do not want to set the channel width forcibly - the Expert Advisor/indicator must detect the presence of the channel regardless of the currency pair and/or current volatility. Accordingly, I set the minimum and the maximum channel length from external parameters, and this only in the process of debugging the algorithm - afterwards these parameters will be sewn into it. At this stage, there are some complaints. Although I can catch the channels in general (the picture was taken from the working code), I would like to see other solutions of this issue.

Well, first, the parameters will not make any difference if they are in the external or in the embedded ones. And second, if you don't set the width of the channel, what will you compare it with when you calculate the 10 bars you specified? How do you want to determine if it's a channel or not? And third, imho, the average candle size will not work adequately. If all 10 bars are bullish, but the average bar size is not bigger than the check. Is it a channel or not? It may be a channel, but it's only a sloping one and we are parsing a horizontal one according to your drawing.
 
yan720:

The point is that I do not want to set the channel width forcibly - the Expert Advisor/indicator has to determine the presence of the channel, regardless of the currency pair and/or the current volatility. Accordingly, I set only the minimum and maximum length of the channel from external parameters, and this only in the process of debugging the algorithm - afterwards these parameters will be sewn into it. At this stage, there are some complaints. Although I can catch the channels in general (the picture was from the working code), I would like to see other solutions for this issue.

Well, there is an idea to catch 2 consecutive top fractals or 2 iHighest ones consisting of, say, 5-10 candlesticks. We catch this case within a certain length range. If values of these peaks are close to each other, between these two peaks we will find iLowest.

Similarly, first search for two lower peaks, and then for the upper peak between them.

Then we will dance from those found peaks. First, we draw levels by them. Then we teach the code to think further.

This option will eliminate the external parameter such as Channel_width.

Whatever way you look at it, I think we need at least some parameters for the length.

 

As far as my robot is concerned, I've got a bit of a handle on the code. I only kept a rough version of it, which is strictly aimed at certain parameters for ХХХ\JPY currency pairs. I remember doing some online testing while working in a channel. I'll send you the code right now, but I don't think it will be of much help.