Hi
I think marketposition have one problem
Example
bar1 --in the chart we get buy in close this bar or we buy in close =>marketposition=0 in this bar1
bar2 --in the chart we have long=> marketposition=1 in this bar2 --Ok
bar3--in the chart we get sell in close in this ba or we sell in closer=> marketposition=0 in this bar
Why this bar1 when this close don´t have marketposition 1---
when in the bar3 have one execution of order sell when this close marketposition change to 0=> marketposition=0 in bar3
Thanks
Jo
marketposition
- Marina Pashkova
- Posts: 2758
- Joined: 27 Jul 2007
Hi Jo,
There is no error. This is the way the script should work.
1. When the order is generated on bar1, market position cannot be calculated yet (market position can only be calculated after the order has been generated. And if the order is generated on close there is no way it can be taken into account for market position on the same bar)
2. Market position will be known on bar2 and will equal 1.
3. The same thing will happen for bar3: sell on close will be executed, but market position won't be recalculated and will still equal 1.
4. Market position will be recalculated on bar4 and will equal 0.
Below is the code and the printed values:
print("B", currentbar, " ", marketposition);
if currentbar = 1 then
Buy 100 contract this bar at close;
if currentbar = 3 then
sell 100 contract this bar at close;
print("A", currentbar, " ", marketposition);
{
B 1.00 0.00
A 1.00 0.00
B 2.00 1.00
A 2.00 1.00
B 3.00 1.00
A 3.00 1.00
B 4.00 0.00
A 4.00 0.00
}
If you have any further questions please let us know.
There is no error. This is the way the script should work.
1. When the order is generated on bar1, market position cannot be calculated yet (market position can only be calculated after the order has been generated. And if the order is generated on close there is no way it can be taken into account for market position on the same bar)
2. Market position will be known on bar2 and will equal 1.
3. The same thing will happen for bar3: sell on close will be executed, but market position won't be recalculated and will still equal 1.
4. Market position will be recalculated on bar4 and will equal 0.
Below is the code and the printed values:
print("B", currentbar, " ", marketposition);
if currentbar = 1 then
Buy 100 contract this bar at close;
if currentbar = 3 then
sell 100 contract this bar at close;
print("A", currentbar, " ", marketposition);
{
B 1.00 0.00
A 1.00 0.00
B 2.00 1.00
A 2.00 1.00
B 3.00 1.00
A 3.00 1.00
B 4.00 0.00
A 4.00 0.00
}
If you have any further questions please let us know.
-
- Posts: 117
- Joined: 08 Nov 2005
- Been thanked: 3 times
thanks for answer this is allright about marketpositionHi Jo,
There is no error. This is the way the script should work.
1. When the order is generated on bar1, market position cannot be calculated yet (market position can only be calculated after the order has been generated. And if the order is generated on close there is no way it can be taken into account for market position on the same bar)
2. Market position will be known on bar2 and will equal 1.
3. The same thing will happen for bar3: sell on close will be executed, but market position won't be recalculated and will still equal 1.
4. Market position will be recalculated on bar4 and will equal 0.
Below is the code and the printed values:
print("B", currentbar, " ", marketposition);
if currentbar = 1 then
Buy 100 contract this bar at close;
if currentbar = 3 then
sell 100 contract this bar at close;
print("A", currentbar, " ", marketposition);
{
B 1.00 0.00
A 1.00 0.00
B 2.00 1.00
A 2.00 1.00
B 3.00 1.00
A 3.00 1.00
B 4.00 0.00
A 4.00 0.00
}
If you have any further questions please let us know.
I test this programs
print(time, currentbar, " ", marketposition);
if currentbar = 1 then
Buy 100 contract this bar at close ;
if currentbar=4 then
sell 100 contract this bar at close ;
and this
print(time, currentbar, " ", marketposition);
if currentbar = 1 then
Buy 100 contract this bar at open ;(PL accept this line) why???? and try with limit orders with (this bar and next bar)
if currentbar=4 then
sell 100 contract this bar at close;
my confuse is from (buy line and arrows in the chart) ,-one is in close and other is open (the arrows move more one bar or move back one bar in the charts (you see in your charts) When a say buy in this bar on open the arrows move to next bar you see
thanks
jo
- Marina Pashkova
- Posts: 2758
- Joined: 27 Jul 2007
Hi Jo,
The script is calculated at the bar's close. That is why it can't generate a signal under conditions which aren't there anymore and will never be there. That is why a signal at open should not be generated. In TS such a code won't compile. In MC, this code compiles but is automatically transferred to the nex bar. But in fact, this code shouldn't compile at all. The fact that MC compiles it is a bug and will be corrected in future MC versions.
The script is calculated at the bar's close. That is why it can't generate a signal under conditions which aren't there anymore and will never be there. That is why a signal at open should not be generated. In TS such a code won't compile. In MC, this code compiles but is automatically transferred to the nex bar. But in fact, this code shouldn't compile at all. The fact that MC compiles it is a bug and will be corrected in future MC versions.