Rank: Advanced Member
Groups: Registered, Registered Users Joined: 2/19/2012(UTC) Posts: 106
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
Hello, I use Metastock 11 Professional edition. I am trying to code a buy and sell order for the system tester—long position only. The buy order should buy the security when the 20 period exponential moving average crosses above the 40 period exponential moving average in a security whose present closing price is greater than 800. Cross(Mov(C,20,E),Mov(C,40,E)) AND C>800 The sell order should sell when the price arises 8 units from the price when it was bought. Something like Create this binary indicator sellx Z1:= Cross(Mov(C,20,E),Mov(C,40,E)) AND C>800; Z2:= (ValueWhen(1,Z1,C) + 8)>=C+8; Z2; then the sell order should read If(sellx=1,(ValueWhen(1,Z1,C)+8),C) Could you check whether the coding is correct as—the ValueWhen function only returns the closing value for the first instance of the MA crossover while the system tester looks historically backward for say 4years. I am aware my code is a bit amateurish But if the coding is not correct—what should it be? Awaiting your reply, Regards, Sourav
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,953
Thanks: 90 times Was thanked: 155 time(s) in 150 post(s)
|
Originally Posted by: gorachand ![Go to Quoted Post Go to Quoted Post](/Themes/yafvision/icon_latest_reply.gif) Hello, I use Metastock 11 Professional edition. I am trying to code a buy and sell order for the system tester—long position only. The buy order should buy the security when the 20 period exponential moving average crosses above the 40 period exponential moving average in a security whose present closing price is greater than 800. Cross(Mov(C,20,E),Mov(C,40,E)) AND C>800 The sell order should sell when the price arises 8 units from the price when it was bought. Something like Create this binary indicator sellx Z1:= Cross(Mov(C,20,E),Mov(C,40,E)) AND C>800; Z2:= (ValueWhen(1,Z1,C) + 8)>=C+8; Z2; then the sell order should read If(sellx=1,(ValueWhen(1,Z1,C)+8),C) Could you check whether the coding is correct as—the ValueWhen function only returns the closing value for the first instance of the MA crossover while the system tester looks historically backward for say 4years. I am aware my code is a bit amateurish But if the coding is not correct—what should it be? Awaiting your reply, Regards, Sourav
Hello, Have you considered using the Profit Stop within the Stops tab? You could enable the Longs option under the Profit Stop, set the Method to Points and the Profit Target to 8.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 2/19/2012(UTC) Posts: 106
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
Have you considered using the Profit Stop within the Stops tab? You could enable the Longs option under the Profit Stop, set the Method to Points and the Profit Target to 8.
When the system tester profit stop is set to 8 as described by you-- what happens in a trade where profits do not rise to 8 units? What is the sell exit signal then?
If I am to put an additional sell order along with the 8 unit profit stop-- which sell signal will be executed first?
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,953
Thanks: 90 times Was thanked: 155 time(s) in 150 post(s)
|
Originally Posted by: gorachand ![Go to Quoted Post Go to Quoted Post](/Themes/yafvision/icon_latest_reply.gif) Have you considered using the Profit Stop within the Stops tab? You could enable the Longs option under the Profit Stop, set the Method to Points and the Profit Target to 8.
When the system tester profit stop is set to 8 as described by you-- what happens in a trade where profits do not rise to 8 units? What is the sell exit signal then?
If I am to put an additional sell order along with the 8 unit profit stop-- which sell signal will be executed first?
Hello again, You may find this excerpt from our MetaStock Help File Useful, from the "Entering Stops" topic: Home > The Power Console > System Tester > Creating a System Test > Stops > Entering Stops
In addition to trading rules, each trading system can have up to five "stops." Stops are set by selecting the Stops tab in the System Editor dialog. Stops are used to close long and/or short positions based on the position's gains/losses. For example, the Maximum Loss stop will close a position if the position loses more than a specified amount. When a stop is triggered, the position is closed regardless of the current status of your trading rules. The price at which the position is closed is the actual stop price or the specified exit price. If the price gaps below a stop level on a long position, MetaStock exits at the open price of the next bar. If no open price is available, the high price of the next bar is used. Likewise, if the price gaps above a stop level on a short position, MetaStock exits at the open price of the next bar. If no open price is available, the low price of the next bar is used. Stops automatically take entry and exit commissions into account. For example, the Maximum Loss stop knows the amount of your "exit" commission and will attempt to close the position so the maximum loss will not be exceeded after you pay the exit commission. If two stops are triggered on the same bar, the more conservative stop takes precedence (i.e., the stop that generates the most losses). The precedence of stops is; Maximum Loss, Breakeven, Trailing, Profit Target, and Inactivity Minimum Change.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 2/19/2012(UTC) Posts: 106
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
It is written in the manual
--"When a stop is triggered, the position is closed regardless of the current status of your trading rules"
1) In a longs only trade what is the relation between the exit sell order and the stops? If the exit rule is trigerred before or after say a maximum profit is reached-- what happens?
2) Supposing no exit rule is written in a longs only step but the maximum profit is set to say eight points-- what happens?
3)In a longs only trade supposing I want to set the maximum loss to three points-- do I tick longs or shorts?
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,953
Thanks: 90 times Was thanked: 155 time(s) in 150 post(s)
|
Originally Posted by: gorachand ![Go to Quoted Post Go to Quoted Post](/Themes/yafvision/icon_latest_reply.gif) It is written in the manual
--"When a stop is triggered, the position is closed regardless of the current status of your trading rules"
1) In a longs only trade what is the relation between the exit sell order and the stops? If the exit rule is trigerred before or after say a maximum profit is reached-- what happens?
2) Supposing no exit rule is written in a longs only step but the maximum profit is set to say eight points-- what happens?
3)In a longs only trade supposing I want to set the maximum loss to three points-- do I tick longs or shorts?
1. Both the Sell Order tab and a Stop can exit your long position. If the Sell Order triggers first, then you would exit the position based on the Sell Order and the Stop would not be relevant to that particular trade. If the Stop triggers first, then you would exit the trade based on the Stop, and the Sell Order would not be relevant to that particular trade. 2. If you do not have a Sell Order and are in a Long position, then the only way to exit the trade would be if a Stop condition occurs. If a Stop condition is not met, then you would remain in the long position. 3. For the Maximum Loss Stop to trigger for a Longs-only trade, you would need to checkmark the Longs checkbox for that Stop.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 2/19/2012(UTC) Posts: 106
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
You wrote
If a Stop condition is not met, then you would remain in the long position.
Does this mean that the position remains long till the next trade comes along or long until the stop profit condition is met?
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,953
Thanks: 90 times Was thanked: 155 time(s) in 150 post(s)
|
Originally Posted by: gorachand ![Go to Quoted Post Go to Quoted Post](/Themes/yafvision/icon_latest_reply.gif) You wrote
If a Stop condition is not met, then you would remain in the long position.
Does this mean that the position remains long till the next trade comes along or long until the stop profit condition is met?
Hello again, Generally speaking the position would remain in the trade until the stop condition is met. More specifically, the "Close all positions on the last bar" option (Trade Options > Trade Execution tab) exits all positions at the end of the system test date range. If you are not limiting positions (System Editor > General Tab > Position Limit checkbox) to 1, then you can get into additional trades as new long signals are generated. When reviewing the Orders Tab in the System Test Details view, you can see that trades were cancelled due to this Position Limit. Edited by user Thursday, May 16, 2024 2:44:34 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 2/19/2012(UTC) Posts: 106
Thanks: 1 times Was thanked: 1 time(s) in 1 post(s)
|
exits all positions at the end of the system test date range.
Please clarify
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,953
Thanks: 90 times Was thanked: 155 time(s) in 150 post(s)
|
Originally Posted by: gorachand ![Go to Quoted Post Go to Quoted Post](/Themes/yafvision/icon_latest_reply.gif) exits all positions at the end of the system test date range.
Please clarify
Hello again, The System Test is designed to give you profit / loss data over a range of dates. If by the end of the system test you are still in a position, the System Tester will exit that position regardless of whether you had an exit signal or stop (if the Close all positions option is checked). You can of course uncheck this option, but then you will not have a complete profit/loss picture by the end of the simulation. Edited by user Friday, May 17, 2024 2:43:41 PM(UTC)
| Reason: Not specified
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.