Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
MC will cancel the order if the limit price was not reach before the end of the bar. I need to set a flag at the begining of the next bar to confirm that the order as been execute. How can i do it?
Martin
Can you help answer these questions from other members on NexusFi?
The simplest way would be to look at MarketPosition and see if it is right (0 flat, 1 long, -1 short). There is also EntryPrice(0) to see the last execution entry price, it may be helpful to you.
But if you are scaling in or out then this may not be sufficient for you. So you could look at BarsSinceEntry as well as CurrentContracts, and figure out where you stand.
All of this is in the help under 'Strategy Positions'.
[ SellShort ("Short1b") ShortSizeOfOrder contracts next bar at ShortEntryPrice Limit;
MC will cancel the order if the limit price was not reach before the end of the bar. I need to set a flag at the begining of the next bar to confirm that the order as been execute. How can i do it?
Martin
This might help. The following code will tell you if a new position was entered.
Variables:
MP(0);
MP = MarketPosition;
If ( MP <> 0 ) And ( MP[1] = 0 ) Then
Begin
// A new position was just entered
End;
My programmed strategy look to enter on all valid signals, even in the same direction. Each trade is manage independently. Up to ten trades per direction. So marketposition is not reliable if trade as occured or not.
I will look for arround Big Mike solution with BarsSinceEntry as well as CurrentContracts.
This verification to be done for bar status = 1 (beginning of a bar) for the first bar following the entry bar.
My programmed strategy look to enter on all valid signals, even in the same direction. Each trade is manage independently. Up to ten trades per direction. So marketposition is not reliable if trade as occured or not.
I will look for arround Big Mike solution with BarsSinceEntry as well as CurrentContracts.
This verification to be done for bar status = 1 (beginning of a bar) for the first bar following the entry bar.
Martin
This might help.
With multiple trades you can manage them independently by using the function "CurrentEntries". Create a variable to hold this value and manage each trade by how many current entries there are.
CE = CurrentEntries;
If ( MP = 1 ) Then
Begin
If ( CE = 1 ) Then {manage one entry}
If ( CE = 2 ) Then {Manage two entries }
If ( CE = 3 ) Then {Manage three entries }
End
Else If ( MP = -1 ) Then
Begin
If ( CE = 1 ) Then {manage one entry}
If ( CE = 2 ) Then {Manage two entries }
If ( CE = 3 ) Then {Manage three entries }
End
With multiple trades you can manage them independently by using the function "CurrentEntries". Create a variable to hold this value and manage each trade by how many current entries there are.
CE = CurrentEntries;
If ( MP = 1 ) Then
Begin
If ( CE = 1 ) Then {manage one entry}
If ( CE = 2 ) Then {Manage two entries }
If ( CE = 3 ) Then {Manage three entries }
End
Else If ( MP = -1 ) Then
Begin
If ( CE = 1 ) Then {manage one entry}
If ( CE = 2 ) Then {Manage two entries }
If ( CE = 3 ) Then {Manage three entries }
End
Thank Jeff
As mention is EL reference, This solution is only applicable in the development and evaluation stage. It could not be applied in live trading
[LEFT]CurrentEntries (Reserved Word) Disclaimer Returns the number of entries currently open within a position. Remarks This function can only be used in the evaluation of strategies. Example[/LEFT] CurrentEntries returns a value of 3 if the strategy has made 3 entries in the current open position.
As mention is EL reference, This solution is only applicable in the development and evaluation stage. It could not be applied in live trading
[LEFT]CurrentEntries (Reserved Word)
Disclaimer
Returns the number of entries currently open within a position.
Remarks
This function can only be used in the evaluation of strategies.
Example[/LEFT]
CurrentEntries returns a value of 3 if the strategy has made 3 entries in the current open position.
Martin
Matrin,
In this case I think you have to label each new entry with an entry label (buy "LE1", buy "LE2", buy "LE3 ...). You'll have to be clever and place these orders with their unique label based on the current shares or contracts you are currently holding. In the end you will have 10 such labels.
Then you can reference each entry as an individual trade with the "From Entry" command such as ...
Sell 1 contract from entry ("LE2") next bar at market ;
In this case the contract from the second buy order is sold at market.
I have not personally coded multi-entry and multi-exits strategies, so I'm not sure if this will work. If I get some time this weekend I can try to code it up and test it.
I have done single entry, multi-exit, but this is different. Hope this helps.
Some code has been developed for me using this approach. Each entry having a different name. Up to to entry's per sides. But the problem persist as the orders are done at market. I'm looking for a limit or stop orders.
With these conditionnals entrys, if price not reach, orders are cancelled. No problem as this is done by MC. Order are canceled automatically at the end of a period if not execute. My interrogation is about orders that where executed. I need a flag or a variable that will confirm it. A unique flag to a unique reason for this entry
A solution could be to compare how many contract in the account before sending the order and comparing at the end. This wont produce a solid system as there is no direct link from an order to the entry. If two programmed systems where issuing similar quantity order, but at a different price and only one was executed, it would be difficult to attribute a position to is system. As entry price could be different as the calculated one.
My conceptual solution could be to ( I dont know if it is possible with MC)
- Issue an order
- Capture the order number from broker
- Capture and read back after each period a trade journal where , executed orders are linked to a new position and a new position number related to it.
- From my database ( array) compare the executed order and attach it to the new position number.
Being able to do it, it will create a solid and accurate plateform. Where orders and positions are linked.
Easier said than done for me. I'm not a programmer and I'm new with MC. I was doing it manually before. A verry fastudious job.
Some code has been developed for me using this approach. Each entry having a different name. Up to to entry's per sides. But the problem persist as the orders are done at market. I'm looking for a limit or stop orders.
With these conditionnals entrys, if price not reach, orders are cancelled. No problem as this is done by MC. Order are canceled automatically at the end of a period if not execute. My interrogation is about orders that where executed. I need a flag or a variable that will confirm it. A unique flag to a unique reason for this entry
A solution could be to compare how many contract in the account before sending the order and comparing at the end. This wont produce a solid system as there is no direct link from an order to the entry. If two programmed systems where issuing similar quantity order, but at a different price and only one was executed, it would be difficult to attribute a position to is system. As entry price could be different as the calculated one.
My conceptual solution could be to ( I dont know if it is possible with MC)
- Issue an order
- Capture the order number from broker
- Capture and read back after each period a trade journal where , executed orders are linked to a new position and a new position number related to it.
- From my database ( array) compare the executed order and attach it to the new position number.
Being able to do it, it will create a solid and accurate plateform. Where orders and positions are linked.
Easier said than done for me. I'm not a programmer and I'm new with MC. I was doing it manually before. A verry fastudious job.
Quest continu.
Martin
My code example below was written before I read your most recent post. Anyway, it is an example of naming entry orders and using the "from entry" syntax to exit. All orders are done at market.
Place this system on the daily bar chart of S&P Emini and watch the money roll in! You can pay me my fee later. It buys 1 contract when the RSI falls below 10 and another contract when it falls below 5. It only takes trades when price is above the 200-period simple moving average. Two independent exits are triggered when price closes above a their respected moving average. Oh, be sure to set your pyramiding configuration on your chart to "2" or this strategy will not work.
As for your most recent post, I may be confused, but this is my understanding. You are entering on limit orders correct? You want to verify that each limit order was actually filled, correct? Is this what you mean when you say you want a "flag" to confirm an entry? If this is true and you know how many contracts you place at each entry point than you can use currentcontracts to interrogate how many of your limit orders have been filled. Am I understanding you correctly?
Input: Lookback(2), ExitBars(5);
Variables: Exit1(0), Exit2(0), MP(0), RSI_Value(0), MA200(0);
RSI_Value = RSI( Close,Lookback );
MA200 = Average( Close, 200 );
Exit1 = Average( Close, 10 );
Exit2 = Average( Close, 5 );
MP = MarketPosition;
// Enter first position when we first go below threshold 10 on rsi
If ( RSI_Value <= 10 ) And ( Close > MA200 ) And ( MP = 0 ) Then
buy ("LE1") 1 contract this bar at close;
// Enter second position if we go below threshold 5 on rsi
If ( RSI_Value <= 5 ) And ( Close > MA200 ) Then
buy ("LE2") 1 contract this bar at close;
// Exit contracts from LE2 when hit exit price
If ( MP = 1 ) And ( CurrentContracts = 2 ) And ( Close > Exit2 ) Then
Sell from entry ("LE2" ) this bar at close;
// Exit contracts from LE1 when hit exit price
If ( MP = 1 ) And ( CurrentContracts = 1 ) And ( Close > Exit1 )Then
Sell from entry ("LE1" ) this bar at close;