First Attempt at Arrays. Could use an expert opinion.
-
First off, if I create a shared project link to this, and then I delete the project, will the link still work? I don't want future people to lose the benefit of studying it if they need help. (If someone says they get deleted, I'll immediately upload a source code below for future people, because I will probably delete this project eventually). (Project link at the bottom of this post)
I created a test project just to see if I understand/grasp how to use Arrays correctly. I've never used them before and I don't generally work with code, so if you give advice pertaining to code, treat me like I'm five. Hahaha. Feel free to comment on anything in the project, but I mainly care about the Array stuff specifically. So, send me whatever pointers you wish, but don't feel like you're required to comment on everything if you don't feel up to it. The arrays are really the heart here.

While there's a lot of blocks here, what I'm trying to achieve is simple. I will explain the premise as well as a brief description of the block by block in case something confuses you. Again, don't get hung up on stuff. I just care about the Arrays, but for completeness, I want to share the rest.
All I'm attempting here is to, when above a 500MA, go find the highest and lowest candle in the last 100. And if the highest price is closer than the lowest price (we're likely making a pullback off of the high right now in this case), I want to loop from the highest high back to the lowest low, count how many "down closed candles" there were between the high and the low, take that count and set my array size to it, then I loop back through the candles again, and I attempt to store the opening price and candle ID of all valid candles in the proper index slot for the proper array. At the end, display "done" (I'm aware this doesn't do anything with the values right now. I'm just trying to make sure I'm doing this correctly before I make something absolutely massive with it that no one can hope to understand). I know some of the "useful" logic isn't here, but I would do that kinda stuff on my own. I really wanted to make this simple.
Block by block, if needed:
On Init, I try to declare my two arrays. I think I did it right?
Price above MA, true, we go left, false we go right.
Store the CandleIDs for the highest and lowest candle in the last 100 candles.
If the high is closer, then the low is further, and I assume there's a bullish leg. I check this by seeing if the candle ID is lower for the "high" candle.
So, I want to find "down closed candles" in the assumed leg.
I set the loop_id equal to that of the High Candle. This is because I will use loop_id for candle ID, and I only want to start at the highest candle. I also set "ValidCandlesFound" to 0. This number will be the ArrayResize value I try to use. Before starting, there is zero valid candles, so my array should ideally be zero at the end of this if no valid candles are found.
Check if my loop_id value is equal to or less than my "low_candleID" because I want the loop to stop at that candle.
If the loop_id allows it to pass true, we check if it's a down closed candle. If we get a true output, in the variables tab, I add one to the ValidCandlesFound variable. And whether true or false, I exit to a pass block, just to visually loop the loop up in a friendly way. I also add +1 onto the loop_id at this point, just because I can.
Once the loop terminates, I attempt to change the size of both of my arrays to the size of "ValidCandlesFound". I've never worked with Arrays before, but I assumed I needed to set the array at a size before I can start cramming values in? If I'm wrong, can I just skip that step and move into the next section? (Which you'll better be able to answer after reading it ahah)
At this point, I set the loop_id to the ID of the high candle again, and I also set the ArrayIndexID to -1. I heard the first index on an array is "zero," so, setting it to negative one made sense here shortly.
I again check if the loop_id is within tolerance. If it is:
I check for down closed candles again. If there is a down closed candle, in the same block, I add one onto the ArrayIndexID.
In the next block, I store the opening price and the candle ID of the candle in temporary variables, for the next block.
The next block, I attempt to fill the value of each index with the values stored in the temporary variables.
If the candle wasn't a down closed candle, I pass the array logic. After exiting the array logic (so either of these), I add one onto my loop_id again and back to the beginning.
I repeat this until the loop_id exceeds my swing I'm referencing, at which point, it hopefully prints a message on the screen that says "done!" (I've not worked with comments either, so idk if I did that correctly).
Naturally, the same type of logic is true for the other side, but I want to spare you. Haha.

So, the biggest things I need to know are:
Are the On Init declarations correct and necessary?
Did I need to do the loop to set the array sizes like I did in blocks 25 and 19?
And, did I fill my arrays correctly in 30/32?Furthermore. I didn't know how to attempt it, but say for instance later, one of these points became "invalid" for whatever reason and I wished to remove them from the array? And it was in the "middle" of the array somewhere. Is there a way to remove it and resize the array? Or would it make more sense to pursue an alternative...like repopulating the entire array again from scratch, without that one. Or would it make more sense to store a zero in it or something so that I can ignore it?
Earlier Link:
https://fxdreema.com/shared/H017dd00bFinal Link:
https://fxdreema.com/shared/kuEfhkS8dThank you so much in advance!

-
@l-andorrà , I don't like tagging people, but on one of my other posts, you mentioned if I was willing to put in serious effort, you'd be willing to assist me where needed. I hope this was a strong enough attempt on my part ahaha. In advance, I appreciate your time. You seem very committed to this community, and I want you to know you're appreciated. Idk if you hear it enough ahaha.
-

It's clearly imperfect in its current state. I'm guessing I don't know how to correctly declare arrays? I thought that's what I did on the "on Init" tab, but it seems incorrect apparently.
It's also possible that I've incorrectly typed things into the variable boxes across the EA, but maybe this just stems from the fact that I declared things incorrectly?

-

This was my attempt to resize the arrays. I don't know if it's broken because I did it wrong or because it was never declared correctly (and that this is actually correct).
-

I noticed I didn't put semicolons on this one. So, I'll fix that.
I also updated the URL for the shared project when I did this.
-
@roar I'm also sorry to tag you. I know L'andorra has said that sometimes you need a "real programmer" to answer your questions.
I've been trying to read through old forum posts to see if I can troubleshoot this myself, and I've noticed that L'andorra seemed to learn Arrays this spring himself. So, I'm hoping he might be able to assist me, but I've seen how competent you seem to be with code, but I also see you've not maybe been as active recently and I also see your time is being fought over by many people. If you have time and L'andorra can't or is unwilling to help, I'd like to humbly request your assistance if at all possible.
And greetings from a different part of Finland. Hahaha. I've noticed you seem to be Finnish. I'm American, but I live in Finland (my wife is Finnish). Anyways. Sorry. Lol. I know. Off topic.
-
To save time and back and forth on all of our parts, I want to share this, too. It's still array stuff and related to the stuff here, but it's from a personal project. I want to ensure I'm typing things correctly in these boxes (like formatted correctly for Dreema). I don't want to create a new forum post over it because it's still related to the same series of problems, and I imagine someone one day will be trying to learn Arrays themselves, and I hope they can learn from my mistakes.

I've typed in the names of these arrays and I've also got something similar to a loop_id (I just called it IndexID). It's an int variable that I keep adding +1 onto for the purpose of rotating index slots in the Arrays. I assumed I was doing this correctly, but now I'm starting to doubt myself. Haha.
-
I also did this little guy here. Again, starting to doubt myself a bit. This seemed like something I should be able to do, right? (It's array name [int variable] and then minus one off of that). The idea is to look one candle further to the right than the int value I have stored in this array (it's an int array, too).

-
This is the last one, I think. Again, not trying to "piggy back" on my own post, but it's all array related and I have a feeling I'm just going to have to create 10 different posts when it could all be done in one place for everyone's benefit.
So, in this one, I have a bool array here, but I can't manually type in the name and index for the bool on the "bool" drop down tab, so I used this text code input one. Was I correct to do this?

-
Hi @MrDaisyBates!
If you were coding in pure mql5 there wouldn't be any problem, but the "blocky" nature of fxdreema requires some extra consideration: when you declare variables in a "custom mql code" block, those variables are usable only inside that block - they are not global.
You can declare them globally by using your Variables menu:

After deleting block 16 and declaring the variables in Variables menu, there's just 2 errors, seemingly typos.

In these situations it often helps to download the .mq5 and try to compile it in your own MetaEditor. Now you see the error line, and somewhere above that you can always see the fxdreema block number.
https://fxdreema.com/shared/CfH27QXP

-
@MrDaisyBates said in First Attempt at Arrays. Could use an expert opinion.:
Was I correct to do this?

This one works, but if you want to look smart and techy, you can also use the other condition block and just set your boolean array as the condition itself:

-
@MrDaisyBates said
And greetings from a different part of Finland. Hahaha. I've noticed you seem to be Finnish. I'm American, but I live in Finland (my wife is Finnish). Anyways. Sorry. Lol. I know. Off topic.
Oh hello there neighbor ':D

-
Ah! @roar You're an absolute legend! So much appreciation here.
I didn't realize arrays could be declared in the normal variable area (and actually NEED to be declared there!) It's actually embarrassing that it's THAT simple. I wish I'd seen it in the documentation. I know it's an advanced feature, but still. For completeness sake. Arrays are so important for so many projects it seems.
It's also really validating to see that I was actually doing it all very right on my end apart from a simple typo! Thanks also for the tip to export the source and debug it in metaeditor directly. I'll def need to keep it in mind. I've got a really big project underway and I might end up needing it.
For the condition block that I have to type in myself, like you suggested, I suppose I'd simply add "== true"?
Is it sensitive to spaces? Do the spaces need to be there or is math/statements fine without spaces in this case?
Hahahaha. Your meme.

I did have a question about arrays above that I'd kinda like an answer to if possible.
I'm using undeclared size arrays here.
If I have an unknown amount of "things." Like "bear candles" in this case. Do I need to count all of them first, THEN size the array to that size, before I can store stuff in the array? Or is it okay for me to somehow add items to the array and adjust it as necessary? Will it break the array somehow or do they tolerate being able to just add to it and expand it as necessary? Would I simply just resize it +1 first and then add whatever value it is to the new slot? I hope that's kinda clear what I'm asking. Sorry it's not more direct.
On a similar point, if something, say, in the "middle" of an array becomes invalid and I no longer need it, is there a way to remove it (simply), or is it better to set the index to "zero" and just filter it that way, or is it better to just repopulate the entire array again in that case?
Thanks again, Roar.

-
@MrDaisyBates here's some more points:
- yes, you can add "== true" to the custom condition
- when mql4/mql5 code is compiled into machine code, all spaces will be removed in the process. So you can put as many spaces as you like, wherever you want.
- if you dont know how big your array is going to grow, you can do as you described: resize the array by +1 and then add your element to the last place
- mql5 has a nifty function to remove one element from the middle of an array, and then combine the tails together again. You can use this in a custom mql code block. On mql4, you have to reconstruct this function with multiple ArrayCopy phases. It is also possible to just set the "disabled" elements as 0 or -1, but you should make sure your array doesn't grow too big, it will start affecting performance at some point. https://www.mql5.com/en/docs/array/arrayremove
I'm not sure what other questions I should answer, maybe you can list them again

-
Oh, @roar ! hahaha. You're the best for this.

For now, I think I can discover my own way through this array stuff! You've been an immense help and are much appreciated.
I am having one issue, though. Today, while working through this array stuff to ensure that I'm grasping it, I started to attempt to set values in one array equal to values from another array. The logic here isn't so important, so I won't bore you with it.
But basically I have a couple arrays with some relatively unfiltered data in them.
I then cycle through them (using loop_id as my index number for the unfiltered ones). And the ones I want to keep, I'm attempting to store into the new arrays with "IndexID" as my loop for those basically. I have a feeling you're going to tell me I should do this by hand instead of using the blocks (but I'm not quite so sure how to do that just yet, and I'm curious if you were going to tell me ahaha). It looks like this basically.

Needless to say, you can imagine that today I've discovered the pure bliss of "Array out of range"! ahahahaha. Though I'm not having this problem at the moment anymore.
I'm really just curious if I'm failing to resize the arrays correctly or if I'm just not storing stuff in them correctly.
But, this was the earlier bit that I was discussing. I have blocks where I resize the arrays: (IndexID has been starting at zero, so I've been attempting to resize 1 larger than that).


If I'm coming to the wrong conclusion, then I'll probably just need to keep investigating and start a new forum post.
Then I go to load the arrays with the modify variable stuff you see on the screen. Best I can figure is none of this data is actually making it into the arrays, so all of my arrays have nothing in them? I don't know how to print the data contained in them on the screen. I keep trying to enter it into the draw text block, but I think I'm entering it incorrectly ahaha. It just tells me the words I'm typing or "text."


I started this project a couple days ago, but I've been combing it over for like 9 hours today. I feel fairly confident that the IndexID and loop_id stuff are correctly staged, and that it's likely something in how I'm resizing my arrays or how I'm trying to store variables.
I really believe I can manage for the most part at this point (as far as figuring out where I did derpy things). But some of these little things are def hanging me up it would seem.
Thanks again in advance, bud.

Edit: Roar, I sent you a private shared link to this if it helps. I know it's hard to help when you can't get your hands in it.
-
@MrDaisyBates Thank you for tagging me, man, but this is FAR OUT of my league!!
I'm not a programmer like roar. I'm just an advanced fxDreema user. He will be able to help you for sure. 
-
@l-andorrà Hahahaha! Big mood! I appreciate you, bud! Absolutely no worries!

-
-
@MrDaisyBates Hi! I dont immediately see any obvious error... To help troubleshooting, you should put some Print() statements here and there, checking the sizes of your array. This often leads to clues to solving the error.
Try checking the array size and id variable before your block #36, as it seems to are getting outside range there.

-
@roar Neat! I'll try messing with that now. Don't kill yourself over it. I'll be working on it again all day tomorrow, too. Until I get it. I didn't know that Print function, so I'll try that and it'll give me a much much better idea what's going on. I really appreciate it!
