You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
WHRoeder, This code looks so simple but I cant work out in my head how it works, won't the if statement always be true if it makes time0 equal to time[0] every time time0 is equal to time[0]? Not saying it doesn't work but I just don't understand how it works structured like that.
1st tick: Time0 does not equal Time[0] so return is not executed, Time0 is set to Time[0] (start time of the current bar) the rest of the start function is executed.
2nd and subsequent ticks: if Time0 still equals the start time of the current bar then we are still on the same bar, return is executed and the start function is exited. If Time0 does not equal the start time of the current bar then we are on a new bar, return is not executed, Time0 is set to Time[0] (start time of the new current bar) the rest of the start function is executed.
How would I go about making a counter where if a pending order is place and it is not triggered with in x amount of bars then it is to be canceled ? All I can come up with is put a counter to count every time a new bar forms and if the amount of bars counted == the specified allowed bars before pending orders are canceled. The bar counter is reset everytime a new pending order is opened? How does that sound?
I would create a function that checks for pending orders, it looks to see when each order was opened, checks how long it has been and if longer than the time limit it closes the order.
I want to make a function that scans eurusd, usdchf, gbpusd, usdjpy on 1hr tf. It goes back to the last 06:00 gmt candle records the open, goes back another 24 bars to the prev 06:00 gmt candle records that open to and records the 6gmt -6gmt range for each pair. Then compares the 6gmt - 6gmt range from all pairs and returns the one which is the highest. Is it possible for an ea to do that from being attached to 1 time chart?
With all problems like this before you think about code you have to figure out your solution first . . IMO. Create a flow chart or write some pseudo code . . . get a solution that makes sense first . . then look at the code.
To answer you last question, yes it is possible to do that, for example, to get the open value for a particular candle from a different pair to the one the EA is on I would use . . .
once you have your values for the rage of the 4 pairs you can easily determine the largest using something like this:
. . . or you could put the values into an array and use ArraySort . . . there is usually more than one way to do anything, first you have to have a plan of how you are going to solve your problem.
EDIT: bear in mind some of this stuff will not work correctly with the Strategy tester.
Alright this is my own attempt to write some code that will scan the eurusd 1hr chart till it finds the last 06:00 bar, records it's open, goes back another 24 bars to record the open of that bar (start of 06:00 day) and gets open-open range from them 2 selected bars.
Surprise surprise it doesn't work . Lol ------> http://myfacewhen.com/307/
Tell me the what I have f*'d up. Or have I just got about this the wrong way? I tried hehe
Spotted one issue . . . 24 hours before b is b+24 . . bars count up from current bar ( 0 ) to the left
Well done for adding the comments, very good practice to get into . . . :-)
Spotted one issue . . . 24 hours before b is b+24 . . bars count up from current bar ( 0 ) to the left
Well done for adding the comments, very good practice to get into . . . :-)
Wow well spotted that would of taken me a while to figure that out lol. I can't believe I got all that right - that silly mistake. I feel like I am getting somewhere now . Yeah I added the comments to help me keep track of what I am doing and to make is super easy for you guys to see what I am trying to do. Now I am going to get it to compare the 4 pairs and spit out the one with the highest value Ill let you know how I go with it . Thanks RaptorUK
Alright so I turned all the variables into arrays and run the checks for each one. Now it has stopped working. Is not possible to have multiple for loops like this?
Yes you can, no problem, but don't use an array in the for loop index, you can use b each time if you like. It is reset to 0 for each of the for loops so re-using it is not a problem. what do you actually NEED to use an array for ? isn't it just for the range values ?