Help with indie that works only on Fully Formed bars.

To add comments, please log in or register
peltF
9
peltF  
Hello. Still trying to work with MT4 indies, and there is a recurring problem I am noticing on all of my scripts, and I'm sure the fix is obvious and simple.

My desire is to create a script that will ONLY work on the most completed bars... I.e., essentially ignore that current bar where the current bar index ==0.

I have broken out the least amount of code that will reproduce this problem. The script is simple and is just to illustrate the problem and simply draws a dot if the most recent bar(index i+1) closes above the prior bar(index i+2). You can see here as I want to work on only formed bars, so I'm not using index 0.

Just some notes about the script...

My iterator is using index "i".

I am storing the time of the most recently formed bar in the var "LastTime".

My main loop where my code goes is "if(LastTime!=Time[i] && initialBarCnt>1)". Here "initialBarCnt" is a var that simply counts how many bars have been processed, and this loop is only entered once i have more than 2 bars, as my script looks at the bar1, and bar2 indexes.

You can replicate the issue likely by loading the indicator, and switching back and fourth through the timeframes. I.e., if you load it on a M15 chart, and switch to a M30, it will fail, producing this error:

2019.03.14 08:44:58.666 FF_HelpWithScript EURUSD,H1: array out of range in 'FF_HelpWithScript.mq4' (42,18)

Can you help me fix this basic template, or show me what I am doing wrong? I'm sure it's something obvious I just don't understand yet?



Files:
whroeder1
18071
whroeder1  
peltF: My iterator is using index "i".

The only un-fully formed bar is zero.

peltF
9
peltF  

I got it.

Removing bars from the lookback period fixes my problem.

This thread can be deleted.

To add comments, please log in or register