Download MetaTrader 5

Finding Programing/Programable Solutions to stated Problems

To add comments, please log in or register
omovaze
37
omovaze  
Say you have a Problem or solution and you do not know apparently or are in need of a less complex method(ideas) on how to tackle this problem or implement a solution in MQL4, then this topic area should be a safe Haven(least created so). Let's be Professionals eh, C y'all. Happy trading folks
omovaze
37
omovaze  

Umm... i am in need of some programing ideas, hopefully someone in here could kindly come up with a less complex solution(it's what we programers do isn't it?) for the soon stated problem. I should start off saying am not new to programing buh however new to programing in MQL4 though relatively same with C++ you might agree.

For weeks now i have been building and testing an EA, and i currently find myself in a position where i need to add a custom function but do no really know how to go about the trade algorithm. I need to count a certain number of candle on a particular timeframe say (20candles on 15mins) from a trade execution time or candle. To explain further: Example trading 15mins: A trade buy is triggered by a 15mins candle, and i want to count 20 15mins candle from that triggered position.

I have tried doing this with the time-function available in MQL4 but the algorithm gets complex if i were to count say 100 candles which obviously exceeds a day. So i was hoping one in here would know how to count each candles on a particular timeframe into the future from a triggered position. Thanks

Tjipke de Vries
6373
Tjipke de Vries  
omovaze:

Umm... i am in need of some programing ideas, hopefully someone in here could kindly come up with a less complex solution(it's what we programers do isn't it?) for the soon stated problem. I should start off saying am not new to programing buh however new to programing in MQL4 though relatively same with C++ you might agree.

For weeks now i have been building and testing an EA, and i currently find myself in a position where i need to add a custom function but do no really know how to go about the trade algorithm. I need to count a certain number of candle on a particular timeframe say (20candles on 15mins) from a trade execution time or candle. To explain further: Example trading 15mins: A trade buy is triggered by a 15mins candle, and i want to count 20 15mins candle from that triggered position.

I have tried doing this with the time-function available in MQL4 but the algorithm gets complex if i were to count say 100 candles which obviously exceeds a day. So i was hoping one in here would know how to count each candles on a particular timeframe into the future from a triggered position. Thanks

on same chart


if( Time[15] > OrderOpentime your trade) then how many bars there has been passed ??

you need to find the bar where your trade is opend how do you find that bar ??

Ian Venner
2584
Ian Venner  
omovaze:

i want to count 20 15mins candle from that triggered position.


Take a look at iBarShift()
omovaze
37
omovaze  
deVries:

on same chart


if( Time[15] > OrderOpentime your trade) then how many bars there has been passed ??

you need to find the bar where your trade is opend how do you find that bar ??


Thanks, it's a strange way answering a question with a question however brilliant it is. I believe i get your point, but this gets complex afterwards as Time[], iTime() would only use a greater than comparison and this functions always would be greater than OrderOpenTime() once HIT. While the challenge is to get exactly in this case 15 candles from OrderOpenTime().

Bar Trade opened i believe can be found using iBarShift() // Yet another time function.

I appreciate your solution, however, the problem remains same. To count exactly 15(or any amount) candles after OrderOpenTime() without the use of time function except of course to know the BAR the order was opened else What happens during the Weekend?.

darksideofthemoon
57
darksideofthemoon  

Cannot see how this would get complex. Do not count bars, calculate ahead-of-time the exit bar time:


Say, 20 bars means 20*PERIOD_XX seconds;

Bar time at the time point of trade is Time[0];


So, in your example, exit_bar_time = Time[0] + 20 * PERIOD_M15;


From there you compare: if(Time[0] >= exit_bar_time) do_what_you_need_to_do_after_20_bars();

omovaze
37
omovaze  
2cent:


Cannot see how this would get complex. Do not count bars, calculate ahead-of-time the exit bar time:


Say, 20 bars means 20*PERIOD_XX seconds;

Bar time at the time point of trade is Time[0];


So, in your example, exit_bar_time = Time[0] + 20 * PERIOD_M15;


From there you compare: if(Time[0] >= exit_bar_time) do_what_you_need_to_do_after_20_bars();



How it would get complex? One question, What happens if the "Future calculated time" falls on weekends? we all know trade price open on Sunday cannot be solely determined nor predicted, so if we use a greater than (>=) || less than (<=). This could get real messy if price spikes moves real bad against you. Instead of recalculating price signals to determine a good exit, since the algo is wrong it would just exit at an position >= | | <= closeTime.
darksideofthemoon
57
darksideofthemoon  

Well, either you want to wait for 20 bars to pass no matter what, or you have to implement exceptions.

With ahead-of-time calculation of the exit bar, you can check if it falls into a weekend (TimeDayOfWeek(exit_bar_time)), and decide from there what you want to do.

Tjipke de Vries
6373
Tjipke de Vries  
omovaze:

Thanks, it's a strange way answering a question with a question however brilliant it is. I believe i get your point, but this gets complex afterwards as Time[], iTime() would only use a greater than comparison and this functions always would be greater than OrderOpenTime() once HIT. While the challenge is to get exactly in this case 15 candles from OrderOpenTime().

Bar Trade opened i believe can be found using iBarShift() // Yet another time function.

I appreciate your solution, however, the problem remains same. To count exactly 15(or any amount) candles after OrderOpenTime() without the use of time function except of course to know the BAR the order was opened else What happens during the Weekend?. //Olympics no trading no new bars

deVries:

on same chart


if( Time[15] > OrderOpentime your trade) then how many bars there has been passed ?? Atleast 15 it can be at bar 16 but also at all bars > 16

you need to find the bar where your trade is opend how do you find that bar ?? It is the first bar where 'OrderOpentime your trade' is equal or greater then Time[bar]


Finding the bar trade has opend

Use a loop counting up from zero and find the first bar where 'OrderOpentime your trade' is equal or greater then Time[bar]
Show me how you do that........

omovaze
37
omovaze  
deVries:

Finding the bar trade has opend

Use a loop counting up from zero and find the first bar where 'OrderOpentime your trade' is equal or greater then Time[bar]
Show me how you do that........


Ummm... @deVries (if you permit my calling you that), that task as already been completed, though with a different approach, figured wouldn't so be the best idea counting bar numbers in open orders. Instead i have come up with a generic algorithm that learns from each tick update. "Hopefully this works" which currently the result have been ++ . But Looking into your solution statement, the problem i believe despite my been inexperienced(2weeks) with the program language, is the fact that we are still using a time function to locate the "OrderOpenTime()", which brings me to my initial question "How can one haven located the Order open Bar and count to current bar(x) a certain number without using a time function". Because looping from 0 would still be incorrect if one cannot identify the order open BAR[location] on chart in regards it's stated timeFrame. Else would lead into weekends/holidays (why? TimeFunction) and wouldn't want that. Great idea though, still with same task/challenge with my question.
omovaze
37
omovaze  
deVries:

Finding the bar trade has opend

Use a loop counting up from zero and find the first bar where 'OrderOpentime your trade' is equal or greater then Time[bar]
Show me how you do that........



This is funny, just had a thought. iBarShift() returns BAR Open Time and Time() returns open time for each BAR, maybe what you are saying is, Get the order BAR open time (iBarShift) then using the open time, identify each bar open time (Time[]) on the specified timeFrame, looping through iBars() or a certain given number. Then find the position where : orderBarOpenTime == Time[i]. This would make it possible to compare the found "position " to current position Thanks a lot.

12
To add comments, please log in or register