Pre-Market Volatility

Posted By: royal

Pre-Market Volatility - 07/31/13 10:45

Hi all!
I am trying to implement this strategy for the FDax with Zorro
FDax Pre-Market System

(I'm afraid it is only in german :()

Here's my script so far:

Code:
function run()
{
	BarPeriod = 60;
	set(TICKS|LOGFILE);		

	int TakeProfit1 = 15;
	int TakeProfit2 = 20;
	int TakeProfit3 = 25;
	int StopLoss1 = 35;
	int StopLoss2 = 30;
	int StopLoss3 = 25;
			
		if (hour() >= 8 && hour() < 9){

			if (price() >= (priceOpen() + 15)){
				
				TakeProfit = TakeProfit1;
				Stop = StopLoss1;				
				enterShort();
			}

			if (price() <= (priceOpen() - 15)){
			
				TakeProfit = TakeProfit1;
				Stop = StopLoss1;
				enterLong();			

			if (price() >= (priceOpen() + 20)){
			
				TakeProfit = TakeProfit2;
				Stop = StopLoss2;				
				enterShort();
			}

			if (price() <= (priceOpen() - 20)){
			
				TakeProfit = TakeProfit2;
				Stop = StopLoss2;
				enterLong();
			}

			if (price() >= (priceOpen() + 25)){
			
				TakeProfit = TakeProfit3;
				Stop = StopLoss3;				
				enterShort();
			}

			if (price() <= (priceOpen() - 25)){
			
				TakeProfit = TakeProfit3;
				Stop = StopLoss3;
				enterLong();
			}
		}
	} 
}



When I look in the Logfile I see that all trades are entered a the same Price, so something must be wrong with my "if (price() >= (priceOpen() + x))" conditions :\
I think it's just a small error, but nevertheless I can't find it.
Hopefully someone can help me and thanks in advance for any advice laugh
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 10:56

I think you need to add * PIP .

if (price() >= (priceOpen() + 15 * PIP))
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 10:58

I have tried this already, with the same results frown
Posted By: Anonymous

Re: Pre-Market Volatility - 07/31/13 11:04

Sundance is right!

Also... are you sure that you want to compare the mean price of the bar (price()) and the open price? What happens if you use priceClose() instead of price()?
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 11:04

Than add some brackets?

if (price() >= (priceOpen() + (15 * PIP) ))
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 11:13

Oh. Also your stops and take profits need the * PIP .
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 11:17

When i remember right. When you set BarPeriod to 60. Zorro will only run your script every 60 minutes. Within those 60 minutes price can move large distances. So that it is no problem to move far away from your 25 pips. So when Zorro checks 60 minutes later there can be three if clauses fullfilled...

@acid: can you confirm this?
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 11:18

The Logfile shows Trades like this:
[GER30::L3400] Long 1@4440 Risk 37 at 08:00
[GER30::L3400] Stop 1@4405: -36.83 at 08:24
[GER30::L3400] Long 1@4440 Risk 32 at 08:00
[GER30::L3400] Stop 1@4410: -31.83 at 08:24
[GER30::L3400] Long 1@4440 Risk 27 at 08:00
[GER30::L3400] Stop 1@4415: -26.83 at 08:23

so the Stoploss works correctly, but all 3 trades are entered at 4440. They should be entered in 5 pips steps. So if open price at 8 o'clock is 4000 the first short should be entered at 4015, the second at 4020 and the third at 4025.
I hope this makes the entry a bit clearer.


Quote:
When i remember right. When you set BarPeriod to 60. Zorro will only run your script every 60 minutes.


I thougt with set(TICKS) this is not the behavior?
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 11:22

Okay found it:

The run function is called once per bar, and trade exit conditions are tested (at least) once per bar regardless of the TimeFrame setting. For this reason, using a different TimeFrame is not fully equivalent to setting Barperiod to the same time frame. Trading algorithms will behave slightly different, even when the resulting time frame (BarPeriod * TimeFrame) is the same.

PS: Haven't seen your SET(TICKS)
Posted By: Anonymous

Re: Pre-Market Volatility - 07/31/13 11:28

Originally Posted By: Sundance
When i remember right. When you set BarPeriod to 60. Zorro will only run your script every 60 minutes. Within those 60 minutes price can move large distances. So that it is no problem to move far away from your 25 pips. So when Zorro checks 60 minutes later there can be three if clauses fullfilled...

@acid: can you confirm this?


In general, yes. But, I haven't checked the strategy, maybe that is desirable? If not, then replacing multiple if's with one if with multiple "else if" clauses would fix it.
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 11:39

Thats right. the code would be much better readable when using "else if".

One thing: When the following if clause

'if (price() <= (priceOpen() - 20))'

is true and you are running your script every tick and price will stay or move more downwards then you will open a trade every tick!? Don't understand why it hasn't done so...
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 11:45

But "else if" would only open one trade and not three or?

Quote:
'if (price() <= (priceOpen() - 20))'

is true and you are running your script every tick and price will stay or move more downwards then you will open a trade every tick!? Don't understand why it hasn't done so...


It hasn't done so, because this condition is not working correctly I think wink
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 11:50

I think we need help from JCL. I don't know if it makes sence to set the BarPeriod to 60 and set the TICKS flag at the same time.

I would consider to use some kind of flag for every tradelevel you use. so when you already entered short at price -20pips than set the flag (ex. ShortLevel2) to true. So you only take it once.

What does the script when you delete the BarPeriod line or set it to one?
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 11:58

With BarPeriod 1 the trades are also entered at the same price frown

[GER30::L3400] Long 1@6976 Risk 37 at 08:55
[GER30::L3401] Long 1@6976 Risk 32 at 08:55
[GER30::L3402] Long 1@6976 Risk 27 at 08:55
Posted By: jcl

Re: Pre-Market Volatility - 07/31/13 12:08

The brackets are not needed because the +/- operators have higher priority than <= or >=.

For having only one open trade, check the NumOpenLong / NumOpenShort variable and enter a new trade only when it's at 0. Alternatively, for entering only one trade, use "else if" conditions to make sure that only one trade is entered per bar, and start with the more distant conditions first.

And the buy price is not up to you I'm afraid. No matter how much code you write, it's always the price of the asset at the moment when you buy laugh.
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 12:21

But up to 3 trades should be opened, not just one, so NumOpenX == 0 is not the right solution here.

I am trying to implement this behavior:

1. Check the open price at 8 o'clock
2. When the price moves 15 pips up, open one short trade
3. When the price moves 20 pips up, open the second short trade
4. When the price moves 25 pips up, open the third short trade
5. All trades should have a stoploss 50 pips from 8 o'clocks opening price and a takeprofit at the 8 o'clock open price.
The long scenario vice versa.
Manually this would be done by pending orders.
Posted By: jcl

Re: Pre-Market Volatility - 07/31/13 12:25

You need pending orders then.

Code:
var Price = priceClose();
TakeProfit = Price;
Stop = Price + 50*PIP;
enterShort(1,-15*PIP);
enterShort(1,-20*PIP);
enterShort(1,-25*PIP);


You need the TICKS flag here, as you're operating with very small entry/stop distances.
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 12:25

I think royal wan't to take one trade per entrylevel. So when price moves down 30 pips from 08:00 o'clock. There will be three open short-trades near the levels he has in his if clauses...
so using pending trades would be the easiest thing to do :-)
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 12:32

I see no problem using a TP at 8 o'clock level when the trade will be taken 15 or more pips above. What does concern me is the poor RR of up to 1:5 ...( SL 50pips and TP only ~9 pips away) ...
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 12:34

Question jcl: Is it okay to set the BarPeriod when setting the TICKS level?
Posted By: jcl

Re: Pre-Market Volatility - 07/31/13 12:40

Yes, I would set BarPeriod to 60 here, so 3 pending trades are entered every hour.
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 12:51

Okay. Thanks. But when he sets BarPeriod to 60 and the TICKS flag and won't use pending orders. Would Zorro open a trade every tick when one of the if clauses would be true?
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 12:54

Thanks for the code jcl laugh I will play around with it a bit and come back when more questions come up (and they'll probably will ;))
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 12:56

We are all learning royal. (except jcl) :-)
Posted By: jcl

Re: Pre-Market Volatility - 07/31/13 12:56

I only have the advantage to be no trader. As to answer the question if the TICKS flag would exeute the run function every tick: no, it only increases the accuracy of pending orders and stop/trail/profit exits.
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 13:03

Ah. Okay. I read the manual but wasn't sure about this.
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 13:46

Code:
function run()
{
	BarPeriod = 60;
	set(TICKS|LOGFILE);		
	var Price = priceClose();
	TakeProfit = Price;

	Stop = Price + 50*PIP;

		if (hour() >= 8 && hour() < 9){
			enterShort(1,-15*PIP);
			enterShort(1,-20*PIP);
			enterShort(1,-25*PIP);
			enterLong(1,-15*PIP);
			enterLong(1,-20*PIP);
			enterLong(1,-25*PIP);
		}
}



This is my code now, but the problem is the Stop for the Long Trades.
I tried it with this instead of the single Stop function:

Code:
if (TradeIsShort){
	Stop = Price + 50*PIP;
}
else if (TradeIsLong){
	Stop = Price - 50*PIP;
}



but this seems not to work frown
Posted By: Anonymous

Re: Pre-Market Volatility - 07/31/13 13:49

A common mistake. Remove "Price" from the equation. E.g. Stop = 50 * PIP; That's all that should be needed.
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 13:54

But I need the Price, as it is the open price and I want the Stop to be 50 Pips +/- from this price and not 50 pips from the price where the trade was entered.
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 13:59

Stop and TakeProfit are relativ to the current price as i know.

The manual says:

enterLong (int Lots, var Entry, var Stop, var TakeProfit, var Trail, var TrailSlope, var TrailLock, var TrailStep): TRADE*

so i don't understand your call of enterLong. Shouldn't it be
enterlong(1,Price,Stop) ?
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 14:04

Are you sure about your TakeProfit? I think you wan't the price at 8 o'clock. So it think TakeProfit = priceOpen(); !?
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 14:15

Quote:
Stop and TakeProfit are relativ to the current price as i know.


With the single Stop function it works.

I don't understand the enterLong function completly also, as it was copied from jcl enterShort function, but it seems to work:

(GER30::S) Short 1@8127 Entry limit
(GER30::S) Short 1@8132 Entry limit
(GER30::S) Short 1@8137 Entry limit
(GER30::L) Long 1@8097 Entry limit
(GER30::L) Long 1@8092 Entry limit
(GER30::L) Long 1@8087 Entry limit

Quote:
Are you sure about your TakeProfit? I think you wan't the price at 8 o'clock. So it think TakeProfit = priceOpen(); !?


This is also from jcl, so I think it should be correct.

Horrible trail and error progamming style from me wink
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 14:19

Oh. You are right about the enterLong function. Mmmh. When i look at the manual you won't get that information.
There seems to be another function overload that isn't listed in the manual!?
Posted By: Anonymous

Re: Pre-Market Volatility - 07/31/13 14:24

Originally Posted By: Sundance
Are you sure about your TakeProfit? I think you wan't the price at 8 o'clock. So it think TakeProfit = priceOpen(); !?


Same mistake. TakeProfit is profit target distance in price units. The trade is closed when the trade profit has reached this amount. So, you shall not add any price to it.

But things like this should work:

TakeProfit = (priceClose() - priceOpen()) + 50 * PIP;

or maybe some other combination of the signs, types of prices. Obviously I haven't followed (or understood) the strategy description completely, but the above should give some idea.

From what I understand you need to resolve the equation to give you TakeProfit from the current price, and if you need to have it against some other price (possibly from the past bars) then you need to find the difference between those two prices first and then add the wanted profit target. Something like that.

jcl must be laughing often, looking at us amateurs fighting the basics. wink
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 14:26

Bullshit. What a nonsense from my part. I won't post today anymore. My brain seems to have gone to sleep...
You are totally right about the TakeProfit and with building the price difference.
He want's TP to be 8 o'clock price so

TakeProfit = (priceClose() - priceOpen())

he doesn't need those additionally 50 pips. That 50pips were for the SL only...
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 14:36

TakeProfit
Profit target value or profit target distance in price units.
So it could also be the value.

Code:
TakeProfit = Price;


and
Code:
Stop = Price + 50*PIP;



were copied from jcl and are working, but I wonder why I can't use the Stop for the Long scenario parallel to the Short one.
Posted By: jcl

Re: Pre-Market Volatility - 07/31/13 14:39

You'll need a different stop for the long and the short trades:

Stop = Price + 50*PIP;
enterShort(1,-15*PIP);
enterShort(1,-20*PIP);
enterShort(1,-25*PIP);

Stop = Price - 50*PIP;
enterLong(1,-15*PIP);
enterLong(1,-20*PIP);
enterLong(1,-25*PIP);

Giving only the 50*PIP distance would not work here because it would then be the distance from the entry price, not from the 8 o'clock price.
Posted By: Anonymous

Re: Pre-Market Volatility - 07/31/13 14:41

Wow, so it can be either of those variants? Talk about confusing. I didn't even understand the manual completely.

I think I'll join Sundance. Signing off for today... grin
Posted By: royal

Re: Pre-Market Volatility - 07/31/13 14:44

Oh man! The solution is so easy when you read it grin Thanks jcl!
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 14:47

Welcome on board acid. Seems i'am not the only one who can't read the manual.
@jcl: So there are more overloaded functions than the manual reveiles!?
Posted By: jcl

Re: Pre-Market Volatility - 07/31/13 15:30

enterLong is not an overloaded function, it's a function with a variable number of arguments. The arguments not needed can be omitted - and, I almost don't dare to say, this is described in the manual.
Posted By: Sundance

Re: Pre-Market Volatility - 07/31/13 20:21

Don't dare.
...too late...

But i don't get it.
The manual has an example: enterLong(0,Price,0,Grid)

So you have the lots, the entry price,the stop and the take profit as parameters.
How can we now call enterLong(1,-15*PIP) ??
What does that mean? When enterLong is not an overloaded function then -15*PIP is the entry price?
So in the background Zorro 'knows' when you give it a price or give it a relative pip value?
So when you talk about price it can be the absolute price or pip-distance!?
Posted By: swingtraderkk

Re: Pre-Market Volatility - 08/01/13 08:42

@royal

Does the original strategy intend that pending long and short orders are hit within the hour, or does it intend that only long or only short orders are hit? If the latter then you need a function to cancel the pending opposite orders if one is hit. I think you will need a trade management function for that as it will have to be executed at each tick and cannot be done at the end of each hour.

I also think that you need a TimeWait = 1; so that the pending orders don't hang around forever and are only entered between 8 & 9.

Also what 8 o'clock do you want the strategy to run is it 8am CET,GMT,UTC?

@jcl

For clarification:

When you set Barperiod = 60 does that default to ending the bars at 00 minutes 00 seconds or does this need to be explicitly specified?

The manual states that:

Code:
hour (int offset): int
Closing UTC hour of the given bar, 0..23. hour(0) gives the current hour and can be used to apply different trade tactics in the New York, European, or Asia-Pacific session.



so hour(0) gives the current closing hour in UTC, so at a few milliseconds past 8am (when zorro runs after the close of the 7am - 8am bar) does this return 9 as the closing hour (end of the bar just started at 8am) or 8 as the closing hour of the bar just finished bar 0, that started at 7am but closed at 8?

Does hour() return the same as hour(0)?
Posted By: royal

Re: Pre-Market Volatility - 08/01/13 10:10

Quote:
Does the original strategy intend that pending long and short orders are hit within the hour, or does it intend that only long or only short orders are hit? If the latter then you need a function to cancel the pending opposite orders if one is hit. I think you will need a trade management function for that as it will have to be executed at each tick and cannot be done at the end of each hour.


Afaik only one direction should be traded, this is missing in the code. Also the entries and stoploss should not be fixed at 15,20,25 / 50 but pending on the 8-9 o'clock volatility of the last 22 trading days.

Quote:
I also think that you need a TimeWait = 1; so that the pending orders don't hang around forever and are only entered between 8 & 9.


The pending orders are cancelled after 9 o'clock, this is working as I see in the Logfile.

Quote:
Also what 8 o'clock do you want the strategy to run is it 8am CET,GMT,UTC?


It's 8 o'clock German time, so CET i think
Posted By: dusktrader

Re: Pre-Market Volatility - 08/01/13 10:19

8am-9am Frankfurt time would be UTC 06:00-07:00 I believe.
I use this site: http://www.timeanddate.com/worldclock/meeting.html
Posted By: jcl

Re: Pre-Market Volatility - 08/01/13 10:36

Prices such as entry, stop, etc. can be given either as a distance, or as an absolute price. Zorro knows what is meant. -> http://manual.zorro-trader.com/stop.htm

hour(0) is the same as hour(). It's the closing time of the current bar, and also the current time at the moment when the script is executed. The start time of the current bar would be hour(1).
Posted By: Sundance

Re: Pre-Market Volatility - 08/01/13 10:54

I found it in the manual. You are right. And i really looked at it bevore... :-(

-------------------------------
'Either an (absolute) price, or a (relative) distance to the trade opening price (TradePriceOpen) can be used for Stop, TakeProfit, Trail, and Entry.'
--------------------------------
Posted By: swingtraderkk

Re: Pre-Market Volatility - 08/01/13 11:56

Code:
hour(0) is the same as hour(). It's the closing time of the current bar, and also the current time at the moment when the script is executed. The start time of the current bar would be hour(1).



Sorry jcl the limited brain is still confused.

In this example, we want the script to execute at some microseconds past 06:00 UTC. The current time when the script executes is not the same as the current bar, my understanding is that the current bar is bar zero, i.e. the most recently fully completed bar.

In the rest of zorro, bar number 0 is the bar just closed i.e. 05:00:00 to 06:00:00, so is the closing time of bar 0 = 06:00:00 and hour(0)=6?

However, where I get confused is because the current time the script is running is now in a new bar not fully formed you could say bar -1, running from 06:00:00 to 07:00:00, in that case the closing time of the bar the script is running in is 07:00:00 and should hour()=7?

So for our current script example is the correct statement to allow for daylight saving:

Code:
if (lhour(CET,0) == 8 or 9)





Posted By: Sundance

Re: Pre-Market Volatility - 08/01/13 12:15

Bar Zero is not completed. You have an open price and a current price. The close price will be the same value as the current price. It is the bar you referred to as -1 bar. AFAIK ...
Posted By: swingtraderkk

Re: Pre-Market Volatility - 08/01/13 12:47

In this thread jcl indicates that price(0) is from the bar just closed.

This raises another question though, when writing a trade management function, that will be executed on ticks in a new bar forming, is there a difference between price() and price(0)?

This was easier to get my head around in metatrader where the scripts ran on each tick and the last completed bar was 1 and anything in the current bar was 0.

Zorro may function like metatrader in the functions that execute at a tick level, but normally the scripts execute immediately after a barperiod closes and I suppose theoretically before anything happens in the new barperiod that would need reference to.
Posted By: Sundance

Re: Pre-Market Volatility - 08/01/13 12:50

Ah. Okay. thats new to me. Thanks for the correction. I will read it...
Posted By: Sundance

Re: Pre-Market Volatility - 08/01/13 12:53

But when priceClose(0) is the close of the last closed bar what is priceOpen(0)? The open of the last closed bar and what is the open price of the current bar???

That really makes no sence to me.


This is what the manual shows me:

'priceClose() returns the close price of the current bar, i.e. the most recent price.'

When priceClose() = priceClose(0) then i don't think that priceClose(0) is the closing price of the last closed bar!

Posted By: swingtraderkk

Re: Pre-Market Volatility - 08/01/13 13:03

Sorry sundance,

I edited the previous post while you were replying.

priceOpen(0) is the opening price in this example of the bar from 5UTC to 6UTC i.e the price at 5am and priceClose(0) is the price at 6UTC.

See my edited post for questions on whether this changes when executing trade management functions at tick level in the newly forming bar - you would need priceClose() to give you the price of the last tick and priceOpen() to give the price from 6UTC and not 5UTC.
Posted By: Sundance

Re: Pre-Market Volatility - 08/01/13 13:13

Okay. I think JCL has to clarify that. I really thought it would be the same as in Metatrader. Cause it did make sence...
Posted By: swingtraderkk

Re: Pre-Market Volatility - 08/01/13 13:20

Condsidering we need a trade management function for the OCO (one cancels the other) aspects of the strategy:

enterLong (oco, var v0, var v1 ...): TRADE*

and we need to specify the entry,

enterLong(1,-15*PIP);


I assume the pending nature of the orders needs to be specified in the trade management function. i.e. we cannot use both syntaxes of the enterLong function.

I was hoping for a very simple trade management function running on each tick along the lines of

Code:
if (NumOpenLong >0) {exitShort();}



but if the trade management function also needs to handle the entering of the pending orders once only and not per tick then it gets more complex.

Is there another way of handling this?
Posted By: royal

Re: Pre-Market Volatility - 08/06/13 10:00

I tried to use JCL's MyTMF function to handle the OCO in the script, but I implemented it wrong somehow, as the results did not change. Maybe someone can help laugh

Code:
int CancelOtherTrades = 0;

int MyTMF()
{
  if(TradeIsPending and CancelOtherTrades == 1)
    return 1;
  if(TradeIsOpen) {
    CancelOtherTrades = 1;
    ThisTrade->manage = 0; // terminate the TMF
  }
  return 0;
}


function run()
{
	NumWFOCycles = 3; 
	Spread = 1;
	BarPeriod = 60;
	set(TICKS|LOGFILE);		
	var Price = priceClose();


		if (hour() >= 8 && hour() < 9 && MyTMF() == 0){
		
			Stop = Price + 51*PIP;
			TakeProfit = Price + 1;
			printf("Price = %.f",Price);
			enterShort(2,-15*PIP);
			enterShort(1,-20*PIP);
			enterShort(1,-25*PIP);
		
			Stop = Price - 50*PIP;
			TakeProfit = Price;
			enterLong(2,-14*PIP);
			enterLong(1,-19*PIP);
			enterLong(1,-24*PIP);
		}
}

Posted By: jcl

Re: Pre-Market Volatility - 08/06/13 11:54

Sundance: priceClose(0) is the close and priceOpen(0) is the open of the current bar.

royal: You need a TMF for OCO. Look here:

http://manual.zorro-trader.com/trade.htm

- there is explained what a TMF is and how to use it.

Posted By: Sundance

Re: Pre-Market Volatility - 08/06/13 12:02

I will think about that JCL. How can the current bar has a closed price?

when its 12:45 then the current H1 bar has an open price at (12:00), a current price (12:45) but no closed priced (13:00).

I will check the manual again...
Posted By: jcl

Re: Pre-Market Volatility - 08/06/13 12:26

A bar has always an open, hi, low, and close price. If you have 1-hour bars that start at every full hour, there is no 12:45 bar. There is only a 12:00 and a 13:00 bar. Otherwise you had no bars, but just a continuous price curve.

By convention, the time associated to a bar is its close time. This is the time when the "run" function is executed. Thus, a 12:00 bar is not the bar that begins at 12:00, it's the bar that closes at 12:00.
Posted By: Sundance

Re: Pre-Market Volatility - 08/06/13 13:08

Surely i know that there is no H1 bar at 12:45 :-)
I said 'when its 12:45'... Just as an example time between 12:00 and 13:00 o'clock.

That is then the difference between Zorro and MT4 i wasn't 100% sure of.
Posted By: DdlV

Re: Pre-Market Volatility - 08/06/13 14:24

Hi Sundance,

My understanding is that intra-bar, (f.i., a TMF being called at every tick) the close price is the current price, and H & L are bar-to-date.

Also, if you use BarOffset there can certainly be a H1 bar at 12:45... laugh
Posted By: swingtraderkk

Re: Pre-Market Volatility - 08/06/13 14:49

DdlV,

Intrabar when a tmf is running on a tick by tick basis, can we use 0 as a reference to the currently forming bar for all purposes?

and the last fully closed bar is now referenced as bar 1 even though it would have been bar 0 when the script last ran?
Posted By: jcl

Re: Pre-Market Volatility - 08/06/13 14:53

Yes, inside a TMF the current bar is incomplete, and priceClose() is just the current price. As soon as the bar is complete, the run function is executed and then the next bar begins. So the run function can never run at 12:45 in the example, but a TMF could.
Posted By: swingtraderkk

Re: Pre-Market Volatility - 08/06/13 17:20

jcl,

Code:
Trade management functions run at every tick, which implies some restrictions. Indicators that create data series can not be called in a TMF; other indicators can be called. The current candle is incomplete, so its range and height is smaller than the other candles; and the last full candle has the index 1, not 0. The price functions can be called, but make no much sense for the current bar because the open, high, or low prices are in relation to the bar boundary. Use TradePriceOpen or TradePriceClose for evaluating the current price of the asset.



I really thought I'd read this part of the manual before!!!
Posted By: Sundance

Re: Pre-Market Volatility - 08/06/13 18:55

Ah. that is what i meant. The close price of bar 0 is then the actual price. Okay. Getting closer.
Its not really that easy to understand jcl. Thanks for your patience.
Posted By: Anonymous

Re: Pre-Market Volatility - 08/06/13 19:01

Originally Posted By: Sundance
Its not really that easy to understand jcl. Thanks for your patience.


Yeah, a sizable amount of little details one has to remember, no other way. I've read the whole manual (whole =~ 80%) at least two times, and I'll have to do it again, probably as soon as 1.14 is released.
Posted By: DdlV

Re: Pre-Market Volatility - 08/06/13 19:03

swingtraderkk, jcl's post answered your questions, right?
Posted By: swingtraderkk

Re: Pre-Market Volatility - 08/06/13 19:48

yes I'm clear thanks to all on the bar numbers - at last!

I was confused thinking how to use indicators etc. in a trade management function, but you are limited to what you can access.

I very strongly suggest that anyone (re)reads the trade management chapter in the manual.
© 2024 lite-C Forums