I am unable to create a signal that starts off the day with 2 contracts long or short (depending on the indicator value) and then stays constantly in the market by selling or buying 4 contracts to reverse the initial and previous positions.
I tried BuyToCover and SellShort to no avail.
Do I need to place 2 orders to reverse an existing position....i.e. BuyToCover 2 Contracts and then enter another order to Buy 2 more contracts ?
The Marketposition variable doesn't seem to understand Stop-and-reverse logic....i.e. Short 2 contracts, then reverse with 4 long contracts for a net of 2 contracts long.
What am I missing ?
Constantly in the market buy/sell logic
- Smoky
- Posts: 518
- Joined: 03 Dec 2010
- Location: Thailand
- Has thanked: 99 times
- Been thanked: 121 times
Re: Constantly in the market buy/sell logic
@syswizard
To reverse a position only need to buy or sell 1 contract on opposite side. MC close all open positions to be in the new opposite side.
use only buy and sell instructions
sorry
@TJ if you are SHORT 1, BUY 2 will get you two net long positions. FALSE !
the first contract close the short position, the second contract make you long 1 contract. use only buy and sell instruction, it's s better than short and buytocover and make a better undestanding for the same reverse, MC manage this for You
edit to answer to TJ
you are long 4 contrats, you want to be short 2, then sell 6 : 4 to close your buy position and 2 to be short 2 contract.
To reverse a position only need to buy or sell 1 contract on opposite side. MC close all open positions to be in the new opposite side.
use only buy and sell instructions
sorry
@TJ if you are SHORT 1, BUY 2 will get you two net long positions. FALSE !
the first contract close the short position, the second contract make you long 1 contract. use only buy and sell instruction, it's s better than short and buytocover and make a better undestanding for the same reverse, MC manage this for You
edit to answer to TJ
you are long 4 contrats, you want to be short 2, then sell 6 : 4 to close your buy position and 2 to be short 2 contract.
Re: Constantly in the market buy/sell logic
Thanks Guys.....but the MarketPosition system variable is not working correctly in this context.
I start the day buying 2 contracts, and then I just buy and sell 4 contracts the rest of the day.....a no-brainer.
However, in my signal......After I buy the 2 contracts and sell 4 contracts, and then buy 4 contracts to reverse that position...the marketposition variable is Zero. THIS IS WRONG....The marketposition should be 1 and the OpenEntryContracts should be 2, but it is zero in my trace.
I'm going to try the "ChangeMarketPosition" keyword to see if it resolves this problem.
I figured it out: Two Buys and Two Sells are required to reverse positions correctly: vMP is MarketPosition
Else if vMP < 0 then
Begin
BuyToCover("Long-PVO") vContracts Contracts This Bar At Close;
Buy("Long-PVO-R") vContracts Contracts This Bar At Close;
vNumTrades = vNumTrades + 1;
End;
Else if vMP > 0 then
Begin
SellShort("short-PVO") vContracts Contracts This Bar At Close;
Sell("short-PVO-R") vContracts Contracts This Bar At Close;
vNumTrades = vNumTrades + 1;
End ;
No wonder they developed the ChangeMarketPosition function !!!!
I start the day buying 2 contracts, and then I just buy and sell 4 contracts the rest of the day.....a no-brainer.
However, in my signal......After I buy the 2 contracts and sell 4 contracts, and then buy 4 contracts to reverse that position...the marketposition variable is Zero. THIS IS WRONG....The marketposition should be 1 and the OpenEntryContracts should be 2, but it is zero in my trace.
I'm going to try the "ChangeMarketPosition" keyword to see if it resolves this problem.
I figured it out: Two Buys and Two Sells are required to reverse positions correctly: vMP is MarketPosition
Else if vMP < 0 then
Begin
BuyToCover("Long-PVO") vContracts Contracts This Bar At Close;
Buy("Long-PVO-R") vContracts Contracts This Bar At Close;
vNumTrades = vNumTrades + 1;
End;
Else if vMP > 0 then
Begin
SellShort("short-PVO") vContracts Contracts This Bar At Close;
Sell("short-PVO-R") vContracts Contracts This Bar At Close;
vNumTrades = vNumTrades + 1;
End ;
No wonder they developed the ChangeMarketPosition function !!!!
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Constantly in the market buy/sell logic
None of my examples have long 4 contrats.. . .
edit to answer to TJ
you are long 4 contrats, you want to be short 2, then sell 6 : 4 to close your buy position and 2 to be short 2 contract.
- Smoky
- Posts: 518
- Joined: 03 Dec 2010
- Location: Thailand
- Has thanked: 99 times
- Been thanked: 121 times
Re: Constantly in the market buy/sell logic
@syswizard
If i take time to answer You it should be nice to read my answers carefuly and listen them.
I used reverse since 9 years now, and MC work perfectly, if something wrong it's your own code (mine work very well) but not MC in this case.
one more time:
1) change your code with buy and sell orders
2) forget to try to make reverse yourself MC will do better than You (only one line of code)
3) forget words buytocover,sellshort, reverse
Logic:
if you are long 5, sell 5 you will be flat, sell more you will be short !
if you are short 5, buy 5 you will be flat, buy more and you will be long !
only speak about position, flat, long, short
If i take time to answer You it should be nice to read my answers carefuly and listen them.
I used reverse since 9 years now, and MC work perfectly, if something wrong it's your own code (mine work very well) but not MC in this case.
one more time:
1) change your code with buy and sell orders
2) forget to try to make reverse yourself MC will do better than You (only one line of code)
3) forget words buytocover,sellshort, reverse
Logic:
if you are long 5, sell 5 you will be flat, sell more you will be short !
if you are short 5, buy 5 you will be flat, buy more and you will be long !
only speak about position, flat, long, short
Last edited by Smoky on 21 Jul 2019, edited 1 time in total.
Re: Constantly in the market buy/sell logic
Sorry Smoky - it wouldn't work for me...I'd open with 2 long, then go 4 short and then 4 long.....and the marketposition was then zero !!! WRONG !!!
Should have been 2 long. Why did they create ChangeMarketPosition ? I would say for this very reason.
Should have been 2 long. Why did they create ChangeMarketPosition ? I would say for this very reason.
Re: Constantly in the market buy/sell logic
It works fine when trading manually via Trade Panel.Good luck Anna !
I do my best LOL
Note: there was nothing wrong with my code.....it starts with 2 contracts at start of day and then trades 4 contracts till the end of the day....
2 long, 4 short, 4 long, 4 short, etc.
As I had mentioned, MarketPosition was completely wrong....indicating zero when it should have been 1 or -1.
Re: Constantly in the market buy/sell logic
syswizard,
Either we're not understanding your issue, or you've gotten very confused about something.
If it's the former:
Can you please add more info; screenshots highlighting what you're saying for example.
I don't follow why simply coding:
Doesn't work for you.
Either we're not understanding your issue, or you've gotten very confused about something.
If it's the former:
Can you please add more info; screenshots highlighting what you're saying for example.
I don't follow why simply coding:
Code: Select all
if marketposition>0 then sellshort 2 shares next bar at market;
if marketposition<0 then buy 2 shares next bar at market;
Re: Constantly in the market buy/sell logic
Sorry, but I discovered BUY and BUYTOCOVER act differently as does SELLSHORT vs. SELL.
Remember: gotta start the day with 2 contracts BUY or SELL.....then BUY or SELL the rest of the day 4 contracts into the close.
At close, BUY or SELL 2 contracts to close-out the position.
You are missing the whole point.....initially get long or short 2 contracts and then REVERSE the position to short 2 contracts or 2 long contracts which requires a BUY/SELL of 4 contracts.
Remember: gotta start the day with 2 contracts BUY or SELL.....then BUY or SELL the rest of the day 4 contracts into the close.
At close, BUY or SELL 2 contracts to close-out the position.
You are missing the whole point.....initially get long or short 2 contracts and then REVERSE the position to short 2 contracts or 2 long contracts which requires a BUY/SELL of 4 contracts.
Re: Constantly in the market buy/sell logic
not following you. it does sound like you’re struggling with the basics perhaps. Like you say, maybe we’ve all just missed the point. There’s certainly minimal info you’ve shared and maximum confusion as a result.
Market position only updates on barstatus=2 events. I don’t know if that helps you. Like i said, lack of detail in your query.
You can lean on MCs backtest engine by using named entries and “from entry” keywords to effect multiple same bar entries and exits. IOG and Bar magnifier may also help you. Again; no idea if that helps you, due to lack of info.
Market position only updates on barstatus=2 events. I don’t know if that helps you. Like i said, lack of detail in your query.
You can lean on MCs backtest engine by using named entries and “from entry” keywords to effect multiple same bar entries and exits. IOG and Bar magnifier may also help you. Again; no idea if that helps you, due to lack of info.