Help needed in modifying values in a sequence
-
Hi, I'm looking for someone to help me create a small configuration in a form of a Block, so that I can use it in my project.
I will gift a subscription to the person who can figure this out.The issue is concerning the "Sequence on loss" input in the "Buy Now" block and it's values.
I need to be able to shift back to previous values in that sequence.
Let's take the following as an example:

I have a custom sequence "sequence on loss": 1,2,3,4,5,6
And let's say we had 3 consecutive losses in a row -> and we are currently on the 4th trade.
If that's the case, then we are trading on the third input value of the "sequence on loss" ( value: 3)I want to be able to shift back to the second value instead (2) or the first value (1) whenever a condition is met (to be able to use a block as a controller would be best)
I previously tried to store the "sequence on loss" in a variable, and change the data using "modify variables" block:

Unfortunately, this method didn't work. The EA either resets the sequence, or continues (I couldn't find a way to change the sequence or shift back to the previous value without breaking it). -
@rafaels919 Hi!
I cannot offer a beatiful one-block solution, but putting the sequence into an array is one solution - check my example: https://fxdreema.com/shared/YYdcM1Wbb
The array determines the sequence number with a variable loses, which tracks consecutive loses (and you can modify the variable directly as well)
-
Hi @roar , thanks for your response!
How do I modify the "sequence on loss"?

Changing the "seq[]" variable didn't change the sequence in the EA (which is set to 1,2,3,4,5,6 somehow):

Also, how do I make a shift to the previous value in the sequence?
( This function is important, as long as this works and I can freely utilize it using conditions and what not, having "one block" is not that important) -
@roar
In this reference, for example:

I have two conditions, where I shift back to the previous value in the sequence.
I want to be able to do similar. It doesn't need to be just 1 block, but it needs to work in a similar fashion, where I can use it multiple times under different conditions.
-
@rafaels919 @miro1360 created a manual martingale system that you may have a look at. Like that you might set or reset the next lot size by yoursel.
-
@roar I see that you had the "sequence on loss" and the "baselot" stored in Constants. It makes sense now.
But it still doesn't shift back. Could you explain the variables and what each one does?:

And how would I set it up to shift back in a similar configuration (having 2 or more separate conditions for a shift back simultaneously):

@trader-philipps I see. But reset is not what I'm looking for. Also that configuration seems to work only with a single value in a variable (e.g. I can't use "modify variables" block with multiple values - aka sequence, such as "1,2,3,4,5" for example, which you pointed out to me in a different topic)
-
@rafaels919 I'm on mobie right now and can't open blocks. But I think to remember that there was an array of the multiplicators. Each array has an index. So you can address each value by the index.
So if you assume to be at trade 3 and want to step back you'd access the value of the array for current index position -1Does that make sense?
-
@trader-philipps I'm not sure what Roar did here, but I guess it's something similar to what you described:

I'm not sure how the "variables" function and how they are adjusting the sequence that is stored in the Constants:Miro's project changes the lot size only as far as I understand, and uses the Multiplicator instead of a Sequence.
-
@rafaels919 Sorry, I mixed up the projects. I meant @roar 's approach.
I pimped the code a bit to make it more obvious what @roar or I with my answer meant.
In roar's project he sets the constants like that

Those are 6 values. Roar splits that sequence string into 6 parts (seperator is the comma) and creates an array seq[i]. In the given case the array index has a size of 6. As arrays are 0 based, this means it starts counting by 0 (not by 1). You can read the integer value of each array position in the index like
seq[0], seq[1], ...,seq[5]I print this out in the log and here is the result ..

Knowing this, you can at each time go wherever you want in the index of the array by selecting the right index value.
So if you count your losses by a variable, you can use the array like roar did in the BUY block.baseLot * seq[loses]

loses is the integer of your losses counter. So if you are at losses 3, it will do like baselot * seq[2]
Unfortunately there is a glitch in roar's code as the array is 0 based. So if the first value is not 1, it will not match corectly (or in other word works different to fxdreema). But that's not that important.Did you get what I mean?
Again in short refering to roar's version.
Sequence is: 1, 3, 5, 7
Startlot is 0.01Will result in ..
seq[0]: 1
seq[1]: 3
seq[2]: 5
seq[3]: 7Where the numbers in brackets represent the value of you losses counter.
Is that clear?
-
@trader-philipps
Let me know if I get this right.- So the sequence string that is in the Constants is converted into 6 separate parts, seq[0]... seq[5]
- What is the Variable "seq[]" used for?
- And the "loses" variable is the consecutive losses counter - and if I set it to 3 for example, it will shift back one value, right?
So let's say the sequence is: 1,2,3,4,5,6 - just as in @roar 's project.
If the "loses" variable is set to 3, and I lost the third consecutive trade (value "3" from the array^) - then it won't proceed to value 4, instead it will repeat the value 3 once -> is this correct?- What is "seqLen" for?
I think I need to know what each variable is for to understand the logic behind the setup.
-
@rafaels919 Hi!
That's right, my approach is to convert the sequence string to an int array (because you can't use a string in any calculation). This converting is done in the "on Init" tab.
- What is the Variable "seq[]" used for?
This is a special kind of variable: an array. Arrays dont store just one value, but multiple values - like a list, or a table.
In MQL, array indexing starts from 0, so the first value of your sequence is seq[0] = 1,
if the original sequence string was "1,2,3,4,5,6".
Last value would be seq[5].
^ This part is for resetting the sequence, in case we go to a 7th loss (and the array doesn't have a value for that). "seqLen" is the size of the array, and because arrays start from 0, the actual last index in the array is seqLen - 1.I admit, this is very confusing setup, lol. But you don't necessarily need to know every detail, just know that you can modify the loses variable to set the sequence to whatever value you like.
If you want revert to 2nd sequence value, modify variable loses to 1.
For 3rd sequence value, modify variable loses to 2. -
https://fxdreema.com/shared/i6NwpEuZc
Here I fixed the array so that you can forget about the 0-start thing:
If you need 3rd value, use seq[3] and so on. (seq[loses] when loses = 3)
So now it is the same as the default "custom sequence" setting, I think it is more convenient to use this way.
(I did this by adding "1" to the beginning of the actual array)

-
So I tried to run a little test following your description, but it didn't shift back neither did it reset at the "seqLen" Limit.

"loses" variable (to control the consecutive losses) - after which it should shift back one value or in other words, to not proceed to the next value in the array for that instance.
"seqLen" variable (to reset the array after number of consecutive losses)

I guess I'm doing something wrong again? @roar
Also, as I mentioned before - I need to be able to freely utilize the "shiftback", using conditions and what not. Could this be possible with your configuration?
By the way, if the sequence string is now an "Array", would it be possible to change that array using "Modify Variables" instead, which I described in my introduction text?

This^, which couldn't work storing the "sequence on loss" in a variable, because the "Modify Variables" block can't change string sequences. If I could somehow use a single block like that to change the whole array at a given condition, that would solve everything. -
@rafaels919 said in Help needed in modifying values in a sequence:
So I tried to run a little test following your description, but it didn't shift back neither did it reset at the "seqLen" Limit.

You can't modify the variables in that builder window, just leave them 0 (because any value will be overwritten in the next step). The variables and arrays will be initialized according the given constants (see the "on Init" tab).
By the way, if the sequence string is now an "Array", would it be possible to change that array using "Modify Variables" instead, which I described in my introduction text?
Yes, you can use the "modify variables" block to modify your array, but only one element at a time. For example, if you want to take the first element of the array, use seq[0]. For second element, use seq[1] and so on... But why would you want to modify the sequence itself? Doesn't it suffice to just modify the "continuation", take a different part from the sequence?
If I could somehow use a single block like that to change the whole array at a given condition, that would solve everything.
Changing the whole array requires a loop and possibly re-sizing the array, if the resulting array is longer or shorter than the original. I don't think that is the easiest solution

-
Also, as I mentioned before - I need to be able to freely utilize the "shiftback", using conditions and what not. Could this be possible with your configuration?
https://fxdreema.com/shared/hjSUXN3Zb
Here I continue my example, with an arbitrary condition: when RSI crosses above 60, modify loses to 2.
The sequence is the default "1,2,3,4,5,6".
I also added a text under each candle to keep track of the active sequence value.
Here's how it behaves:

-
@roar I see. So I can use the "Modify Variables" block and change the "loses" variable -> and it will revert to that value from the array and continue from there, right?
I will test that thoroughly a bit later with other conditions, so far I noticed few issues:
-
When it loses 6 times in a row (full array length) it doesn't reset and stops working completely.

-
It skips second value from the array (0.02=0.01*2) from time to time, not sure why:

-
It also reverts back to the third value sometimes, which doesn't make sense (from 0.06 to 0.03):

PS: used your latest version. Didn't edit anything.
-
-
@rafaels919 Don't take the code for granted! It should show you the way you can go.
-
@trader-philipps said in Help needed in modifying values in a sequence:
Don't take the code for granted! It should show you the way you can go.
What do you mean by that?
-
@rafaels919 I fixed the bugs you found, check this one:
https://fxdreema.com/shared/J3efZjb2e -
Hey @roar
it looks great, the bugs are gone. Do you think it is possible to have it to shift two values back instead of reverting to value two?For example:
-
We have the "loses" variable changed to "2" by "modify variables" block when RSI crosses 60 (just as in your example)
-
If we are on 5th value - we don't revert back to the 2nd value - instead -> we shift back two values (so we would be on the 3rd value instead of 2nd value) -> so it doesn't REVERT to two when the condition triggers but SHIFTS BACK two values.
Your configuration looks great, hopefully we can make this last adjustment.
-