Looking for an indicator..


TopFroxx

Well-Known Member
that i can attach to e.g. an m1 chart (MT4), that just tells me if the current price is above or below the price X candles ago.
does anyone know such an indicator? i would need it to compare current price with multiple other prices (e.g. 10 candles ago, 100 candles ago, 1000 candles ago)
IF i could wish for one it should show me in a small table if current price is above or below the price 10, 100, and 1000 candles ago.

for example:
current>Timeframe1 => true
current>Timeframe2 => true
current>Timeframe3 => false

could anybody help? does such an indicator exist? (obviously most likely without the table)
i think it shouldnt be too hard to code this for someone who knows how to code mt4 indicators (TRO maybe? :)), because the idea is super simple. but i dont possess any knowledge in mql4

would really really appreciate it!

cheers
 

rod178

Well-Known Member
This is very easy to code.

Use iHighest and iLowest.

eg
double price;
// calculating the highest value on the 20 consecutive bars in the range
price=High[iHighest(Symbol(),PERIOD_M1,MODE_HIGH,20,0)];

I am supposing you would want an arrow are whatever to display on the chart? The table is simple to construct

I can code up an indicator, although would prefer a detailed spec.
 

TopFroxx

Well-Known Member
rod178 said:
This is very easy to code.

Use iHighest and iLowest.

eg
double price;
// calculating the highest value on the 20 consecutive bars in the range
price=High[iHighest(Symbol(),PERIOD_M1,MODE_HIGH,20,0)];

I am supposing you would want an arrow are whatever to display on the chart? The table is simple to construct

I can code up an indicator, although would prefer a detailed spec.
hey rod, thank you for the reply. with "detailed spec" you mean i should describe more cleary what i want?
the variable input for the indicator should be (at least) 8 different numbers of bars. i'll just give a full example:
input:
tf1: 10
tf2: 20
tf3: 50
tf4: 100
tf5: 200
tf6: 400
tf7: 800
tf8: 1600

the indicator would then compare the current price to the open price of the candle 10 candles ago, 20 candles ago.. and so on. (i would only use it on the m1 timeframe, so this could be fixed, but whatever is less work)
if the current price is above the open of the historic candle, then the table would show a green up-arrow, otherwise a red down-arrow. so the table would show 8 arrows.
what also would help alot is if the table had a third column (1. column is the timeframe, second the arrow) with the difference of the current price and the respective price X candles ago. so just
pricedifference=current price - price(X candles ago)

do you need anything else?

p.s.: i attached a crappy with paint drawn example
p.p.s.: price difference numbers are made up
 

Attachments

rod178

Well-Known Member
OK no problem, understand what you want.

I will endeavor to make the indicator as flexible as possible so that you can easily modify it to suit your future requirements. What you think you want and what you decide that you require in the future often become somewhat different.

I'll code up a Beta by the end of next week after my visitors depart and during that time have the opportunity to think about the alternative approaches. The actual coding will only take a couple of hours, if that.
 

TopFroxx

Well-Known Member
rod178 said:
OK no problem, understand what you want.

I will endeavor to make the indicator as flexible as possible so that you can easily modify it to suit your future requirements. What you think you want and what you decide that you require in the future often become somewhat different.

I'll code up a Beta by the end of next week after my visitors depart and during that time have the opportunity to think about the alternative approaches. The actual coding will only take a couple of hours, if that.
thank you very very much!
 

TopFroxx

Well-Known Member
dont want to sound too demanding, but there would be something else that would be super helpful.
is it easily possible to include an alarm (a simple one, just making a sound in mt4 and show a pop up window) if some conditions are met? conditions in this case would be a certain combination of up and down arrows, so e.g.

tf1: up
tf2: down
tf3: down
tf4: up
tf5: down
tf6: up
tf7: down
tf8: up

these conditions would have to be variable as well. so maybe a drop down menu with the two choices "up" and "down", or just a cell where one could put in a 1 (for up) or a 0 (for down). this is what the indicator is supposed to be for in the end, monitoring if certain combinations of "ups" and "downs" are met.

if this isnt as little work as i think it is, please dont feel obligated to code it.
 

rod178

Well-Known Member
Using 10 Bars lookback as an example -


Do you want the indicator to trigger on breaking the High/Low on any of the previous High/Lows up to 10 bars previous or just the High/Low at 10 Bars previous.

My assumption from reading your posts is the latter. Correct?

PS I'll also add an Alarm as requested.
 

TopFroxx

Well-Known Member
rod178 said:
Using 10 Bars lookback as an example -


Do you want the indicator to trigger on breaking the High/Low on any of the previous High/Lows up to 10 bars previous or just the High/Low at 10 Bars previous.

My assumption from reading your posts is the latter. Correct?

PS I'll also add an Alarm as requested.
the "path" doesnt matter. i just need a comparison of the current price with the open price 10 candles ago.
so for example (on a m1 chart):
current price: 1.3812
open price of the one! 1 minute candle 10 minutes ago is 1.3805
then the price difference would be 1.3812-1.3805=0.0007, which will equate to an up arrow, because current price is higher than the price 10 minutes ago.
you dont need to look at highs or lows.
 

rod178

Well-Known Member
I coded it up last night, excepting the Alert.

Have a think about how you want the Alerts to potentially trigger (eg every new M1 bar), especially to avoid continuous triggering (would drive you crazy), which is what would happen using your posted requirement.

Continuous refreshing is desirable on the Chart, not so for MT4 alerts, which are rather clunky. The logic is the issue rather than the coding.
 

TopFroxx

Well-Known Member
hey, looking good :)
as for the alarm: maybe just one, once the conditions are met. and you could then put another text on the screen which says "conditions met" (green text) or "conditions not met" (red text). that would be perfect.
another thing: are the specific number of pips in your picture correct? a few things i noticed:
- the open price 5 bars ago was not 1 pip lower than the current price. looks more like 6 pips or so
- the absolute height of the pip differences seems rather small (could be true, but seems unlikely)
- there is a yellow arrow. i wouldnt need that. +1 or -1 pip qualify for a green or red arrow respectively.

cheers
 

rod178

Well-Known Member
TopFroxx said:
hey, looking good :)
as for the alarm: maybe just one, once the conditions are met. and you could then put another text on the screen which says "conditions met" (green text) or "conditions not met" (red text). that would be perfect.
another thing: are the specific number of pips in your picture correct? a few things i noticed:
- the open price 5 bars ago was not 1 pip lower than the current price. looks more like 6 pips or so
- the absolute height of the pip differences seems rather small (could be true, but seems unlikely)
- there is a yellow arrow. i wouldnt need that. +1 or -1 pip qualify for a green or red arrow respectively.

cheers
Alarm - issue is that although the alarm will trigger once for when the conditions are met it will trigger on each tick that they are met. This will give the appearance of continuous Alarms. It is a logic issue. One solution is to kill the alarm after each condition is met. However you would then have to reset the alarm to pick up future triggers. Probably the best solution in this case. Other options are time interval or new bar . refer below comment.

Open Price 5 Bars ago was indeed only about 1pip lower. I also initially thought that there as an error with the small pip ranges. Some testing indicated that the pip ranges are correct.

Additionally, use the Bid and Ask lines on the image as a reference. The spread is 1 pip or less. Note that all prices are based upon the Bid and that current price is Close 0 and the Bar 5 open is Open 5. The count does not include the latest bar ie bar 0.

I will also give you the option of using Close x (ie 1) as the latest price, which, imho is preferable to Close 0 . This would for example minimise false alarm triggers and stabilise the chart image.

I am never wrong except when I am, so we can confirm the pip ranges later, with further testing.

Yellow Arrow - I rounded to the nearest pip. Anything less than a pip is a Yellow Arrow, including for Alarms. Hence even though +1 could be a green yellow or red arrow, the unrounded values may be up to 1 pip different. I can give you the option to disable rounding. However, you may find flicking between -0.6 and +0.6 pips will provide too many "false" alarms, especially using Close 0 .
 

TopFroxx

Well-Known Member
i see. as for the alarm, resetting would be fine. could you still put on a text whether the conditions are met or not met on the chart? or is that too much work? would be nice to instantly know if i am currently in a "buy or sell market state" (defined by the conditions), or not.
as for the pip differences, yeah i would have to play around with it and see for myself to verify. could you upload the current version so i can check? thanks

p.s.: maybe a bit of background, as to what this thing is for. currently i have one explicit strategy i would want to use it for. i would attach the indicator to an m1 chart and if certain conditions are met i would get a buy or a sell signal. now that i am writing it down i realize something: i would need to put in 2 sets of conditions (1 for a buy and 1 for a sell). but i think i could just attach the indicator 2 times with different conditions. nevermind.
the current strategy would only give me 1-2 signals a month, with about a week holding period. i could open a thread and post the trades when they come, so you could follow and see that your work wasnt for nothing if you like :)
 

rod178

Well-Known Member
TopFroxx said:
i see. as for the alarm, resetting would be fine. could you still put on a text whether the conditions are met or not met on the chart? or is that too much work? would be nice to instantly know if i am currently in a "buy or sell market state" (defined by the conditions), or not.
as for the pip differences, yeah i would have to play around with it and see for myself to verify. could you upload the current version so i can check? thanks

p.s.: maybe a bit of background, as to what this thing is for. currently i have one explicit strategy i would want to use it for. i would attach the indicator to an m1 chart and if certain conditions are met i would get a buy or a sell signal. now that i am writing it down i realize something: i would need to put in 2 sets of conditions (1 for a buy and 1 for a sell). but i think i could just attach the indicator 2 times with different conditions. nevermind.
the current strategy would only give me 1-2 signals a month, with about a week holding period. i could open a thread and post the trades when they come, so you could follow and see that your work wasnt for nothing if you like :)
The code is currently integated with some library functions. I'll have to remove the library calls and make the indicator 'stand alone' before I can give yo a copy. I'll try and get around to it over the weekend.

Not a good idea to attach it two times as the object names would overwrite each other. I've set up ten alarm conditions. Is that enough ie 5 Buy and 5 Sell ?

"put on a text whether the conditions are met or not met on the chart? or is that too much work" - About five minutes worth. Where / how do you want it formatted to the chart? Under what conditions is it to be removed from the Chart.


It is a simple matter to construct the indicator to attach to any Period (Timframe) and use any base Period eg PERIOD_ M1 on PERIOD_D1 , so no need to flick back to M1, just use your preferred TF to view.
 

TopFroxx

Well-Known Member
rod178 said:
The code is currently integated with some library functions. I'll have to remove the library calls and make the indicator 'stand alone' before I can give yo a copy. I'll try and get around to it over the weekend.

Not a good idea to attach it two times as the object names would overwrite each other. I've set up ten alarm conditions. Is that enough ie 5 Buy and 5 Sell ?

"put on a text whether the conditions are met or not met on the chart? or is that too much work" - About five minutes worth. Where / how do you want it formatted to the chart? Under what conditions is it to be removed from the Chart.


It is a simple matter to construct the indicator to attach to any Period (Timframe) and use any base Period eg PERIOD_ M1 on PERIOD_D1 , so no need to flick back to M1, just use your preferred TF to view.
i just realized another thing...

"Where / how do you want it formatted to the chart?"

i would only need two sets of conditions really. just below the table there could then be 2 lines of text with: "condition 1 met" (or "not met") and "condition 2 met" (or "not met"). "condition 1" could also be called "long condition" and "condition 2" could be called "short condition". ok that was the easy part, i think the next one might be a bit tricky, but not sure.

"Under what conditions is it to be removed from the Chart."

ideally i would need another input parameter. which would be the "tradetime". this would be the time that the signal would be valid, after it got triggered the FIRST time. for example upon the closed of the latest m1 bar, the conditions for a long are met, the alarm triggers. the chart would then read "long condition met" for "tradetime" number of m1 bars (could also be minutes, if that's easier. as i said earlier, i would only use it on a m1 chart). for my current strategy i would set the "tradetime" parameter to 7200, which is 7200 m1 bars, which is roughly one week. is that possible?
alternatively i would just need the time stamp, for when the conditions were first met. i could then just add the tradetime by hand. but the time when the signal first triggers is really essential for me. could you make this time visible somehow?
 

rod178

Well-Known Member
TopFroxx said:
i just realized another thing...

"Where / how do you want it formatted to the chart?"

i would only need two sets of conditions really. just below the table there could then be 2 lines of text with: "condition 1 met" (or "not met") and "condition 2 met" (or "not met"). "condition 1" could also be called "long condition" and "condition 2" could be called "short condition". ok that was the easy part, i think the next one might be a bit tricky, but not sure.

"Under what conditions is it to be removed from the Chart."

ideally i would need another input parameter. which would be the "tradetime". this would be the time that the signal would be valid, after it got triggered the FIRST time. for example upon the closed of the latest m1 bar, the conditions for a long are met, the alarm triggers. the chart would then read "long condition met" for "tradetime" number of m1 bars (could also be minutes, if that's easier. as i said earlier, i would only use it on a m1 chart). for my current strategy i would set the "tradetime" parameter to 7200, which is 7200 m1 bars, which is roughly one week. is that possible?
alternatively i would just need the time stamp, for when the conditions were first met. i could then just add the tradetime by hand. but the time when the signal first triggers is really essential for me. could you make this time visible somehow?
1) Do you require that the TradeTime expiry remains current from previous, after you have restarted MT4?
2) No problem to make TimeStamp visible.
3) Need clarification - Do you want the Trigger on M1 last bar completed close OR current M1 price? I'll set up the defaults accordingly, although they can be user modified.
 

TopFroxx

Well-Known Member
rod178 said:
1) Do you require that the TradeTime expiry remains current from previous, after you have restarted MT4?
2) No problem to make TimeStamp visible.
3) Need clarification - Do you want the Trigger on M1 last bar completed close OR current M1 price? I'll set up the defaults accordingly, although they can be user modified.
1) yes, i would need that if it's possible. EDIT: actually i am not quite sure if i understood you correctly. the tradetime expiry basically needs to "count down", from when the conditions got first met. and it should not only count the time i have MT4 running.
2) awesome. need to know "how late i am to the party" :)
3) whatever is easier. on m1 it really doesnt make much of a difference. especially because i dont intend to scalp. if you want me to decide i'd say m1 last bar completed close.
 

rod178

Well-Known Member
TopFroxx said:
1) yes, i would need that if it's possible. EDIT: actually i am not quite sure if i understood you correctly. the tradetime expiry basically needs to "count down", from when the conditions got first met. and it should not only count the time i have MT4 running...
Yes, I understand. The issue is that when you restart MT4 the TimeStamps will be reinitialized, unless they are stored in a File or as Terminal Global Variables. Requires a little more coding although no big deal.

I'll use M1 bars to count, so as to skip weekends and other non trading days.
 

rod178

Well-Known Member
TopFroxx

Attached is a Beta (well maybe not even that- make it Alpha) with short expanation on the User defined parameters below. Play with it and I can make required changes about end of the week.


ShowBarsPips = true; //otherwise suppress
ShowAlarmSettings = false; // otherwise display TimeStamps
SetTimeStampsToZero = true; // clears TimeStamps on init (requires further testing)
CountBarsStart = 0; //Close Bar to commences testing conditions met (0 is current bar)
TimeFrame1 = PERIOD_M1; // Base Timeframe (can also use M5 etc etc)
UseTradeTimeExpiryBars = true; // otherwise use seconds
TradeTimeExpiryBars = 7200; // bars (eg M1) from when conditions met to expiry
TradeTimeExpirySeconds = 604800; //seconds from when conditions met to expiry(ie one week inc non trade days)
MaxLines =10; // lines display Bars Pips
MaxAlarms=9; // lines Display AND Check TimeStamps OR AlarmSettings
CountBars1 = 5; // BarsPips display 1-19
Alarm0 = "-400 -800 -1600"; //Alarms 0-9 NOTE format leading "-" or "+" and trailing space ("-"= trigger Above Bid, "+"=trigger Below
AlarmType0 = 0; // 0=Short 1=Long // arrow indicates 0 or 1 , colour indicates if triggered // Sound and popups still to be implemented


EDIT: CountBarsStart = 1 etc // small bug // will correct next release
 

Attachments


Top