[MQL5] Dynamic level based stop
-
Hi,
I'm running into a challenge which i can't figure out (yet) so if someone could provide a pointer or two that would be great.
Problem:
I'm using the Camarilla levels (indicator with n buffers, each buffer contains a level) as a stop.
What i would like to do is detect a level cross by the price and based on that get the last previous level (or x levels away) . So, price breaks the Pivot level upwards so stop moves to the L3 level. Subsequent break of the H3 level and the stop moves to the Pivot level, etc.Obviously i could make a test for each level but that seems quite silly. I'm not a newbee when it comes to coding so i have a function that takes an array with values and the price and returns the proper level.
The thing that i do not yet see is how to include such a custom function as a block in fxdreema.Any suggestion would be appreciated.
Cheers,
Fermin -
-
Hi @roar ,
Thx for your reply.
This is indeed a thought that has crossed my mind but how do i gain direct access to an output-buffer of an indicator. In MQL5 we would use the handle, call the copyBuffer function and that would be it.
How would one go about that in a custom block?
Or, where could one find a snip of sample code reading indi buffers via the studio option you mentioned (did stumble across it already but without some sample snips it's a bit hard to decipher
)Cheers
-
@dcg I'm afraid studio is the way to go here, unfortunately I can't provide any sample for that...
Well, you could make an array for the latest buffer values, and update it in a loop.
Maybe this is useful for you, I'm not sure: -
@roar Yes, this is indeed quite useful. I had completely missed the loop block (although i would not have come up with the way to access the array with the loop_index
).
Guess i still have to write a custom block to test if a level was crossed by a certain bar and determine which level it was. As well as getting the next level going up or down. -
@roar
Filling a static array will indeed work in the way you described.
To make the whole setup complete one can add a condition block to the modify block that tests for the last index value, thus determining the end of the loop. -
@dcg awesome!
-
Following is the link to a sample prj containing a way to properly fill an array.
Array fill example
